a_maze_ing 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -4
- data/images/annoying_friend.jpg +0 -0
- data/images/classic.jpg +0 -0
- data/images/multiplayer.jpg +0 -0
- data/lib/a_maze_ing/cell.rb +2 -2
- data/lib/a_maze_ing/cli.rb +14 -2
- data/lib/a_maze_ing/game_window.rb +40 -16
- data/lib/a_maze_ing/maze.rb +28 -16
- data/lib/a_maze_ing/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e82ad01583c85bbed0d72e448782de05d0e83a16
|
4
|
+
data.tar.gz: 6bcb06478a9d7ff899fba4970ca12282c24543c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39deed34083af90d8a56d15a0e107aa6440ff60af2c9d8fa6118018e83a97e78679dbc1a8d8e3b17b38af73085e080c48b1de345d1246637a53d2258a7584ec3
|
7
|
+
data.tar.gz: 737d15e2dfd466083f3180ce4c8e242d10b33ea28a92a0137a88f60fdf95af4b195809beda395eb0ba47a72be1ad4fb092ff5a4db42d9ef218c4ceb35b9a2e8f
|
data/README.md
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# AMazeIng
|
2
2
|
|
3
|
-
This is a small video game about maze, create on Gosu library.
|
3
|
+
This is a small video game about maze, create on Gosu library. Solve the maze yourself or play with friend.
|
4
4
|
|
5
|
-
Classic mode
|
5
|
+
Classic mode | Multiplayer mode
|
6
6
|
:-------------------------:|:-------------------------:
|
7
7
|
 | 
|
8
8
|
|
9
|
+
Annoying Friend mode |
|
10
|
+
:-------------------------:|:-------------------------:
|
11
|
+
 |
