keep_calm_and_balance 0.3.1 → 0.4
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/CHANGELOG.md +13 -1
- data/lib/keep_calm_and_balance.gemspec +2 -2
- data/lib/keep_calm_and_balance.rb +1 -1
- data/lib/lib/effects/effect_dealer.rb +89 -0
- data/lib/lib/effects/wind_effect.rb +26 -0
- data/lib/lib/items/barrel.rb +1 -0
- data/lib/lib/user_interface/game_window.rb +12 -6
- data/lib/lib/user_interface/infopane.rb +34 -0
- data/lib/media/KCaB 0.3.1.png +0 -0
- data/lib/media/logo.png +0 -0
- metadata +7 -3
- data/lib/lib/user_interface/timer.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72de35bfb0bdfdc35b79adc3dd6e3bd40e4bff42210bf8e6556dc2eade4ddc99
|
4
|
+
data.tar.gz: 01e0cb0378d78ed993fb0b309bbd6ff9bf12fe2a41cc5151979f0e6479ab496d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b50ac0264d12a23d0baefd75008484a2b5b71e8a5f0c329ee2c772e9d2d96e7a7a9002b4ee53799d4a93b777ff412f11aa4e84a1f289d2f0a3e8e2e02fecb809
|
7
|
+
data.tar.gz: b6a9327ef6efc84174a744a8c07b740ed5314938bfbc8efd7d9b3c7454e3690be1e28a0c5f32056e00bc018a85eef3ac0437d55ba6a1cb04248e6d4d049d0ec5
|
data/lib/CHANGELOG.md
CHANGED
@@ -9,7 +9,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
9
9
|
### Removed
|
10
10
|
|
11
11
|
|
12
|
-
## [
|
12
|
+
## [v4](../../tags/v4) – 2021-10-24
|
13
|
+
### Added
|
14
|
+
- effect dealer
|
15
|
+
- wind effect
|
16
|
+
- show counter of effects
|
17
|
+
- show latest effect
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
- timer is now aligned to the centre
|
21
|
+
- effects moved to a separate folder
|
22
|
+
|
23
|
+
|
24
|
+
## [v3.1](../../tags/v3.1) – 2021-10-21
|
13
25
|
### Added
|
14
26
|
- timer
|
15
27
|
- deceleration when on seasaw
|
@@ -2,8 +2,8 @@ require 'rake'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'keep_calm_and_balance'
|
5
|
-
spec.version = '0.
|
6
|
-
spec.date = '2021-10-
|
5
|
+
spec.version = '0.4'
|
6
|
+
spec.date = '2021-10-24'
|
7
7
|
spec.license = 'CC-BY-SA-3.0'
|
8
8
|
|
9
9
|
spec.summary = "An action balancing game"
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require_relative './wind_effect'
|
2
|
+
|
3
|
+
FIRST_EFFECT_TIME = 2 # seconds til the first effect
|
4
|
+
NEXT_EFFECT_TIME = 3 # seconds til the next effect
|
5
|
+
SHOW_LATEST_TIME = 1.0 # seconds to show the latest effect for (float needed!)
|
6
|
+
|
7
|
+
class EffectDealer
|
8
|
+
#attr_reader :active # TODO nothing?
|
9
|
+
|
10
|
+
def initialize(infopane, seasaw, barrel)
|
11
|
+
@infopane = infopane
|
12
|
+
@seasaw = seasaw
|
13
|
+
@barrel = barrel
|
14
|
+
|
15
|
+
@known = [WindEffect] # TODO not used
|
16
|
+
reset!
|
17
|
+
end
|
18
|
+
|
19
|
+
# Load default setup
|
20
|
+
def reset!
|
21
|
+
@available = [WindEffect]
|
22
|
+
@active = []
|
23
|
+
@latest = nil
|
24
|
+
@latest_at = nil
|
25
|
+
@next_at = FIRST_EFFECT_TIME
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
@active.each { |ee| ee.update }
|
30
|
+
|
31
|
+
if time_for_next?
|
32
|
+
@latest = @available.sample.new(@infopane, @seasaw, @barrel) # pick random one
|
33
|
+
@active.push(@latest)
|
34
|
+
@latest_at = @infopane.time
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def draw
|
39
|
+
@active.each { |ee| ee.draw }
|
40
|
+
draw_latest
|
41
|
+
draw_counter
|
42
|
+
end
|
43
|
+
|
44
|
+
def draw_latest
|
45
|
+
if @latest and @infopane.time < (@latest_at + SHOW_LATEST_TIME)
|
46
|
+
latest = Gosu::Image.from_text(
|
47
|
+
"+#{@latest.name.capitalize}", LINE_HEIGHT,
|
48
|
+
{:width => WINDOW_WIDTH, :align => :left}
|
49
|
+
)
|
50
|
+
latest.draw(0, 0, ZTEXT)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def draw_counter
|
55
|
+
counter_text = ""
|
56
|
+
counts_of_effects.each { | kk, vv | counter_text += "#{vv}x #{kk.capitalize}\n"}
|
57
|
+
|
58
|
+
counter = Gosu::Image.from_text(
|
59
|
+
counter_text, LINE_HEIGHT,
|
60
|
+
{:width => WINDOW_WIDTH, :align => :right}
|
61
|
+
)
|
62
|
+
counter.draw(0, 0, ZTEXT)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Return count of each active variant of effect, sorted alphabetically
|
66
|
+
def counts_of_effects
|
67
|
+
counts = {}
|
68
|
+
|
69
|
+
@active.each { |ee|
|
70
|
+
if counts[ee.name]
|
71
|
+
counts[ee.name] += 1
|
72
|
+
else
|
73
|
+
counts[ee.name] = 1
|
74
|
+
end
|
75
|
+
}
|
76
|
+
|
77
|
+
return counts.sort.to_h
|
78
|
+
end
|
79
|
+
|
80
|
+
# Is it time to activate the next effect?
|
81
|
+
def time_for_next?
|
82
|
+
if @infopane.time > @next_at # equality is not safe enough as update() can just miss the mark
|
83
|
+
@next_at += NEXT_EFFECT_TIME
|
84
|
+
return true
|
85
|
+
else
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
WEST = 'west' # blowing to the right
|
2
|
+
EAST = 'east' # blowing to the left
|
3
|
+
|
4
|
+
class WindEffect
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(infopane, seasaw, barrel)
|
8
|
+
@infopane = infopane
|
9
|
+
@seasaw = seasaw # not utilized
|
10
|
+
@barrel = barrel
|
11
|
+
|
12
|
+
@direction = [WEST, EAST].sample
|
13
|
+
@name = "#{@direction} wind"
|
14
|
+
end
|
15
|
+
|
16
|
+
def update
|
17
|
+
@strength = rand(5)
|
18
|
+
@speed = {WEST => 1, EAST => -1}[@direction] * @strength * ACCELERATION
|
19
|
+
|
20
|
+
@barrel.speed = (@barrel.speed + @speed).round(SPEED_PRECISION)
|
21
|
+
end
|
22
|
+
|
23
|
+
def draw
|
24
|
+
# TODO nothing?
|
25
|
+
end
|
26
|
+
end
|
data/lib/lib/items/barrel.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require_relative './background'
|
2
|
-
require_relative './
|
2
|
+
require_relative './infopane'
|
3
3
|
|
4
4
|
require_relative './../items/barrel'
|
5
5
|
require_relative './../items/seesaw'
|
6
6
|
|
7
|
+
require_relative './../effects/effect_dealer'
|
8
|
+
|
7
9
|
TILESIZE = 50
|
8
10
|
MAPX = 10
|
9
11
|
MAPY = MAPX
|
@@ -33,10 +35,12 @@ class GameWindow < Gosu::Window
|
|
33
35
|
reset!
|
34
36
|
|
35
37
|
@background = Background.new()
|
36
|
-
@
|
38
|
+
@infopane = Infopane.new(self)
|
37
39
|
|
38
40
|
@seesaw = Seesaw.new()
|
39
41
|
@barrel = Barrel.new(@seesaw)
|
42
|
+
|
43
|
+
@effect_dealer = EffectDealer.new(@infopane, @seesaw, @barrel)
|
40
44
|
end
|
41
45
|
|
42
46
|
# Start processing the pushed button
|
@@ -60,12 +64,13 @@ class GameWindow < Gosu::Window
|
|
60
64
|
|
61
65
|
# Update game state
|
62
66
|
def update
|
63
|
-
@
|
67
|
+
@infopane.update
|
64
68
|
|
65
69
|
unless @loss
|
66
70
|
@seesaw.update(@button)
|
67
71
|
@barrel.update # let seesaw update first
|
68
72
|
check_loss
|
73
|
+
@effect_dealer.update
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
@@ -83,16 +88,18 @@ class GameWindow < Gosu::Window
|
|
83
88
|
def draw
|
84
89
|
@background.draw
|
85
90
|
@barrel.draw
|
91
|
+
@effect_dealer.draw
|
92
|
+
@infopane.draw
|
86
93
|
@seesaw.draw
|
87
|
-
@timer.draw
|
88
94
|
end
|
89
95
|
|
90
96
|
# Reset scene
|
91
97
|
def reset
|
92
98
|
reset!
|
93
99
|
@barrel.reset!
|
100
|
+
@effect_dealer.reset!
|
101
|
+
@infopane.reset!
|
94
102
|
@seesaw.reset!
|
95
|
-
@timer.reset!
|
96
103
|
end
|
97
104
|
|
98
105
|
# Load default setup
|
@@ -103,6 +110,5 @@ class GameWindow < Gosu::Window
|
|
103
110
|
# Switch debug flag
|
104
111
|
def switch_debug!
|
105
112
|
$debug = !$debug
|
106
|
-
puts $debug
|
107
113
|
end
|
108
114
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Infopane
|
2
|
+
attr_reader :time
|
3
|
+
|
4
|
+
def initialize(window)
|
5
|
+
@window = window
|
6
|
+
reset!
|
7
|
+
end
|
8
|
+
|
9
|
+
# Load default setup
|
10
|
+
def reset!
|
11
|
+
@starttime = Gosu.milliseconds
|
12
|
+
@time = 0
|
13
|
+
end
|
14
|
+
|
15
|
+
def update()
|
16
|
+
unless @window.loss
|
17
|
+
@time = (Gosu.milliseconds - @starttime) / 1000.0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def draw
|
22
|
+
text = "#{@time}s"
|
23
|
+
|
24
|
+
if @window.loss
|
25
|
+
text += "\nBackspace to restart"
|
26
|
+
end
|
27
|
+
|
28
|
+
text = Gosu::Image.from_text(
|
29
|
+
text, LINE_HEIGHT,
|
30
|
+
{:width => WINDOW_WIDTH, :align => :center}
|
31
|
+
)
|
32
|
+
text.draw(0, 0, ZTEXT)
|
33
|
+
end
|
34
|
+
end
|
Binary file
|
data/lib/media/logo.png
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keep_calm_and_balance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Detros
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -50,12 +50,16 @@ files:
|
|
50
50
|
- lib/README.md
|
51
51
|
- lib/keep_calm_and_balance.gemspec
|
52
52
|
- lib/keep_calm_and_balance.rb
|
53
|
+
- lib/lib/effects/effect_dealer.rb
|
54
|
+
- lib/lib/effects/wind_effect.rb
|
53
55
|
- lib/lib/items/barrel.rb
|
54
56
|
- lib/lib/items/seesaw.rb
|
55
57
|
- lib/lib/user_interface/background.rb
|
56
58
|
- lib/lib/user_interface/game_window.rb
|
57
|
-
- lib/lib/user_interface/
|
59
|
+
- lib/lib/user_interface/infopane.rb
|
60
|
+
- lib/media/KCaB 0.3.1.png
|
58
61
|
- lib/media/circle.png
|
62
|
+
- lib/media/logo.png
|
59
63
|
- lib/media/square.png
|
60
64
|
homepage: https://rasunadon.itch.io/keep-calm-and-balance
|
61
65
|
licenses:
|
@@ -1,32 +0,0 @@
|
|
1
|
-
class Timer
|
2
|
-
def initialize(window)
|
3
|
-
@window = window
|
4
|
-
reset!
|
5
|
-
end
|
6
|
-
|
7
|
-
# Load default setup
|
8
|
-
def reset!
|
9
|
-
@starttime = Gosu.milliseconds
|
10
|
-
@time = 0
|
11
|
-
end
|
12
|
-
|
13
|
-
def update()
|
14
|
-
unless @window.loss
|
15
|
-
@time = (Gosu.milliseconds - @starttime) / 1000.0
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def draw
|
20
|
-
info = Gosu::Image.from_text("#{@time}s", LINE_HEIGHT)
|
21
|
-
info.draw(0, 0, ZTEXT)
|
22
|
-
|
23
|
-
if @window.loss
|
24
|
-
restart_text = "Backspace to restart"
|
25
|
-
restart = Gosu::Image.from_text(
|
26
|
-
restart_text, LINE_HEIGHT,
|
27
|
-
{:width => WINDOW_WIDTH, :align => :center}
|
28
|
-
)
|
29
|
-
restart.draw(0, LINE_HEIGHT, ZTEXT)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|