a_maze_ing 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7fb0b68dd5272233aacbaf58ba3171c3868b5bb
4
- data.tar.gz: efb0b850c4c09a1b0e93df8ea343e65109ca47ae
3
+ metadata.gz: 7391d4bf4b8f310472a2f81b01986bb1b4ba20aa
4
+ data.tar.gz: 65c1d69c552717d4f9781341f30b3e9221951df9
5
5
  SHA512:
6
- metadata.gz: 1f2a6c7732b8cf21090d0a626925d178e7fd9933a91d75a7cacd62f89acbb63811e86e2f700c2e452c63ab6ef2b8f9265347455fe4b9e470be6ac048f9de6d03
7
- data.tar.gz: '08fd8dc8244cf49114533fba404a97f00fcb56c9fd95391c7b03d69abc7d2684cfeffe69010bdd67416644fa0dd37403153d7231dd2a8030e3efbca4a047e147'
6
+ metadata.gz: 729b9aea9602cbba76e667f4e28825a65d29c2caf1f1155519f8e1c18ebbbd0c8d08746a5b7df109c295b7bd23452ccfa2bf531dcbfd3ab71658aaf17c93f60b
7
+ data.tar.gz: a7af82ca54fde9040cad68e5f8da9b3fe0d0144bab6c5497c9dba732e60ee950545532f099ad8c08f8b1165cc3556c8557c50a0c3608a5941fd49923a015a9fe
data/README.md CHANGED
@@ -2,12 +2,16 @@
2
2
 
3
3
  This is a small video game about maze, create on Gosu library. You need to find the way to specific point in the maze to win the game
4
4
 
5
- ![](./images/cover.jpg?raw=true)
5
+ Classic mode | Multiplayer mode
6
+ :-------------------------:|:-------------------------:
7
+ ![](./images/classic.jpg?raw=true) | ![](./images/multiplayer.jpg?raw=true)
6
8
 
7
9
  ## Requirements
8
10
 
