Class: RubyFighter::Player

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

Defined Under Namespace

Classes: Tileset

Constant Summary collapse

SCALE =

same for all players

3
POS_Y =
180
SPEED =
3

Instance Method Summary collapse

Constructor Details

#initialize(window, name, flip = false) ⇒ Player

Returns a new instance of Player.



8
9
10
11
12
13
14
15
16
# File 'lib/ruby_fighter/player.rb', line 8

def initialize(window, name, flip=false)
  @tiles = Tileset.new(window, name)
  @pos_x = 0
  @flip  = flip
  @max_x = window.width

  move_to flip ? @max_x - 100 - width : 100
  idle!
end

Instance Method Details

#blocking!Object



27
28
29
# File 'lib/ruby_fighter/player.rb', line 27

def blocking!
  @tiles.blocking!
end

#drawObject



71
72
73
74
75
76
# File 'lib/ruby_fighter/player.rb', line 71

def draw
  pos_x   = @pos_x + (@flip ? width : 0)
  scale_x = SCALE * (@flip ? -1 : 1)

  @tiles.draw(pos_x, POS_Y, 1, scale_x, SCALE)
end

#idle!Object



18
19
20
21
# File 'lib/ruby_fighter/player.rb', line 18

def idle!
  return if @busy
  @tiles.idle!
end

#kick!Object



39
40
41
42
43
44
45
# File 'lib/ruby_fighter/player.rb', line 39

def kick!
  @busy = true
  @tiles.kick! do
    @busy = false
    idle!
  end
end

#leftObject



59
60
61
# File 'lib/ruby_fighter/player.rb', line 59

def left
  @pos_x
end

#move_leftObject



51
52
53
# File 'lib/ruby_fighter/player.rb', line 51

def move_left
  @pos_x -= SPEED
end

#move_rightObject



55
56
57
# File 'lib/ruby_fighter/player.rb', line 55

def move_right
  @pos_x += SPEED
end

#move_to(x) ⇒ Object



47
48
49
# File 'lib/ruby_fighter/player.rb', line 47

def move_to(x)
  @pos_x = x
end

#punch!Object



31
32
33
34
35
36
37
# File 'lib/ruby_fighter/player.rb', line 31

def punch!
  @busy = true
  @tiles.punch! do
    @busy = false
    idle!
  end
end

#rightObject



63
64
65
# File 'lib/ruby_fighter/player.rb', line 63

def right
  @pos_x + width
end

#walking!Object



23
24
25
# File 'lib/ruby_fighter/player.rb', line 23

def walking!
  @tiles.walking!
end

#widthObject



67
68
69
# File 'lib/ruby_fighter/player.rb', line 67

def width
  @tiles.width * SCALE
end