Created
January 14, 2016 17:32
-
-
Save krokrob/6632fb77b15da793a2b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'gosu' | |
| class Player | |
| attr_reader :score | |
| def initialize | |
| @image = Gosu::Image.new("images/xwing.png") | |
| @x = @y = @vel_x = @vel_y = @angle = 0.0 | |
| @score = 0 | |
| end | |
| def warp(x, y) | |
| @x, @y = x, y | |
| end | |
| def turn_left | |
| @x -= 10 | |
| end | |
| def turn_right | |
| @x += 10 | |
| end | |
| def accelerate | |
| @vel_x += Gosu::offset_x(@angle, 0.5) | |
| @vel_y += Gosu::offset_y(@angle, 0.5) | |
| end | |
| def move | |
| @x += @vel_x | |
| @y += @vel_y | |
| @x %= 640 | |
| @y %= 480 | |
| @vel_x *= 0.95 | |
| @vel_y *= 0.95 | |
| end | |
| def collect_stars(stars) | |
| if stars.reject! {|star| Gosu::distance(@x, @y, star.x, star.y) < 35 } then | |
| @score += 1 | |
| end | |
| end | |
| def draw | |
| @image.draw_rot(@x, @y, 1, @angle) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment