Class: Figure

Inherits:
Object
  • Object
show all
Defined in:
lib/figure.rb

Overview

Trida Figure reprezentuje postavy ve hre.

Direct Known Subclasses

Ghost, Player

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#directionObject

Returns the value of attribute direction.



97
98
99
# File 'lib/figure.rb', line 97

def direction
  @direction
end

#leftObject (readonly)

Pozice na ose X



89
90
91
# File 'lib/figure.rb', line 89

def left
  @left
end

#speedObject (readonly)

Rychlost pohybu



95
96
97
# File 'lib/figure.rb', line 95

def speed
  @speed
end

#topObject (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

#moveObject

Posune hrace soucasnym smerem



50
51
52
53
54
# File 'lib/figure.rb', line 50

def move
  real_move
  modulo
  future_make
end