Class: Figure
- Inherits:
-
Object
- Object
- Figure
- Defined in:
- lib/figure.rb
Overview
Trida Figure reprezentuje postavy ve hre.
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#left ⇒ Object
readonly
Pozice na ose X.
-
#speed ⇒ Object
readonly
Rychlost pohybu.
-
#top ⇒ Object
readonly
Pozice na ose Y.
Instance Method Summary collapse
-
#can_move(area) ⇒ Object
Overi, jestli se postava puze dale pohybovat soucasnym smerem v oblasti
area
* Args : -area
-> mapa hry * Returns : - true -> postava se muze dal pohybovat stejnym smrem - false -> postava musi zmeni smer pohybu. -
#initialize(left, top, speed, r) ⇒ Figure
constructor
Vytvori novou postavu umestenou na mape v poloze
left
atop
, pohybujici se rychlostispeed
a vychozim smerem pohybur
. -
#move ⇒ Object
Posune hrace soucasnym smerem.
Constructor Details
#initialize(left, top, speed, r) ⇒ Figure
Vytvori novou postavu umestenou na mape v poloze left
a top
, pohybujici se rychlosti speed
a vychozim smerem pohybu r
.
-
Args :
-
left
-> poloha na ose X -
top
-> poloha na ose Y -
speed
-> poloha na ose rychlost pohybu -
r
-> vychozi smer pohybu
-
14 15 16 17 18 19 20 21 22 |
# File 'lib/figure.rb', line 14 def initialize(left, top, speed, r) @directions = [:left, :right, :up, :down] @left = left @top = top @future_left = @left @future_top = @top @speed = speed @direction = @directions[r] end |
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
97 98 99 |
# File 'lib/figure.rb', line 97 def direction @direction end |
#left ⇒ Object (readonly)
Pozice na ose X
89 90 91 |
# File 'lib/figure.rb', line 89 def left @left end |
#speed ⇒ Object (readonly)
Rychlost pohybu
95 96 97 |
# File 'lib/figure.rb', line 95 def speed @speed end |
#top ⇒ Object (readonly)
Pozice na ose Y
92 93 94 |
# File 'lib/figure.rb', line 92 def top @top end |
Instance Method Details
#can_move(area) ⇒ Object
Overi, jestli se postava puze dale pohybovat soucasnym smerem v oblasti area
-
Args :
-
area
-> mapa hry
-
-
Returns :
-
true -> postava se muze dal pohybovat stejnym smrem
-
false -> postava musi zmeni smer pohybu
-
43 44 45 46 |
# File 'lib/figure.rb', line 43 def can_move(area) future_move area.colidate(@future_left + CROFTWIDTH / 2, @future_top + CROFTWIDTH / 2) end |
#move ⇒ Object
Posune hrace soucasnym smerem
50 51 52 53 54 |
# File 'lib/figure.rb', line 50 def move real_move modulo future_make end |