|
12
|
+
|
9
13
|
## Requirements
|
10
14
|
|
11
15
|
This gem needs [Gosu](https://www.libgosu.org/) installed on your machine in order to render graphics
|
@@ -38,9 +42,13 @@ or
|
|
38
42
|
|
39
43
|
$ a_maze_ing classic
|
40
44
|
|
41
|
-
To play in
|
45
|
+
To play in Multiplayer mode run the following command:
|
46
|
+
|
47
|
+
$ a_maze_ing m
|
48
|
+
|
49
|
+
To play in Annoying Friend mode run the following command:
|
42
50
|
|
43
|
-
$ a_maze_ing
|
51
|
+
$ a_maze_ing af
|
44
52
|
|
45
53
|
Global Options:
|
46
54
|
|
Binary file
|
data/images/classic.jpg
CHANGED
Binary file
|
data/images/multiplayer.jpg
CHANGED
Binary file
|
data/lib/a_maze_ing/cell.rb
CHANGED
@@ -13,13 +13,13 @@ module AMazeIng
|
|
13
13
|
|
14
14
|
def cell_index(i, j, cells_length)
|
15
15
|
if i < 0 || j < 0 || i > $cols-1 || j > $rows-1
|
16
|
-
return cells_length
|
16
|
+
return cells_length # cause the cell (neighbor) equal nil
|
17
17
|
else
|
18
18
|
return i + j * $cols
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def get_random_neighbor(cells)
|
23
23
|
@neigh_bors = Array.new
|
24
24
|
|
25
25
|
top = cells[cell_index(cell_index_x, cell_index_y - 1, cells.length)]
|
data/lib/a_maze_ing/cli.rb
CHANGED
@@ -20,6 +20,7 @@ module AMazeIng
|
|
20
20
|
@full_screen = true
|
21
21
|
}
|
22
22
|
|
23
|
+
|
23
24
|
command :classic do |c|
|
24
25
|
c.syntax = 'a_maze_ing classic [options]'
|
25
26
|
c.description = 'Classic mode, difficulty increase with level'
|
@@ -30,12 +31,23 @@ module AMazeIng
|
|
30
31
|
|
31
32
|
command :multiplayer do |c|
|
32
33
|
c.syntax = 'a_maze_ing multiplayer [options]'
|
33
|
-
c.description = 'Multiplayer mode, two player race to the
|
34
|
+
c.description = 'Multiplayer mode, two player race to the gate, player 2 use W/S/A/D key to move up/down/left/right'
|
34
35
|
c.action do
|
35
36
|
AMazeIng::GameWindow.new(@full_screen,2).show
|
36
37
|
end
|
37
38
|
end
|
38
|
-
|
39
|
+
alias_command :'m', :multiplayer
|
40
|
+
|
41
|
+
|
42
|
+
command :annoying_friend do |c|
|
43
|
+
c.syntax = 'a_maze_ing anfri [options]'
|
44
|
+
c.description = 'feuded friend mode, player 1 try to get to the gate while the player 2(annoying friend) try to catch him'
|
45
|
+
c.action do
|
46
|
+
AMazeIng::GameWindow.new(@full_screen,3).show
|
47
|
+
end
|
48
|
+
end
|
49
|
+
alias_command :'af', :annoying_friend, :'anfri', :'multiplayer2', :'multiplayer_2'
|
50
|
+
|
39
51
|
run!
|
40
52
|
end
|
41
53
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# cGREENits to: http://en.wikipedia.org/wiki/Maze_generation_algorithm
|
3
3
|
|
4
4
|
require 'gosu'
|
5
5
|
include Gosu
|
@@ -20,20 +20,28 @@ module AMazeIng
|
|
20
20
|
if @game_mode == 1
|
21
21
|
@infor = Infor.new
|
22
22
|
elsif @game_mode == 2
|
23
|
-
@infor = Infor.new(Color::
|
23
|
+
@infor = Infor.new(Color::GREEN, Color::AQUA)
|
24
|
+
elsif @game_mode == 3
|
25
|
+
@infor = Infor.new(Color::GREEN, Color::RED)
|
24
26
|
end
|
25
27
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def new_round
|
31
|
+
$rows += 2
|
32
|
+
$cols += 2
|
29
33
|
@maze = Maze.new
|
30
34
|
@maze.generate_maze
|
31
35
|
if @game_mode == 1
|
32
|
-
@player = Player.new(1, 0, Color::
|
36
|
+
@player = Player.new(1, 0, Color::GREEN)
|
33
37
|
elsif @game_mode == 2
|
34
|
-
@player = Player.new(1, 0, Color::
|
35
|
-
@player_2 = Player.new(0, 1, Color::
|
38
|
+
@player = Player.new(1, 0, Color::GREEN)
|
39
|
+
@player_2 = Player.new(0, 1, Color::AQUA)
|
40
|
+
elsif @game_mode == 3
|
41
|
+
@player = Player.new(1, 0, Color::GREEN)
|
42
|
+
@player_2 = Player.new($cols-1, 0, Color::RED)
|
36
43
|
end
|
44
|
+
|
37
45
|
end
|
38
46
|
|
39
47
|
def draw_target(cell)
|
@@ -41,16 +49,14 @@ module AMazeIng
|
|
41
49
|
cell_index_y = cell.cell_index_y
|
42
50
|
x = (cell_index_x * $cell_size) + $cell_size/2 - $player_size/2
|
43
51
|
y = (cell_index_y * $cell_size) + $cell_size/2 - $player_size/2
|
44
|
-
draw_quad x, y, Color::
|
45
|
-
x+$player_size, y, Color::
|
46
|
-
x+$player_size, y+$player_size, Color::
|
47
|
-
x, y+$player_size, Color::
|
52
|
+
draw_quad x, y, Color::WHITE,
|
53
|
+
x+$player_size, y, Color::WHITE,
|
54
|
+
x+$player_size, y+$player_size, Color::WHITE,
|
55
|
+
x, y+$player_size, Color::WHITE
|
48
56
|
end
|
49
57
|
|
50
58
|
def check_for_finish(player)
|
51
59
|
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
60
|
new_round
|
55
61
|
@infor.level += 1
|
56
62
|
return true
|
@@ -59,14 +65,22 @@ module AMazeIng
|
|
59
65
|
end
|
60
66
|
end
|
61
67
|
|
68
|
+
def check_for_collision(player_1, player_2)
|
69
|
+
if player_2.cell_index_x == player_1.cell_index_x and player_2.cell_index_y == player_1.cell_index_y
|
70
|
+
new_round
|
71
|
+
@infor.level += 1
|
72
|
+
return true
|
73
|
+
else
|
74
|
+
return false
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
62
78
|
def update
|
63
79
|
|
64
80
|
if @game_mode == 1
|
65
81
|
check_for_finish(@player)
|
66
82
|
@player.move
|
67
|
-
|
68
|
-
|
69
|
-
if @game_mode == 2
|
83
|
+
elsif @game_mode == 2
|
70
84
|
if check_for_finish(@player)
|
71
85
|
@infor.player_1_point += 1
|
72
86
|
end
|
@@ -75,7 +89,17 @@ module AMazeIng
|
|
75
89
|
@infor.player_2_point += 1
|
76
90
|
end
|
77
91
|
@player_2.move
|
92
|
+
elsif @game_mode == 3
|
93
|
+
if check_for_finish(@player)
|
94
|
+
@infor.player_1_point += 1
|
95
|
+
end
|
96
|
+
@player.move
|
97
|
+
if check_for_collision(@player, @player_2)
|
98
|
+
@infor.player_2_point += 1
|
99
|
+
end
|
100
|
+
@player_2.move
|
78
101
|
end
|
102
|
+
|
79
103
|
@infor.update
|
80
104
|
end
|
81
105
|
|
@@ -88,7 +112,7 @@ module AMazeIng
|
|
88
112
|
end
|
89
113
|
end
|
90
114
|
@player.draw
|
91
|
-
@player_2.draw if @game_mode == 2
|
115
|
+
@player_2.draw if @game_mode == 2 or @game_mode == 3
|
92
116
|
@infor.draw
|
93
117
|
draw_target($cells[-1])
|
94
118
|
end
|
@@ -121,7 +145,7 @@ module AMazeIng
|
|
121
145
|
end
|
122
146
|
|
123
147
|
# control keys for player 2
|
124
|
-
if @game_mode == 2
|
148
|
+
if @game_mode == 2 or @game_mode == 3
|
125
149
|
|
126
150
|
if id == Gosu::KB_A
|
127
151
|
check_available_move(3, @player_2)
|
data/lib/a_maze_ing/maze.rb
CHANGED
@@ -31,7 +31,7 @@ module AMazeIng
|
|
31
31
|
@stack.push(@current_cell)
|
32
32
|
|
33
33
|
while @stack.length > 0 do
|
34
|
-
next_cell = @current_cell.
|
34
|
+
next_cell = @current_cell.get_random_neighbor($cells)
|
35
35
|
if next_cell
|
36
36
|
remove_walls(@current_cell, next_cell)
|
37
37
|
next_cell.visited = true
|
@@ -43,28 +43,40 @@ module AMazeIng
|
|
43
43
|
@current_cell = @stack.pop
|
44
44
|
end
|
45
45
|
end
|
46
|
+
remove_extra_walls
|
46
47
|
end
|
47
48
|
|
48
49
|
def remove_walls(current_cell, next_cell)
|
49
|
-
|
50
|
-
|
51
|
-
# next cell is on the right
|
52
|
-
current_cell.walls[1] = next_cell.walls[3] = false
|
53
|
-
elsif magic_number == -1
|
54
|
-
# next cell is on the left
|
55
|
-
current_cell.walls[3] = next_cell.walls[1] = false
|
56
|
-
elsif magic_number == 0
|
57
|
-
# next cell is either on top or bottom
|
58
|
-
magic_number = next_cell.cell_index_y - current_cell.cell_index_y
|
50
|
+
if next_cell != nil
|
51
|
+
magic_number = next_cell.cell_index_x - current_cell.cell_index_x
|
59
52
|
if magic_number == 1
|
60
|
-
#next cell is
|
61
|
-
current_cell.walls[
|
62
|
-
elsif magic_number
|
63
|
-
#next cell is on
|
64
|
-
current_cell.walls[
|
53
|
+
# next cell is on the right
|
54
|
+
current_cell.walls[1] = next_cell.walls[3] = false
|
55
|
+
elsif magic_number == -1
|
56
|
+
# next cell is on the left
|
57
|
+
current_cell.walls[3] = next_cell.walls[1] = false
|
58
|
+
elsif magic_number == 0
|
59
|
+
# next cell is either on top or bottom
|
60
|
+
magic_number = next_cell.cell_index_y - current_cell.cell_index_y
|
61
|
+
if magic_number == 1
|
62
|
+
#next cell is bottom
|
63
|
+
current_cell.walls[2] = next_cell.walls[0] = false
|
64
|
+
elsif magic_number ==-1
|
65
|
+
#next cell is on top
|
66
|
+
current_cell.walls[0] = next_cell.walls[2] = false
|
67
|
+
end
|
65
68
|
end
|
66
69
|
end
|
67
70
|
end
|
68
71
|
|
72
|
+
def remove_extra_walls
|
73
|
+
a_count_number = $cells.length/2/5
|
74
|
+
while a_count_number > 0 do
|
75
|
+
cell_index = rand(0..$cells.length/2)
|
76
|
+
# wall_index = rand(0..3)
|
77
|
+
remove_walls($cells[cell_index], $cells[cell_index+1])
|
78
|
+
a_count_number -= 1
|
79
|
+
end
|
80
|
+
end
|
69
81
|
end
|
70
82
|
end
|
data/lib/a_maze_ing/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: a_maze_ing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- at-cuongtran
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- bin/a_maze_ing
|
86
86
|
- bin/console
|
87
87
|
- bin/setup
|
88
|
+
- images/annoying_friend.jpg
|
88
89
|
- images/classic.jpg
|
89
90
|
- images/multiplayer.jpg
|
90
91
|
- lib/a_maze_ing.rb
|