Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'gosu'
- class Ducky
- attr_reader :x, :y, :timer
- def initialize(image, turnsLeft)
- @img = image
- @scale = (rand * 0.3) + 0.1
- @x = rand * 640
- @y = rand * 480
- @turn_x = rand * 0.6
- @turn_y = rand * 0.6
- @angle = rand(360)
- @turnDir = turnsLeft
- @colorMod = 0
- @alphaMod = 0
- @finalColor = 0xffffffff
- @timer = 0
- end
- def update
- if @turnDir == 0
- @angle += 1
- if @angle > 360
- @angle = 0
- end
- end
- if @turnDir == 1
- @angle -= 1
- if @angle < 0
- @angle = 360
- end
- end
- if @colorMod < 255
- if rand(2) == 1
- @colorMod += 1
- end
- else
- @alphaMod += 5
- if @alphaMod > 100
- @alphaMod = 0
- end
- @timer += 1
- end
- @finalColor = 0xffffffff - (0x00000101 * @colorMod) - (0x01000000 * @alphaMod)
- end
- def draw
- @img.draw_rot(@x, @y, 1, @angle, @turn_x, @turn_y, @scale, @scale, @finalColor);
- end
- end
- class GameWindow < Gosu::Window
- def initialize
- super(640, 480, false)
- self.caption = "Amie-Jo'z Game"
- @background_image = Gosu::Image.new(self, "tornado.png", true)
- @ducky_image = Gosu::Image.new(self, "duck.png", true)
- @ducks = Array.new
- @font = Gosu::Font.new(self, Gosu::default_font_name, 20)
- @score = 0
- @lives = 10
- @squeak = Gosu::Sample.new(self, "squeak.wav")
- @alreadyClicked = false
- end
- def update
- if !button_down? Gosu::Button::MsLeft
- @alreadyClicked = false
- end
- if rand(100) < 4 and @ducks.size < 25 then
- @ducks.push(Ducky.new(@ducky_image, rand(2)))
- end
- @ducks.reject! do |star|
- if Gosu::distance(star.x, star.y, self.mouse_x, self.mouse_y) < 50 and button_down? Gosu::Button::MsLeft and @alreadyClicked != true and @lives > 0
- @score += 1
- @squeak.play
- @alreadyClicked = true
- true
- elsif star.timer > 100
- if @lives > -1
- @lives -= 1
- end
- true
- else
- false
- end
- end
- @ducks.each { |ducky| ducky.update }
- end
- def draw
- @background_image.draw(0, 0, 0);
- @ducks.each { |ducky| ducky.draw }
- @font.draw("Score: #{@score}", 10, 10, 2, 1.0, 1.0, 0xffffffff)
- @font.draw("Lives: #{@lives}", 10, 30, 2, 1.0, 1.0, 0xffffffff)
- if @lives < 0
- @font.draw("GAME OVER!!1!", 120, 80, 2, 3.0, 3.0, 0xffffffff)
- @font.draw("Press Enter to Restart.", 240, 160, 2, 1.0, 1.0, 0xffffffff)
- end
- end
- def button_down(id)
- if id == Gosu::Button::KbEscape
- close
- end
- if id == Gosu::Button::KbReturn
- restart
- end
- end
- def needs_cursor?
- true
- end
- def restart
- @ducks = Array.new
- @score = 0
- @lives = 10
- end
- end
- window = GameWindow.new
- window.show
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement