Class: GamesAndRpgParadise::Cannon

Inherits:
Object
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/gui/gosu/battle_city/cannon.rb

Overview

GamesAndRpgParadise::Cannon

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver) ⇒ Cannon

#

initialize

#


19
20
21
22
23
24
25
26
27
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/cannon.rb', line 19

def initialize(driver)
  @driver = driver
  @cannon_ball = Gosu::Image.new("media/blueball.png") if @driver.class == Player 
  @cannon_ball = Gosu::Image.new("media/orangeball.png") if @driver.class == EnemyTank
  @x = @driver.x + 20.5
  @y = @driver.y + 20.5
  @west, @east, @north, @south = [false] * 4
  reset
end

Instance Attribute Details

#launchObject (readonly)

Returns the value of attribute launch.



10
11
12
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/cannon.rb', line 10

def launch
  @launch
end

#launchedObject (readonly)

Returns the value of attribute launched.



9
10
11
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/cannon.rb', line 9

def launched
  @launched
end

#neutralisedObject

Returns the value of attribute neutralised.



14
15
16
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/cannon.rb', line 14

def neutralised
  @neutralised
end

#wallObject (readonly)

Returns the value of attribute wall.



13
14
15
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/cannon.rb', line 13

def wall
  @wall
end

#xObject (readonly)

Returns the value of attribute x.



11
12
13
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/cannon.rb', line 11

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



12
13
14
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/cannon.rb', line 12

def y
  @y
end

Instance Method Details

#drawObject

#

draw

#


83
84
85
86
87
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/cannon.rb', line 83

def draw
  unless @neutralised
    @cannon_ball.draw(@x, @y, 2)
  end
end

#fireObject

#

fire

#


41
42
43
44
45
46
47
48
49
50
51
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/cannon.rb', line 41

def fire
  unless @launched
    @launch = true
    case true
    when @driver.head_west; @west, @east, @north, @south = true, false, false, false
    when @driver.head_east; @west, @east, @north, @south = false, true, false, false
    when @driver.head_north; @west, @east, @north, @south = false, false, true, false
    when @driver.head_south; @west, @east, @north, @south = false, false, false, true 
    end       
  end    
end

#resetObject

#

reset

#


32
33
34
35
36
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/cannon.rb', line 32

def reset
  @neutralised = false
  @launch = false
  @launched = false
end

#updateObject

#

update

#


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/cannon.rb', line 56

def update
  if @launch
    @launched = true
    case true
    when @west
      @x -= 4
    when @east
      @x += 4
    when @north
      @y -= 4
    when @south
      @y += 4
    end
    if @y < 0 || @x < 0 || @y > 710 || @x > 800 || @neutralised
      @launch = false  # turn off the cannon launch path
      @neutralised = false
    end
  else
    @launched = false # reload the cannon
    @x = @driver.x + 20.5  
    @y = @driver.y + 20.5      
  end
end