9
11
  This gem needs [Gosu](https://www.libgosu.org/) installed on your machine in order to render graphics
10
12
 
13
+ To install, follow the constructions in [Gosu's documentation](https://github.com/gosu/gosu/wiki) on Github
14
+
11
15
  ## Installation
12
16
 
13
17
  Add this line to your application's Gemfile:
@@ -26,14 +30,25 @@ Or install it yourself as:
26
30
 
27
31
  ## Usage
28
32
 
29
- After install AMazeIng run following command to play
30
-
33
+ After install AMazeIng you can quickly run the game in classic mode by excecute the following command:
34
+
31
35
  $ a_maze_ing
32
36
 
37
+ or
38
+
39
+ $ a_maze_ing classic
40
+
41
+ To play in multiplayer mode run the following command:
42
+
43
+ $ a_maze_ing multiplayer
44
+
45
+ Global Options:
46
+
47
+ --fullscreen (-f) will run the game in full screen mode
48
+
33
49
  ## Features Todo List
34
50
 
35
51
  * Menu screen
36
- * Multiplayer mode - two player race to the target
37
52
  * Custom mode - custom difficulty
38
53
  * Enemy mode - Race to the target before get hit by the enemies
39
54
 
data/a_maze_ing.gemspec CHANGED
@@ -11,8 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ["tranhuu.phucuong@gmail.com"]
12
12
 
13
13
  spec.summary = %q{Maze solving game design on Gosu library}
14
- spec.description = %q{A fun and easy to play maze game with graphic.
15
- Maze randomly generate with difficulty increase evey level}
14
+ spec.description = %q{A maze game that is fun and easy to play, available for 2 player with 2D graphics render by Gosu library.}
16
15
  spec.homepage = "https://github.com/at-cuongtran/a_maze_ing"
17
16
  spec.license = "MIT"
18
17
 
@@ -36,6 +35,6 @@ Gem::Specification.new do |spec|
36
35
  spec.add_development_dependency "bundler", "~> 1.15"
37
36
  spec.add_development_dependency "rake", "~> 10.0"
38
37
  spec.add_development_dependency "rspec", "~> 3.0"
39
- spec.add_runtime_dependency "gosu","~> 0.12.0"
38
+ # spec.add_runtime_dependency "gosu","~> 0.12.0"
40
39
  spec.add_runtime_dependency "commander", "~> 4.4.3"
41
40
  end
Binary file
@@ -24,20 +24,18 @@ module AMazeIng
24
24
  c.syntax = 'a_maze_ing classic [options]'
25
25
  c.description = 'Classic mode, difficulty increase with level'
26
26
  c.action do
27
- AMazeIng::GameWindow.new(@full_screen).show
27
+ AMazeIng::GameWindow.new(@full_screen,1).show
28
28
  end
29
29
  end
30
- # command :bar do |c|
31
- # c.syntax = 'foobar bar [options]'
32
- # c.description = 'Display bar with optional prefix and suffix'
33
- # c.option '-p', '--prefix STRING', String, 'Adds a prefix to bar'
34
- # c.option '-s', '--suffix STRING', String, 'Adds a suffix to bar'
35
- # c.action do |args, options|
36
- # options.default :prefix => '(', :suffix => ')'
37
- # say "#{options.prefix}bar#{options.suffix}"
38
- # end
39
- # end
40
30
 
31
+ command :multiplayer do |c|
32
+ c.syntax = 'a_maze_ing multiplayer [options]'
33
+ c.description = 'Multiplayer mode, two player race to the target, player 2 use W/S/A/D key to move up/down/left/right'
34
+ c.action do
35
+ AMazeIng::GameWindow.new(@full_screen,2).show
36
+ end
37
+ end
38
+
41
39
  run!
42
40
  end
43
41
 
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env ruby
2
+ # credits to: http://en.wikipedia.org/wiki/Maze_generation_algorithm
3
+
4
+ require 'gosu'
5
+ include Gosu
6
+ require "observer"
7
+
8
+ module AMazeIng
9
+ DIMENSION = 700
10
+ SIDE_BAR = 180
11
+
12
+ class GameWindow < Window
13
+ $rows = $cols = 10
14
+ def initialize(full_screen, game_mode)
15
+ @game_mode = game_mode
16
+ super DIMENSION + SIDE_BAR, DIMENSION, full_screen, 1
17
+ self.caption = "Maze"
18
+
19
+ new_round
20
+ if @game_mode == 1
21
+ @infor = Infor.new
22
+ elsif @game_mode == 2
23
+ @infor = Infor.new(Color::RED, Color::YELLOW)
24
+ end
25
+
26
+ end
27
+
28
+ def new_round
29
+ @maze = Maze.new
30
+ @maze.generate_maze
31
+ if @game_mode == 1
32
+ @player = Player.new(1, 0, Color::RED)
33
+ elsif @game_mode == 2
34
+ @player = Player.new(1, 0, Color::RED)
35
+ @player_2 = Player.new(0, 1, Color::YELLOW)
36
+ end
37
+ end
38
+
39
+ def draw_target(cell)
40
+ cell_index_x = cell.cell_index_x
41
+ cell_index_y = cell.cell_index_y
42
+ x = (cell_index_x * $cell_size) + $cell_size/2 - $player_size/2
43
+ y = (cell_index_y * $cell_size) + $cell_size/2 - $player_size/2
44
+ draw_quad x, y, Color::GREEN,
45
+ x+$player_size, y, Color::GREEN,
46
+ x+$player_size, y+$player_size, Color::GREEN,
47
+ x, y+$player_size, Color::GREEN
48
+ end
49
+
50
+ def check_for_finish(player)
51
+ if player.cell_index_x == $cells[-1].cell_index_x && player.cell_index_y == $cells[-1].cell_index_y
52
+ $rows += 2
53
+ $cols += 2
54
+ new_round
55
+ @infor.level += 1
56
+ return true
57
+ else
58
+ return false
59
+ end
60
+ end
61
+
62
+ def update
63
+
64
+ if @game_mode == 1
65
+ check_for_finish(@player)
66
+ @player.move
67
+ end
68
+
69
+ if @game_mode == 2
70
+ if check_for_finish(@player)
71
+ @infor.player_1_point += 1
72
+ end
73
+ @player.move
74
+ if check_for_finish(@player_2)
75
+ @infor.player_2_point += 1
76
+ end
77
+ @player_2.move
78
+ end
79
+ @infor.update
80
+ end
81
+
82
+ def draw
83
+ $cells.each do |cell|
84
+ if cell.visited
85
+ cell.draw($cell_size, Color::BLUE)
86
+ else
87
+ cell.draw($cell_size, Color::GREEN)
88
+ end
89
+ end
90
+ @player.draw
91
+ @player_2.draw if @game_mode == 2
92
+ @infor.draw
93
+ draw_target($cells[-1])
94
+ end
95
+
96
+ # check weather the direction player want to go to available or not
97
+ # if available, set new status for player
98
+ def check_available_move(path, player)
99
+ if !$cells[player.cell_index_x + player.cell_index_y * $cols].walls[path]
100
+
101
+ player.set_status(path)
102
+ player.is_moving = true
103
+ end
104
+ end
105
+
106
+ def button_down(id)
107
+ if id == Gosu::KB_LEFT
108
+ check_available_move(3, @player)
109
+ end
110
+
111
+ if id == Gosu::KB_RIGHT
112
+ check_available_move(1, @player)
113
+ end
114
+
115
+ if id == Gosu::KB_UP
116
+ check_available_move(0, @player)
117
+ end
118
+
119
+ if id == Gosu::KB_DOWN
120
+ check_available_move(2, @player)
121
+ end
122
+
123
+ # control keys for player 2
124
+ if @game_mode == 2
125
+
126
+ if id == Gosu::KB_A
127
+ check_available_move(3, @player_2)
128
+ end
129
+
130
+ if id == Gosu::KB_D
131
+ check_available_move(1, @player_2)
132
+ end
133
+
134
+ if id == Gosu::KB_W
135
+ check_available_move(0, @player_2)
136
+ end
137
+
138
+ if id == Gosu::KB_S
139
+ check_available_move(2, @player_2)
140
+ end
141
+
142
+ end
143
+
144
+ if id == Gosu::KB_ESCAPE
145
+ close
146
+ else
147
+ super
148
+ end
149
+ end
150
+
151
+
152
+ end
153
+ end
@@ -1,21 +1,99 @@
1
1
  module AMazeIng
2
2
  class Infor
3
- attr_accessor :level
4
- def initialize
5
- @level = 1
6
- @label = 'LEVEL'
3
+ attr_accessor :level, :player_1_point, :player_2_point
4
+ def initialize(*player_color)
5
+ @player_color = player_color
6
+ if @player_color.length == 2
7
+ @initial_block = lambda {
8
+ @player_1_color = player_color[0]
9
+ @player_2_color = player_color[1]
10
+
11
+ @level = 1
12
+ @level_image = Gosu::Image.from_text @level.to_s, 36
13
+ @label = 'LEVEL'
14
+ @label_image = Gosu::Image.from_text @label, 40
15
+
16
+ @x = center_x(@label_image.width)
17
+ @y_1 = 210
18
+ @y_2 = 290
19
+
20
+ @player_1_point = 0
21
+ @player_2_point = 0
7
22
 
8
- @label_image = Gosu::Image.from_text @label, 40
23
+ @player_1_point_image = Gosu::Image.from_text @player_1_point.to_s, 36
24
+ @player_2_point_image = Gosu::Image.from_text @player_2_point.to_s, 36
25
+ }
26
+ @update_block = lambda {
27
+ @level_image = Gosu::Image.from_text @level.to_s, 36
28
+ @player_1_point_image = Gosu::Image.from_text @player_1_point.to_s, 36
29
+ @player_2_point_image = Gosu::Image.from_text @player_2_point.to_s, 36
30
+ }
31
+ @draw_block = lambda {
32
+ @label_image.draw(center_x(@label_image.width), 80, 1)
33
+ @level_image.draw(center_x(@level_image.width), 130, 1)
34
+
35
+ draw_quad @x, @y_1, @player_1_color,
36
+ @x+30, @y_1, @player_1_color,
37
+ @x+30, @y_1+30, @player_1_color,
38
+ @x, @y_1+30, @player_1_color
39
+
40
+ draw_quad @x, @y_2, @player_2_color,
41
+ @x+30, @y_2, @player_2_color,
42
+ @x+30, @y_2+30, @player_2_color,
43
+ @x, @y_2+30, @player_2_color
44
+
45
+ @player_1_point_image.draw(@x + 60, @y_1, 1)
46
+ @player_2_point_image.draw(@x + 60, @y_2, 1)
47
+ }
48
+ end
49
+
50
+ if @player_color.length == 0
51
+ @initial_block = lambda {
52
+ @level = 1
53
+ @label = 'LEVEL'
54
+ @label_image = Gosu::Image.from_text @label, 40
55
+ }
56
+ @update_block = lambda {
57
+ @level_image = Gosu::Image.from_text @level.to_s, 36
58
+ }
59
+ @draw_block = lambda {
60
+ @label_image.draw(center_x(@label_image.width), 80, 1)
61
+ @level_image.draw(center_x(@level_image.width), 130, 1)
62
+ }
63
+ end
64
+ @initial_block.call
9
65
  end
10
66
 
11
67
  def center_x(width)
12
68
  return $dimension + SIDE_BAR/2 - width/2
13
69
  end
14
70
 
71
+ def update
72
+ @update_block.call
73
+ # @level_image = Gosu::Image.from_text @level.to_s, 36
74
+ # @player_1_point_image = Gosu::Image.from_text @player_1_point.to_s, 36
75
+ # @player_2_point_image = Gosu::Image.from_text @player_2_point.to_s, 36
76
+ end
77
+
15
78
  def draw
16
- @level_image = Gosu::Image.from_text @level.to_s, 36
17
- @label_image.draw(center_x(@label_image.width), 80, 1)
18
- @level_image.draw(center_x(@level_image.width), 130, 1)
79
+ @draw_block.call
80
+ # @label_image.draw(center_x(@label_image.width), 80, 1)
81
+ # @level_image.draw(center_x(@level_image.width), 130, 1)
82
+
83
+ # draw_quad @x, @y_1, @player_1_color,
84
+ # @x+30, @y_1, @player_1_color,
85
+ # @x+30, @y_1+30, @player_1_color,
86
+ # @x, @y_1+30, @player_1_color
87
+
88
+ # draw_quad @x, @y_2, @player_2_color,
89
+ # @x+30, @y_2, @player_2_color,
90
+ # @x+30, @y_2+30, @player_2_color,
91
+ # @x, @y_2+30, @player_2_color
92
+
93
+ # @player_1_point_image.draw(@x + 60, @y_1, 1)
94
+ # @player_1_point_image.draw(@x + 60, @y_2, 1)
95
+
96
+
19
97
  end
20
98
  end
21
99
  end
@@ -1,19 +1,5 @@
1
- #!/usr/bin/env ruby
2
- # credits to: http://en.wikipedia.org/wiki/Maze_generation_algorithm
3
- require 'gosu'
4
- include Gosu
5
-
6
1
  module AMazeIng
7
- DIMENSION = 700
8
- SIDE_BAR = 180
9
- class GameWindow < Window
10
- $rows = $cols = 10
11
- def initialize(full_screen)
12
- super DIMENSION + SIDE_BAR, DIMENSION, full_screen, 1
13
- self.caption = "Maze"
14
- generate_maze
15
- @infor = Infor.new
16
- end
2
+ class Maze
17
3
 
18
4
  def check_dimension
19
5
  until $dimension/$cols % 4 == 0
@@ -30,7 +16,7 @@ module AMazeIng
30
16
 
31
17
  $cells = Array.new
32
18
  @stack = Array.new
33
- @player = Player.new
19
+
34
20
 
35
21
  $rows.times do |row_index|
36
22
  $cols.times do |col_index|
@@ -80,90 +66,5 @@ module AMazeIng
80
66
  end
81
67
  end
82
68
 
83
- def draw_target(cell)
84
- cell_index_x = cell.cell_index_x
85
- cell_index_y = cell.cell_index_y
86
- x = (cell_index_x * $cell_size) + $cell_size/2 - $player_size/2
87
- y = (cell_index_y * $cell_size) + $cell_size/2 - $player_size/2
88
- draw_quad x, y, Color::GREEN,
89
- x+$player_size, y, Color::GREEN,
90
- x+$player_size, y+$player_size, Color::GREEN,
91
- x, y+$player_size, Color::GREEN
92
- end
93
-
94
- def check_for_finish
95
- if @player.cell_index_x == $cells[-1].cell_index_x && @player.cell_index_y == $cells[-1].cell_index_y
96
- $rows += 2
97
- $cols += 2
98
- generate_maze
99
- @infor.level += 1
100
- end
101
- end
102
-
103
- def update
104
- check_for_finish
105
- end
106
-
107
- def draw
108
- $cells.each do |cell|
109
- if cell.visited
110
- cell.draw($cell_size, Color::BLUE)
111
- else
112
- cell.draw($cell_size, Color::GREEN)
113
- end
114
- end
115
- @player.draw
116
- @player.move
117
- @infor.draw
118
- draw_target($cells[-1])
119
- end
120
-
121
- def button_down(id)
122
- if id == Gosu::KB_LEFT
123
- if !$cells[@player.cell_index_x + @player.cell_index_y * $cols].walls[3]
124
-
125
- @player.path = 3
126
- @player.cell_index_x -= 1
127
- @player.set_target
128
- @player.is_moving = true
129
- end
130
- end
131
-
132
- if id == Gosu::KB_RIGHT
133
- if !$cells[@player.cell_index_x + @player.cell_index_y * $cols].walls[1]
134
-
135
- @player.path = 1
136
- @player.cell_index_x += 1
137
- @player.set_target
138
- @player.is_moving = true
139
- end
140
- end
141
-
142
- if id == Gosu::KB_UP
143
- if !$cells[@player.cell_index_x + @player.cell_index_y * $cols].walls[0]
144
-
145
- @player.path = 0
146
- @player.cell_index_y -= 1
147
- @player.set_target
148
- @player.is_moving = true
149
- end
150
- end
151
-
152
- if id == Gosu::KB_DOWN
153
- if !$cells[@player.cell_index_x + @player.cell_index_y * $cols].walls[2]
154
-
155
- @player.path = 2
156
- @player.cell_index_y += 1
157
- @player.set_target
158
- @player.is_moving = true
159
- end
160
- end
161
-
162
- if id == Gosu::KB_ESCAPE
163
- close
164
- else
165
- super
166
- end
167
- end
168
69
  end
169
- end
70
+ end
@@ -1,9 +1,10 @@
1
1
  module AMazeIng
2
2
  class Player
3
- attr_accessor :cell_index_x, :cell_index_y, :color, :target_x, :target_y, :is_moving, :path
4
- def initialize
5
- @color = Color::RED
6
- @cell_index_x = @cell_index_y = 0
3
+ attr_accessor :cell_index_x, :cell_index_y, :target_x, :target_y, :is_moving, :path
4
+ def initialize(cell_index_x, cell_index_y, color)
5
+ @color = color
6
+ @cell_index_x = cell_index_x
7
+ @cell_index_y = cell_index_y
7
8
  @is_moving = false
8
9
  @path = nil
9
10
  set_target
@@ -31,6 +32,20 @@ module AMazeIng
31
32
  return path
32
33
  end
33
34
 
35
+ def set_status(path)
36
+ @path = path
37
+ if @path == 0
38
+ @cell_index_y -= 1
39
+ elsif @path == 1
40
+ @cell_index_x += 1
41
+ elsif @path == 2
42
+ @cell_index_y += 1
43
+ else
44
+ @cell_index_x -= 1
45
+ end
46
+ set_target
47
+ end
48
+
34
49
  def move
35
50
  if @is_moving
36
51
  if @x == @target_x && @y == @target_y
@@ -42,19 +57,11 @@ module AMazeIng
42
57
  @path == 2 ? 0: 1)
43
58
  if @path != nil
44
59
  # set new player's cell index depend on "current @path"
45
- if @path == 0
46
- @cell_index_y -= 1
47
- elsif @path == 1
48
- @cell_index_x += 1
49
- elsif @path == 2
50
- @cell_index_y += 1
51
- else
52
- @cell_index_x -= 1
53
- end
60
+ set_status(@path)
54
61
  set_target
55
62
  else
56
63
 
57
- # no "available" @path found player stop moving
64
+ # no "available" path found, player stop moving
58
65
  @is_moving = false
59
66
  end
60
67
  else
@@ -1,3 +1,3 @@
1
1
  module AMazeIng
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/a_maze_ing.rb CHANGED
@@ -3,4 +3,5 @@ require "a_maze_ing/cell"
3
3
  require "a_maze_ing/player"
4
4
  require "a_maze_ing/infor"
5
5
  require "a_maze_ing/maze"
6
- require "a_maze_ing/cli"
6
+ require "a_maze_ing/cli"
7
+ require "a_maze_ing/game_window"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: a_maze_ing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - at-cuongtran
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- - !ruby/object:Gem::Dependency
56
- name: gosu
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 0.12.0
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 0.12.0
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: commander
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,8 +66,8 @@ dependencies:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
68
  version: 4.4.3
83
- description: "A fun and easy to play maze game with graphic. \n Maze randomly generate
84
- with difficulty increase evey level"
69
+ description: A maze game that is fun and easy to play, available for 2 player with
70
+ 2D graphics render by Gosu library.
85
71
  email:
86
72
  - tranhuu.phucuong@gmail.com
87
73
  executables:
@@ -99,11 +85,13 @@ files:
99
85
  - bin/a_maze_ing
100
86
  - bin/console
101
87
  - bin/setup
102
- - images/cover.jpg
88
+ - images/classic.jpg
89
+ - images/multiplayer.jpg
103
90
  - lib/a_maze_ing.rb
104
91
  - lib/a_maze_ing/cell.rb
105
92
  - lib/a_maze_ing/cli.rb
106
93
  - lib/a_maze_ing/configuration.rb
94
+ - lib/a_maze_ing/game_window.rb
107
95
  - lib/a_maze_ing/infor.rb
108
96
  - lib/a_maze_ing/maze.rb
109
97
  - lib/a_maze_ing/player.rb
File without changes