-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetamorphian.rb
190 lines (168 loc) · 4.94 KB
/
metamorphian.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#--------------------------------------------------------------------#
# Program: Metamorphian #
# Author: Jacob Preston #
# #
# Description: Bullet Hell Rogue-Like Game #
#--------------------------------------------------------------------#
require 'chingu'
include Gosu
include Chingu
require_relative 'src\animation'
require_relative 'src\sound_manager'
require_relative 'src\menu_button'
require_relative 'src\vector'
require_relative 'src\meter'
require_relative 'src\bullet_emitter'
require_relative 'src\gate'
require_relative 'src\wall'
require_relative 'src\hallway'
require_relative 'src\item'
require_relative 'src\chest'
require_relative 'src\player'
require_relative 'src\food'
require_relative 'src\essence'
require_relative 'src\spawner'
require_relative 'src\enemy'
require_relative 'src\caterpillar'
require_relative 'src\nymph'
require_relative 'src\cocoon'
require_relative 'src\butterfly'
require_relative 'src\dragonfly'
require_relative 'src\room'
require_relative 'src\map'
require_relative 'src\hud'
#---------------------------------------------------------------------
# ZOrder Module
# specifies in which order objects are drawn
#---------------------------------------------------------------------
module ZOrder
BACKGROUND = 0
BUTTON = 1
ROOM = 1
FOOD = 2
WALL = 3
CHEST = 3
ENEMY = 4
GATE = 4
ITEM = 4
PLAYER = 5
GUN = 6
ESSENCE = 6
BUTTERFLY = 6
BULLETS = 7
INFO = 8
UI = 9
MOUSE = 10
end
#---------------------------------------------------------------------
# Global variables and data structures
#---------------------------------------------------------------------
$width = nil
$height = nil
$player = nil
$map = nil
$hud = nil
$p_bullets = []
$e_bullets = []
$sm = SoundManager.new
$item_table = {"boots" => SpeedBoots }
#---------------------------------------------------------------------
# Game Window Setup
#---------------------------------------------------------------------
class Metamorphian < Chingu::Window
def initialize()
$width = (Gosu.screen_width * 1.5).to_i
$height = (Gosu.screen_height * 1.5).to_i
super($width,$height,true)
$window.caption = "Metamorphian"
@cursor = false
@cursor = Gosu::Image.new("sprites/crosshairs.png")
end
def setup
#retrofy
#self.factor = 3
switch_game_state(Play.new)
end
def draw
super
@cursor.draw(self.mouse_x-10, self.mouse_y-10, 100)
end
def needs_cursor?
false
end
def close
close!
end
end
#---------------------------------------------------------------------
# Play state
#---------------------------------------------------------------------
class Play < GameState
trait :viewport
attr_reader :spawner, :pause
def initialize(options = {})
super
@pause = false
self.input = { :escape => :exit, :holding_p => :pause}
$sm.play_sound("everglades", 0.1, 1.5, true)
self.viewport.lag = 0
self.viewport.game_area = [0, 0, 12000+$width+$width/2, 12000+$width]
$map = Map.new
$map.generate_floor()
$player = Player.create(:x => $map.starting_room.x,
:y => $map.starting_room.y,
:zorder => ZOrder::PLAYER,
:cr => $map.starting_room
)
$hud = Hud.create(:x => $player.x, :y => $player.y)
end
def update
super
self.viewport.center_around($player)
end
def pause
if @pause
game_objects.unpause!
@pause = false
else
game_objects.pause!
@pause = true
end
end
end
#---------------------------------------------------------------------
# Start Menu state
#---------------------------------------------------------------------
class StartMenu < GameState
attr_reader :start, :quit, :logo
def initialize(options = {})
super
self.input = {:escape => :exit}
offset = 200
@start = MenuButton.create(:x=>$width/2,
:y=>$height/2 + offset,
:main => Gosu::Image.new("sprites/buttons/p.png"),
:hover => Gosu::Image.new("sprites/buttons/ph.png"))
@quit = MenuButton.create( :x=>$width/2,
:y=>$height/2 + offset + 80,
:main => Gosu::Image.new("sprites/buttons/q.png"),
:hover => Gosu::Image.new("sprites/buttons/qh.png"))
# logo by Robert Won
@logo = Gosu::Image.new("sprites/logo.png")
end
def update
super
if start.event?
switch_game_state(Play.new)
end
if quit.event?
exit
end
end
def draw
super
fill(Gosu::Color.rgba(0, 0, 0, 255), ZOrder::BACKGROUND)
logo.draw_rot($width/2, $height/2-40, ZOrder::UI,0)
end
end
Metamorphian.new.show