-
Notifications
You must be signed in to change notification settings - Fork 0
/
asteroids.rb
63 lines (55 loc) · 1.16 KB
/
asteroids.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
59
60
61
62
63
require 'ruby2d'
set title: 'Asteroides'
set width: 800
set height: 600
require './star'
require './player'
require './loading_screen'
require './home_screen'
require './projectile'
require './asteroid'
current_screen = PlayerSelectScreen.new
update do
current_screen.update
end
on :key_down do |event|
case current_screen
when PlayerSelectScreen
case event.key
when 'left'
current_screen.move(:left)
when 'right'
current_screen.move(:right)
when 'return'
Window.clear
current_screen = GameScreen.new(current_screen.selected_player)
end
end
end
on :key_held do |event|
case current_screen
when GameScreen
case event.key
when 'up'
current_screen.accelerate_player(:forwards)
when 'down'
current_screen.accelerate_player(:backwards)
when 'left'
current_screen.rotate_player(:left)
when 'right'
current_screen.rotate_player(:right)
when 'space'
current_screen.player_fire_projectile
end
end
end
on :key_up do |event|
case current_screen
when GameScreen
case event.key
when 'up', 'down'
current_screen.stop_accelerating_player
end
end
end
show