scorched_earth 5.0.4.pre-java → 5.0.5.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/bin/console +1 -1
- data/exe/scorched +3 -1
- data/lib/scorched_earth/event_runner.rb +1 -1
- data/lib/scorched_earth/events/{game_ending.rb → game_over.rb} +1 -1
- data/lib/scorched_earth/events/{entity_created.rb → game_update.rb} +1 -1
- data/lib/scorched_earth/events/{entity_destroyed.rb → hit.rb} +1 -1
- data/lib/scorched_earth/game.rb +39 -53
- data/lib/scorched_earth/game_window.rb +2 -7
- data/lib/scorched_earth/helpers.rb +2 -1
- data/lib/scorched_earth/objects/explosion.rb +17 -0
- data/lib/scorched_earth/objects/mouse.rb +13 -0
- data/lib/scorched_earth/objects/player.rb +12 -0
- data/lib/scorched_earth/objects/shot.rb +41 -0
- data/lib/scorched_earth/renders/explosion.rb +33 -0
- data/lib/scorched_earth/renders/map.rb +76 -0
- data/lib/scorched_earth/renders/mouse.rb +27 -0
- data/lib/scorched_earth/renders/player.rb +30 -0
- data/lib/scorched_earth/renders/shot.rb +23 -0
- data/lib/scorched_earth/renders/trajectory.rb +34 -0
- data/lib/scorched_earth/renders.rb +16 -0
- data/lib/scorched_earth/services/cie94.rb +23 -23
- data/lib/scorched_earth/services/color_palette.rb +66 -0
- data/lib/scorched_earth/services/deform.rb +30 -0
- data/lib/scorched_earth/services/wave.rb +21 -0
- data/lib/scorched_earth/subscribers/game_over/timeout.rb +15 -0
- data/lib/scorched_earth/subscribers/game_update/collisions.rb +18 -0
- data/lib/scorched_earth/subscribers/hit/deform.rb +18 -0
- data/lib/scorched_earth/subscribers/hit/effect.rb +15 -0
- data/lib/scorched_earth/subscribers/hit/radius.rb +17 -0
- data/lib/scorched_earth/subscribers/mouse_moved.rb +13 -0
- data/lib/scorched_earth/subscribers/mouse_pressed.rb +13 -0
- data/lib/scorched_earth/subscribers/mouse_released/fire.rb +35 -0
- data/lib/scorched_earth/subscribers/mouse_released/next_player.rb +13 -0
- data/lib/scorched_earth/version.rb +1 -1
- data/lib/scorched_earth.rb +1 -0
- metadata +28 -11
- data/lib/scorched_earth/color_palette.rb +0 -66
- data/lib/scorched_earth/explosion.rb +0 -23
- data/lib/scorched_earth/mouse.rb +0 -75
- data/lib/scorched_earth/player.rb +0 -18
- data/lib/scorched_earth/shot.rb +0 -52
- data/lib/scorched_earth/terrain.rb +0 -72
@@ -0,0 +1,66 @@
|
|
1
|
+
include Java
|
2
|
+
|
3
|
+
import java.awt.Color
|
4
|
+
|
5
|
+
require 'scorched_earth/services/cie94'
|
6
|
+
|
7
|
+
module ScorchedEarth
|
8
|
+
module Services
|
9
|
+
class ColorPalette
|
10
|
+
include Enumerable
|
11
|
+
|
12
|
+
attr_reader :cache, :colors, :strategy
|
13
|
+
|
14
|
+
def initialize(*colors)
|
15
|
+
@cache = {}
|
16
|
+
@colors = colors
|
17
|
+
@strategy = Strategies::TriadMixing
|
18
|
+
end
|
19
|
+
|
20
|
+
def get(key)
|
21
|
+
cache[key] ||= begin
|
22
|
+
first
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def each
|
27
|
+
return enum_for(:each) unless block_given?
|
28
|
+
|
29
|
+
loop do
|
30
|
+
color = strategy.color colors
|
31
|
+
yield color unless already_exists?(color)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def already_exists?(color)
|
36
|
+
cache.values.any? do |color2|
|
37
|
+
delta_e94 = Services::CIE94.new.call color, color2
|
38
|
+
|
39
|
+
delta_e94 < 750 # MAX: 10_0000 e.g. black vs. white
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module Strategies
|
44
|
+
module TriadMixing
|
45
|
+
def self.color(colors)
|
46
|
+
sum = 0.0
|
47
|
+
|
48
|
+
colors.map do |color|
|
49
|
+
sum += ratio = rand
|
50
|
+
|
51
|
+
[color, ratio]
|
52
|
+
end.inject(Color.new(0, 0, 0)) do |mix, (color, ratio)|
|
53
|
+
scale = ratio / sum
|
54
|
+
|
55
|
+
Color.new(
|
56
|
+
(mix.red + color.red * scale).to_i,
|
57
|
+
(mix.green + color.green * scale).to_i,
|
58
|
+
(mix.blue + color.blue * scale).to_i
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'scorched_earth/helpers'
|
2
|
+
|
3
|
+
module ScorchedEarth
|
4
|
+
module Services
|
5
|
+
class Deform
|
6
|
+
include Helpers
|
7
|
+
attr_reader :array
|
8
|
+
|
9
|
+
def initialize(array)
|
10
|
+
@array = array
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(center_x, radius, center_y = array[center_x])
|
14
|
+
new_array = array.dup
|
15
|
+
circle(radius) do |offset_x, offset_y|
|
16
|
+
x = center_x + offset_x
|
17
|
+
y = array[x]
|
18
|
+
next unless y
|
19
|
+
z = offset_y * 2
|
20
|
+
q = center_y - offset_y
|
21
|
+
q = y if q > y
|
22
|
+
|
23
|
+
new_array[x] = [y - z, q, 0].max
|
24
|
+
end
|
25
|
+
|
26
|
+
new_array
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ScorchedEarth
|
2
|
+
module Services
|
3
|
+
class Wave
|
4
|
+
attr_reader :width, :height, :phases
|
5
|
+
|
6
|
+
def initialize(width, height, phases)
|
7
|
+
@width = width
|
8
|
+
@height = height
|
9
|
+
@phases = phases
|
10
|
+
end
|
11
|
+
|
12
|
+
def each
|
13
|
+
return enum_for(:each) unless block_given?
|
14
|
+
|
15
|
+
width.times do |index|
|
16
|
+
yield Math.sin(index.to_f / width * phases) * height / 4 + (height / 4)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'scorched_earth/events/game_over'
|
2
|
+
|
3
|
+
module ScorchedEarth
|
4
|
+
module Subscribers
|
5
|
+
module Timeout
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
|
9
|
+
event_runner.subscribe(Events::GameOver) do |event|
|
10
|
+
event.time < Time.now ? setup : event_runner.publish(event)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ScorchedEarth
|
2
|
+
module Subscribers
|
3
|
+
module Collisions
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
|
7
|
+
event_runner.subscribe(Events::GameUpdate) do
|
8
|
+
objects
|
9
|
+
.select { |object| object.is_a? Shot }
|
10
|
+
.select { |object| array.fetch(object.x, 0) > object.y }
|
11
|
+
.each { |object| event_runner.publish Events::Hit.new(object, radius = 50) }
|
12
|
+
.each { |object| objects << object.trajectory }
|
13
|
+
.each { |object| objects.delete object }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'scorched_earth/events/hit'
|
2
|
+
|
3
|
+
module ScorchedEarth
|
4
|
+
module Subscribers
|
5
|
+
module Deform
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
|
9
|
+
event_runner.subscribe(Events::Hit) do |event|
|
10
|
+
if event.object.x < array.size && event.object.x > 0
|
11
|
+
@array = Services::Deform.new(array).call(event.object.x, event.radius)
|
12
|
+
@players = players.map { |player| Player.new player.x, array[player.x] }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'scorched_earth/events/hit'
|
2
|
+
|
3
|
+
module ScorchedEarth
|
4
|
+
module Subscribers
|
5
|
+
module Effect
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
|
9
|
+
event_runner.subscribe(Events::Hit) do |event|
|
10
|
+
objects << Explosion.new(event.object.x, event.object.y)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'scorched_earth/events/hit'
|
2
|
+
|
3
|
+
module ScorchedEarth
|
4
|
+
module Subscribers
|
5
|
+
module Radius
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
|
9
|
+
event_runner.subscribe(Events::Hit) do |event|
|
10
|
+
if players.any? { |player| inside_radius? event.object.x - player.x, 0, event.radius }
|
11
|
+
event_runner.publish Events::GameOver.new(Time.now + 0.25)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ScorchedEarth
|
2
|
+
module Subscribers
|
3
|
+
module Fire
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
|
7
|
+
event_runner.subscribe(Events::MouseReleased) do |_event|
|
8
|
+
if mouse.pressed_at && mouse.x && mouse.y
|
9
|
+
shot = Shot.new current_player.x, array[current_player.x], velocity_x, velocity_y
|
10
|
+
|
11
|
+
objects << shot
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def delta
|
19
|
+
(Time.now - mouse.pressed_at) * 1000 + 1000
|
20
|
+
end
|
21
|
+
|
22
|
+
def degrees
|
23
|
+
angle(height - current_player.y - mouse.y, current_player.x - mouse.x) + 180
|
24
|
+
end
|
25
|
+
|
26
|
+
def velocity_x
|
27
|
+
offset_x(degrees, delta)
|
28
|
+
end
|
29
|
+
|
30
|
+
def velocity_y
|
31
|
+
offset_y(degrees, delta)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/scorched_earth.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.5.pre
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- James Moriarty
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -99,23 +99,40 @@ files:
|
|
99
99
|
- bin/setup
|
100
100
|
- exe/scorched
|
101
101
|
- lib/scorched_earth.rb
|
102
|
-
- lib/scorched_earth/color_palette.rb
|
103
102
|
- lib/scorched_earth/event_runner.rb
|
104
|
-
- lib/scorched_earth/events/
|
105
|
-
- lib/scorched_earth/events/
|
106
|
-
- lib/scorched_earth/events/
|
103
|
+
- lib/scorched_earth/events/game_over.rb
|
104
|
+
- lib/scorched_earth/events/game_update.rb
|
105
|
+
- lib/scorched_earth/events/hit.rb
|
107
106
|
- lib/scorched_earth/events/mouse_moved.rb
|
108
107
|
- lib/scorched_earth/events/mouse_pressed.rb
|
109
108
|
- lib/scorched_earth/events/mouse_released.rb
|
110
|
-
- lib/scorched_earth/explosion.rb
|
111
109
|
- lib/scorched_earth/game.rb
|
112
110
|
- lib/scorched_earth/game_window.rb
|
113
111
|
- lib/scorched_earth/helpers.rb
|
114
|
-
- lib/scorched_earth/
|
115
|
-
- lib/scorched_earth/
|
112
|
+
- lib/scorched_earth/objects/explosion.rb
|
113
|
+
- lib/scorched_earth/objects/mouse.rb
|
114
|
+
- lib/scorched_earth/objects/player.rb
|
115
|
+
- lib/scorched_earth/objects/shot.rb
|
116
|
+
- lib/scorched_earth/renders.rb
|
117
|
+
- lib/scorched_earth/renders/explosion.rb
|
118
|
+
- lib/scorched_earth/renders/map.rb
|
119
|
+
- lib/scorched_earth/renders/mouse.rb
|
120
|
+
- lib/scorched_earth/renders/player.rb
|
121
|
+
- lib/scorched_earth/renders/shot.rb
|
122
|
+
- lib/scorched_earth/renders/trajectory.rb
|
116
123
|
- lib/scorched_earth/services/cie94.rb
|
117
|
-
- lib/scorched_earth/
|
118
|
-
- lib/scorched_earth/
|
124
|
+
- lib/scorched_earth/services/color_palette.rb
|
125
|
+
- lib/scorched_earth/services/deform.rb
|
126
|
+
- lib/scorched_earth/services/wave.rb
|
127
|
+
- lib/scorched_earth/subscribers/game_over/timeout.rb
|
128
|
+
- lib/scorched_earth/subscribers/game_update/collisions.rb
|
129
|
+
- lib/scorched_earth/subscribers/hit/deform.rb
|
130
|
+
- lib/scorched_earth/subscribers/hit/effect.rb
|
131
|
+
- lib/scorched_earth/subscribers/hit/radius.rb
|
132
|
+
- lib/scorched_earth/subscribers/mouse_moved.rb
|
133
|
+
- lib/scorched_earth/subscribers/mouse_pressed.rb
|
134
|
+
- lib/scorched_earth/subscribers/mouse_released/fire.rb
|
135
|
+
- lib/scorched_earth/subscribers/mouse_released/next_player.rb
|
119
136
|
- lib/scorched_earth/version.rb
|
120
137
|
- scorched_earth.gemspec
|
121
138
|
homepage: https://github.com/jamesmoriarty/scorched-earth
|
@@ -1,66 +0,0 @@
|
|
1
|
-
include Java
|
2
|
-
|
3
|
-
import java.awt.Color
|
4
|
-
|
5
|
-
require 'scorched_earth/services/cie94'
|
6
|
-
|
7
|
-
module ScorchedEarth
|
8
|
-
class ColorPalette
|
9
|
-
include Enumerable
|
10
|
-
|
11
|
-
attr_reader :cache, :colors, :strategy
|
12
|
-
|
13
|
-
def initialize(*colors)
|
14
|
-
@cache = {}
|
15
|
-
@colors = colors
|
16
|
-
@strategy = Strategies::TriadMixing
|
17
|
-
end
|
18
|
-
|
19
|
-
def get(key)
|
20
|
-
cache[key] ||= begin
|
21
|
-
first
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def each
|
26
|
-
return enum_for(:each) unless block_given?
|
27
|
-
|
28
|
-
loop do
|
29
|
-
color = strategy.color colors
|
30
|
-
unless already_exists?(color)
|
31
|
-
yield color
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def already_exists?(color)
|
37
|
-
cache.values.any? do |color2|
|
38
|
-
delta_e94 = Services::CIE94.new.call color, color2
|
39
|
-
|
40
|
-
delta_e94 < 1000
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
module Strategies
|
45
|
-
module TriadMixing
|
46
|
-
def self.color(colors)
|
47
|
-
sum = 0.0
|
48
|
-
|
49
|
-
colors.map do |color|
|
50
|
-
sum += ratio = rand
|
51
|
-
|
52
|
-
[color, ratio]
|
53
|
-
end.inject(Color.new(0, 0, 0)) do |mix, (color, ratio)|
|
54
|
-
scale = ratio / sum
|
55
|
-
|
56
|
-
Color.new(
|
57
|
-
(mix.red + color.red * scale).to_i,
|
58
|
-
(mix.green + color.green * scale).to_i,
|
59
|
-
(mix.blue + color.blue * scale).to_i
|
60
|
-
)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module ScorchedEarth
|
2
|
-
class Explosion
|
3
|
-
attr_reader :x, :y, :color, :radius
|
4
|
-
|
5
|
-
def initialize(x, y)
|
6
|
-
@x = x
|
7
|
-
@y = y
|
8
|
-
@radius = 25
|
9
|
-
end
|
10
|
-
|
11
|
-
def update(_delta)
|
12
|
-
@radius += 25
|
13
|
-
@x -= 1_000_000 if radius > 100
|
14
|
-
end
|
15
|
-
|
16
|
-
def draw(graphics)
|
17
|
-
height = graphics.destination.height
|
18
|
-
|
19
|
-
graphics.set_color Color.white
|
20
|
-
graphics.fill_oval x - radius / 2, height - y - radius / 2, radius, radius
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/scorched_earth/mouse.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
include Java
|
2
|
-
|
3
|
-
import java.awt.BasicStroke
|
4
|
-
|
5
|
-
require 'scorched_earth/helpers'
|
6
|
-
require 'scorched_earth/events/mouse_pressed'
|
7
|
-
require 'scorched_earth/events/mouse_released'
|
8
|
-
require 'scorched_earth/events/mouse_moved'
|
9
|
-
|
10
|
-
module ScorchedEarth
|
11
|
-
class Mouse
|
12
|
-
include Helpers
|
13
|
-
|
14
|
-
attr_reader :event_runner, :players, :terrain, :mouse_pressed_at, :x, :y
|
15
|
-
|
16
|
-
def initialize(event_runner, players, terrain)
|
17
|
-
@event_runner = event_runner
|
18
|
-
@players = players
|
19
|
-
@terrain = terrain
|
20
|
-
end
|
21
|
-
|
22
|
-
def current_player
|
23
|
-
players.first
|
24
|
-
end
|
25
|
-
|
26
|
-
def next_player
|
27
|
-
players.rotate!
|
28
|
-
end
|
29
|
-
|
30
|
-
def mouse_released(event)
|
31
|
-
return unless mouse_pressed_at
|
32
|
-
|
33
|
-
delta = (Time.now - mouse_pressed_at) * 1000 + 1000
|
34
|
-
x1 = event.x
|
35
|
-
y1 = event.y
|
36
|
-
x2 = current_player.x
|
37
|
-
y2 = height - terrain[current_player.x]
|
38
|
-
degrees = angle(y2 - y1, x2 - x1) + 180
|
39
|
-
velocity_x = offset_x(degrees, delta)
|
40
|
-
velocity_y = offset_y(degrees, delta)
|
41
|
-
shot = Shot.new current_player.x, terrain[current_player.x], velocity_x, velocity_y, Color.white
|
42
|
-
|
43
|
-
event_runner.publish Events::EntityCreated.new shot
|
44
|
-
|
45
|
-
next_player
|
46
|
-
end
|
47
|
-
|
48
|
-
def mouse_pressed(_event)
|
49
|
-
@mouse_pressed_at = Time.now
|
50
|
-
end
|
51
|
-
|
52
|
-
def mouse_moved(event)
|
53
|
-
@x = event.x
|
54
|
-
@y = event.y
|
55
|
-
end
|
56
|
-
|
57
|
-
def height
|
58
|
-
terrain.height
|
59
|
-
end
|
60
|
-
|
61
|
-
def draw(graphics)
|
62
|
-
return unless x && y
|
63
|
-
|
64
|
-
height = graphics.destination.height
|
65
|
-
x1 = x
|
66
|
-
y1 = y
|
67
|
-
x2 = current_player.x
|
68
|
-
y2 = height - terrain[current_player.x]
|
69
|
-
|
70
|
-
graphics.set_color current_player.color
|
71
|
-
graphics.setStroke BasicStroke.new 3
|
72
|
-
graphics.draw_line x1, y1, x2, y2
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module ScorchedEarth
|
2
|
-
class Player
|
3
|
-
attr_reader :x, :color
|
4
|
-
|
5
|
-
def initialize(x, color)
|
6
|
-
@x = x
|
7
|
-
@color = color
|
8
|
-
end
|
9
|
-
|
10
|
-
def draw(graphics, y)
|
11
|
-
height = graphics.destination.height
|
12
|
-
radius = 25
|
13
|
-
|
14
|
-
graphics.set_color color
|
15
|
-
graphics.fill_oval x - radius / 2, height - y - radius / 2, radius, radius
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/scorched_earth/shot.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
include Java
|
2
|
-
|
3
|
-
import java.awt.BasicStroke
|
4
|
-
|
5
|
-
require 'scorched_earth/helpers'
|
6
|
-
|
7
|
-
module ScorchedEarth
|
8
|
-
class Shot
|
9
|
-
include Helpers
|
10
|
-
|
11
|
-
attr_reader :x, :y, :velocity_x, :velocity_y, :color
|
12
|
-
|
13
|
-
def initialize(x, y, velocity_x, velocity_y, color)
|
14
|
-
@x = x
|
15
|
-
@y = y
|
16
|
-
@velocity_x = velocity_x
|
17
|
-
@velocity_y = velocity_y
|
18
|
-
@color = color
|
19
|
-
end
|
20
|
-
|
21
|
-
def update(delta)
|
22
|
-
@velocity_y -= gravity * delta
|
23
|
-
@x += velocity_x * delta
|
24
|
-
@y += velocity_y * delta
|
25
|
-
end
|
26
|
-
|
27
|
-
def draw(graphics)
|
28
|
-
height = graphics.destination.height
|
29
|
-
degrees = angle velocity_y, velocity_x
|
30
|
-
x1 = x
|
31
|
-
y1 = height - y
|
32
|
-
x2 = x1 + offset_x(degrees, length)
|
33
|
-
y2 = y1 + offset_y(degrees, length)
|
34
|
-
|
35
|
-
graphics.set_color color
|
36
|
-
graphics.setStroke BasicStroke.new 3
|
37
|
-
graphics.draw_line x1, y1, x2, y2
|
38
|
-
end
|
39
|
-
|
40
|
-
def length
|
41
|
-
10
|
42
|
-
end
|
43
|
-
|
44
|
-
def width
|
45
|
-
3
|
46
|
-
end
|
47
|
-
|
48
|
-
def gravity
|
49
|
-
2000
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'scorched_earth/helpers'
|
2
|
-
|
3
|
-
include Java
|
4
|
-
|
5
|
-
import java.awt.Transparency
|
6
|
-
|
7
|
-
module ScorchedEarth
|
8
|
-
class Terrain < Array
|
9
|
-
include Helpers
|
10
|
-
|
11
|
-
attr_reader :color, :height
|
12
|
-
|
13
|
-
def initialize(width, height, cycles, color)
|
14
|
-
@color = color
|
15
|
-
@height = height
|
16
|
-
|
17
|
-
super(width) do |index|
|
18
|
-
Math.sin(index.to_f / width * cycles) * height / 4 + (height / 4)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def width
|
23
|
-
size
|
24
|
-
end
|
25
|
-
|
26
|
-
def draw(graphics)
|
27
|
-
graphics.draw_image cache { _draw(graphics) }, 0, 0, nil
|
28
|
-
end
|
29
|
-
|
30
|
-
def bite(center_x, radius, center_y = self[center_x])
|
31
|
-
circle(radius) do |offset_x, offset_y|
|
32
|
-
x = center_x + offset_x
|
33
|
-
y = self[x]
|
34
|
-
next unless y
|
35
|
-
z = offset_y * 2
|
36
|
-
q = center_y - offset_y
|
37
|
-
q = y if q > y
|
38
|
-
|
39
|
-
self[x] = [y - z, q, 0].max
|
40
|
-
end
|
41
|
-
|
42
|
-
clear_cache!
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
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
|
-
def cache
|
63
|
-
@cache ||= begin
|
64
|
-
yield
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def clear_cache!
|
69
|
-
@cache = nil
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|