Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Would You Like To Make A Game?

Would You Like To Make A Game?

miamirb, 2/20/2017

Bryce "BonzoESC" Kerley

February 20, 2017
Tweet

More Decks by Bryce "BonzoESC" Kerley

Other Decks in Programming

Transcript

  1. Making a Game • Who should make games, and why

    • Basics of Gosu • Making a character move
 • Game Design • Class Hierarchies • Developing Cat AI • Win Conditions
  2. class Human < Sprite SPEED = 2 def update if

    window.button_down? Gosu::KbLeft self.x -= SPEED elsif window.button_down? Gosu::KbRight self.x += SPEED end if window.button_down? Gosu::KbUp self.y -= SPEED elsif window.button_down? Gosu::KbDown self.y += SPEED end end end Let’s get moving!
  3. Developing Cat AI • Start with “get near cat, cat

    runs somewhere randomly” • Cat doesn’t teleport, cat does have to travel through space between origin and destination • Break movement into discrete frames
  4. We calculate delta x and delta y by subtracting each

    part of the coördinates from each other From there, we also calculate the angle theta by getting the arctangent of delta y over delta x
  5. Since we have to split the movement into frames, we

    use the magnitude of the move and the cat speed to figure out how many frames the move should take. From that, we take the angle of the move, calculate the cosine and sine of the angle, and multiply those values by the speed to figure out how much we should move per frame in both axes
  6. def take_off target_x = rand(window.width - image.width) target_y = rand(window.height

    - image.height) delta_x = x - target_x delta_y = y - target_y angle = Math.atan2(delta_y, delta_x) magnitude = Math.sqrt((delta_x ** 2) + (delta_y ** 2)) self.step_x = -SPEED * Math.cos(angle) self.step_y = -SPEED * Math.sin(angle) self.step_count = magnitude / SPEED self.state = :running end
  7. def running_update if step_count <= 0 self.state = :waiting return

    end self.step_count -= 1 self.x += step_x self.y += step_y end
  8. Win Conditions • Cat checks proximity to bowl • If

    close, win and quit (TODO: not that lol)