keep_calm_and_balance 0.3.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5b1cf6c0ef25e6512d61ee5b7bd15b8ad59f18d65281584ebdc2f0e7b2f3b688
4
+ data.tar.gz: be31cb72b8de471cd7ac05fc01e027c70670de785f60e61a73c07a44841a976c
5
+ SHA512:
6
+ metadata.gz: 9f3d538772c525359c27f9e72773d7720615ca337ba716c9c33a857159ffa430980f71c44aeeb00f10dbea0181f7462b7b89d57b4207c7c13b59ea6a860fa2bd
7
+ data.tar.gz: d1f94241fcc75c676f5007182cedc308c31be6b9e57cd8b07d19646ef7f97d1365ce4ee26efe886477e7c03fe009adf21c33440e83abeed4056020abb0a0bfd5
data/lib/CHANGELOG.md ADDED
@@ -0,0 +1,46 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4
+
5
+ ## Not released yet
6
+ ### Added
7
+ ### Changed
8
+ ### Fixed
9
+ ### Removed
10
+
11
+
12
+ ## [v3](../../tags/v3) – 2021-10-21
13
+ ### Added
14
+ - timer
15
+ - deceleration when on seasaw
16
+ - gravity when not on seasaw
17
+ - loss condition
18
+ - Rubygems gem and Itch.io project
19
+
20
+ ### Changed
21
+ - barrel rolling along seesaw instead of just left and right
22
+ - debug messages hidden by default
23
+
24
+ ### Fixed
25
+ - repository also renamed
26
+
27
+
28
+ ## [v2](../../tags/v2) – 2021-10-19
29
+ ### Added
30
+ - barrel above seesaw
31
+ - barrel accelerating left and right by angled seesaw
32
+ - quit and quick reset hotkeys
33
+ - controls listed in README
34
+
35
+ ### Changed
36
+ - seesaw placed in the centre, no more movable
37
+ - game renamed from plain "Jam Game"
38
+
39
+ ### Removed
40
+ - mouse input
41
+
42
+
43
+ ## [v1](../../tags/v1) – 2021-10-17
44
+ ### Added
45
+ - bar follows mouse
46
+ - keyboard input
data/lib/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Keep Calm & Balance
2
+ - game jam: https://itch.io/jam/gosu-game-jam
3
+ - gem: (TODO link to RubyGems)
4
+ - repository: https://gitlab.com/rasunadon/gosu-game-jam
5
+ - bug tracker: https://gitlab.com/rasunadon/gosu-game-jam/issues
6
+ - licence: CC-BY-SA 3.0, Detros
7
+ - email: rasunadon@seznam.cz
8
+
9
+ _Keep Calm & Balance_ was created during the first Gosu Game Jam which run for
10
+ a week between 2021-10-17 and 2021-10-25. Your goal is to keep balancing the
11
+ barrel on the seesaw for as long as possible. Game ends when the centre of
12
+ barrel leaves the window area.
13
+
14
+
15
+ # Controls
16
+ - turn left: left arrow, key A or numpad key N4
17
+ - turn right: right arrow, key D or numpad key N6
18
+ - show debug info: Tab
19
+ - reset: Backspace
20
+ - quit: Esc
21
+
22
+
23
+ # Other documentation
24
+ - CHANGELOG: list of what has been added/changed/fixed/removed in given version
@@ -0,0 +1,33 @@
1
+ require 'rake'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'keep_calm_and_balance'
5
+ spec.version = '0.3.1'
6
+ spec.date = '2021-10-21'
7
+ spec.license = 'CC-BY-SA-3.0'
8
+
9
+ spec.summary = "An action balancing game"
10
+ spec.description = "Keep Calm & Balance is an action balancing game. It was
11
+ created during the first Gosu Game Jam."
12
+ spec.files = Rake::FileList["lib/lib/**/*",
13
+ "lib/media/*.png",
14
+ "lib/CHANGELOG.md",
15
+ "lib/keep_calm_and_balance.gemspec",
16
+ "lib/keep_calm_and_balance.rb",
17
+ "lib/README.md"]
18
+
19
+ spec.author = 'Detros'
20
+ spec.homepage = 'https://rasunadon.itch.io/keep-calm-and-balance'
21
+ spec.email = 'rasunadon@seznam.cz'
22
+ spec.metadata = {
23
+ "source_code_uri" => "https://gitlab.com/rasunadon/keep-calm-and-balance",
24
+ "bug_tracker_uri" => "https://gitlab.com/rasunadon/keep-calm-and-balance/issues",
25
+ "documentation_uri" => "https://gitlab.com/rasunadon/keep-calm-and-balance/blob/master/README.md",
26
+ "changelog_uri" => "https://gitlab.com/rasunadon/keep-calm-and-balance/blob/master/CHANGELOG.md",
27
+ "homepage_uri" => "https://rasunadon.itch.io/keep-calm-and-balance",
28
+ }
29
+
30
+ spec.platform = Gem::Platform::RUBY
31
+ spec.add_runtime_dependency 'gosu', '~> 0.9'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'gosu'
3
+
4
+ require_relative './lib/user_interface/game_window'
5
+
6
+ PROMPT = '> '
7
+
8
+ version = '0.3.1'
9
+ $window = GameWindow.new(version)
10
+ $window.show
@@ -0,0 +1,104 @@
1
+ ACCELERATION = 0.003 # per degree of seasaw angledness
2
+ DECELERATION = 0.001 # cap of deterioration of speed
3
+ SPEED_PRECISION = 3 # rounding precision, affects minimal effective angle
4
+
5
+ FALLING_ACCELERATION = 9.8 # gravity-like
6
+
7
+ class Barrel
8
+ attr_reader :x, :y
9
+
10
+ def initialize(seesaw)
11
+ dir_path = File.dirname(__FILE__)
12
+ @image = Gosu::Image.new(dir_path + '/../../media/circle.png')
13
+ @seesaw = seesaw
14
+ reset!
15
+ end
16
+
17
+ # Load default setup
18
+ def reset!
19
+ @onseasaw = true
20
+ @position = 0 # along seesaw
21
+ @radius = TILESIZE / 2
22
+ @speed = 0
23
+ @falling_speed = 0
24
+ @time_of_start_of_fall = nil
25
+ update_coords!
26
+ end
27
+
28
+ def update()
29
+ if @onseasaw # barrel rolling
30
+ update_speed!
31
+ update_position!
32
+ update_coords!
33
+ check_onseasawness
34
+ else # barrel falling
35
+ update_position! # still apply speed...
36
+ update_coords! # ... from previous rolling
37
+ update_fall!
38
+ end
39
+ end
40
+
41
+ # Change speed on seasaw according to previous speed and current angle of seesaw
42
+ def update_speed!
43
+ if @speed >= 0
44
+ decel = [@speed, DECELERATION].min
45
+ else
46
+ decel = [@speed, -DECELERATION].max
47
+ end
48
+
49
+ @speed = (@speed - decel + ACCELERATION * @seesaw.angle).round(SPEED_PRECISION)
50
+ end
51
+
52
+ # Change position along seesaw according to previous position and current speed
53
+ def update_position!
54
+ @position = (@position + @speed).round(2)
55
+ end
56
+
57
+ # Convert position along seasow to general x and y coords
58
+ def update_coords!
59
+ angle_in_radians = -@seesaw.angle * Math::PI / 180 # minus to convert to counterclockwise
60
+
61
+ # From seesaw axis to radius-far above seesaw
62
+ ss_vertical_x = Math::sin(angle_in_radians) * (@seesaw.thickness / 2 + @radius)
63
+ ss_vertical_y = Math::cos(angle_in_radians) * (@seesaw.thickness / 2 + @radius)
64
+
65
+ # From radius-far above seesaw to barrel axis
66
+ ss_horizontal_x = Math::cos(-angle_in_radians) * @position
67
+ ss_horizontal_y = Math::sin(-angle_in_radians) * @position
68
+
69
+ # Combine both parts
70
+ @x = (@seesaw.x - ss_vertical_x + ss_horizontal_x).round(1)
71
+ @y = (@seesaw.y - ss_vertical_y + ss_horizontal_y).round(1)
72
+ end
73
+
74
+ # Find out whether barrel is still on seasaw or whether it should start falling
75
+ def check_onseasawness
76
+ if @position < (-@seesaw.length / 2) or
77
+ @position > (@seesaw.length / 2)
78
+ @onseasaw = false
79
+ @time_of_start_of_fall = Gosu.milliseconds
80
+ end
81
+ end
82
+
83
+ # When not over seasaw, apply falling speed to y-coords and then accelerate down
84
+ def update_fall!
85
+ seconds_falling = (Gosu.milliseconds - @time_of_start_of_fall) / 1000.0
86
+ fall_accel = FALLING_ACCELERATION * seconds_falling * seconds_falling
87
+ @falling_speed = (@falling_speed + fall_accel).round(SPEED_PRECISION)
88
+ @y = (@y + @falling_speed).round(1)
89
+ end
90
+
91
+ def draw
92
+ @image.draw_rot(@x, @y, ZITEMS, angle = 0,
93
+ center_x = 0.5, center_y = 0.5,
94
+ scale_x = 1, scale_y = 1,
95
+ color = Gosu::Color::RED)
96
+
97
+ if $debug
98
+ coords = Gosu::Image.from_text("[#{@x}, #{@y}\nv = #{@speed}]", LINE_HEIGHT)
99
+ coords.draw_rot(@x, @y, ZTEXT, angle = 0)
100
+ puts "x = #{@x}, y = #{@y}, v = #{@speed}, pos = #{@position}, " \
101
+ "on = #{@onseasaw}, v_fall = #{@falling_speed}"
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,50 @@
1
+ ANGLE_CHANGE = 0.3
2
+
3
+ class Seesaw
4
+ attr_reader :x, :y, :angle, :scale_x, :scale_y
5
+
6
+ def initialize()
7
+ dir_path = File.dirname(__FILE__)
8
+ @image = Gosu::Image.new(dir_path + '/../../media/square.png')
9
+ reset!
10
+ end
11
+
12
+ # Load default setup
13
+ def reset!
14
+ @x = CENTRE
15
+ @y = CENTRE
16
+ @angle = 0
17
+ @scale_x = 6
18
+ @scale_y = 0.5
19
+ end
20
+
21
+ def update(button)
22
+ case button
23
+ when Gosu::KB_LEFT, Gosu::KB_A, Gosu::KB_NUMPAD_4 then
24
+ @angle -= ANGLE_CHANGE
25
+ when Gosu::KB_RIGHT, Gosu::KB_D, Gosu::KB_NUMPAD_6 then
26
+ @angle += ANGLE_CHANGE
27
+ end
28
+ @angle = @angle.round(1)
29
+ end
30
+
31
+ def draw
32
+ @image.draw_rot(@x, @y, ZITEMS, @angle,
33
+ center_x = 0.5, center_y = 0.5,
34
+ @scale_x, @scale_y,
35
+ color = Gosu::Color::AQUA)
36
+
37
+ if $debug
38
+ coords = Gosu::Image.from_text("[#{@x}, #{@y}, #{@angle}°]", LINE_HEIGHT)
39
+ coords.draw_rot(@x, @y, ZTEXT, @angle)
40
+ end
41
+ end
42
+
43
+ def length
44
+ TILESIZE * @scale_x
45
+ end
46
+
47
+ def thickness
48
+ TILESIZE * @scale_y
49
+ end
50
+ end
@@ -0,0 +1,12 @@
1
+ class Background
2
+ def initialize()
3
+ dir_path = File.dirname(__FILE__)
4
+ @image = Gosu::Image.new(dir_path + '/../../media/square.png')
5
+ end
6
+
7
+ def draw
8
+ @image.draw(0, 0, ZBACKGROUND,
9
+ scale_x = MAPX, scale_y = MAPY,
10
+ color = Gosu::Color::BLUE)
11
+ end
12
+ end
@@ -0,0 +1,108 @@
1
+ require_relative './background'
2
+ require_relative './timer'
3
+
4
+ require_relative './../items/barrel'
5
+ require_relative './../items/seesaw'
6
+
7
+ TILESIZE = 50
8
+ MAPX = 10
9
+ MAPY = MAPX
10
+ LINE_HEIGHT = 20
11
+
12
+ WINDOW_WIDTH = MAPX * TILESIZE
13
+ WINDOW_HEIGHT = MAPY * TILESIZE
14
+ CENTRE = MAPX * TILESIZE / 2
15
+
16
+ ZBACKGROUND = 0
17
+ ZITEMS = 1
18
+ ZTEXT = 2
19
+
20
+ # Main window
21
+ class GameWindow < Gosu::Window
22
+ attr_reader :loss
23
+
24
+ def initialize(version,
25
+ width = WINDOW_WIDTH, \
26
+ height = WINDOW_HEIGHT, \
27
+ fullscreen = false)
28
+ super(width, height, fullscreen)
29
+
30
+ # Set version name
31
+ self.caption = "Keep Calm & Balance #{version}"
32
+ $debug = false # debug messages turned off by default
33
+ reset!
34
+
35
+ @background = Background.new()
36
+ @timer = Timer.new(self)
37
+
38
+ @seesaw = Seesaw.new()
39
+ @barrel = Barrel.new(@seesaw)
40
+ end
41
+
42
+ # Start processing the pushed button
43
+ def button_down(key)
44
+ case key
45
+ when Gosu::KB_ESCAPE then
46
+ self.close
47
+ when Gosu::KB_BACKSPACE then
48
+ reset
49
+ when Gosu::KB_TAB then
50
+ switch_debug!
51
+ else
52
+ @button = key
53
+ end
54
+ end
55
+
56
+ # Stop processing the pushed button
57
+ def button_up(key)
58
+ @button = nil
59
+ end
60
+
61
+ # Update game state
62
+ def update
63
+ @timer.update
64
+
65
+ unless @loss
66
+ @seesaw.update(@button)
67
+ @barrel.update # let seesaw update first
68
+ check_loss
69
+ end
70
+ end
71
+
72
+ # Check whether player has lost yet
73
+ def check_loss
74
+ if @barrel.x < 0 or
75
+ @barrel.x > WINDOW_WIDTH or
76
+ @barrel.y < 0 or
77
+ @barrel.y > WINDOW_HEIGHT
78
+ @loss = true
79
+ end
80
+ end
81
+
82
+ # Draw scene
83
+ def draw
84
+ @background.draw
85
+ @barrel.draw
86
+ @seesaw.draw
87
+ @timer.draw
88
+ end
89
+
90
+ # Reset scene
91
+ def reset
92
+ reset!
93
+ @barrel.reset!
94
+ @seesaw.reset!
95
+ @timer.reset!
96
+ end
97
+
98
+ # Load default setup
99
+ def reset!
100
+ @loss = false
101
+ end
102
+
103
+ # Switch debug flag
104
+ def switch_debug!
105
+ $debug = !$debug
106
+ puts $debug
107
+ end
108
+ end
@@ -0,0 +1,32 @@
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
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keep_calm_and_balance
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Detros
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gosu
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: |-
42
+ Keep Calm & Balance is an action balancing game. It was
43
+ created during the first Gosu Game Jam.
44
+ email: rasunadon@seznam.cz
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - lib/CHANGELOG.md
50
+ - lib/README.md
51
+ - lib/keep_calm_and_balance.gemspec
52
+ - lib/keep_calm_and_balance.rb
53
+ - lib/lib/items/barrel.rb
54
+ - lib/lib/items/seesaw.rb
55
+ - lib/lib/user_interface/background.rb
56
+ - lib/lib/user_interface/game_window.rb
57
+ - lib/lib/user_interface/timer.rb
58
+ - lib/media/circle.png
59
+ - lib/media/square.png
60
+ homepage: https://rasunadon.itch.io/keep-calm-and-balance
61
+ licenses:
62
+ - CC-BY-SA-3.0
63
+ metadata:
64
+ source_code_uri: https://gitlab.com/rasunadon/keep-calm-and-balance
65
+ bug_tracker_uri: https://gitlab.com/rasunadon/keep-calm-and-balance/issues
66
+ documentation_uri: https://gitlab.com/rasunadon/keep-calm-and-balance/blob/master/README.md
67
+ changelog_uri: https://gitlab.com/rasunadon/keep-calm-and-balance/blob/master/CHANGELOG.md
68
+ homepage_uri: https://rasunadon.itch.io/keep-calm-and-balance
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.7.6
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: An action balancing game
89
+ test_files: []