/
animable_spec.rb
78 lines (67 loc) · 2.4 KB
/
animable_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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