-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.rb
56 lines (48 loc) · 1.23 KB
/
game.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require "gosu"
require_relative "player"
require_relative "bullet"
class GameWindow < Gosu::Window
def initialize
super 640, 480, false
self.caption = "Wordpress game lulz"
@background_image = Gosu::Image.new(self, "resources/images/lisinge.jpg", true)
@player = Player.new(self)
@player.warp(320, 240)
@bullets = []
end
def update
if button_down? Gosu::KbLeft or button_down? Gosu::GpLeft then
@player.turn_left
end
if button_down? Gosu::KbRight or button_down? Gosu::GpRight then
@player.turn_right
end
if button_down? Gosu::KbUp or button_down? Gosu::GpButton0 then
@player.accelerate
end
if button_down? Gosu::KbSpace
bullet = Bullet.new(self, @player.x, @player.y, @player.angle, @player.ssj)
@bullets << bullet
end
if button_down? Gosu::KbEnter or button_down? Gosu::KbReturn then
@player.toggleSSJ(self)
end
@bullets.each do |bullet|
bullet.move
@bullets.delete(bullet) if bullet.remove?
end
@player.move
end
def draw
@player.draw
@bullets.each(&:draw)
@background_image.draw(0, 0, 0);
end
def button_down(id)
if id == Gosu::KbEscape
close
end
end
end
window = GameWindow.new
window.show