Skip to content

Commit

Permalink
cleanups and modifications for compatibility w/ latest Chingu
Browse files Browse the repository at this point in the history
  • Loading branch information
ippa committed Sep 30, 2009
1 parent 93c8514 commit 38e4893
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/cave_objects.rb
Expand Up @@ -82,7 +82,7 @@ def update


class Cursor < Chingu::GameObject
def initialize
def initialize(options = {})
super
@center_x = 0
@center_y = 0
Expand Down
49 changes: 28 additions & 21 deletions src/cavern_state.rb
Expand Up @@ -24,13 +24,13 @@ def initialize
# :esc => :exit }

self.input = { :left_mouse_button => :click, :esc => :exit}
@cursor = Cursor.new
@cursor = Cursor.create

@riches = 100
@score = 0
@riches_rect = Rect.new(10, 10, @riches, 20)
@riches_text = Text.new(:text => "Riches: ", :x => 20, :y => 13, :color => Color.new(0xFF000000), :zorder => 1000)
@score_text = Text.new(:text => "Score: #{@score}", :x => 150, :y => 13, :color => Color.new(0xFFFFFFFF), :zorder => 1000)
@riches_text = Text.create(:text => "Riches: ", :x => 20, :y => 13, :color => Color.new(0xFF000000), :zorder => 1000)
@score_text = Text.create(:text => "Score: #{@score}", :x => 150, :y => 13, :color => Color.new(0xFFFFFFFF), :zorder => 1000)
end

def setup
Expand All @@ -40,7 +40,7 @@ def setup
@first_drill = true
@first_gem = true
@milliseconds = milliseconds()
game_objects.delete_if { |o| o.is_a?(Miner) || o.is_a?(Machine) || o.is_a?(Gemstone) || o.is_a?(Stalactite)}
game_objects.destroy_if { |o| o.is_a?(Miner) || o.is_a?(Machine) || o.is_a?(Gemstone) || o.is_a?(Stalactite)}
spawn_miner
5.times { spawn_stalactite }
end
Expand All @@ -65,17 +65,17 @@ def spawn_miner; spawn_enemy(Miner); end
def spawn_machine; spawn_enemy(Machine); end
def spawn_enemy(klass)
if rand(2) == 1
klass.new(:x => 0, :y => @floor_y).move_right
klass.create(:x => 0, :y => @floor_y).move_right
else
klass.new(:x => $window.width, :y => @floor_y).move_left
klass.create(:x => $window.width, :y => @floor_y).move_left
end
end
def spawn_stalactite
Stalactite.new(:x => rand($window.width), :y => @ceiling_height)
Stalactite.create(:x => rand($window.width), :y => @ceiling_height)
end
def spawn_gemstone(x=200, y = @floor_y)
type = Gemstone.gem_types[rand(Gemstone.gem_types.size)]
Gemstone.new(:x => x, :y => y, :type => type)
Gemstone.create(:x => x, :y => y, :type => type)
end

#
Expand All @@ -90,31 +90,36 @@ def update

# Increases 1 each 10 second
value = (game_state_age / 10).to_i
if game_objects_of_class(Miner).size < 20
#if game_objects_of_class(Miner).size < 20
if Miner.size < 20
spawn_miner if (game_state_age > 20) && rand(7 * (60-value)) == 0
end

if game_objects_of_class(Machine).size < 6
#if game_objects_of_class(Machine).size < 6
if Machine.size < 20
spawn_machine if (game_state_age > 120) && rand(7 * (120-value)) == 0
end

if game_objects_of_class(Stalactite).size < 5
#if game_objects_of_class(Stalactite).size < 5
if Stalactite.size < 5
spawn_stalactite if rand(100) == 0
elsif game_objects_of_class(Stalactite).size < 10
#elsif game_objects_of_class(Stalactite).size < 10
elsif Stalactite.size < 10
spawn_stalactite if rand(200) == 0
elsif game_objects_of_class(Stalactite).size < 20
#elsif game_objects_of_class(Stalactite).size < 20
elsif Stalactite.size < 20
spawn_stalactite if rand(300) == 0
end


game_objects.select { |o| o.outside_window? && o.is_a?(Gemstone) }.each do |gemstone|
@riches -= gemstone.score
CavernText.new("They stole my beautiful child, #{gemstone.type}. I raised her for #{gemstone.score} years.")
CavernText.create("They stole my beautiful child, #{gemstone.type}. I raised her for #{gemstone.score} years.")
@riches_rect.width = @riches
push_game_state(GameOver.new(:score => @score)) if @riches <= 0
end

game_objects.delete_if { |o| (o.outside_window? || o.color.alpha == 0) && o.class != Cursor }
game_objects.destroy_if { |o| (o.outside_window? || o.color.alpha == 0) && o.class != Cursor }

