Class: GamesAndRpgParadise::Level_2
- Inherits:
-
Chingu::GameState
- Object
- Chingu::GameState
- GamesAndRpgParadise::Level_2
- Defined in:
- lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb
Overview
LEVEL 2 GAMESTATE
nearly identical to Level_1, but with more meteors
Instance Method Summary collapse
- #collision_check ⇒ Object
- #draw ⇒ Object
-
#initialize ⇒ Level_2
constructor
A new instance of Level_2.
- #new_meteor ⇒ Object
- #screen_shake ⇒ Object
- #setup ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize ⇒ Level_2
Returns a new instance of Level_2.
162 163 164 165 166 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 162 def initialize super self.input = { :return => Level_3, :p => Pause, :r => lambda{ current_game_state.setup } } $window.caption = "Level 2" end |
Instance Method Details
#collision_check ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 201 def collision_check Player.each_collision(Star) do |player, star| # Collide player with stars star.destroy $score += 300 $stars += 1 if $stars != 3 $star_grab.play(0.6) else $power_up.play(0.6) $stars = 0 $weapon += 1 end end Bullet.each_collision(Meteor1) do |bullet, meteor| # Collide bullets with meteors Explosion.create(:x => meteor.x, :y => meteor.y) Meteor2.create(:x => meteor.x, :y => meteor.y) Meteor2.create(:x => meteor.x, :y => meteor.y) meteor.destroy bullet.destroy $score += 100 Sound["media/audio/explosion.ogg"].play(0.2) break end Bullet.each_collision(Meteor2) do |bullet, meteor| # Collide bullets with meteors Explosion.create(:x => meteor.x, :y => meteor.y) Meteor3.create(:x => meteor.x, :y => meteor.y) Meteor3.create(:x => meteor.x, :y => meteor.y) meteor.destroy bullet.destroy $score += 100 Sound["media/audio/asplode.ogg"].play(0.2) break end Bullet.each_collision(Meteor3) do |bullet, meteor| # Collide bullets with meteors Explosion.create(:x => meteor.x, :y => meteor.y) meteor.destroy bullet.destroy $score += 100 Sound["media/audio/asplode.ogg"].play(0.2) break end Player.each_collision(Meteor1) do |starship, meteor| # Collide player with meteors @player.damage screen_shake end Player.each_collision(Meteor2) do |starship, meteor| # Collide player with meteors @player.damage screen_shake end Player.each_collision(Meteor3) do |starship, meteor| # Collide player with meteors @player.damage screen_shake end end |
#draw ⇒ Object
273 274 275 276 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 273 def draw Image["../media/assets/background.png"].draw(0, 0, 0) # Background Image super end |
#new_meteor ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 193 def new_meteor Meteor1.create(:x => rand * 800, :y => rand * 600) Meteor2.create(:x => rand * 800, :y => rand * 600) Meteor3.create(:x => rand * 800, :y => rand * 600) Star.create Star.create end |
#screen_shake ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 256 def screen_shake if @shaking == false @shaking = true game_objects.each do |object| object.x += 10 after(30) {object.y += 10} after(60) {object.x -= 10} after(90) {object.y -= 10} after(120) {object.x += 10} after(150) {object.y += 10} after(180) {object.x -= 10} after(210) {object.y -= 10} end after(1000) {@shaking = false} end end |
#setup ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 168 def setup super Bullet.destroy_all # destroy lingering GameObjects Player.destroy_all Star.destroy_all Meteor1.destroy_all Meteor2.destroy_all Meteor3.destroy_all Explosion.destroy_all if @player != nil; @player.destroy; end # Player location, angle, and velocity were saved as constants in Level_1.update @player = Player.create(:x => $player_x, :y => $player_y, :angle => $player_angle, :velocity_x => $player_x_vel, :velocity_y => $player_y_vel, :zorder => Zorder::Main_Character) @player.input = {:holding_left => :turn_left, :holding_right => :turn_right, :holding_up => :accelerate, :holding_down => :brake, :space => :fire} @gui = GUI.create(@player) @shaking = true after(1000) {@shaking = false} Sound["media/audio/asplode.ogg"] # cache sound Sound["media/audio/exploded.ogg"] # cache sound @player.cool_down 2.times { new_meteor } # creates 6 meteors and 4 stars end |
#update ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 278 def update super collision_check $player_x, $player_y = @player.x, @player.y # save position, angle, velocity for next level $player_angle, $player_x_vel, $player_y_vel = @player.angle, @player.velocity_x, @player.velocity_y if Meteor1.size + Meteor2.size + Meteor3.size == 0 after(1000) { push_game_state(Level_3) } end if $health == 0 Explosion.create(:x => @player.x, :y => @player.y) @player.destroy $music.stop after(1000) { push_game_state(Chingu::GameStates::FadeTo.new(GameOver.new, :speed => 10)) } end end |