Gosuplus 1.0 → 1.0.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 +4 -4
- data/lib/Gosuplus/body.rb +8 -6
- data/lib/Gosuplus/collision.rb +11 -9
- data/lib/Gosuplus/contentmanager.rb +25 -23
- data/lib/Gosuplus/drawable.rb +5 -3
- data/lib/Gosuplus/drawable_rot.rb +5 -3
- data/lib/Gosuplus/entity.rb +4 -2
- data/lib/Gosuplus/essentials.rb +5 -3
- data/lib/Gosuplus/gui/button.rb +32 -30
- data/lib/Gosuplus/gui/buttonrenderer.rb +5 -3
- data/lib/Gosuplus/gui/form/base.rb +16 -14
- data/lib/Gosuplus/gui/form/renderer.rb +7 -5
- data/lib/Gosuplus/gui/form/text.rb +6 -4
- data/lib/Gosuplus/gui/gui.rb +34 -32
- data/lib/Gosuplus/gui/guirenderer.rb +15 -13
- data/lib/Gosuplus/gui/icon.rb +12 -10
- data/lib/Gosuplus/gui/text.rb +17 -15
- data/lib/Gosuplus/gui/toggleable.rb +25 -23
- data/lib/Gosuplus/resourceloader.rb +36 -34
- data/lib/Gosuplus/resourcemanager.rb +13 -11
- data/lib/Gosuplus/state.rb +22 -20
- data/lib/Gosuplus/stateinputhandler.rb +11 -9
- data/lib/Gosuplus/statemanager.rb +29 -27
- data/lib/Gosuplus/staterenderer.rb +5 -3
- data/lib/Gosuplus/states/example_state.rb +26 -24
- data/lib/Gosuplus/stateupdater.rb +5 -3
- data/lib/Gosuplus/timer.rb +14 -12
- data/lib/Gosuplus/vec2.rb +8 -6
- data/lib/Gosuplus/vec3.rb +6 -4
- data/lib/Gosuplus/version.rb +1 -1
- data/lib/Gosuplus/window.rb +30 -0
- data/lib/Gosuplus.rb +1 -32
- 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: 0f1cf51c1664c32d665169a7e2ae59ecde5cc3f9
|
|
4
|
+
data.tar.gz: d5c7b1f247083360b3552365500b4903a3f20e3a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c6262830c074e21d1f6e81c004888349eba26e1b5beaea22db42352d0c335990cc8f6757235400839ea4cd9566ada44a0a04c6f9df6d0040863617f618cbc79f
|
|
7
|
+
data.tar.gz: f1c41a68149b91243b7d7dcd957d371dc808258f19ac9079547d6fa5817a5d2ff6d786dc72cb2c3c07f125ebb89529f37da4fda349fdca556793324a220a911c
|
data/lib/Gosuplus/body.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def initialize(position, width, height, angle = 90)
|
|
5
|
-
raise ArgumentError, 'Position is not a instance of Vec2' unless position.is_a? Vec2
|
|
1
|
+
module Gosuplus
|
|
2
|
+
class Body
|
|
3
|
+
attr_accessor :position, :a, :width, :height
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
def initialize(position, width, height, angle = 90)
|
|
6
|
+
raise ArgumentError, 'Position is not a instance of Vec2' unless position.is_a? Vec2
|
|
7
|
+
|
|
8
|
+
@position, @width, @height, @angle = position, width, height, angle
|
|
9
|
+
end
|
|
8
10
|
end
|
|
9
11
|
end
|
data/lib/Gosuplus/collision.rb
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
module
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
module Collision
|
|
3
|
+
def self.rectangular_collision?(body, body2)
|
|
4
|
+
b1 = generate_quadratic_sides body
|
|
5
|
+
b2 = generate_quadratic_sides body2
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
((b1[:left] >= b2[:left] and b1[:left] <= b2[:right]) || (b2[:left] >= b1[:left] && b2[:left] <= b1[:right])) &&
|
|
8
|
+
((b1[:top] >= b2[:top] && b1[:top] <= b2[:bottom]) || (b2[:top] >= b1[:top] && b2[:top] <= b1[:bottom]))
|
|
9
|
+
end
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
def self.generate_quadratic_sides(body)
|
|
12
|
+
@sides = {left: body.position.x, right: body.position.x + body.width, top: body.position.y, bottom: body.position.y + body.height}
|
|
13
|
+
end
|
|
12
14
|
end
|
|
13
15
|
end
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
class ContentManager
|
|
3
|
+
def initialize
|
|
4
|
+
# [Y, X]
|
|
5
|
+
@grid_width, @grid_height = 32, 32
|
|
6
|
+
@content_grid = Array.new(GameWindow::HEIGHT/@grid_height + 1) { Array.new(GameWindow::WIDTH/@grid_width + 1) { nil }}
|
|
7
|
+
end
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
def update(objects)
|
|
10
|
+
clean_array
|
|
11
|
+
objects.each do |object|
|
|
12
|
+
@content_grid[(object.y/@grid_height).round][(object.x/@grid_width).round] = object
|
|
13
|
+
end
|
|
14
|
+
end
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
def surrounding_objects(object)
|
|
17
|
+
surrounding_objects = []
|
|
18
|
+
((object.x/@grid_width-1).round..(object.x/@grid_width+1).round).each do |x|
|
|
19
|
+
((object.y/@grid_height-1).round..(object.y/@grid_height+1).round).each do |y|
|
|
20
|
+
if @content_grid[y][x] and object != @content_grid[y][x]
|
|
21
|
+
surrounding_objects << @content_grid[y][x]
|
|
22
|
+
end
|
|
21
23
|
end
|
|
22
24
|
end
|
|
23
|
-
end
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
surrounding_objects
|
|
27
|
+
end
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
def clean_array
|
|
30
|
+
@content_grid = Array.new(GameWindow::HEIGHT/@grid_height + 1) { Array.new(GameWindow::WIDTH/@grid_width + 1) { nil }}
|
|
31
|
+
end
|
|
30
32
|
end
|
|
31
33
|
end
|
data/lib/Gosuplus/drawable.rb
CHANGED
data/lib/Gosuplus/entity.rb
CHANGED
data/lib/Gosuplus/essentials.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
module
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
module Essentials
|
|
3
|
+
def center(area)
|
|
4
|
+
@body.position = Vec2.new(area.body.position.x + area.body.width/2 - @body.width/2, area.body.position.y + area.body.height/2 - @body.height/2)
|
|
5
|
+
end
|
|
4
6
|
end
|
|
5
7
|
end
|
data/lib/Gosuplus/gui/button.rb
CHANGED
|
@@ -1,41 +1,43 @@
|
|
|
1
|
-
module
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
module GUI
|
|
3
|
+
class Button
|
|
4
|
+
attr_accessor :timer
|
|
5
|
+
def initialize(position, image, input_handler, key_id, text = nil, font = nil)
|
|
6
|
+
@icon = Icon.new(image, position)
|
|
7
|
+
@input_handler, @key_id = input_handler, key_id
|
|
8
|
+
if text && font
|
|
9
|
+
@text = Text.new(text, font)
|
|
10
|
+
@text.center(@icon)
|
|
11
|
+
end
|
|
10
12
|
end
|
|
11
|
-
end
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
def draw
|
|
15
|
+
ButtonRenderer.draw(@icon, @text)
|
|
16
|
+
end
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
def update(x, y)
|
|
19
|
+
@active = false if @active
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
unless @timer.nil?
|
|
22
|
+
if activated?(x, y)
|
|
23
|
+
@timer.reset
|
|
24
|
+
@active = true
|
|
25
|
+
end
|
|
26
|
+
else
|
|
27
|
+
@active = false
|
|
24
28
|
end
|
|
25
|
-
else
|
|
26
|
-
@active = false
|
|
27
|
-
end
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
@timer.update
|
|
31
|
+
end
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
def active?
|
|
34
|
+
@active
|
|
35
|
+
end
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
private
|
|
38
|
+
def activated?(x, y)
|
|
39
|
+
Collision.rectangular_collision?(@icon.body, Body.new(Vec2.new(x, y), 1, 1)) && @timer.ready? && @input_handler.get_state(256)
|
|
40
|
+
end
|
|
39
41
|
end
|
|
40
42
|
end
|
|
41
43
|
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
class ButtonRenderer
|
|
3
|
+
def self.draw(*entities)
|
|
4
|
+
entities.each {|entity| entity.draw unless entity.is_a? NilClass}
|
|
5
|
+
end
|
|
4
6
|
end
|
|
5
7
|
end
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
module
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
module GUI
|
|
3
|
+
module Form
|
|
4
|
+
class Base
|
|
5
|
+
def initialize(position, image, input_handler, key_id, font, text = nil)
|
|
6
|
+
@icon = Icon.new(image, position)
|
|
7
|
+
@input_handler, @key_id, @font = input_handler, key_id, font
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
@visible_text = text ? text : String
|
|
10
|
+
@actual_text = String
|
|
11
|
+
end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
def draw
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
def update(x, y)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
end
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
def activated?(x, y)
|
|
21
22
|
|
|
23
|
+
end
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
end
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
module
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
module GUI
|
|
3
|
+
module Form
|
|
4
|
+
class Renderer
|
|
5
|
+
def self.draw(*entities)
|
|
6
|
+
entities.each {|entity| entity.draw unless entity.is_a? NilClass}
|
|
7
|
+
end
|
|
6
8
|
end
|
|
7
9
|
end
|
|
8
10
|
end
|
data/lib/Gosuplus/gui/gui.rb
CHANGED
|
@@ -1,42 +1,44 @@
|
|
|
1
|
-
module
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
module GUI
|
|
3
|
+
class GUI
|
|
4
|
+
include Collision
|
|
5
|
+
def initialize(renderer)
|
|
6
|
+
@renderer = renderer
|
|
7
|
+
@items = {}
|
|
8
|
+
end
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
def draw
|
|
11
|
+
@renderer.draw(@items)
|
|
12
|
+
end
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
def update(mouse_x, mouse_y)
|
|
15
|
+
@items.each {|key, element| element.update(mouse_x, mouse_y)}
|
|
16
|
+
end
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
def set_font(font)
|
|
19
|
+
@font = font
|
|
20
|
+
end
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
def get_button(key)
|
|
23
|
+
@items[key]
|
|
24
|
+
end
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
def add_button(key, button)
|
|
27
|
+
@items[key] = button
|
|
28
|
+
end
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
def add_text(key, text, position)
|
|
31
|
+
raise ArgumentError, 'Font has not been set!' unless @font
|
|
32
|
+
@items[key] = Text.new(text, @font, position)
|
|
33
|
+
end
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
def add_icon(key, image, position)
|
|
36
|
+
@items[key] = Icon.new(image, position)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def [](key)
|
|
40
|
+
@items[key]
|
|
41
|
+
end
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
44
|
end
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
class GUIRenderer
|
|
3
|
+
attr_reader :visible
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
def initialize(visible = true)
|
|
6
|
+
@visible = visible
|
|
7
|
+
end
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
def draw(items)
|
|
10
|
+
items.each {|key, value| value.draw} if @visible && items.size > 0
|
|
11
|
+
end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
def hide
|
|
14
|
+
@visible = false
|
|
15
|
+
end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
def display
|
|
18
|
+
@visible = true
|
|
19
|
+
end
|
|
18
20
|
end
|
|
19
21
|
end
|
data/lib/Gosuplus/gui/icon.rb
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
module
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
module GUI
|
|
3
|
+
class Icon
|
|
4
|
+
include Essentials
|
|
5
|
+
attr_accessor :body
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
def initialize(image, position)
|
|
8
|
+
@image = image
|
|
9
|
+
@body = Body.new(position, image.width, image.height)
|
|
10
|
+
end
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
def update; end
|
|
13
|
+
def draw; @image.draw(@body.position.x, @body.position.y, 499); end
|
|
14
|
+
end
|
|
13
15
|
end
|
|
14
16
|
end
|
data/lib/Gosuplus/gui/text.rb
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
module
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
module GUI
|
|
3
|
+
class Text
|
|
4
|
+
include Essentials
|
|
5
|
+
attr_accessor :body
|
|
6
|
+
|
|
7
|
+
def initialize(text, font, position = nil)
|
|
8
|
+
position = Vec2.new(0, 0) if position.is_a? NilClass
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
@text, @font = text, font
|
|
11
|
+
@body = Body.new(position, font.text_width(text), font.height)
|
|
12
|
+
end
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
def update; end
|
|
15
|
+
def draw; @font.draw(@text, @body.position.x, @body.position.y, 500); end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
def text=(new_text)
|
|
18
|
+
@text = new_text
|
|
19
|
+
@width = @font.text_width(text)
|
|
20
|
+
end
|
|
19
21
|
end
|
|
20
22
|
end
|
|
21
23
|
end
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
module
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
module GUI
|
|
3
|
+
class Toggleable < Button
|
|
4
|
+
attr_reader :state
|
|
5
|
+
def initialize(position, image, checkbox, checkmark, input_handler, key_id)
|
|
6
|
+
super(position, image, input_handler, key_id)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
@checkbox = Icon.new(checkbox, position)
|
|
9
|
+
@checkmark = Icon.new(checkmark, position)
|
|
10
|
+
@checkbox.center(@icon)
|
|
11
|
+
@checkmark.center(@icon)
|
|
12
|
+
@state = :checked
|
|
13
|
+
end
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
def draw
|
|
16
|
+
super
|
|
17
|
+
ButtonRenderer.draw(@checkbox)
|
|
18
|
+
ButtonRenderer.draw(@checkmark) if @state == :checked
|
|
19
|
+
end
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
def update(x, y)
|
|
22
|
+
super(x, y)
|
|
23
|
+
next_state if @active
|
|
24
|
+
end
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
def next_state; @state = @state == :checked ? :unchecked : :checked; end
|
|
27
|
+
def set_checkbox(image); @checkbox = image; end
|
|
28
|
+
def set_checker(image); @checker = image; end
|
|
29
|
+
end
|
|
28
30
|
end
|
|
29
31
|
end
|
|
@@ -1,45 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
class ResourceLoader
|
|
3
|
+
def initialize(window, state_name)
|
|
4
|
+
@state_name, @window = window, state_name
|
|
5
|
+
@resources = {}
|
|
6
|
+
end
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
def load_resources
|
|
9
|
+
filepath = "./lib/states/#{@state_name}_resources.txt".downcase
|
|
10
|
+
File.new(filepath, 'w') unless File.file?(filepath)
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
data = File.readlines(filepath)
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
data.each do |content|
|
|
15
|
+
content = content.strip.split(" ")
|
|
16
|
+
content[2].insert(0, './assets/')
|
|
17
|
+
content[1] = content[1].to_sym
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
case content[0]
|
|
20
|
+
when 'image'
|
|
21
|
+
load_image(content[1], content[2])
|
|
22
|
+
when 'font'
|
|
23
|
+
load_font(content[1], content[2], content[3].to_i)
|
|
24
|
+
when 'spritesheet'
|
|
25
|
+
load_spritesheet(content[1], content[2], content[3].to_i, content[4].to_i)
|
|
26
|
+
end
|
|
25
27
|
end
|
|
28
|
+
@resources
|
|
26
29
|
end
|
|
27
|
-
@resources
|
|
28
|
-
end
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
private
|
|
32
|
+
def load_image(key, path)
|
|
33
|
+
raise IOError, 'path must point to a existing file!' unless File.file?(path)
|
|
34
|
+
@resources[key] = Gosu::Image.new(@window, path, false) if @resources[key].nil?
|
|
35
|
+
end
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
def load_font(key, path, height)
|
|
38
|
+
raise IOError, 'path must point to a existing file!' unless File.file?(path)
|
|
39
|
+
@resources[key] = Gosu::Font.new(@window, path, height) if @resources[key].nil?
|
|
40
|
+
end
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
def load_spritesheet(key, path, width, height)
|
|
43
|
+
raise IOError, 'path must point to a existing file!' unless File.file?(path)
|
|
44
|
+
@resources[key] = Gosu::Image.load_tiles(@window, path, width, height, true) if @resources[key].nil?
|
|
45
|
+
end
|
|
44
46
|
end
|
|
45
47
|
end
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
class ResourceManager
|
|
3
|
+
def initialize(window)
|
|
4
|
+
@window = window
|
|
5
|
+
@resources = {}
|
|
6
|
+
end
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
def load_resources(state_name)
|
|
9
|
+
@resources = ResourceLoader.new(state_name, @window).load_resources
|
|
10
|
+
end
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
def [](*keys)
|
|
13
|
+
return @resources[keys[0]] if keys.size == 1
|
|
14
|
+
keys.map {|key| @resources[key]}
|
|
15
|
+
end
|
|
14
16
|
end
|
|
15
17
|
end
|
data/lib/Gosuplus/state.rb
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
class State
|
|
3
|
+
def initialize(window, rm, input_handler)
|
|
4
|
+
@window, @rm, @input_handler = window, rm, input_handler
|
|
5
|
+
@GUI = GUI::GUI.new(GUIRenderer.new)
|
|
6
|
+
@objects = []
|
|
7
|
+
end
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
def update
|
|
10
|
+
StateUpdater.update(@objects)
|
|
11
|
+
@GUI.update(@window.mouse_x, @window.mouse_y)
|
|
12
|
+
end
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
def draw
|
|
15
|
+
StateRenderer.render(@objects)
|
|
16
|
+
@GUI.draw
|
|
17
|
+
end
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
def handle_input(key, state)
|
|
20
|
+
@input_handler.set_state(key, state)
|
|
21
|
+
end
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
def load; end
|
|
24
|
+
def on_load; @rm.load_resources(self.class.name); load; end
|
|
25
|
+
def on_exit; end
|
|
26
|
+
end
|
|
25
27
|
end
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
class StateInputHandler
|
|
3
|
+
def initialize
|
|
4
|
+
@button_state = {}
|
|
5
|
+
end
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
def set_state(key, state)
|
|
8
|
+
@button_state[key] = state
|
|
9
|
+
end
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
def get_state(key)
|
|
12
|
+
@button_state[key]
|
|
13
|
+
end
|
|
12
14
|
end
|
|
13
15
|
end
|
|
@@ -1,36 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
class StateManager
|
|
3
|
+
def initialize(window)
|
|
4
|
+
@states = []
|
|
5
|
+
@index = 0
|
|
6
|
+
end
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
def update
|
|
9
|
+
@states[@index].update
|
|
10
|
+
end
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
def draw
|
|
13
|
+
@states[@index].draw
|
|
14
|
+
end
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
def handle_input(key, type)
|
|
17
|
+
@states[@index].handle_input(key, type)
|
|
18
|
+
end
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
def next
|
|
21
|
+
@states[@index].on_exit
|
|
22
|
+
@states[@index].on_load
|
|
23
|
+
@index += 1
|
|
24
|
+
end
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
def previous
|
|
27
|
+
@states[@index].on_exit
|
|
28
|
+
@states[@index].on_load
|
|
29
|
+
@index -= 1
|
|
30
|
+
end
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
def add(state)
|
|
33
|
+
state.on_load unless @states.size > 0
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
@states << state
|
|
36
|
+
end
|
|
35
37
|
end
|
|
36
38
|
end
|
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
class ExampleState < State
|
|
3
|
+
def load
|
|
4
|
+
button = GUI::Button.new(Vec2.new(50, 50), @rm[:background], @input_handler,
|
|
5
|
+
256,'Calculate', @rm[:font_default])
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
button_2 = GUI::Button.new(Vec2.new(250, 50), @rm[:background], @input_handler,
|
|
8
|
+
256,'Calculate', @rm[:font_default])
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
checkbox = GUI::Toggleable.new(Vec2.new(50, 100), @rm[:background], @rm[:checkbox],
|
|
11
|
+
@rm[:checkmark], @input_handler, 256)
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
checkbox_2 = GUI::Toggleable.new(Vec2.new(50, 150), @rm[:background], @rm[:checkbox],
|
|
14
|
+
@rm[:checkmark], @input_handler, 256)
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
button.timer = Timer.new(120)
|
|
17
|
+
button_2.timer = Timer.new(120)
|
|
18
|
+
checkbox.timer = Timer.new(30)
|
|
19
|
+
checkbox_2.timer = Timer.new(30, 0)
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
@GUI.add_button(:default, button)
|
|
22
|
+
@GUI.add_button(:button_2, button_2)
|
|
23
|
+
@GUI.add_button(:checkbox, checkbox)
|
|
24
|
+
@GUI.add_button(:checkbox_2, checkbox_2)
|
|
25
|
+
end
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
def update
|
|
28
|
+
super
|
|
29
|
+
puts "CLICKED 2" if @GUI.get_button(:button_2).active?
|
|
30
|
+
puts "clicked" if @GUI.get_button(:default).active?
|
|
31
|
+
puts "CHECKED" if @GUI.get_button(:checkbox).active?
|
|
32
|
+
end
|
|
31
33
|
end
|
|
32
34
|
end
|
data/lib/Gosuplus/timer.rb
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
module Gosuplus
|
|
2
|
+
class Timer
|
|
3
|
+
def initialize(time, time_start = 0)
|
|
4
|
+
@time, @time_ready = time_start, time
|
|
5
|
+
end
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
def update
|
|
8
|
+
@time += 1 if @time < @time_ready
|
|
9
|
+
end
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
def ready?
|
|
12
|
+
@time_ready == @time
|
|
13
|
+
end
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
def reset
|
|
16
|
+
@time = 0
|
|
17
|
+
end
|
|
16
18
|
end
|
|
17
19
|
end
|
data/lib/Gosuplus/vec2.rb
CHANGED
data/lib/Gosuplus/vec3.rb
CHANGED
data/lib/Gosuplus/version.rb
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Gosuplus
|
|
2
|
+
class Window < Gosu::Window
|
|
3
|
+
def initialize
|
|
4
|
+
super 640, 480, false
|
|
5
|
+
self.caption = "GosuPlus"
|
|
6
|
+
@state_manager = StateManager.new(self)
|
|
7
|
+
@state_manager.add(ExampleState.new(self, ResourceManager.new(self), StateInputHandler.new))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def update
|
|
11
|
+
@state_manager.update
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def draw
|
|
15
|
+
@state_manager.draw
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def button_down(id)
|
|
19
|
+
@state_manager.handle_input(id, true)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def button_up(id)
|
|
23
|
+
@state_manager.handle_input(id, false)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def needs_cursor?
|
|
27
|
+
true
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/Gosuplus.rb
CHANGED
|
@@ -1,33 +1,2 @@
|
|
|
1
1
|
require 'gosu'
|
|
2
|
-
Dir['/lib/Gosuplus/.*rb'].each {|file| require file}
|
|
3
|
-
|
|
4
|
-
module Gosuplus
|
|
5
|
-
class Window < Gosu::Window
|
|
6
|
-
def initialize
|
|
7
|
-
super 640, 480, false
|
|
8
|
-
self.caption = "GosuPlus"
|
|
9
|
-
@state_manager = StateManager.new(self)
|
|
10
|
-
@state_manager.add(ExampleState.new(self, ResourceManager.new(self), StateInputHandler.new))
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def update
|
|
14
|
-
@state_manager.update
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def draw
|
|
18
|
-
@state_manager.draw
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def button_down(id)
|
|
22
|
-
@state_manager.handle_input(id, true)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def button_up(id)
|
|
26
|
-
@state_manager.handle_input(id, false)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def needs_cursor?
|
|
30
|
-
true
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
2
|
+
Dir['/lib/Gosuplus/.*rb'].each {|file| require file}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: Gosuplus
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Freddan962
|
|
@@ -84,6 +84,7 @@ files:
|
|
|
84
84
|
- lib/Gosuplus/vec2.rb
|
|
85
85
|
- lib/Gosuplus/vec3.rb
|
|
86
86
|
- lib/Gosuplus/version.rb
|
|
87
|
+
- lib/Gosuplus/window.rb
|
|
87
88
|
homepage: https://github.com/Freddan962/GosuPlus
|
|
88
89
|
licenses:
|
|
89
90
|
- MIT
|