blast_mavens_multiplayer 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,11 @@
1
1
  class Bomb
2
2
  include Tileable
3
-
4
3
  attr_accessor :time_counter, :solid
4
+
5
5
  def initialize(x,y)
6
6
  register!(x, y)
7
7
  @t_size = Processor::TileSize
8
- @sprites = Gosu::Image.load_tiles(Processor.game_window, BLAST_IMG_PATH + "dynamite.png", @t_size, @t_size, false)
8
+ @sprites = Gosu::Image.load_tiles(Processor.window, BLAST_IMG_PATH + "dynamite.png", @t_size, @t_size, false)
9
9
  @time_counter = 80
10
10
  @sprite_index = 0
11
11
  @solid = false
@@ -5,7 +5,7 @@ class Explosion
5
5
  def initialize(x,y)
6
6
  register!(x, y)
7
7
  @t_size = Processor::TileSize
8
- @sprites = Gosu::Image.load_tiles(Processor.game_window, BLAST_IMG_PATH + "explosion.png", @t_size, @t_size, false)
8
+ @sprites = Gosu::Image.load_tiles(Processor.window, BLAST_IMG_PATH + "explosion.png", @t_size, @t_size, false)
9
9
  @time_counter = 20
10
10
  @sprite_index = 0
11
11
  end
@@ -1,18 +1,13 @@
1
- class GameWindow < Gosu::Window
2
- def initialize
3
- super(*Processor::Screen)
4
- self.caption = Processor::Caption
1
+ class Game
2
+ def initialize(window, opts={})
3
+ @window = window
5
4
  @players_hit = {:player_0 => [], :player_1 => []}
6
5
  @finish_game = false
7
- @song = Gosu::Song.new(self, BLAST_SND_PATH + 'battle.mp3')
6
+ @song = Gosu::Song.new(@window, BLAST_SND_PATH + 'battle.mp3')
8
7
  @song.volume = 0.3
9
8
  @song.play(true)
10
9
  end
11
10
 
12
- def map
13
- @map ||= Map.new(BLAST_MAP_PATH + 'basic.txt')
14
- end
15
-
16
11
  def draw
17
12
  map.draw(0, 0)
18
13
  Processor.players.each do |player|
@@ -36,17 +31,20 @@ class GameWindow < Gosu::Window
36
31
  if @finish_game && Processor.players.map(&:explosions).flatten.empty?
37
32
  @song.stop
38
33
  Processor.game_over(@players_hit)
39
- close
40
34
  end
41
35
  end
42
36
 
43
- private
37
+ def map
38
+ @map ||= Map.new(BLAST_MAP_PATH + 'basic.txt')
39
+ end
40
+
44
41
  def button_down(id)
45
- close if id == Gosu::KbEscape
42
+ Processor.close if id == Gosu::KbEscape
46
43
  @song.volume -= 0.1 if id == Gosu::KbNumpadSubtract
47
44
  @song.volume += 0.1 if id == Gosu::KbNumpadAdd
48
45
  end
49
46
 
47
+ private
50
48
  def players_hit?(explosion, index)
51
49
  Processor.players.each do |player|
52
50
  if explosion.at?(player.x, player.y)
@@ -1,10 +1,8 @@
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
1
+ class GameOver
2
+ def initialize(window, death_toll)
3
+ @window = window
4
+ @font = Gosu::Font.new(@window, Gosu::default_font_name, 20)
5
+ @death_toll = death_toll
8
6
  end
9
7
 
10
8
  def draw
@@ -13,6 +11,14 @@ class GameOverWindow < Gosu::Window
13
11
  @font.draw("Player 1 won. Player 2 was blown up by #{killer(:player_1)}", 200, 200, 1) if player_1_hit?
14
12
  end
15
13
 
14
+ def button_down(id)
15
+ Processor.close if id == Gosu::KbEscape
16
+ end
17
+
18
+ def update
19
+ # do nothing
20
+ end
21
+ private
16
22
  def draw?
17
23
  player_0_hit? && player_1_hit?
18
24
  end
@@ -28,8 +34,4 @@ class GameOverWindow < Gosu::Window
28
34
  def killer(player)
29
35
  "Player #{@death_toll[player].first.to_s[-1..-1].to_i + 1}"
30
36
  end
31
-
32
- def button_down(id)
33
- close if id == Gosu::KbEscape
34
- end
35
37
  end
data/lib/map.rb CHANGED
@@ -5,7 +5,7 @@ class Map
5
5
  def initialize(path)
6
6
  @path = path
7
7
  @t_size = Processor::TileSize
8
- @set = Gosu::Image.load_tiles(Processor.game_window, BLAST_IMG_PATH + 'tileset.png', @t_size, @t_size, true)
8
+ @set = Gosu::Image.load_tiles(Processor.window, BLAST_IMG_PATH + 'tileset.png', @t_size, @t_size, true)
9
9
  register_solid_tiles
10
10
  end
