Class: Core::Game::Player

Inherits:
MapNPC show all
Includes:
Gosu
Defined in:
lib/game/map/player.rb

Constant Summary

Constants inherited from MapObject

MapObject::DELIM

Instance Attribute Summary collapse

Attributes inherited from MapNPC

#behaviour, #children, #gamename, #goal

Attributes inherited from MapObject

#dx, #dy, #follow, #name, #properties, #through, #tx, #ty, #z

Instance Method Summary collapse

Methods inherited from MapNPC

#destroy_goal, #draw, #find_path_to, #setup, #talk

Methods inherited from MapObject

#dead?, #direction, #do_setup?, #draw, #setup, #to_save, #trigger, #update_move, #update_trigger

Constructor Details

#initialize(x = 0, y = 0) ⇒ Player

Returns a new instance of Player.



12
13
14
15
16
17
18
# File 'lib/game/map/player.rb', line 12

def initialize(x=0, y=0)
  super(x, y, {:file => Core.window.state.party.player.charset})
  @speed = 2
  @x, @y = x, y
  @name = "player"
  @gamename = Core.window.state.party.player.name
end

Instance Attribute Details

#xObject

Returns the value of attribute x.



10
11
12
# File 'lib/game/map/player.rb', line 10

def x
  @x
end

#yObject

Returns the value of attribute y.



10
11
12
# File 'lib/game/map/player.rb', line 10

def y
  @y
end

Instance Method Details

#teleport(tx, ty) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/game/map/player.rb', line 59

def teleport(tx, ty)
  if tx < @tx
    Core.window.state.map.xoff += (@tx - tx) * 32
  elsif @tx < tx
    Core.window.state.map.xoff -= (tx - @tx) * 32
  end
  if ty < @ty
    Core.window.state.map.yoff += (@ty - ty) * 32
  elsif @ty < ty
    Core.window.state.map.yoff -= (ty - @ty) * 32
  end
  @tx = tx
  @ty = ty
  @x = @tx * 32
  @y = @ty * 32
end

#updateObject



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
# File 'lib/game/map/player.rb', line 20

def update
  window = Core.window
  if @dx == 0 and @dy == 0
    if window.button_down?(KbLeft)
      @dx = -32
      @dy = 0
      destroy_goal
    elsif window.button_down?(KbRight)
      @dx = 32
      @dy = 0
      destroy_goal
    elsif window.button_down?(KbUp)
      @dx = 0
      @dy = -32
      destroy_goal
    elsif window.button_down?(KbDown)
      @dx = 0
      @dy = 32
      destroy_goal
    end
  end
  if window.pressed?(KbSpace) or window.pressed?(KbReturn) or window.pressed?(KbEnter)
    update_trigger
  end
  super
  if @stepped
    if @dx < 0
      Core.window.state.map.xoff += @speed
    elsif @dx > 0
      Core.window.state.map.xoff -= @speed
    end
    if @dy < 0
      Core.window.state.map.yoff += @speed
    elsif @dy > 0
      Core.window.state.map.yoff -= @speed
    end
  end
end