Gosuplus 1.0
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 +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/Gosuplus.gemspec +23 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/Gosuplus/body.rb +9 -0
- data/lib/Gosuplus/collision.rb +13 -0
- data/lib/Gosuplus/contentmanager.rb +31 -0
- data/lib/Gosuplus/drawable.rb +5 -0
- data/lib/Gosuplus/drawable_rot.rb +5 -0
- data/lib/Gosuplus/entity.rb +3 -0
- data/lib/Gosuplus/essentials.rb +5 -0
- data/lib/Gosuplus/gui/button.rb +41 -0
- data/lib/Gosuplus/gui/buttonrenderer.rb +5 -0
- data/lib/Gosuplus/gui/form/base.rb +25 -0
- data/lib/Gosuplus/gui/form/renderer.rb +9 -0
- data/lib/Gosuplus/gui/form/text.rb +9 -0
- data/lib/Gosuplus/gui/gui.rb +42 -0
- data/lib/Gosuplus/gui/guirenderer.rb +19 -0
- data/lib/Gosuplus/gui/icon.rb +14 -0
- data/lib/Gosuplus/gui/text.rb +21 -0
- data/lib/Gosuplus/gui/toggleable.rb +29 -0
- data/lib/Gosuplus/resourceloader.rb +45 -0
- data/lib/Gosuplus/resourcemanager.rb +15 -0
- data/lib/Gosuplus/state.rb +25 -0
- data/lib/Gosuplus/stateinputhandler.rb +13 -0
- data/lib/Gosuplus/statemanager.rb +36 -0
- data/lib/Gosuplus/staterenderer.rb +5 -0
- data/lib/Gosuplus/states/example_state.rb +32 -0
- data/lib/Gosuplus/states/examplestate_resources.txt +4 -0
- data/lib/Gosuplus/stateupdater.rb +5 -0
- data/lib/Gosuplus/timer.rb +17 -0
- data/lib/Gosuplus/vec2.rb +7 -0
- data/lib/Gosuplus/vec3.rb +7 -0
- data/lib/Gosuplus/version.rb +3 -0
- data/lib/Gosuplus.rb +33 -0
- metadata +111 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: be3141ac9cbf6ae61c2d33c1a2fe60eae5c755a4
|
|
4
|
+
data.tar.gz: 9ce70ac4b13234b71749e1cdfbb830fedfddb8f8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 50d30a60837d3c01771bd2469d4c7ccb10d2b92a250bddc402eb920920b9c617552144fd3f6931f33d5b4b20e0af7ae7772d57fac003846514f97fd5358a70b7
|
|
7
|
+
data.tar.gz: cbeecd746c7ec36dbd2f99f7eb13d11f25cdba2f862dce7ec63096b25e32233baf9b23e4a21f87208e0bfe4fde1e0305f0bd11e9b98eec6c512e3f178309b3cd
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gosuplus.gemspec
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'Gosuplus/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "Gosuplus"
|
|
8
|
+
spec.version = Gosuplus::VERSION
|
|
9
|
+
spec.authors = ["Freddan962"]
|
|
10
|
+
spec.email = ["fredde.sander@gmail.se"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Gosuplus is a extension for Gosu}
|
|
13
|
+
spec.description = %q{}
|
|
14
|
+
spec.homepage = "https://github.com/Freddan962/GosuPlus"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
23
|
+
end
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Freddan962
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Gosuplus
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/Gosuplus`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'Gosuplus'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install Gosuplus
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/Gosuplus/fork )
|
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "Gosuplus"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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
|
|
6
|
+
|
|
7
|
+
@position, @width, @height, @angle = position, width, height, angle
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Collision
|
|
2
|
+
def self.rectangular_collision?(body, body2)
|
|
3
|
+
b1 = generate_quadratic_sides body
|
|
4
|
+
b2 = generate_quadratic_sides body2
|
|
5
|
+
|
|
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
|
|
9
|
+
|
|
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}
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
|
7
|
+
|
|
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
|
|
14
|
+
|
|
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]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
surrounding_objects
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def clean_array
|
|
29
|
+
@content_grid = Array.new(GameWindow::HEIGHT/@grid_height + 1) { Array.new(GameWindow::WIDTH/@grid_width + 1) { nil }}
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
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)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def draw
|
|
14
|
+
ButtonRenderer.draw(@icon, @text)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def update(x, y)
|
|
18
|
+
@active = false if @active
|
|
19
|
+
|
|
20
|
+
unless @timer.nil?
|
|
21
|
+
if activated?(x, y)
|
|
22
|
+
@timer.reset
|
|
23
|
+
@active = true
|
|
24
|
+
end
|
|
25
|
+
else
|
|
26
|
+
@active = false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
@timer.update
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def active?
|
|
33
|
+
@active
|
|
34
|
+
end
|
|
35
|
+
|
|
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)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
|
7
|
+
|
|
8
|
+
@visible_text = text ? text : String
|
|
9
|
+
@actual_text = String
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def draw
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def update(x, y)
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def activated?(x, y)
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module GUI
|
|
2
|
+
class GUI
|
|
3
|
+
include Collision
|
|
4
|
+
def initialize(renderer)
|
|
5
|
+
@renderer = renderer
|
|
6
|
+
@items = {}
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def draw
|
|
10
|
+
@renderer.draw(@items)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def update(mouse_x, mouse_y)
|
|
14
|
+
@items.each {|key, element| element.update(mouse_x, mouse_y)}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def set_font(font)
|
|
18
|
+
@font = font
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def get_button(key)
|
|
22
|
+
@items[key]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def add_button(key, button)
|
|
26
|
+
@items[key] = button
|
|
27
|
+
end
|
|
28
|
+
|
|
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
|
|
33
|
+
|
|
34
|
+
def add_icon(key, image, position)
|
|
35
|
+
@items[key] = Icon.new(image, position)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def [](key)
|
|
39
|
+
@items[key]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class GUIRenderer
|
|
2
|
+
attr_reader :visible
|
|
3
|
+
|
|
4
|
+
def initialize(visible = true)
|
|
5
|
+
@visible = visible
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def draw(items)
|
|
9
|
+
items.each {|key, value| value.draw} if @visible && items.size > 0
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def hide
|
|
13
|
+
@visible = false
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def display
|
|
17
|
+
@visible = true
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module GUI
|
|
2
|
+
class Icon
|
|
3
|
+
include Essentials
|
|
4
|
+
attr_accessor :body
|
|
5
|
+
|
|
6
|
+
def initialize(image, position)
|
|
7
|
+
@image = image
|
|
8
|
+
@body = Body.new(position, image.width, image.height)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def update; end
|
|
12
|
+
def draw; @image.draw(@body.position.x, @body.position.y, 499); end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
|
8
|
+
|
|
9
|
+
@text, @font = text, font
|
|
10
|
+
@body = Body.new(position, font.text_width(text), font.height)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def update; end
|
|
14
|
+
def draw; @font.draw(@text, @body.position.x, @body.position.y, 500); end
|
|
15
|
+
|
|
16
|
+
def text=(new_text)
|
|
17
|
+
@text = new_text
|
|
18
|
+
@width = @font.text_width(text)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
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)
|
|
6
|
+
|
|
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
|
|
13
|
+
|
|
14
|
+
def draw
|
|
15
|
+
super
|
|
16
|
+
ButtonRenderer.draw(@checkbox)
|
|
17
|
+
ButtonRenderer.draw(@checkmark) if @state == :checked
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def update(x, y)
|
|
21
|
+
super(x, y)
|
|
22
|
+
next_state if @active
|
|
23
|
+
end
|
|
24
|
+
|
|
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
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
class ResourceLoader
|
|
2
|
+
def initialize(window, state_name)
|
|
3
|
+
@state_name, @window = window, state_name
|
|
4
|
+
@resources = {}
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def load_resources
|
|
8
|
+
filepath = "./lib/states/#{@state_name}_resources.txt".downcase
|
|
9
|
+
File.new(filepath, 'w') unless File.file?(filepath)
|
|
10
|
+
|
|
11
|
+
data = File.readlines(filepath)
|
|
12
|
+
|
|
13
|
+
data.each do |content|
|
|
14
|
+
content = content.strip.split(" ")
|
|
15
|
+
content[2].insert(0, './assets/')
|
|
16
|
+
content[1] = content[1].to_sym
|
|
17
|
+
|
|
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)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
@resources
|
|
28
|
+
end
|
|
29
|
+
|
|
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
|
|
35
|
+
|
|
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
|
|
40
|
+
|
|
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?
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class ResourceManager
|
|
2
|
+
def initialize(window)
|
|
3
|
+
@window = window
|
|
4
|
+
@resources = {}
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def load_resources(state_name)
|
|
8
|
+
@resources = ResourceLoader.new(state_name, @window).load_resources
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def [](*keys)
|
|
12
|
+
return @resources[keys[0]] if keys.size == 1
|
|
13
|
+
keys.map {|key| @resources[key]}
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
|
7
|
+
|
|
8
|
+
def update
|
|
9
|
+
StateUpdater.update(@objects)
|
|
10
|
+
@GUI.update(@window.mouse_x, @window.mouse_y)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def draw
|
|
14
|
+
StateRenderer.render(@objects)
|
|
15
|
+
@GUI.draw
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def handle_input(key, state)
|
|
19
|
+
@input_handler.set_state(key, state)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def load; end
|
|
23
|
+
def on_load; @rm.load_resources(self.class.name); load; end
|
|
24
|
+
def on_exit; end
|
|
25
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
class StateManager
|
|
2
|
+
def initialize(window)
|
|
3
|
+
@states = []
|
|
4
|
+
@index = 0
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def update
|
|
8
|
+
@states[@index].update
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def draw
|
|
12
|
+
@states[@index].draw
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def handle_input(key, type)
|
|
16
|
+
@states[@index].handle_input(key, type)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def next
|
|
20
|
+
@states[@index].on_exit
|
|
21
|
+
@states[@index].on_load
|
|
22
|
+
@index += 1
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def previous
|
|
26
|
+
@states[@index].on_exit
|
|
27
|
+
@states[@index].on_load
|
|
28
|
+
@index -= 1
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def add(state)
|
|
32
|
+
state.on_load unless @states.size > 0
|
|
33
|
+
|
|
34
|
+
@states << state
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
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])
|
|
5
|
+
|
|
6
|
+
button_2 = GUI::Button.new(Vec2.new(250, 50), @rm[:background], @input_handler,
|
|
7
|
+
256,'Calculate', @rm[:font_default])
|
|
8
|
+
|
|
9
|
+
checkbox = GUI::Toggleable.new(Vec2.new(50, 100), @rm[:background], @rm[:checkbox],
|
|
10
|
+
@rm[:checkmark], @input_handler, 256)
|
|
11
|
+
|
|
12
|
+
checkbox_2 = GUI::Toggleable.new(Vec2.new(50, 150), @rm[:background], @rm[:checkbox],
|
|
13
|
+
@rm[:checkmark], @input_handler, 256)
|
|
14
|
+
|
|
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)
|
|
19
|
+
|
|
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
|
|
25
|
+
|
|
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?
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/Gosuplus.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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
|
metadata
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: Gosuplus
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '1.0'
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Freddan962
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-02-15 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.8'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.8'
|
|
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
|
+
email:
|
|
43
|
+
- fredde.sander@gmail.se
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- ".gitignore"
|
|
49
|
+
- Gemfile
|
|
50
|
+
- Gosuplus.gemspec
|
|
51
|
+
- LICENSE.txt
|
|
52
|
+
- README.md
|
|
53
|
+
- Rakefile
|
|
54
|
+
- bin/console
|
|
55
|
+
- bin/setup
|
|
56
|
+
- lib/Gosuplus.rb
|
|
57
|
+
- lib/Gosuplus/body.rb
|
|
58
|
+
- lib/Gosuplus/collision.rb
|
|
59
|
+
- lib/Gosuplus/contentmanager.rb
|
|
60
|
+
- lib/Gosuplus/drawable.rb
|
|
61
|
+
- lib/Gosuplus/drawable_rot.rb
|
|
62
|
+
- lib/Gosuplus/entity.rb
|
|
63
|
+
- lib/Gosuplus/essentials.rb
|
|
64
|
+
- lib/Gosuplus/gui/button.rb
|
|
65
|
+
- lib/Gosuplus/gui/buttonrenderer.rb
|
|
66
|
+
- lib/Gosuplus/gui/form/base.rb
|
|
67
|
+
- lib/Gosuplus/gui/form/renderer.rb
|
|
68
|
+
- lib/Gosuplus/gui/form/text.rb
|
|
69
|
+
- lib/Gosuplus/gui/gui.rb
|
|
70
|
+
- lib/Gosuplus/gui/guirenderer.rb
|
|
71
|
+
- lib/Gosuplus/gui/icon.rb
|
|
72
|
+
- lib/Gosuplus/gui/text.rb
|
|
73
|
+
- lib/Gosuplus/gui/toggleable.rb
|
|
74
|
+
- lib/Gosuplus/resourceloader.rb
|
|
75
|
+
- lib/Gosuplus/resourcemanager.rb
|
|
76
|
+
- lib/Gosuplus/state.rb
|
|
77
|
+
- lib/Gosuplus/stateinputhandler.rb
|
|
78
|
+
- lib/Gosuplus/statemanager.rb
|
|
79
|
+
- lib/Gosuplus/staterenderer.rb
|
|
80
|
+
- lib/Gosuplus/states/example_state.rb
|
|
81
|
+
- lib/Gosuplus/states/examplestate_resources.txt
|
|
82
|
+
- lib/Gosuplus/stateupdater.rb
|
|
83
|
+
- lib/Gosuplus/timer.rb
|
|
84
|
+
- lib/Gosuplus/vec2.rb
|
|
85
|
+
- lib/Gosuplus/vec3.rb
|
|
86
|
+
- lib/Gosuplus/version.rb
|
|
87
|
+
homepage: https://github.com/Freddan962/GosuPlus
|
|
88
|
+
licenses:
|
|
89
|
+
- MIT
|
|
90
|
+
metadata: {}
|
|
91
|
+
post_install_message:
|
|
92
|
+
rdoc_options: []
|
|
93
|
+
require_paths:
|
|
94
|
+
- lib
|
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
|
+
requirements:
|
|
97
|
+
- - ">="
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: '0'
|
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - ">="
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '0'
|
|
105
|
+
requirements: []
|
|
106
|
+
rubyforge_project:
|
|
107
|
+
rubygems_version: 2.2.3
|
|
108
|
+
signing_key:
|
|
109
|
+
specification_version: 4
|
|
110
|
+
summary: Gosuplus is a extension for Gosu
|
|
111
|
+
test_files: []
|