11
11
 
@@ -0,0 +1,68 @@
1
+ class Menu
2
+ def initialize(window, opts={})
3
+ @window = window
4
+ @pointer = Gosu::Image.new(@window,BLAST_IMG_PATH + "cursor.png",true)
5
+ @background = Gosu::Image.load_tiles(@window, BLAST_IMG_PATH + 'menu.png', 1024, 768, true).first
6
+ @title = Gosu::Image.load_tiles(@window, BLAST_IMG_PATH + 'title.png', 350, 80, true)
7
+ @new_game = Gosu::Image.load_tiles(@window, BLAST_IMG_PATH + 'newgame.png', 150, 40, true)
8
+ @options = Gosu::Image.load_tiles(@window, BLAST_IMG_PATH + 'options.png', 150, 40, true)
9
+ @exit_game = Gosu::Image.load_tiles(@window, BLAST_IMG_PATH + 'exitgame.png', 150, 40, true)
10
+ @song = Gosu::Song.new(@window, BLAST_SND_PATH + 'menu.wav')
11
+ @new_game_index = @options_index = @exit_game_index = 1
12
+ @song.play(true)
13
+ @song.volume = 0.3
14
+ @px = @py = 0
15
+ end
16
+
17
+ def update
18
+ @px, @py = @window.mouse_x, @window.mouse_y
19
+ update_hovers
20
+ end
21
+
22
+ def draw
23
+ @background.draw(0,0,0)
24
+ @title.first.draw(340, 190, 1)
25
+ @new_game[@new_game_index].draw(450, 280, 1)
26
+ @options[@options_index].draw(450, 330, 1)
27
+ @exit_game[@exit_game_index].draw(450, 380, 1)
28
+ @pointer.draw(@px,@py,2)
29
+ end
30
+
31
+ def button_down(id)
32
+ Processor.close if id == Gosu::KbEscape
33
+ start_game if id == Gosu::KbReturn
34
+ mouse_clicked(@px, @py) if id == Gosu::MsLeft
35
+ @song.volume -= 0.1 if id == Gosu::KbNumpadSubtract
36
+ @song.volume += 0.1 if id == Gosu::KbNumpadAdd
37
+ end
38
+
39
+ private
40
+
41
+ def mouse_clicked(x, y)
42
+ start_game if at_new_game?(x,y)
43
+ Processor.close if at_exit_game?(x,y)
44
+ end
45
+
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
+ @song.stop
66
+ Processor.start_game
67
+ end
68
+ end
@@ -6,10 +6,10 @@ class Player
6
6
  @t_size = Processor::TileSize
7
7
  #more animation to come
8
8
  @facing = :down
9
- @animation_sprites = {:left => Gosu::Image.load_tiles(Processor.game_window, BLAST_IMG_PATH + "player_left#{@index}.png", @t_size, @t_size, false),
10
- :down => Gosu::Image.load_tiles(Processor.game_window, BLAST_IMG_PATH + "player_down#{@index}.png", @t_size, @t_size, false),
11
- :up => Gosu::Image.load_tiles(Processor.game_window, BLAST_IMG_PATH + "player_up#{@index}.png", @t_size, @t_size, false),
12
- :right => Gosu::Image.load_tiles(Processor.game_window, BLAST_IMG_PATH + "player_right#{@index}.png", @t_size, @t_size, false)}
9
+ @animation_sprites = {:left => Gosu::Image.load_tiles(Processor.window, BLAST_IMG_PATH + "player_left#{@index}.png", @t_size, @t_size, false),
10
+ :down => Gosu::Image.load_tiles(Processor.window, BLAST_IMG_PATH + "player_down#{@index}.png", @t_size, @t_size, false),
11
+ :up => Gosu::Image.load_tiles(Processor.window, BLAST_IMG_PATH + "player_up#{@index}.png", @t_size, @t_size, false),
12
+ :right => Gosu::Image.load_tiles(Processor.window, BLAST_IMG_PATH + "player_right#{@index}.png", @t_size, @t_size, false)}
13
13
  @bombs = []
14
14
  @explosions = []
