-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.rb
58 lines (47 loc) · 1.2 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
57
58
ROOT_PATH = File.dirname(File.expand_path(__FILE__))
require 'chingu'
require './mario'
require './item'
class Game < Chingu::Window
def initialize
super
@bg = Background.create
@mario = Mario.create
@mario.input = {holding_left: :move_left,
holding_right: :move_right,
holding_up: :move_up,
holding_down: :move_down,
released_left: :halt,
released_right: :halt,
released_up: :halt,
released_down: :halt,
space: :jump,
f: :punch,
g: :spawn_item}
end
def update
if @mario.x >= self.width
@mario.x -= 5
Item.all.each { |item| item.x += 10 }
end
if @mario.y >= self.height
@bg.y -= 10
@mario.y -= 5
Item.all.each { |item| item.y -= 10 }
end
if @mario.y <= 0
@bg.y += 10
@mario.y += 5
Item.all.each { |item| item.y += 10 }
end
super
end
end
class Background < Chingu::GameObject
def initialize options={}
super(options.merge(image: Gosu::Image["./images/light_world.png"]))
@x = 0
@y = 0
end
end
Game.new.show