-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.rb
More file actions
144 lines (119 loc) · 3.18 KB
/
Copy pathapplication.rb
File metadata and controls
144 lines (119 loc) · 3.18 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
require 'ruby2d'
set title: 'Doggo-Adventure!'
set width: 800, height: 600
MOUNTAIN_SPEED = 1.1/6
RUN_SPEED = 3
############################### MENU ###############################
# class MainMenu
# def initialize
# title_text = Text.new(
# 'Doggo Adventure!',
# y: 100,
# size: 72,
# )
# title_text.x = (Window.width - title_text.width) / 2
# play_text = Text.new(
# 'PLAY',
# y: 400,
# size: 50,
# )
# play_text.x = (Window.width - play_text.width) / 2
# about_text = Text.new(
# 'About',
# y: 470,
# size: 40,
# )
# about_text.x = (Window.width - about_text.width) / 2
# end
# end
# menu = MainMenu.new
# menu_music = Music.new("assets/audio/menu-music.mp3")
# menu_music.play
# menu_music.loop = true
# on :key_down do |event|
# case event.key
# when 'x'
# menu_music.stop
# # Find way to remove menu and start game.
# end
# end
############################### GAME ###############################
# class Game
# def initialize
@score = 0
game_music = Music.new("assets/audio/game-music.mp3")
score = Text.new("Score: #{@score}")
sky = Image.new(
'assets/background/layer-1-sky.png',
x: 0, y: 0,
width: 1000, height: 600
)
mountain = Image.new(
'assets/background/layer-2-mountain.png',
x: 0, y: 0,
width: 1000, height: 600,
)
ground = Image.new(
'assets/background/layer-3-ground.png',
x: 0, y: 0,
width: 1000, height: 600,
)
dog = Sprite.new(
'./assets/dog-full.png',
width: 92,
height: 54,
clip_width: 46,
time:200,
y: 470,
x:300,
animations: {
walk: 1..3,
stand: 4..5,
}
)
# Coins
coin = Sprite.new(
'./assets/coin.png',
clip_width: 16,
time: 200,
loop: true,
x: 550,
y: 470,
width: 35,
height: 35
)
coin.play
on :key_held do |event|
case event.key
when 'a'
dog.play animation: :walk, loop: true
if dog.x > 0
dog.x -= RUN_SPEED
else
if ground.x < 0
ground.x += RUN_SPEED
end
end
when 'd'
dog.play animation: :walk, loop: true, flip: :horizontal
if dog.x < (Window.width - dog.width)
dog.x += RUN_SPEED
else
if (ground.x - Window.width) > -ground.width
ground.x -= RUN_SPEED
mountain.x -= MOUNTAIN_SPEED
end
end
end
end
on :key_up do
dog.stop
end
#COIN SCORE
if dog.x >= coin.x && dog.y >= coin.y
@score += 1
end
game_music.play
# end
# end
show