Class: GamesAndRpgParadise::Wall

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWall

initialize



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/wall.rb', line 17

def initialize
  @bricks = 64.times.map { Brick.new }
  @all_brick_x = (100..300).step(40).to_a + (460..660).step(40).to_a + (280..480).step(40).to_a + 
  (0..280).step(40).to_a + (480..760).step(40).to_a + (240..520).step(40).to_a +
  (0..200).step(40).to_a + (360..400).step(40).to_a + (560..760).step(40).to_a + 
  (320..440).step(40).to_a + [320] + [440] + [320] + [440]
  @all_brick_y = [90] * 12 + [200] * 6 + [310] * 16 + [420] * 8 + [530] * 6 + [460] * 2 + [530] * 6 + [590] * 4 + 
  [630] * 2 + [670] * 2
  @wall_units = []
  (0..63).each { |n| @wall_units.push([@bricks[n]] << @all_brick_x[n] << @all_brick_y[n]) } # pack each brick profile into wall 
  (0..63).each { |n| @wall_units[n][0].x = @wall_units.assoc(@wall_units[n][0])[1] } # write all brick instance :x 
  (0..63).each { |n| @wall_units[n][0].y = @wall_units.assoc(@wall_units[n][0])[2] } # write all brick instance :y
  @struck = false
  @brick_explosion = Gosu::Image.load_tiles("media/brick_explode.png", 50, 50)
  @brick_exploded = false
  @time_struck = nil
end

Instance Attribute Details

#brick_explodedObject

Returns the value of attribute brick_exploded.



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

def brick_exploded
  @brick_exploded
end

#bricksObject (readonly)

Returns the value of attribute bricks.



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

def bricks
  @bricks
end

#struck_xObject

Returns the value of attribute struck_x.



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

def struck_x
  @struck_x
end

#struck_yObject

Returns the value of attribute struck_y.



15
16
17
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/wall.rb', line 15

def struck_y
  @struck_y
end

#time_struckObject

Returns the value of attribute time_struck.



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

def time_struck
  @time_struck
end

#wall_unitsObject (readonly)

Returns the value of attribute wall_units.



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

def wall_units
  @wall_units
end

Instance Method Details

#check_existObject

check_exist



36
37
38
39
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/wall.rb', line 36

def check_exist
  @bricks.select! { |brick| brick.exist }
  @wall_units.select! { |element| element[0].exist }
end

#drawObject

draw



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/wall.rb', line 47

def draw
  @wall_units.each { |brick|
    brick[0].brick.draw(brick[1], brick[2], 0)
  }
  if @brick_exploded   # Show the brick explosion  
    img = @brick_explosion[Gosu::milliseconds / 25 % @brick_explosion.size]
    img.draw(@struck_x - 5, @struck_y - 5, 2) # Minus is for adjusting the explosion image
    if Time.now - @time_struck > 0.5
      @brick_exploded = false
    end
  end
end

#updateObject

update



42
43
44
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/wall.rb', line 42

def update
  check_exist
end