Permalink
Browse files

Adde Death GameState and the start of death handling

Move intro initialize into initialize to correctly use GameState methods

Esc in gameplay takes you to main menu, esc in main menu quits
  • Loading branch information...
1 parent 4d8c010 commit 99a950ef6a0f812a04abea80e7610a026321c37d @spilth committed Apr 6, 2012
View
@@ -4,6 +4,7 @@
include Gosu
require_relative 'astroblast/pause'
+require_relative 'astroblast/death'
require_relative 'astroblast/play'
require_relative 'astroblast/intro'
require_relative 'astroblast/game'
View
Binary file not shown.
Binary file not shown.
View
@@ -0,0 +1,15 @@
+class Death < Chingu::GameState
+ traits :timer
+
+ def setup
+ $window.caption = "Death!"
+ @text = Chingu::Text.create("You died!", :x => 320, :y => 200, :zorder => 55, :factor_x => 2.0, :factor_y => 2.0, :center_x => 0.5, :center_y => 0.5)
+ after(3000) { pop_game_state :setup => false, :finalize => false }
+ end
+
+ def draw
+ previous_game_state.draw
+ end
+
+
+end
View
@@ -1,8 +1,11 @@
class Intro < Chingu::GameState
- def setup
- self.input = { :space => Play }
+ def initialize
+ super
+ self.input = { :space => Play, :escape => :exit }
$window.caption = "Main Menu"
@text = Chingu::Text.create("Press Space to Play!", :x => 320, :y => 200, :zorder => 55, :factor_x => 2.0, :factor_y => 2.0, :center_x => 0.5, :center_y => 0.5)
+ @text2 = Chingu::Text.create("Press Esc to Quit!", :x => 320, :y => 240, :zorder => 55, :factor_x => 2.0, :factor_y => 2.0, :center_x => 0.5, :center_y => 0.5)
end
+
end
@@ -17,7 +17,6 @@ def setup
@lives = INITIAL_LIVES
@respawning = false
- @lives_text = Chingu::Text.create(lives, :x => $window.width - 64, :y => $window.height - 64, :zorder => 55, :factor_x => 2.0, :factor_y => 2)
@hyperspaces_text = Chingu::Text.create(hyperspaces, :x => 64, :y => $window.height - 64, :zorder => 55, :factor_x => 2.0, :factor_y => 2)
@x = $window.width / 2
@y = $window.height - 96
View
@@ -1,6 +1,9 @@
class Play < Chingu::GameState
def setup
- self.input = { :escape => :exit, :p => Chingu::GameStates::Pause }
+ self.input = {
+ :escape => lambda{ pop_game_state },
+ :p => Chingu::GameStates::Pause
+ }
$window.caption = "Play"
@background = Chingu::GameObject.create(:image => "background.png", :x => 512, :y => 384, :zorder => 10)
@@ -13,13 +16,27 @@ def setup
}
@spawner = AsteroidSpawner.create
@text = Chingu::Text.create(@player.score, :x => $window.width / 2, :y => $window.height - 64, :zorder => 55, :factor_x => 2.0, :factor_y => 2)
+ @lives_text = Chingu::Text.create(@player.lives, :x => $window.width - 64, :y => $window.height - 64, :zorder => 55, :factor_x => 2.0, :factor_y => 2)
end
def update
super
Asteroid.each_collision(LaserCannon) do |asteroid, laser_cannon|
puts "You died!"
+
+ @player.lives -= 1
+ @lives_text.destroy
+ @lives_text = Chingu::Text.create(@player.lives, :x => $window.width - 64, :y => $window.height - 64, :zorder => 55, :factor_x => 2.0, :factor_y => 2)
+ # If no lives left, go to GameOver state
+ Asteroid.destroy_all
+ LaserBlast.destroy_all
+ # Hide Cannon
+ # Show animation of exploding cannon
+ push_game_state(Death)
+
+ # Center cannon and show again
+ @player.x = $window.width / 2
end
Asteroid.each_collision(LaserBlast) do |asteroid, laser_blast|

0 comments on commit 99a950e

Please sign in to comment.