blast_mavens_multiplayer 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.md +55 -0
- data/bin/blast_mavens +1 -2
- data/config/boot.rb +6 -0
- data/lib/basic_brain.rb +25 -0
- data/lib/bomb.rb +28 -0
- data/lib/explosion.rb +22 -0
- data/lib/game_over_window.rb +35 -0
- data/lib/game_window.rb +60 -0
- data/lib/map.rb +58 -0
- data/lib/menu_window.rb +69 -0
- data/lib/player.rb +132 -0
- data/lib/processor.rb +66 -0
- data/lib/solid_tile.rb +12 -0
- data/lib/tileable.rb +28 -0
- data/resources/images/cursor.png +0 -0
- data/resources/images/dynamite.png +0 -0
- data/resources/images/exitgame.png +0 -0
- data/resources/images/explosion.png +0 -0
- data/resources/images/menu.png +0 -0
- data/resources/images/newgame.png +0 -0
- data/resources/images/options.png +0 -0
- data/resources/images/player_down0.png +0 -0
- data/resources/images/player_down1.png +0 -0
- data/resources/images/player_left0.png +0 -0
- data/resources/images/player_left1.png +0 -0
- data/resources/images/player_right0.png +0 -0
- data/resources/images/player_right1.png +0 -0
- data/resources/images/player_up0.png +0 -0
- data/resources/images/player_up1.png +0 -0
- data/resources/images/tileset.png +0 -0
- data/resources/images/title.png +0 -0
- data/resources/maps/basic.txt +16 -0
- data/resources/maps/open.txt +16 -0
- data/resources/sounds/battle.mp3 +0 -0
- data/resources/sounds/boom.wav +0 -0
- data/resources/sounds/menu.wav +0 -0
- data/resources/sounds/menu_2.mp3 +0 -0
- metadata +40 -3
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Nickolay Schwarz
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Blast Mavens Multiplayer Beta #
|
2
|
+
|
3
|
+
Blast Mavens Multiplayer is 2D game written in ruby using [Gosu libruary](http://github.com/jlnr/gosu) inspired by the [bomberman](http://en.wikipedia.org/wiki/Bomberman).
|
4
|
+
|
5
|
+
## Installation ##
|
6
|
+
|
7
|
+
Install it from the gem:
|
8
|
+
gem install blast_mavens_multiplayer
|
9
|
+
|
10
|
+
Run it via:
|
11
|
+
blast_mavens_multiplayer
|
12
|
+
|
13
|
+
-OR-
|
14
|
+
|
15
|
+
Alternatively you can check out the code from this repository and run game.rb.
|
16
|
+
|
17
|
+
## Controls ##
|
18
|
+
|
19
|
+
Until help hints will be implemented in-game, until options will be implemented in-game you will have to use the following controls:
|
20
|
+
|
21
|
+
* **ESC** exit the game, close all the windows
|
22
|
+
* **NUMPAD+** increase the volume of the music
|
23
|
+
* **NUMPAD-** decrease the volume of the music
|
24
|
+
* **W** Player 1 up
|
25
|
+
* **A** Player 1 left
|
26
|
+
* **S** Player 1 down
|
27
|
+
* **D** Player 1 right
|
28
|
+
* **Space** Player 1 place dynamite
|
29
|
+
* **UP** Player 2 up
|
30
|
+
* **LEFT** Player 2 left
|
31
|
+
* **DOWN** Player 2 down
|
32
|
+
* **RIGHT** Player 2 right
|
33
|
+
* **RIGHTSHIFT** Player 2 place dynamite
|
34
|
+
|
35
|
+
## Purpose ##
|
36
|
+
|
37
|
+
This game (repository) will serve as a base for the open AI competition as well as different single player AI scripts. For repo, api and documentation as
|
38
|
+
well as examples of the AI scripts could be found [here]().
|
39
|
+
|
40
|
+
## Notes ##
|
41
|
+
|
42
|
+
All art, functionality are subject to change. Tons of features yet to be implemented.
|
43
|
+
You can change map by modifying basic.txt under maps with any editor.
|
44
|
+
|
45
|
+
## Copyright ##
|
46
|
+
|
47
|
+
Copyright (c) 2011 Nickolay Schwarz. See LICENSE.txt for further details.
|
48
|
+
|
49
|
+
Art and acknowledgments:
|
50
|
+
|
51
|
+
* mrpoly - CC0 (menu music track 1)
|
52
|
+
* Marcus Rasseli - CC-BY 3.0 (battle music track 1)
|
53
|
+
* Paulius Jurgelevičius - CC0 (menu music track 2)
|
54
|
+
* Cuzco - explosion(CC0) animation (modified)
|
55
|
+
* Badassbill - pg_hero served as a base for idea for character animation (unreached)
|
data/bin/blast_mavens
CHANGED
data/config/boot.rb
ADDED
data/lib/basic_brain.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
class BasicBrain
|
2
|
+
def initialize(brainholder, enemy)
|
3
|
+
@me = brainholder
|
4
|
+
@you = enemy
|
5
|
+
@move_control = {:left => [:left, [-1, 0],[0, 0, 0, 40]],
|
6
|
+
:right => [:right, [1, 0], [40, 0, 40, 40]],
|
7
|
+
:up => [:up, [0, -1],[40, 0, 0, 0]],
|
8
|
+
:down => [:down, [0, 1],[40, 40, 0, 40 ]]}
|
9
|
+
end
|
10
|
+
|
11
|
+
def move_instructions
|
12
|
+
x_diff = @me.x - @you.x
|
13
|
+
y_diff = @me.y - @you.y
|
14
|
+
|
15
|
+
return @move_control[:left] if x_diff > 24
|
16
|
+
return @move_control[:right] if x_diff < -24
|
17
|
+
return @move_control[:up] if y_diff > 24
|
18
|
+
return @move_control[:down] if y_diff < -24
|
19
|
+
return nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def placing_bomb?
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
end
|
data/lib/bomb.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class Bomb
|
2
|
+
include Tileable
|
3
|
+
|
4
|
+
attr_accessor :time_counter, :solid
|
5
|
+
def initialize(x,y)
|
6
|
+
register!(x, y)
|
7
|
+
@t_size = Processor::TileSize
|
8
|
+
@sprites = Gosu::Image.load_tiles(Processor.game_window, "resources/images/dynamite.png", @t_size, @t_size, false)
|
9
|
+
@time_counter = 80
|
10
|
+
@sprite_index = 0
|
11
|
+
@solid = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def draw
|
15
|
+
@sprites[@sprite_index].draw(top_x, top_y, 1)
|
16
|
+
update
|
17
|
+
end
|
18
|
+
|
19
|
+
def update
|
20
|
+
@time_counter -= 1
|
21
|
+
@sprite_index += 1 if @time_counter % 20 == 0
|
22
|
+
@sprite_index = 3 if @sprite_index > 3
|
23
|
+
end
|
24
|
+
|
25
|
+
def solid_at?(x, y)
|
26
|
+
@solid && at?(x, y)
|
27
|
+
end
|
28
|
+
end
|
data/lib/explosion.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class Explosion
|
2
|
+
include Tileable
|
3
|
+
attr_accessor :time_counter
|
4
|
+
|
5
|
+
def initialize(x,y)
|
6
|
+
register!(x, y)
|
7
|
+
@t_size = Processor::TileSize
|
8
|
+
@sprites = Gosu::Image.load_tiles(Processor.game_window, "resources/images/explosion.png", @t_size, @t_size, false)
|
9
|
+
@time_counter = 20
|
10
|
+
@sprite_index = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def draw
|
14
|
+
@sprites[@sprite_index].draw(top_x, top_y, 2)
|
15
|
+
update
|
16
|
+
end
|
17
|
+
|
18
|
+
def update
|
19
|
+
@time_counter -= 1
|
20
|
+
@sprite_index += 1 if @time_counter % 2 == 0
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class GameOverWindow < Gosu::Window
|
2
|
+
|
3
|
+
def initialize(death_toll)
|
4
|
+
super(*Processor::Screen)
|
5
|
+
self.caption = Processor::Caption
|
6
|
+
@font = Gosu::Font.new(self, Gosu::default_font_name, 20)
|
7
|
+
@death_toll = death_toll
|
8
|
+
end
|
9
|
+
|
10
|
+
def draw
|
11
|
+
@font.draw('It is a draw, both players died', 200, 200, 1) if draw?
|
12
|
+
@font.draw("Player 2 won. Player 1 was blown up by #{killer(:player_0)}", 200, 200, 1) if player_0_hit?
|
13
|
+
@font.draw("Player 1 won. Player 2 was blown up by #{killer(:player_1)}", 200, 200, 1) if player_1_hit?
|
14
|
+
end
|
15
|
+
|
16
|
+
def draw?
|
17
|
+
player_0_hit? && player_1_hit?
|
18
|
+
end
|
19
|
+
|
20
|
+
def player_0_hit?
|
21
|
+
!@death_toll[:player_0].empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
def player_1_hit?
|
25
|
+
!@death_toll[:player_1].empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
def killer(player)
|
29
|
+
"Player #{@death_toll[player].first.to_s[-1..-1].to_i + 1}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def button_down(id)
|
33
|
+
close if id == Gosu::KbEscape
|
34
|
+
end
|
35
|
+
end
|
data/lib/game_window.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
class GameWindow < Gosu::Window
|
2
|
+
def initialize
|
3
|
+
super(*Processor::Screen)
|
4
|
+
self.caption = Processor::Caption
|
5
|
+
@players_hit = {:player_0 => [], :player_1 => []}
|
6
|
+
@finish_game = false
|
7
|
+
@song = Gosu::Song.new(self, 'resources/sounds/battle.mp3')
|
8
|
+
@song.volume = 0.3
|
9
|
+
@song.play(true)
|
10
|
+
end
|
11
|
+
|
12
|
+
def map
|
13
|
+
@map ||= Map.new('resources/maps/basic.txt')
|
14
|
+
end
|
15
|
+
|
16
|
+
def draw
|
17
|
+
map.draw(0, 0)
|
18
|
+
Processor.players.each do |player|
|
19
|
+
player.draw
|
20
|
+
player.bombs.each(&:draw)
|
21
|
+
player.explosions.each(&:draw)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
Processor.players.each_with_index do |player, index|
|
27
|
+
player.update
|
28
|
+
player.explosions.each do |explosion|
|
29
|
+
Processor.all_bombs.each do |bomb|
|
30
|
+
bomb.time_counter = 1 if explosion.at?(bomb.top_x, bomb.top_y)
|
31
|
+
end
|
32
|
+
players_hit?(explosion, index)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
if @finish_game && Processor.players.map(&:explosions).flatten.empty?
|
37
|
+
@song.stop
|
38
|
+
Processor.game_over(@players_hit)
|
39
|
+
close
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def button_down(id)
|
45
|
+
close if id == Gosu::KbEscape
|
46
|
+
@song.volume -= 0.1 if id == Gosu::KbNumpadSubtract
|
47
|
+
@song.volume += 0.1 if id == Gosu::KbNumpadAdd
|
48
|
+
end
|
49
|
+
|
50
|
+
def players_hit?(explosion, index)
|
51
|
+
Processor.players.each do |player|
|
52
|
+
if explosion.at?(player.x, player.y)
|
53
|
+
hit = "player_#{player.index}".to_sym
|
54
|
+
hit_by = "player_#{index}".to_sym
|
55
|
+
@players_hit[hit] << hit_by unless @players_hit[hit].include?(hit_by)
|
56
|
+
@finish_game = true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/map.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
class Map
|
2
|
+
attr_accessor :solid_tiles
|
3
|
+
SOLID = [1, 2, 3, 4, 5, 10]
|
4
|
+
|
5
|
+
def initialize(path)
|
6
|
+
@path = path
|
7
|
+
@t_size = Processor::TileSize
|
8
|
+
@set = Gosu::Image.load_tiles(Processor.game_window, 'resources/images/tileset.png', @t_size, @t_size, true)
|
9
|
+
register_solid_tiles
|
10
|
+
end
|
11
|
+
|
12
|
+
def draw(screen_x, screen_y)
|
13
|
+
tiles.each_with_index do |row_array, y|
|
14
|
+
row_array.each_with_index do |col, x|
|
15
|
+
@set[col].draw(x * @t_size, y * @t_size, 0) #z-order is 0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def tiles
|
21
|
+
@tiles ||= File.readlines(@path).inject([]) do |acc, line|
|
22
|
+
tile = []
|
23
|
+
line.strip.each_char do |char|
|
24
|
+
tile << legend[char]
|
25
|
+
end
|
26
|
+
acc << tile
|
27
|
+
acc
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def register_solid_tiles
|
32
|
+
@solid_tiles = []
|
33
|
+
tiles.each_with_index do |row, y|
|
34
|
+
row.each_with_index do |col, x|
|
35
|
+
@solid_tiles << SolidTile.new(x*@t_size, y*@t_size) if SOLID.include?(col)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def solid_at?(x,y)
|
41
|
+
@solid_tiles.detect {|tile| tile.at?(x,y) } || x < 0 || y < 0
|
42
|
+
end
|
43
|
+
|
44
|
+
def legend
|
45
|
+
{
|
46
|
+
'.' => 0,
|
47
|
+
'x' => 10,
|
48
|
+
']' => 2,
|
49
|
+
'-' => 3,
|
50
|
+
'=' => 1,
|
51
|
+
'[' => 5,
|
52
|
+
'/' => 6,
|
53
|
+
'\\' => 7,
|
54
|
+
'<' => 8,
|
55
|
+
'>' => 9
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
data/lib/menu_window.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
class MenuWindow < Gosu::Window
|
2
|
+
def initialize
|
3
|
+
super(*Processor::Screen)
|
4
|
+
self.caption = Processor::Caption
|
5
|
+
@pointer = Gosu::Image.new(self,"resources/images/cursor.png",true)
|
6
|
+
@background = Gosu::Image.load_tiles(self, 'resources/images/menu.png', 1024, 768, true).first
|
7
|
+
@title = Gosu::Image.load_tiles(self, 'resources/images/title.png', 350, 80, true)
|
8
|
+
@new_game = Gosu::Image.load_tiles(self, 'resources/images/newgame.png', 150, 40, true)
|
9
|
+
@options = Gosu::Image.load_tiles(self, 'resources/images/options.png', 150, 40, true)
|
10
|
+
@exit_game = Gosu::Image.load_tiles(self, 'resources/images/exitgame.png', 150, 40, true)
|
11
|
+
@song = Gosu::Song.new(self, 'resources/sounds/menu.wav')
|
12
|
+
@new_game_index = @options_index = @exit_game_index = 1
|
13
|
+
@song.play(true)
|
14
|
+
@song.volume = 0.3
|
15
|
+
@px = @py = 0
|
16
|
+
end
|
17
|
+
|
18
|
+
def update
|
19
|
+
@px, @py = mouse_x, mouse_y
|
20
|
+
update_hovers
|
21
|
+
end
|
22
|
+
|
23
|
+
def draw
|
24
|
+
@background.draw(0,0,0)
|
25
|
+
@title.first.draw(340, 190, 1)
|
26
|
+
@new_game[@new_game_index].draw(450, 280, 1)
|
27
|
+
@options[@options_index].draw(450, 330, 1)
|
28
|
+
@exit_game[@exit_game_index].draw(450, 380, 1)
|
29
|
+
@pointer.draw(@px,@py,2)
|
30
|
+
end
|
31
|
+
|
32
|
+
def mouse_clicked(x, y)
|
33
|
+
start_game if at_new_game?(x,y)
|
34
|
+
close if at_exit_game?(x,y)
|
35
|
+
end
|
36
|
+
|
37
|
+
def button_down(id)
|
38
|
+
close if id == Gosu::KbEscape
|
39
|
+
start_game if id == Gosu::KbReturn
|
40
|
+
mouse_clicked(@px, @py) if id == Gosu::MsLeft
|
41
|
+
@song.volume -= 0.1 if id == Gosu::KbNumpadSubtract
|
42
|
+
@song.volume += 0.1 if id == Gosu::KbNumpadAdd
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def update_hovers
|
47
|
+
@new_game_index = at_new_game?(@px, @py) ? 0 : 1
|
48
|
+
@options_index = at_options?(@px, @py) ? 0 : 1
|
49
|
+
@exit_game_index = at_exit_game?(@px, @py) ? 0 : 1
|
50
|
+
end
|
51
|
+
|
52
|
+
def at_new_game?(x,y)
|
53
|
+
(450..600).include?(x) && (280..320).include?(y)
|
54
|
+
end
|
55
|
+
|
56
|
+
def at_options?(x,y)
|
57
|
+
(450..600).include?(x) && (330..370).include?(y)
|
58
|
+
end
|
59
|
+
|
60
|
+
def at_exit_game?(x,y)
|
61
|
+
(450..600).include?(x) && (380..420).include?(y)
|
62
|
+
end
|
63
|
+
|
64
|
+
def start_game
|
65
|
+
close
|
66
|
+
@song.stop
|
67
|
+
Processor.start_game
|
68
|
+
end
|
69
|
+
end
|
data/lib/player.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
class Player
|
2
|
+
|
3
|
+
attr_reader :bombs, :explosions, :x, :y, :index
|
4
|
+
def initialize
|
5
|
+
@index = Processor.has_at_least_one_player? ? 1 : 0
|
6
|
+
@t_size = Processor::TileSize
|
7
|
+
#more animation to come
|
8
|
+
@facing = :down
|
9
|
+
@animation_sprites = {:left => Gosu::Image.load_tiles(Processor.game_window, "resources/images/player_left#{@index}.png", @t_size, @t_size, false),
|
10
|
+
:down => Gosu::Image.load_tiles(Processor.game_window, "resources/images/player_down#{@index}.png", @t_size, @t_size, false),
|
11
|
+
:up => Gosu::Image.load_tiles(Processor.game_window, "resources/images/player_up#{@index}.png", @t_size, @t_size, false),
|
12
|
+
:right => Gosu::Image.load_tiles(Processor.game_window, "resources/images/player_right#{@index}.png", @t_size, @t_size, false)}
|
13
|
+
@bombs = []
|
14
|
+
@explosions = []
|
15
|
+
@move_control = {[Gosu::Button::KbA, Gosu::Button::KbLeft] => [:left, [-1, 0],[0, 0, 0, 40]],
|
16
|
+
[Gosu::Button::KbD, Gosu::Button::KbRight] => [:right, [1, 0], [40, 0, 40, 40]],
|
17
|
+
[Gosu::Button::KbW, Gosu::Button::KbUp ] => [:up, [0, -1],[40, 0, 0, 0]],
|
18
|
+
[Gosu::Button::KbS, Gosu::Button::KbDown ] => [:down, [0, 1],[40, 40, 0, 40 ]]}
|
19
|
+
@bomb_control = [Gosu::Button::KbSpace, Gosu::Button::KbRightAlt]
|
20
|
+
@img_counter = 0
|
21
|
+
@img_index = 4
|
22
|
+
|
23
|
+
@x = @y = [@t_size * 1 + 1, @t_size * 14 + 1][@index]
|
24
|
+
# if @index == 1
|
25
|
+
# @brain = BasicBrain.new(self, Processor.players[0])
|
26
|
+
# end
|
27
|
+
end
|
28
|
+
|
29
|
+
def draw
|
30
|
+
@animation_sprites[@facing][@img_index].draw(@x, @y, 2)
|
31
|
+
end
|
32
|
+
|
33
|
+
def update
|
34
|
+
movement!
|
35
|
+
bombs!
|
36
|
+
end
|
37
|
+
|
38
|
+
def no_collision?(target)
|
39
|
+
target_x = @x+target[0]+target[2]
|
40
|
+
target_y = @y+target[1]+target[3]
|
41
|
+
!solid_at?(target_x, target_y) && !Processor.all_bombs.detect{|bomb| bomb.solid_at?(target_x, target_y)}
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def movement!
|
46
|
+
@img_counter += 1
|
47
|
+
move_instruct = @brain ? @brain.move_instructions : input_move_instructions
|
48
|
+
if move_instruct
|
49
|
+
@img_index = 0 unless (0..2).include?(@img_index)
|
50
|
+
@img_index += 1 if @img_counter % 5 == 0
|
51
|
+
x_y = move_instruct[1]
|
52
|
+
inc_x, inc_y = x_y
|
53
|
+
tar_x1, tar_y1, tar_x2, tar_y2 = *move_instruct.last
|
54
|
+
4.times do |i|#speed
|
55
|
+
if no_collision?(x_y + [tar_x1, tar_y1]) && no_collision?(x_y + [tar_x2, tar_y2])
|
56
|
+
update_bomb_solidness
|
57
|
+
@x += inc_x
|
58
|
+
@y += inc_y
|
59
|
+
@facing = move_instruct[0]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
else
|
63
|
+
@img_index = 4
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def bombs!
|
68
|
+
if placing_bomb? && !@bombs.detect {|bomb| bomb.at?(center_x, center_y)}
|
69
|
+
@bombs << Bomb.new(center_x, center_y)
|
70
|
+
end
|
71
|
+
check_bomb_existance
|
72
|
+
check_explosion_existance
|
73
|
+
end
|
74
|
+
|
75
|
+
def check_bomb_existance
|
76
|
+
@bombs.reject! do |bomb|
|
77
|
+
if bomb.time_counter == 0
|
78
|
+
@explosions << Explosion.new(bomb.top_x, bomb.top_y)
|
79
|
+
explode_direction(bomb.top_x, bomb.top_y, :right)
|
80
|
+
explode_direction(bomb.top_x, bomb.top_y, :left)
|
81
|
+
explode_direction(bomb.top_x, bomb.top_y, :up)
|
82
|
+
explode_direction(bomb.top_x, bomb.top_y, :down)
|
83
|
+
true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def check_explosion_existance
|
89
|
+
@explosions.reject! { |explosion| explosion.time_counter == 0}
|
90
|
+
end
|
91
|
+
|
92
|
+
def center_x
|
93
|
+
@x + 24
|
94
|
+
end
|
95
|
+
|
96
|
+
def center_y
|
97
|
+
@y + 24
|
98
|
+
end
|
99
|
+
|
100
|
+
def solid_at?(x, y)
|
101
|
+
Processor.game_window.map.solid_at?(x, y)
|
102
|
+
end
|
103
|
+
|
104
|
+
def explode_direction(x,y, direction)
|
105
|
+
[@t_size, @t_size*2].each do |inc|
|
106
|
+
case direction
|
107
|
+
when :right then new_x, new_y = x + inc, y
|
108
|
+
when :left then new_x, new_y = x - inc, y
|
109
|
+
when :down then new_x, new_y = x, y + inc
|
110
|
+
when :up then new_x, new_y = x, y - inc
|
111
|
+
end
|
112
|
+
|
113
|
+
break if solid_at?(new_x, new_y)
|
114
|
+
@explosions << Explosion.new(new_x, new_y)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def update_bomb_solidness
|
119
|
+
bombs.each do |bomb|
|
120
|
+
bomb.solid = true unless bomb.solid || bomb.at?(center_x, center_y)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def input_move_instructions
|
125
|
+
move = @move_control.detect {|keys, movement| Processor.game_window.button_down?(keys[@index]) }
|
126
|
+
move.last if move
|
127
|
+
end
|
128
|
+
|
129
|
+
def placing_bomb?
|
130
|
+
@brain ? @brain.placing_bomb? : Processor.game_window.button_down?(@bomb_control[@index])
|
131
|
+
end
|
132
|
+
end
|
data/lib/processor.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'tileable'
|
2
|
+
require 'solid_tile'
|
3
|
+
require 'menu_window'
|
4
|
+
require 'game_window'
|
5
|
+
require 'map'
|
6
|
+
require 'explosion'
|
7
|
+
require 'bomb'
|
8
|
+
require 'player'
|
9
|
+
require 'basic_brain'
|
10
|
+
require 'game_over_window'
|
11
|
+
# Processor is responsible to keep overall configuration knowledge, state
|
12
|
+
# transitions and keeping track of windows
|
13
|
+
class Processor
|
14
|
+
Screen = [1024, 768, false]
|
15
|
+
TileSize = 48
|
16
|
+
Caption = "Blast Mavens: Multiplayer Beta v0.1.1"
|
17
|
+
class << self
|
18
|
+
attr_reader :game_window
|
19
|
+
attr_accessor :players
|
20
|
+
|
21
|
+
def new
|
22
|
+
@players = []
|
23
|
+
MenuWindow.new.show
|
24
|
+
end
|
25
|
+
|
26
|
+
def has_at_least_one_player?
|
27
|
+
!players.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def allow_multiplayer?
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
def center_map
|
35
|
+
@center_map ||={}.tap do |center_coords|
|
36
|
+
(0...768).each_slice(48) do |coords_range|
|
37
|
+
center_coords[coords_range[24]] = coords_range
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def center_for(x, y)
|
43
|
+
[center_for_coord(x), center_for_coord(y)]
|
44
|
+
end
|
45
|
+
|
46
|
+
def all_bombs
|
47
|
+
players.map {|p| p.bombs}.flatten
|
48
|
+
end
|
49
|
+
|
50
|
+
def start_game
|
51
|
+
@game_window = GameWindow.new
|
52
|
+
2.times { @players << Player.new }
|
53
|
+
@game_window.show
|
54
|
+
end
|
55
|
+
|
56
|
+
def game_over(death_toll)
|
57
|
+
GameOverWindow.new(death_toll).show
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def center_for_coord(coord)
|
62
|
+
center = center_map.detect{|center, coords| coords.include?(coord)}
|
63
|
+
center && center.first
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/solid_tile.rb
ADDED
data/lib/tileable.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Tileable
|
2
|
+
def self.included(base)
|
3
|
+
base.send(:include, InstanceMethods)
|
4
|
+
end
|
5
|
+
|
6
|
+
module InstanceMethods
|
7
|
+
def register!(x,y)
|
8
|
+
@center_x, @center_y = *Processor.center_for(x, y)
|
9
|
+
@top = [@center_x - 24, @center_y - 24]
|
10
|
+
end
|
11
|
+
|
12
|
+
def at?(x,y)
|
13
|
+
center == Processor.center_for(x, y)
|
14
|
+
end
|
15
|
+
|
16
|
+
def center
|
17
|
+
[@center_x, @center_y]
|
18
|
+
end
|
19
|
+
|
20
|
+
def top_x
|
21
|
+
@top.first
|
22
|
+
end
|
23
|
+
|
24
|
+
def top_y
|
25
|
+
@top.last
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/--------------\
|
2
|
+
[..............]
|
3
|
+
[..............]
|
4
|
+
[..x..x..x..x..]
|
5
|
+
[..............]
|
6
|
+
[..............]
|
7
|
+
[..x..x..x..x..]
|
8
|
+
[..............]
|
9
|
+
[..............]
|
10
|
+
[..x..x..x..x..]
|
11
|
+
[..............]
|
12
|
+
[..............]
|
13
|
+
[..x..x..x..x..]
|
14
|
+
[..............]
|
15
|
+
[..............]
|
16
|
+
<==============>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/--------------\
|
2
|
+
[..............]
|
3
|
+
[..............]
|
4
|
+
[..............]
|
5
|
+
[..............]
|
6
|
+
[..............]
|
7
|
+
[..............]
|
8
|
+
[..............]
|
9
|
+
[..............]
|
10
|
+
[..............]
|
11
|
+
[..............]
|
12
|
+
[..............]
|
13
|
+
[..............]
|
14
|
+
[..............]
|
15
|
+
[..............]
|
16
|
+
<==============>
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blast_mavens_multiplayer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- tjbladez
|
@@ -42,6 +42,43 @@ extra_rdoc_files: []
|
|
42
42
|
|
43
43
|
files:
|
44
44
|
- bin/blast_mavens
|
45
|
+
- lib/basic_brain.rb
|
46
|
+
- lib/bomb.rb
|
47
|
+
- lib/explosion.rb
|
48
|
+
- lib/game_over_window.rb
|
49
|
+
- lib/game_window.rb
|
50
|
+
- lib/map.rb
|
51
|
+
- lib/menu_window.rb
|
52
|
+
- lib/player.rb
|
53
|
+
- lib/processor.rb
|
54
|
+
- lib/solid_tile.rb
|
55
|
+
- lib/tileable.rb
|
56
|
+
- config/boot.rb
|
57
|
+
- resources/images/cursor.png
|
58
|
+
- resources/images/dynamite.png
|
59
|
+
- resources/images/exitgame.png
|
60
|
+
- resources/images/explosion.png
|
61
|
+
- resources/images/menu.png
|
62
|
+
- resources/images/newgame.png
|
63
|
+
- resources/images/options.png
|
64
|
+
- resources/images/player_down0.png
|
65
|
+
- resources/images/player_down1.png
|
66
|
+
- resources/images/player_left0.png
|
67
|
+
- resources/images/player_left1.png
|
68
|
+
- resources/images/player_right0.png
|
69
|
+
- resources/images/player_right1.png
|
70
|
+
- resources/images/player_up0.png
|
71
|
+
- resources/images/player_up1.png
|
72
|
+
- resources/images/tileset.png
|
73
|
+
- resources/images/title.png
|
74
|
+
- resources/maps/basic.txt
|
75
|
+
- resources/maps/open.txt
|
76
|
+
- resources/sounds/battle.mp3
|
77
|
+
- resources/sounds/boom.wav
|
78
|
+
- resources/sounds/menu.wav
|
79
|
+
- resources/sounds/menu_2.mp3
|
80
|
+
- README.md
|
81
|
+
- LICENSE.txt
|
45
82
|
has_rdoc: false
|
46
83
|
homepage: http://github.com/tjbladez/blast_mavens_multiplayer
|
47
84
|
licenses: []
|