15
15
  @move_control = {[Gosu::Button::KbA, Gosu::Button::KbLeft] => [:left, [-1, 0],[0, 0, 0, 40]],
@@ -95,7 +95,7 @@ private
95
95
  end
96
96
 
97
97
  def solid_at?(x, y)
98
- Processor.game_window.map.solid_at?(x, y)
98
+ Processor.solid_at?(x, y)
99
99
  end
100
100
 
101
101
  def explode_direction(x,y, direction)
@@ -119,11 +119,11 @@ private
119
119
  end
120
120
 
121
121
  def input_move_instructions
122
- move = @move_control.detect {|keys, movement| Processor.game_window.button_down?(keys[@index]) }
122
+ move = @move_control.detect {|keys, movement| Processor.window.button_down?(keys[@index]) }
123
123
  move.last if move
124
124
  end
125
125
 
126
126
  def placing_bomb?
127
- @brain ? @brain.placing_bomb? : Processor.game_window.button_down?(@bomb_control[@index])
127
+ Processor.window.button_down?(@bomb_control[@index])
128
128
  end
129
129
  end
@@ -1,26 +1,27 @@
1
1
  require 'tileable'
2
2
  require 'solid_tile'
3
- require 'menu_window'
4
- require 'game_window'
5
3
  require 'map'
6
4
  require 'explosion'
7
5
  require 'bomb'
8
6
  require 'player'
9
- require 'basic_brain'
10
- require 'game_over_window'
7
+ require 'menu'
8
+ require 'game_over'
9
+ require 'game'
10
+ require 'window'
11
11
  # Processor is responsible to keep overall configuration knowledge, state
12
12
  # transitions and keeping track of windows
13
13
  class Processor
14
14
  Screen = [1024, 768, false]
15
15
  TileSize = 48
16
- Caption = "Blast Mavens: Multiplayer Beta v0.1.3"
16
+ Caption = "Blast Mavens: Multiplayer Beta v0.1.4"
17
17
  class << self
18
- attr_reader :game_window
18
+ attr_reader :window
19
19
  attr_accessor :players
20
20
 
21
21
  def new
22
22
  @players = []
23
- MenuWindow.new.show
23
+ @window = Window.new("Menu")
24
+ @window.show
24
25
  end
25
26
 
26
27
  def has_at_least_one_player?
@@ -48,13 +49,20 @@ class Processor
48
49
  end
49
50
 
50
51
  def start_game
51
- @game_window = GameWindow.new
52
52
  2.times { @players << Player.new }
53
- @game_window.show
53
+ @window.set_delegate("Game")
54
54
  end
55
55
 
56
56
  def game_over(death_toll)
57
- GameOverWindow.new(death_toll).show
57
+ @window.set_delegate("GameOver", death_toll)
58
+ end
59
+
60
+ def close
61
+ @window.close
62
+ end
63
+
64
+ def solid_at?(x,y)
65
+ @window.map ? @window.map.solid_at?(x,y) : false
58
66
  end
59
67
 
60
68
  private
@@ -0,0 +1,27 @@
1
+ class Window < Gosu::Window
2
+ def initialize(name)
3
+ super(*Processor::Screen)
4
+ self.caption = "Blast Mavens: Multiplayer Beta v0.1.0"
5
+ set_delegate(name)
6
+ end
7
+
8
+ def draw
9
+ @delegate.draw
10
+ end
11
+
12
+ def update
13
+ @delegate.update
14
+ end
15
+
16
+ def button_down(id)
17
+ @delegate.button_down(id)
18
+ end
19
+
20
+ def set_delegate(name, opts={})
21
+ @delegate = Object.const_get(name).new(self, opts)
22
+ end
23
+
24
+ def method_missing(sym, *args, &block)
25
+ @delegate.send(sym, *args, &block)
26
+ end
27
+ end
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: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - tjbladez
@@ -42,17 +42,17 @@ extra_rdoc_files: []
42
42
 
43
43
  files:
44
44
  - bin/blast_mavens
45
- - lib/basic_brain.rb
46
45
  - lib/bomb.rb
47
46
  - lib/explosion.rb
48
- - lib/game_over_window.rb
49
- - lib/game_window.rb
47
+ - lib/game.rb
48
+ - lib/game_over.rb
50
49
  - lib/map.rb
51
- - lib/menu_window.rb
50
+ - lib/menu.rb
52
51
  - lib/player.rb
53
52
  - lib/processor.rb
54
53
  - lib/solid_tile.rb
55
54
  - lib/tileable.rb
55
+ - lib/window.rb
56
56
  - resources/images/cursor.png
57
57
  - resources/images/dynamite.png
58
58
  - resources/images/exitgame.png
@@ -1,25 +0,0 @@
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
@@ -1,69 +0,0 @@
1
- class MenuWindow < Gosu::Window
2
- def initialize
3
- super(*Processor::Screen)
4
- self.caption = Processor::Caption
5
- @pointer = Gosu::Image.new(self, BLAST_IMG_PATH + "cursor.png",true)
6
- @background = Gosu::Image.load_tiles(self, BLAST_IMG_PATH + 'menu.png', 1024, 768, true).first
7
- @title = Gosu::Image.load_tiles(self, BLAST_IMG_PATH + 'title.png', 350, 80, true)
8
- @new_game = Gosu::Image.load_tiles(self, BLAST_IMG_PATH + 'newgame.png', 150, 40, true)
9
- @options = Gosu::Image.load_tiles(self, BLAST_IMG_PATH + 'options.png', 150, 40, true)
10
- @exit_game = Gosu::Image.load_tiles(self, BLAST_IMG_PATH + 'exitgame.png', 150, 40, true)
11
- @song = Gosu::Song.new(self, BLAST_SND_PATH + '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