fill_gradient(:from => @dark_gold, :to => @light_gold, :rect => @riches_rect, :zorder => 999)
@riches_text.text = "Riches: #{@riches}"
Expand All @@ -124,7 +129,7 @@ def update
game_objects_of_class(Gemstone).select { |gemstone| gemstone.status != :attached }.each do |gemstone|
if miner.rect.collide_rect?(gemstone.rect)
miner.attach(gemstone)
CavernText.new("They're stealing my loved ones!") if @first_gem
CavernText.create("They're stealing my loved ones!") if @first_gem
@first_gem = false
end
end
Expand Down Expand Up @@ -154,7 +159,9 @@ def update
2.times { spawn_smoke(stalactite.rect.centerx, @floor_y - enemy.rect.height, stalactite.power/800) }
enemy.rect.y = @floor_y
Sample["explosion.wav"].play(0.5)
game_objects.delete(stalactite)

#game_objects.delete(stalactite)
stalactite.destroy!
end
end
end
Expand All @@ -165,7 +172,7 @@ def update
def spawn_smoke(x, y, factor)
x += 10 - rand(20)
y += 10 - rand(20)
Particle.new(:x => x, :y => y, :image => Image["particle.png"], :fading => -5, :rotating => 10, :zooming => 0.04, :zorder => 100, :mode => :default, :factor => factor)
Particle.create(:x => x, :y => y, :image => Image["particle.png"], :fading => -5, :rotating => 10, :zooming => 0.04, :zorder => 100, :mode => :default, :factor => factor)
end

def click
Expand All @@ -181,16 +188,16 @@ def digg(object)
else

if @first_dig && object.is_a?(Miner)
CavernText.new("... That hurt.")
CavernText.create("... That hurt.")
@first_dig = false
end

if @first_drill && object.is_a?(Machine)
CavernText.new("... What is this big evil thing?")
CavernText.create("... What is this big evil thing?")
@first_drill = false
end

Crack.new(:x => object.attack_x, :y => @floor_y)
Crack.create(:x => object.attack_x, :y => @floor_y)
end
end

Expand Down
9 changes: 0 additions & 9 deletions src/core_extensions.rb

This file was deleted.

15 changes: 4 additions & 11 deletions src/game_over_state.rb
@@ -1,18 +1,11 @@
class GameOver < Chingu::GameState

def initialize(options)
super
@score = options[:score]
@text = Chingu::Text.new(:text => "GAME OVER - They stole all your riches. Score: #{@score}.", :x => 200, :y => 200, :size => 30, :zorder => 1000)
@text2 = Chingu::Text.new(:text => "ESC: quit SPACE: try again",:x => 400, :y => 300, :size => 20, :zorder => 1000)
self.input = { :esc => :exit, :space => :play_again }
@text = Chingu::Text.create(:text => "GAME OVER - They stole all your riches. Score: #{@score}.", :x => 200, :y => 200, :size => 30, :zorder => 1000)
@text2 = Chingu::Text.create(:text => "ESC: quit SPACE: try again",:x => 400, :y => 300, :size => 20, :zorder => 1000)
self.input = { :esc => :exit, :space => Cavern }
end

def play_again
switch_game_state(Cavern.new)
end

# def draw
# previous_game_state.draw
# super
# end
end
13 changes: 6 additions & 7 deletions src/intro_state.rb
Expand Up @@ -13,12 +13,16 @@ def initialize
self.input = { :space => Cavern, :esc => :exit }
end

def setup
Song["the_eternally_grey_1.ogg"].play(true)
end

def update
game_objects.reject! { |object| object.color.alpha == 0}
game_objects.destroy_if { |object| object.color.alpha == 0}

if game_objects.size == 0
if string = @strings.pop
@text = Chingu::Text.new(:text => string, :x => 100, :y => 200)
@text = Chingu::Text.create(:text => string, :x => 100, :y => 200)
else
switch_game_state(Cavern.new)
end
Expand All @@ -29,9 +33,4 @@ def update
@text.color.alpha -= 1 if @text.color.alpha > 0
end
end

def setup
Song["the_eternally_grey_1.ogg"].play(true)
end

end
2 changes: 1 addition & 1 deletion src/my_game_object.rb
Expand Up @@ -28,7 +28,7 @@ def dead?
def hit_by(power)
@energy -= power
self.die! if @energy < 0
puts "Hit by #{power}, energy: #{@energy}"
#puts "Hit by #{power}, energy: #{@energy}"
end

def die!
Expand Down
2 changes: 1 addition & 1 deletion the_eternally_grey.rb
Expand Up @@ -7,7 +7,7 @@
ROOT_PATH = File.dirname(File.expand_path(__FILE__))

require 'gosu'
require 'chingu'
require '../chingu/lib/chingu'

include Gosu
include Chingu
Expand Down

0 comments on commit 38e4893

Please sign in to comment.