scorched_earth 5.0.1.pre-java → 5.0.2.pre-java
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/lib/scorched_earth/color_palette.rb +3 -3
- data/lib/scorched_earth/event_runner.rb +7 -6
- data/lib/scorched_earth/events/entity_destroyed.rb +5 -0
- data/lib/scorched_earth/game.rb +34 -19
- data/lib/scorched_earth/mouse.rb +0 -4
- data/lib/scorched_earth/player.rb +1 -1
- data/lib/scorched_earth/shot.rb +6 -1
- data/lib/scorched_earth/terrain.rb +16 -16
- data/lib/scorched_earth/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28ec71507af5b6c4c986dfe98825053cd5020e57
|
4
|
+
data.tar.gz: 3a437e2bf60c1461586f239789ac9b2cb4228a1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c5eb534155f895af79fa11b1dde3812d3e6e26b891df7c36ae18ef843ace49f7d1234c305fad0558503204ed296e99bf70394bcbd29ca085393f0b73b8350cd
|
7
|
+
data.tar.gz: 383e0c02b970496f8ed3be4d4ee11460ac30ff7f436f9cdda2a0727fc65303278c857437453f7cb3360cfe72ee6357ae461f54bf7af21ef1f6ea2d50458a47be
|
@@ -15,8 +15,8 @@ module ScorchedEarth
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def get(key)
|
18
|
-
cache
|
19
|
-
|
18
|
+
cache[key] ||= begin
|
19
|
+
first
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -24,7 +24,7 @@ module ScorchedEarth
|
|
24
24
|
return enum_for(:each) unless block_given?
|
25
25
|
|
26
26
|
loop do
|
27
|
-
color = strategy.color
|
27
|
+
color = strategy.color colors
|
28
28
|
yield color
|
29
29
|
end
|
30
30
|
end
|
@@ -1,24 +1,25 @@
|
|
1
1
|
module ScorchedEarth
|
2
2
|
class EventRunner
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :queue, :subscribers
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@
|
6
|
+
@queue = Queue.new
|
7
7
|
@subscribers = []
|
8
8
|
end
|
9
9
|
|
10
10
|
def publish(event)
|
11
|
-
|
11
|
+
queue << event
|
12
12
|
end
|
13
13
|
|
14
14
|
def subscribe(klass, &block)
|
15
15
|
subscribers << [klass, block]
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
event = events.pop
|
18
|
+
def process!
|
19
|
+
processing = queue.size.times.map { queue.pop }
|
21
20
|
|
21
|
+
processing.each do |event|
|
22
|
+
puts event.inspect
|
22
23
|
subscribers.each do |klass, block|
|
23
24
|
block.call event if event.is_a? klass
|
24
25
|
end
|
data/lib/scorched_earth/game.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
include Java
|
2
|
+
|
3
|
+
import java.awt.Color
|
4
|
+
|
1
5
|
require 'scorched_earth/helpers'
|
2
6
|
require 'scorched_earth/terrain'
|
3
7
|
require 'scorched_earth/player'
|
@@ -7,12 +11,9 @@ require 'scorched_earth/mouse'
|
|
7
11
|
require 'scorched_earth/color_palette'
|
8
12
|
require 'scorched_earth/event_runner'
|
9
13
|
require 'scorched_earth/events/entity_created'
|
14
|
+
require 'scorched_earth/events/entity_destroyed'
|
10
15
|
require 'scorched_earth/events/game_ending'
|
11
16
|
|
12
|
-
include Java
|
13
|
-
|
14
|
-
import java.awt.Color
|
15
|
-
|
16
17
|
module ScorchedEarth
|
17
18
|
class Game
|
18
19
|
include Helpers
|
@@ -27,30 +28,23 @@ module ScorchedEarth
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def setup
|
30
|
-
@color_palette = ColorPalette.new Color
|
31
|
+
@color_palette = ColorPalette.new Color.red, Color.yellow, Color.white
|
31
32
|
@entities = []
|
32
33
|
@event_runner = EventRunner.new
|
33
34
|
@players = Array.new(2) { |index| Player.new rand(width), color_palette.get("player_#{index}") }
|
34
35
|
@terrain = Terrain.new width, height, rand(10), color_palette.get('terrain')
|
35
36
|
@mouse = Mouse.new event_runner, players, terrain
|
36
37
|
|
37
|
-
|
38
|
-
event_runner.subscribe(Events::GameEnding) { |event| event.time < Time.now ? setup : event_runner.publish(event) }
|
38
|
+
register_events
|
39
39
|
end
|
40
40
|
|
41
41
|
def update(delta)
|
42
|
-
event_runner.
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
.select { |entity| entity.is_a? Shot }
|
49
|
-
.select { |entity| entity.x < terrain.width && entity.x > 0 }
|
50
|
-
.each { |entity| terrain.bite entity.x, radius }
|
51
|
-
.each { |entity| event_runner.publish Events::EntityCreated.new(Explosion.new(entity.x, entity.y)) }
|
52
|
-
.select { |entity| players.any? { |player| inside_radius? entity.x - player.x, 0, radius } }
|
53
|
-
.each { event_runner.publish Events::GameEnding.new(Time.now + 1) }
|
42
|
+
event_runner.process!
|
43
|
+
|
44
|
+
@entities
|
45
|
+
.each { |entity| entity.update delta }
|
46
|
+
.reject { |entity| terrain.fetch(entity.x, 0) < entity.y }
|
47
|
+
.each { |entity| event_runner.publish Events::EntityDestroyed.new(entity) }
|
54
48
|
end
|
55
49
|
|
56
50
|
def render(graphics)
|
@@ -73,5 +67,26 @@ module ScorchedEarth
|
|
73
67
|
def publish(event)
|
74
68
|
event_runner.publish event
|
75
69
|
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def register_events
|
74
|
+
event_runner.subscribe Events::MousePressed, &mouse.method(:mouse_pressed)
|
75
|
+
event_runner.subscribe Events::MouseReleased, &mouse.method(:mouse_released)
|
76
|
+
event_runner.subscribe Events::MouseMoved, &mouse.method(:mouse_moved)
|
77
|
+
event_runner.subscribe(Events::GameEnding) { |event| event.time < Time.now ? setup : event_runner.publish(event) }
|
78
|
+
event_runner.subscribe(Events::EntityCreated) { |event| entities << event.entity }
|
79
|
+
event_runner.subscribe(Events::EntityDestroyed) { |event| entities.delete event.entity }
|
80
|
+
event_runner.subscribe(Events::EntityDestroyed) do |event|
|
81
|
+
radius = 50
|
82
|
+
[event.entity]
|
83
|
+
.select { |entity| entity.is_a? Shot }
|
84
|
+
.select { |entity| entity.x < terrain.width && entity.x > 0 }
|
85
|
+
.each { |entity| terrain.bite entity.x, radius }
|
86
|
+
.each { |entity| event_runner.publish Events::EntityCreated.new(Explosion.new(entity.x, entity.y)) }
|
87
|
+
.select { |entity| players.any? { |player| inside_radius? entity.x - player.x, 0, radius } }
|
88
|
+
.each { event_runner.publish Events::GameEnding.new(Time.now + 0.25) }
|
89
|
+
end
|
90
|
+
end
|
76
91
|
end
|
77
92
|
end
|
data/lib/scorched_earth/mouse.rb
CHANGED
@@ -13,10 +13,6 @@ module ScorchedEarth
|
|
13
13
|
@event_runner = event_runner
|
14
14
|
@players = players
|
15
15
|
@terrain = terrain
|
16
|
-
|
17
|
-
event_runner.subscribe Events::MousePressed, &method(:mouse_pressed)
|
18
|
-
event_runner.subscribe Events::MouseReleased, &method(:mouse_released)
|
19
|
-
event_runner.subscribe Events::MouseMoved, &method(:mouse_moved)
|
20
16
|
end
|
21
17
|
|
22
18
|
def current_player
|
data/lib/scorched_earth/shot.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
include Java
|
2
|
+
|
3
|
+
import java.awt.BasicStroke
|
4
|
+
|
1
5
|
require 'scorched_earth/helpers'
|
2
6
|
|
3
7
|
module ScorchedEarth
|
@@ -22,13 +26,14 @@ module ScorchedEarth
|
|
22
26
|
|
23
27
|
def draw(graphics)
|
24
28
|
height = graphics.destination.height
|
25
|
-
degrees = angle
|
29
|
+
degrees = angle velocity_y, velocity_x
|
26
30
|
x1 = x
|
27
31
|
y1 = height - y
|
28
32
|
x2 = x1 + offset_x(degrees, length)
|
29
33
|
y2 = y1 + offset_y(degrees, length)
|
30
34
|
|
31
35
|
graphics.set_color color
|
36
|
+
graphics.setStroke BasicStroke.new 3
|
32
37
|
graphics.draw_line x1, y1, x2, y2
|
33
38
|
end
|
34
39
|
|
@@ -11,7 +11,7 @@ module ScorchedEarth
|
|
11
11
|
attr_reader :color, :height
|
12
12
|
|
13
13
|
def initialize(width, height, cycles, color)
|
14
|
-
@color
|
14
|
+
@color = color
|
15
15
|
@height = height
|
16
16
|
|
17
17
|
super(width) do |index|
|
@@ -27,21 +27,6 @@ module ScorchedEarth
|
|
27
27
|
graphics.draw_image cache { _draw(graphics) }, 0, 0, nil
|
28
28
|
end
|
29
29
|
|
30
|
-
def _draw(graphics)
|
31
|
-
image = graphics
|
32
|
-
.get_device_configuration
|
33
|
-
.create_compatible_image width, height, Transparency::TRANSLUCENT
|
34
|
-
|
35
|
-
each_with_index do |y, x|
|
36
|
-
image.graphics.tap do |image_graphics|
|
37
|
-
image_graphics.set_color color
|
38
|
-
image_graphics.draw_line x, height - y, x, height
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
image
|
43
|
-
end
|
44
|
-
|
45
30
|
def bite(center_x, radius, center_y = self[center_x])
|
46
31
|
circle(radius) do |offset_x, offset_y|
|
47
32
|
x = center_x + offset_x
|
@@ -59,6 +44,21 @@ module ScorchedEarth
|
|
59
44
|
|
60
45
|
private
|
61
46
|
|
47
|
+
def _draw(graphics)
|
48
|
+
image = graphics
|
49
|
+
.get_device_configuration
|
50
|
+
.create_compatible_image width, height, Transparency::TRANSLUCENT
|
51
|
+
|
52
|
+
each_with_index do |y, x|
|
53
|
+
image.graphics.tap do |image_graphics|
|
54
|
+
image_graphics.set_color color
|
55
|
+
image_graphics.draw_line x, height - y, x, height
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
image
|
60
|
+
end
|
61
|
+
|
62
62
|
def cache
|
63
63
|
@cache ||= begin
|
64
64
|
yield
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scorched_earth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.2.pre
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- James Moriarty
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/scorched_earth/color_palette.rb
|
103
103
|
- lib/scorched_earth/event_runner.rb
|
104
104
|
- lib/scorched_earth/events/entity_created.rb
|
105
|
+
- lib/scorched_earth/events/entity_destroyed.rb
|
105
106
|
- lib/scorched_earth/events/game_ending.rb
|
106
107
|
- lib/scorched_earth/events/mouse_moved.rb
|
107
108
|
- lib/scorched_earth/events/mouse_pressed.rb
|