1 / 18

CRE Programming Club Class #9

CRE Programming Club Class #9. Robert Eckstein and Robert Heard. Let’s Look at some Homework. JGT020-6 (Andy Friedrich) BDJ016-0 (Ashley Hartenstein) BXX981 (Arnav Chopra). Video. https://www.youtube.com/watch?v=dU1xS07N-FA. Collision Detection.

brita
Download Presentation

CRE Programming Club Class #9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CRE Programming Club Class #9 • Robert Eckstein and Robert Heard

  2. Let’s Look at some Homework • JGT020-6 (Andy Friedrich) • BDJ016-0 (Ashley Hartenstein) • BXX981 (Arnav Chopra)

  3. Video • https://www.youtube.com/watch?v=dU1xS07N-FA

  4. Collision Detection • Two objects are said to “collide” if they come in contact with each other. • Collision detection is an essential aspect of nearly all video games. • Algorithms help to detect the collision. For the most part, you can just find someone else’s algorithm and copy it!

  5. Collision Detection • Import LLW706 • Have fun with this “game” for a little bit. • Enter an angle between 0 and 360 (0 is up, angles increase clockwise) and a distance in pixels. See if you can get the turtle to collide with the CRE Logo.

  6. Source Code Hunting • Look through the source code for LLW706. • See if you can find where the code that checks for the collision detection is… • Look for a place where the X and Y position of the turtle is compared to the right, left, top, and bottom position of the graphic.

  7. Line 52! • If Turtle.x > x and Turtle.x < x + 93 • and Turtle.y > y and Turtle.y < y + 96 Then • ‘ There is a collision between logo/turtle! • EndIf

  8. Bounding Boxes • When working with collision detection, it helps to think of shapes or graphics as being surrounded by a “shrinkwrapped rectangle.” This is called a bounding box. Here is a blue bounding box around an early Mario.

  9. Bounding Boxes • Bounding Boxes can also be very complex, and are used in more modern 3D games as well!

  10. Why Use a Bounding Box? • Because it’s quick and easy to compute when things run into each other…. just figure out if the rectangles are touching!

  11. Works With Circles Too • To figure out if something is colliding with a circle, just see if the distance between some point and the center of the circle is less than the radius. • Two circles? Just see if the distance between the centers is less than the two radius values added together. • You’ll need to be familiar with the Pythagoreon Therom.

  12. Are BBs Perfect? • No! But for simple games, it’s generally good enough. • Sub DoBoxesIntersect • box1Left = box1X • box1Top = box1Y • box1Bottom = box1Y + box1Height • box1Right = box1X + box1Width • box2Left = box2X • box2Top = box2Y • box2Bottom = box2Y + box2Height • box2Right = box2X + box2Width

  13. Here’s the Rest of It… • If (box1Bottom < box2Top) Or (box1Top > box2Bottom) Or (box1Left > box2Right) Or (box1Right < box2Left) Then • Shapes.HideShape(intersect) • Else • Shapes.ShowShape(intersect) • EndIf • EndSub

  14. Import QSP227 • Run this program. Use the arrow keys to move one of the rectangles around. • Note that when it collides with the other rectangle, a message appears at the bottom. • USE THIS ALGORITHM IN YOUR OWN PROGRAMS!

  15. Why Does This Work? • Talk To Your Teachers! See if you can figure out why that algorithm works. (HINT: Look at the intersecting rectangle made by the two squares on slide 12.) • It’s much more efficient than checking to see if any of the four corners of one rectangle are inside the boundaries of another rectangle.

  16. Homework • Continue working on your state machine. • This time, when in the PLAY_GAME state, don’t kick it into the third state unless there is a collision of some sort. Add multiple shapes. Be creative! Have fun! • Email me with questions…

  17. Next Time... • No class next week due to STAAR tests. • We’ll get back together the following week and really start cranking out some game code.

More Related