Permalink
Browse files

Renamed "Player" to "Animable".

  • Loading branch information...
1 parent f14b7b8 commit 92e8d5ba007d85777f4a172ce4aa3b8c8607e7ea @mauricioszabo committed Feb 24, 2012
Showing with 79 additions and 79 deletions.
  1. +1 −1 lib/{player.rb → animable.rb}
  2. +78 −0 spec/animable_spec.rb
  3. +0 −78 spec/player_spec.rb
@@ -1,6 +1,6 @@
require_relative "square"
-class Player
+class Animable
STEP_SIZE = 5
TURN_DELAY = 3
SIZE = 60
View
@@ -0,0 +1,78 @@
+require_relative "helper"
+
+describe Animable do
+ let(:screen) { MockScreen.new }
+ let(:animable) { Animable.new :p1, 10, 10 }
+
+ Animable.send :attr_accessor, :current_animation
+
+ it 'should calculate the direction of the walk' do
+ animable.direction_to(0, 1).should == 7
+ animable.direction_to(0, 10).should == 6
+ animable.direction_to(0, 20).should == 5
+ animable.direction_to(10, 20).should == 4
+ animable.direction_to(20, 20).should == 3
+ animable.direction_to(20, 10).should == 2
+ animable.direction_to(20, 0).should == 1
+ animable.direction_to(10, 0).should == 0
+ end
+
+ it 'should not move if direction is not given' do
+ animable.update
+ animable.x.should == 10
+ animable.y.should == 10
+ end
+
+ it 'should calculate the turning animation' do
+ animable.turn_to(Animable::UPPER_RIGHT).should == Animable::UPPER
+ animable.turn_to(Animable::LOWER_LEFT).should == Animable::LEFT
+ animable.current_animation = Animable::LOWER_LEFT
+ animable.turn_to(Animable::UPPER).should == Animable::LEFT
+ animable.turn_to(Animable::LOWER).should == Animable::LOWER
+ end
+
+ describe 'when walking' do
+ it 'should update the current position if the animable is moving on only one direction' do
+ animable.goto 10, 0
+ animable.update
+ animable.y.should == 5
+ animable.x.should == 10
+ end
+
+ it 'should change the animation but mantain position, if changes the direction' do
+ animable.goto 0, 0
+ Animable::TURN_DELAY.times { animable.update }
+ animable.x.should == 10
+ animable.y.should == 10
+ animable.current_animation.should == 7
+ end
+
+ it 'should end the animation on final position' do
+ animable.goto 10, 9
+ animable.update
+ animable.x.should == 10
+ animable.y.should == 9
+ end
+
+ it 'should update the current position, but not walk more than 5 steps' do
+ animable.goto 0, 0
+ Animable::TURN_DELAY.times { animable.update }
+ animable.update
+ animable.y.should == 7.5
+ animable.x.should == 7.5
+ end
+ end
+
+ it 'should draw the ship' do
+ Animable.send :attr_accessor, :animations
+ animable.draw_on(screen)
+ screen.should have_a(animable.animations[0]).on(-20, -20)
+ end
+
+ it 'should have a collision box' do
+ animable.collision_box.x1.should == -3
+ animable.collision_box.x2.should == 23
+ animable.collision_box.y1.should == -3
+ animable.collision_box.y2.should == 23
+ end
+end
View
@@ -1,78 +0,0 @@
-require_relative "helper"
-
-describe Player do
- let(:screen) { MockScreen.new }
- let(:player) { Player.new :p1, 10, 10 }
-
- Player.send :attr_accessor, :current_animation
-
- it 'should calculate the direction of the walk' do
- player.direction_to(0, 1).should == 7
- player.direction_to(0, 10).should == 6
- player.direction_to(0, 20).should == 5
- player.direction_to(10, 20).should == 4
- player.direction_to(20, 20).should == 3
- player.direction_to(20, 10).should == 2
- player.direction_to(20, 0).should == 1
- player.direction_to(10, 0).should == 0
- end
-
- it 'should not move if direction is not given' do
- player.update
- player.x.should == 10
- player.y.should == 10
- end
-
- it 'should calculate the turning animation' do
- player.turn_to(Player::UPPER_RIGHT).should == Player::UPPER
- player.turn_to(Player::LOWER_LEFT).should == Player::LEFT
- player.current_animation = Player::LOWER_LEFT
- player.turn_to(Player::UPPER).should == Player::LEFT
- player.turn_to(Player::LOWER).should == Player::LOWER
- end
-
- describe 'when walking' do
- it 'should update the current position if the player is moving on only one direction' do
- player.goto 10, 0
- player.update
- player.y.should == 5
- player.x.should == 10
- end
-
- it 'should change the animation but mantain position, if changes the direction' do
- player.goto 0, 0
- Player::TURN_DELAY.times { player.update }
- player.x.should == 10
- player.y.should == 10
- player.current_animation.should == 7
- end
-
- it 'should end the animation on final position' do
- player.goto 10, 9
- player.update
- player.x.should == 10
- player.y.should == 9
- end
-
- it 'should update the current position, but not walk more than 5 steps' do
- player.goto 0, 0
- Player::TURN_DELAY.times { player.update }
- player.update
- player.y.should == 7.5
- player.x.should == 7.5
- end
- end
-
- it 'should draw the ship' do
- Player.send :attr_accessor, :animations
- player.draw_on(screen)
- screen.should have_a(player.animations[0]).on(-20, -20)
- end
-
- it 'should have a collision box' do
- player.collision_box.x1.should == -3
- player.collision_box.x2.should == 23
- player.collision_box.y1.should == -3
- player.collision_box.y2.should == 23
- end
-end

0 comments on commit 92e8d5b

Please sign in to comment.