Class: MazePuzzle::GameWindow
- Defined in:
- lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/game_window.rb
Instance Method Summary collapse
- #button_down(id) ⇒ Object
-
#check_available_move(path, player) ⇒ Object
check weather the direction player want to go to available or not if available, set new status for player.
- #check_for_collision(player_1, player_2) ⇒ Object
- #check_for_finish(player) ⇒ Object
-
#draw ⇒ Object
draw.
- #draw_target ⇒ Object
-
#initialize(full_screen = false, game_mode = 1) ⇒ GameWindow
constructor
initialize.
- #new_round ⇒ Object
-
#update ⇒ Object
update.
Methods included from Window
<<, close, fullscreen=, fullscreen?, height, now, toggle_fullscreen, width
Constructor Details
#initialize(full_screen = false, game_mode = 1) ⇒ GameWindow
initialize
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/game_window.rb', line 40 def initialize( full_screen = false, game_mode = 1 ) @game_mode = game_mode super( DIMENSION + SIDE_BAR, DIMENSION, full_screen, 30 ) self. = TITLE #---------------------------------------------------------------------------------# # create code block (update, player_draw and new_player) for different game mode # #---------------------------------------------------------------------------------# if @game_mode == 1 @update_lambda = lambda { check_for_finish(@player) @player.move } @player_draw_lambda = lambda { @player.draw } @new_player_lambda = lambda { @player = Player.new(1, 0, PLAYER_COLOR_PRIMARY) } elsif @game_mode == 2 @update_lambda = lambda { if check_for_finish(@player) @infor.player_1_point += 1 end @player.move if check_for_finish(@player_2) @infor.player_2_point += 1 end @player_2.move } @player_draw_lambda = lambda { @player.draw @player_2.draw } @new_player_lambda = lambda { @player = Player.new(1, 0, PLAYER_COLOR_PRIMARY) @player_2 = Player.new(0, 1, PLAYER_COLOR_SECONDARY) } elsif @game_mode == 3 @update_lambda = lambda { if check_for_finish(@player) @infor.player_1_point += 1 end @player.move if check_for_collision(@player, @player_2) @infor.player_2_point += 1 end @player_2.move } @player_draw_lambda = lambda { @player.draw @player_2.draw } @new_player_lambda = lambda { @player = Player.new(1, 0, PLAYER_COLOR_PRIMARY) @player_2 = Player.new($cols-1, 0, PLAYER_COLOR_ANGRY) } end #-------------------------# # end create code block # #-------------------------# new_round if @game_mode == 1 @infor = Infor.new elsif @game_mode == 2 @infor = Infor.new(PLAYER_COLOR_PRIMARY, PLAYER_COLOR_SECONDARY) elsif @game_mode == 3 @infor = Infor.new(PLAYER_COLOR_PRIMARY, PLAYER_COLOR_ANGRY) end end |
Instance Method Details
#button_down(id) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/game_window.rb', line 194 def (id) if id == Gosu::KB_LEFT check_available_move(3, @player) end if id == Gosu::KB_RIGHT check_available_move(1, @player) end if id == Gosu::KB_UP check_available_move(0, @player) end if id == Gosu::KB_DOWN check_available_move(2, @player) end # control keys for player 2 if @game_mode == 2 or @game_mode == 3 if id == Gosu::KB_A check_available_move(3, @player_2) end if id == Gosu::KB_D check_available_move(1, @player_2) end if id == Gosu::KB_W check_available_move(0, @player_2) end if id == Gosu::KB_S check_available_move(2, @player_2) end end case id when Gosu::KB_ESCAPE close else super end end |
#check_available_move(path, player) ⇒ Object
check weather the direction player want to go to available or not if available, set new status for player
186 187 188 189 190 191 192 |
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/game_window.rb', line 186 def check_available_move(path, player) if !$cells[player.cell_index_x + player.cell_index_y * $cols].walls[path] player.set_status(path) player.is_moving = true end end |
#check_for_collision(player_1, player_2) ⇒ Object
154 155 156 157 158 159 160 161 162 |
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/game_window.rb', line 154 def check_for_collision(player_1, player_2) if (player_2.x - player_1.x).abs < $player_size and (player_2.y - player_1.y).abs < $player_size new_round @infor.level += 1 return true else return false end end |
#check_for_finish(player) ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/game_window.rb', line 144 def check_for_finish(player) if player.x == @target_x and player.y == @target_y new_round @infor.level += 1 return true else return false end end |
#draw ⇒ Object
draw
171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/game_window.rb', line 171 def draw $cells.each { |cell| if cell.visited cell.draw($cell_size, Color::BLUE) else cell.draw($cell_size, PLAYER_COLOR_PRIMARY) end } @player_draw_lambda.call @infor.draw draw_target end |
#draw_target ⇒ Object
137 138 139 140 141 142 |
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/game_window.rb', line 137 def draw_target draw_quad @target_x, @target_y, Color::WHITE, @target_x + $player_size, @target_y, Color::WHITE, @target_x + $player_size, @target_y + $player_size, Color::WHITE, @target_x, @target_y + $player_size, Color::WHITE end |
#new_round ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/game_window.rb', line 125 def new_round $rows += 2 $cols += 2 @maze = Maze.new @maze.generate_maze @new_player_lambda.call $target_cell_index_x += 2 $target_cell_index_y += 2 @target_x = ($target_cell_index_x * $cell_size) + $cell_size/2 - $player_size/2 @target_y = ($target_cell_index_y * $cell_size) + $cell_size/2 - $player_size/2 end |
#update ⇒ Object
update
165 166 167 168 |
# File 'lib/games_and_rpg_paradise/gui/gosu/maze_puzzle/game_window.rb', line 165 def update @update_lambda.call @infor.update end |