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