Input and CollisionProvided Files main.c myLib.c myLib.hFiles to Edit/Add main.c myLib.c myLib.h Makefile .vscode tasks.jsonInstructionsNote: Make sure to copy over your Makefile and .vscode/tasks.json from one of yourprevious assignments.TODO 1.0 void drawRect(int col, int row) Complete this function in myLib.c (right under the setPixel function).You should already know how to do this from your last lab, and itshould for a filled in rectangle. In main.c, find and uncomment UNCOMMENT #1. You should see ayellow rectangle in the bottom half of the screen.TODO 2.0 void fillScreen(unsigned short color) Head back to myLib.c, find fillScreen (right beneath drawRect) andcomplete it.CS 2261 Spring 2021 You may only use a single loop (one for-loop) to complete this one. Hint: the GBA screen has a total of 240 x 160 pixels which isequal to 38400. Enter main.c and uncomment UNCOMMENT #2. The background ofyour game should now be a beautiful shade of blue, and you should seetwo new rectangles. There should be one green land rectangle at thebottom of the screen, and one white cloud rectangle towards the topof the screen that moves horizontally. There should also still be theyellow rectangle in the center of the screen.TODO 3.0-3.2This one requires a lot of moving parts to work, so it is broken into three parts. TODO 3.0 Open myLib.h, find the button macros, and complete them. For BUTTON_PRESSED, assume that buttons and oldButtons have beenset up appropriately. TODO 3.1 Since buttons and oldButtons havent been set up correctly (yet!), headon back to main.c and initialize them in the initialize function. They have already been declared in main.c (and in myLib.h as externvariables), so you dont have to worry about that part this time, but youwill when you code things yourself for your homeworks. TODO 3.2 The buttons still wont do anything unless you update them each frame,so do that in the main while-loop. After you have completed these tasks, find UNCOMMENT #3 in theupdate function and do the thing. Run it, and now you can press button A to toggle the clouds betweenwhite and gray, as if they are switching between light, fluffy whiteclouds and gray clouds preparing for rainfall. Holding down the A button for a long time should have the same effectas just tapping it a single time. If that is not the case, you did one of thesethree TODOs incorrectly.TODO 4.0 Now that you can take button input, find TODO 4.0 in the update function andcomplete it so that the yellow rectangle can move up, down, left, and right ifCS 2261 Spring 2021you press the corresponding arrow key. This time, it should move for as long as the key is held, meaning that ifyou tap it once quickly, it will barely move, but if you press it for severalseconds, it will move a lot. If not, fix that. Compile and run, and you should be able to move the yellow rectangleanywhere on the screen.TODO 5.0-5.2This is the most exhaustive part of the lab, but also the most important. TODO 5.0 At the bottom of myLib.c, implement the collision function. It takes inthe positions and dimensions of two rectangles, and returns a 1 if theyare colliding, or a 0 if not. Hint: using graph paper, or drawing a grid yourself, is extremelyuseful. This function should work regardless of the size orvelocity of the rectangle (if one is moving). TODO 5.1 Now that you have the collision function implemented, use it in theupdate function. If the yellow rectangle collides with the moving cloudrectangle, reset the yellow rectangles position to where it was firstinitialized (refer to the initialize function to see the exact location).Also, make the cloud rectangle stop moving (the clouds horizontalvelocity variable is cCDel) if its moving. If the cloud is not moving, makeit start moving horizontally to the right side of the screen. TODO 5.2 Now use the collision function to account for if the yellow rectanglecollides with the land rectangle. Additionally, if lColor (the landscurrent color) is green, change it to black. If it is already black, changeit to green. Hint: you can refer to the logic that was used to make the cloudschange colors when you press A. Compile and run. Verify that it runs correctly, and then you are done. Hint: since there are two separate rectangles for which you need to detect acollision, youll need to use the collision function two separate times.CS 2261 Spring 2021You will know if it runs correctly if you can: Move the yellow rectangle using the arrow keys. Press A to change the cloud color from white to gray, and vice versa. Make the yellow rectangle collide with any of the other rectangles and betransported to its initial position. Collide with the land rectangle at the bottom, changing the color from black togreen, or vice versa. Collide with the moving cloud rectangle at the top, making the cloud stopmoving or start moving to the right side of the screen.Tips Start early, and attend recitation. Use graph paper and draw pictures to conceptualize what is happening. Follow each TODO in order, and only move forward if everything is correct
CS2261
[Solved] CS2261 LAB2-Input and Collision
$25
File Name: CS2261_LAB2-Input_and_Collision.zip
File Size: 292.02 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.