Class: GamesAndRpgParadise::Level_3
- Inherits:
-
Chingu::GameState
- Object
- Chingu::GameState
- GamesAndRpgParadise::Level_3
- Defined in:
- lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb
Overview
Instance Method Summary collapse
- #collision_check ⇒ Object
- #draw ⇒ Object
-
#initialize ⇒ Level_3
constructor
A new instance of Level_3.
- #new_meteor ⇒ Object
- #screen_shake ⇒ Object
- #setup ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize ⇒ Level_3
Returns a new instance of Level_3.
301 302 303 304 305 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 301 def initialize super self.input = { :return => Win, :p => Pause, :r => lambda{ current_game_state.setup } } $window.caption = "Level 3" end |
Instance Method Details
#collision_check ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 342 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
414 415 416 417 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 414 def draw Image["../media/assets/background.png"].draw(0, 0, 0) # Background Image super end |
#new_meteor ⇒ Object
334 335 336 337 338 339 340 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 334 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
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 397 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
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 307 def setup super Bullet.destroy_all 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 = 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} @song_fade = false # music fade used at end of gamestate @fade_count = 0 Sound["media/audio/asplode.ogg"] # cache sound Sound["media/audio/exploded.ogg"] @player.cool_down 3.times { new_meteor } end |
#update ⇒ Object
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/games_and_rpg_paradise/gui/gosu/chinguroids/levels.rb', line 419 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 $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 if Meteor1.size + Meteor2.size + Meteor3.size == 0 # if there are no more meteors after(1000) { @song_fade = true } # fade out music after(3000) { push_game_state(Win) } # push Win gamestate This is the exact moment when you win! end case @song_fade when true # music fades out when true @fade_count += 1 if @fade_count == 20 @fade_count = 0 $music.volume -= 0.1 end end end |