Skip to content

Commit

Permalink
Adapted to Ruby 1.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioszabo committed Nov 24, 2011
1 parent fde7b6e commit 7927ded
Show file tree
Hide file tree
Showing 36 changed files with 59 additions and 66 deletions.
4 changes: 2 additions & 2 deletions ar_sdl.rb → lib/ar_sdl.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rubygems"
require "sdl"
require "scene"
require "screen"
require_relative "scene"
require_relative "screen"

class ArSDL
PAUSE = 20
Expand Down
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
3 changes: 2 additions & 1 deletion player.rb → lib/player.rb
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
Expand Down
6 changes: 3 additions & 3 deletions scene.rb → lib/scene.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "sprite"
require "energy"
require "player"
require_relative "sprite"
require_relative "energy"
require_relative "player"

class Scene
WIDTH = 800
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion sprite.rb → lib/sprite.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "screen"
require_relative "screen"

class Sprite
DIR = File.expand_path File.join(File.dirname(__FILE__), "images")
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions spec/energy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "spec/helper"
require_relative "helper"

describe Energy do
it_should_behave_like 'a mocked screen'
let(:screen) { MockScreen.new }
class Energy; attr_reader :tank, :energy; end

before do
Expand All @@ -20,10 +20,10 @@ class Energy; attr_reader :tank, :energy; end
end

it 'should draw correctly on the screen' do
@energy.draw_on @screen, 0, 0
@screen.should have_a(@energy.tank).on(0, 0)
@screen.should have(100).objects_like(@energy.energy)
@screen.should have_a(@energy.energy).on(4, 3)
@screen.should have_a(@energy.energy).on(5, 3)
@energy.draw_on screen, 0, 0
screen.should have_a(@energy.tank).on(0, 0)
screen.should have(100).objects_like(@energy.energy)
screen.should have_a(@energy.energy).on(4, 3)
screen.should have_a(@energy.energy).on(5, 3)
end
end
4 changes: 2 additions & 2 deletions spec/helper.rb
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"

6 changes: 0 additions & 6 deletions spec/mock_screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,3 @@ def objects_like(sprite)
objects.select { |o| o.sprite == sprite }
end
end

describe 'a mocked screen', :shared => true do
before do
@screen = MockScreen.new
end
end
82 changes: 40 additions & 42 deletions spec/player_spec.rb
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
2 changes: 1 addition & 1 deletion spec/sprite_spec.rb
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
Expand Down
2 changes: 1 addition & 1 deletion spec/square_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "spec/helper"
require_relative "helper"

describe Square do
it 'should verify if collides with another square' do
Expand Down

0 comments on commit 7927ded

Please sign in to comment.