Class: GamesAndRpgParadise::MazePuzzle::Infor

Inherits:
Object
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/infor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*player_color) ⇒ Infor

Returns a new instance of Infor.



13
14
15
16
17
18
19
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/infor.rb', line 13

def initialize(*player_color)
  @player_color = player_color
  # This class will renders information of the game, like points and level

  #---------------------------------------------------------------------------------#
  # create code block (initial, update and draw) for different game mode            #
  #---------------------------------------------------------------------------------#
  if @player_color.length == 2
    @initial_lambda = lambda {
      @player_1_color = player_color[0]
      @player_2_color = player_color[1]
      
      @level = 1
      @level_image = Gosu::Image.from_text(@level.to_s, 36)
        
      @label = 'LEVEL'
      @label_image = Gosu::Image.from_text(@label, 40)
        
      @x = center_by_x(@label_image.width)
      @y_1 = 210
      @y_2 = 290
        
      @player_1_point = 0
      @player_2_point = 0

      @player_1_point_image = Gosu::Image.from_text @player_1_point.to_s, 36
      @player_2_point_image = Gosu::Image.from_text @player_2_point.to_s, 36
    }
    @update_lambda = lambda {
      @level_image = Gosu::Image.from_text @level.to_s, 36
      @player_1_point_image = Gosu::Image.from_text @player_1_point.to_s, 36
      @player_2_point_image = Gosu::Image.from_text @player_2_point.to_s, 36
    }
    @draw_lambda = lambda {
      @label_image.draw(center_by_x(@label_image.width), 80, 1)
      @level_image.draw(center_by_x(@level_image.width), 130, 1)

      draw_quad @x,    @y_1,    @player_1_color,
                @x+30, @y_1,    @player_1_color,
                @x+30, @y_1+30, @player_1_color,
                @x,    @y_1+30, @player_1_color

      draw_quad @x,    @y_2,    @player_2_color,
                @x+30, @y_2,    @player_2_color,
                @x+30, @y_2+30, @player_2_color,
                @x,    @y_2+30, @player_2_color
        
      @player_1_point_image.draw(@x + 60, @y_1, 1)
      @player_2_point_image.draw(@x + 60, @y_2, 1)
    }
  elsif @player_color.length == 0
    @initial_lambda = lambda {
      @level = 1
      @label = 'LEVEL'
      @label_image = Gosu::Image.from_text @label, 40
    }
    @update_lambda = lambda {
      @level_image = Gosu::Image.from_text @level.to_s, 36
    }
    @draw_lambda = lambda {
      @label_image.draw(center_by_x(@label_image.width), 80, 1)
      @level_image.draw(center_by_x(@level_image.width), 130, 1)
    }
  end

  #-------------------------#
  # end create code block   #
  #-------------------------#
  @initial_lambda.call
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



11
12
13
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/infor.rb', line 11

def level
  @level
end

#player_1_pointObject

Returns the value of attribute player_1_point.



11
12
13
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/infor.rb', line 11

def player_1_point
  @player_1_point
end

#player_2_pointObject

Returns the value of attribute player_2_point.



11
12
13
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/infor.rb', line 11

def player_2_point
  @player_2_point
end

Instance Method Details

#center_by_x(width) ⇒ Object

#

center_by_x

#


87
88
89
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/infor.rb', line 87

def center_by_x(width)
  return $dimension + SIDE_BAR/2 - width/2
end

#drawObject

#

draw

#


101
102
103
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/infor.rb', line 101

def draw
  @draw_lambda.call
end

#updateObject

#

update

#


94
95
96
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/infor.rb', line 94

def update
  @update_lambda.call
end