Skip to content
Browse files

some refactoring + cleanup

  • Loading branch information...
1 parent bef8094 commit 5b8e6804f9af1b021fe3cc8ddb9153a7c7b5ca21 ippa committed Aug 24, 2010
Showing with 14 additions and 43 deletions.
  1. +1 −0 src/level.rb
  2. +5 −39 src/player.rb
  3. +8 −4 start_game.rb
View
1 src/level.rb
@@ -7,6 +7,7 @@ def initialize(options = {})
@secret_letters = [:c,:h,:u,:n,:k,:y,:b,:a,:c,:o,:n]
self.input = { :escape => :exit, [:c,:h,:u,:n,:k,:y,:b,:a,:o] => :chunky_bacon }
+ on_input(:e, :edit)
self.viewport.game_area = [0, 0, 12000, 250]
View
44 src/player.rb
@@ -1,6 +1,6 @@
class Player < Chingu::GameObject
trait :bounding_box, :scale => 0.8, :debug => false
- traits :timer, :collision_detection , :timer, :velocity
+ traits :collision_detection, :timer, :velocity
attr_reader :camping_count
@@ -10,8 +10,7 @@ def setup
[:down, :s] => :down,
[:up, :w] => :jump,
}
-
- #@image = Image["rabbit.png"]
+
@animation = Animation.new(:file => "rabbit.png", :size => [56,64])
@image = @animation.first
@@ -28,11 +27,6 @@ def setup
self.factor = 0.4
end
- def level_up
- new_factor = self.factor + 3
- between(1,500) { self.factor += 0.1 }.then { self.factor = new_factor }
- end
-
def jumping
@jumps > 0
end
@@ -49,30 +43,10 @@ def hit_by(object)
end
end
- def die
- self.collidable = false
- @color = Color::RED
- @died_at = [self.x, self.y]
- between(1,600) { self.scale += 0.4; self.alpha -= 5; }.then { resurrect }
- Sound["hurt.wav"].play(0.3)
- self.velocity_y = -13
- end
-
def down
self.velocity_y = 4
end
-
- def resurrect
- self.x, self.y = @died_at
- self.velocity_x = 0
- self.velocity_y = 0
- self.alpha = 255
- self.factor = 3
- self.collidable = true
- @color = Color::WHITE
- game_state.restore_player_position
- end
-
+
def holding_left
move(-@speed, 0)
end
@@ -94,28 +68,20 @@ def land
def move(x,y)
self.factor_x = self.factor_x.abs if x > 0
self.factor_x = -self.factor_x.abs if x < 0
+ @image = @animation.next if @animation
self.x += x
- if game_state.game_object_map.from_game_object(self)
- self.x = previous_x
- self.velocity_x = 0
- end
- @image = @animation.next if @animation
+ self.x = previous_x if game_state.game_object_map.from_game_object(self)
self.y += y
- end
-
- def update
if block = game_state.game_object_map.from_game_object(self)
-
if self.velocity_y < 0
self.y = block.bb.bottom + self.height
else
self.y = block.bb.top-1
land
end
self.velocity_y = 0
- self.velocity_x = 0
end
end
end
View
12 start_game.rb
@@ -1,6 +1,11 @@
#!/usr/bin/env ruby
require 'rubygems' rescue nil
-require 'chingu'
+begin
+ raise LoadError if defined?(Ocra)
+ require '../chingu/lib/chingu'
+rescue LoadError
+ require 'chingu'
+end
include Gosu
include Chingu
@@ -14,10 +19,9 @@ def initialize
end
def setup
- retrofy
- # Sound["camping.wav"] # lame cache line
+ self.retrofy
push_game_state(Level1)
- end
+ end
end
Game.new.show

0 comments on commit 5b8e680

Please sign in to comment.
Something went wrong with that request. Please try again.