-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fde7b6e
commit 7927ded
Showing
36 changed files
with
59 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require "square" | ||
require_relative "square" | ||
|
||
class Player | ||
STEP_SIZE = 5 | ||
TURN_DELAY = 3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require "ar_sdl" | ||
require "spec/mock_screen" | ||
require "spec/objects_matcher" | ||
require_relative "mock_screen" | ||
require_relative "objects_matcher" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,71 @@ | ||
require "spec/helper" | ||
require_relative "helper" | ||
|
||
describe Player do | ||
it_should_behave_like 'a mocked screen' | ||
before do | ||
@player = Player.new :p1, 10, 10 | ||
end | ||
let(:screen) { MockScreen.new } | ||
let(:player) { Player.new :p1, 10, 10 } | ||
|
||
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 | ||
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 calculate the turning animation' do | ||
Player.send :attr_accessor, :current_animation | ||
@player.turn_to(2).should == 1 | ||
@player.turn_to(6).should == 7 | ||
@player.current_animation = 6 | ||
@player.turn_to(0).should == 7 | ||
@player.turn_to(5).should == 5 | ||
player.turn_to(2).should == 1 | ||
player.turn_to(6).should == 7 | ||
player.current_animation = 6 | ||
player.turn_to(0).should == 7 | ||
player.turn_to(5).should == 5 | ||
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 | ||
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 | ||
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 not update the position if it\'s not enough distant' do | ||
@player.goto 10, 9 | ||
@player.update | ||
@player.x.should == 10 | ||
@player.y.should == 10 | ||
player.goto 10, 9 | ||
player.update | ||
player.x.should == 10 | ||
player.y.should == 10 | ||
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 | ||
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) | ||
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 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require "spec/helper" | ||
require_relative "helper" | ||
|
||
describe Sprite do | ||
before do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters