cyberarm_engine 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cyberarm_engine.gemspec +36 -0
- data/lib/cyberarm_engine.rb +36 -0
- data/lib/cyberarm_engine/background.rb +166 -0
- data/lib/cyberarm_engine/common.rb +85 -0
- data/lib/cyberarm_engine/engine.rb +95 -0
- data/lib/cyberarm_engine/game_object.rb +256 -0
- data/lib/cyberarm_engine/game_state.rb +90 -0
- data/lib/cyberarm_engine/lib/bounding_box.rb +124 -0
- data/lib/cyberarm_engine/lib/vector.rb +97 -0
- data/lib/cyberarm_engine/objects/multi_line_text.rb +67 -0
- data/lib/cyberarm_engine/objects/text.rb +96 -0
- data/lib/cyberarm_engine/objects/timer.rb +23 -0
- data/lib/cyberarm_engine/ui/border_canvas.rb +101 -0
- data/lib/cyberarm_engine/ui/button.rb +53 -0
- data/lib/cyberarm_engine/ui/check_box.rb +52 -0
- data/lib/cyberarm_engine/ui/container.rb +154 -0
- data/lib/cyberarm_engine/ui/dsl.rb +82 -0
- data/lib/cyberarm_engine/ui/edit_line.rb +88 -0
- data/lib/cyberarm_engine/ui/element.rb +197 -0
- data/lib/cyberarm_engine/ui/event.rb +46 -0
- data/lib/cyberarm_engine/ui/flow.rb +15 -0
- data/lib/cyberarm_engine/ui/gui_state.rb +119 -0
- data/lib/cyberarm_engine/ui/image.rb +42 -0
- data/lib/cyberarm_engine/ui/label.rb +34 -0
- data/lib/cyberarm_engine/ui/stack.rb +11 -0
- data/lib/cyberarm_engine/ui/style.rb +15 -0
- data/lib/cyberarm_engine/ui/theme.rb +91 -0
- data/lib/cyberarm_engine/ui/toggle_button.rb +49 -0
- data/lib/cyberarm_engine/version.rb +4 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fa7bd8af9a8d26136e5db4b7dc00dd803d0d3162ec1c391d7c39ea05017096a0
|
4
|
+
data.tar.gz: c6b3c5625ee5ca921f7bae1bf0e0b48774cf999e2c7a794d645331c4031b4fee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f1700a96782765f37bfa11d7dc79dc7a45aaa7ca434a27ee968264d1ea00beb399de8599973eb8fc1055cfd71426350b203a6d973dcd560689e9d32d05d4eea9
|
7
|
+
data.tar.gz: 8eee3937538240a58f0dfbcbcdb9ad02c02bee21ff66fda91dd74bbcd66953997c12aa9bd1f0e120682ee9f3d645b905aa71299c0ad509276b577bd4467377f6
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Cyberarm
|
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,43 @@
|
|
1
|
+
# CyberarmEngine
|
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/cyberarm_engine`. 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 'cyberarm_engine'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install cyberarm_engine
|
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 `rake test` to run the tests. You can also 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`, which will 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
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cyberarm/cyberarm_engine.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the CyberarmEngine project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the ruby moto of "Matz is nice so we are nice."
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cyberarm_engine"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "cyberarm_engine/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cyberarm_engine"
|
8
|
+
spec.version = CyberarmEngine::VERSION
|
9
|
+
spec.authors = ["Cyberarm"]
|
10
|
+
spec.email = ["matthewlikesrobots@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Make games quickly and easily with gosu}
|
13
|
+
spec.description = %q{Yet another game making framework around gosu}
|
14
|
+
spec.homepage = "https://github.com/cyberarm/cyberarm_engine"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
19
|
+
else
|
20
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
21
|
+
"public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
f.match(%r{^(test|spec|features)/})
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_dependency "gosu", "~> 0.14.0"
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "gosu"
|
2
|
+
|
3
|
+
require_relative "cyberarm_engine/version"
|
4
|
+
|
5
|
+
require_relative "cyberarm_engine/common"
|
6
|
+
|
7
|
+
require_relative "cyberarm_engine/game_object"
|
8
|
+
require_relative "cyberarm_engine/engine"
|
9
|
+
|
10
|
+
require_relative "cyberarm_engine/lib/bounding_box"
|
11
|
+
require_relative "cyberarm_engine/lib/vector"
|
12
|
+
require_relative "cyberarm_engine/background"
|
13
|
+
|
14
|
+
require_relative "cyberarm_engine/objects/text"
|
15
|
+
require_relative "cyberarm_engine/objects/timer"
|
16
|
+
require_relative "cyberarm_engine/objects/multi_line_text"
|
17
|
+
|
18
|
+
require_relative "cyberarm_engine/ui/theme"
|
19
|
+
require_relative "cyberarm_engine/ui/event"
|
20
|
+
require_relative "cyberarm_engine/ui/style"
|
21
|
+
require_relative "cyberarm_engine/ui/border_canvas"
|
22
|
+
require_relative "cyberarm_engine/ui/element"
|
23
|
+
require_relative "cyberarm_engine/ui/label"
|
24
|
+
require_relative "cyberarm_engine/ui/button"
|
25
|
+
require_relative "cyberarm_engine/ui/toggle_button"
|
26
|
+
require_relative "cyberarm_engine/ui/edit_line"
|
27
|
+
require_relative "cyberarm_engine/ui/image"
|
28
|
+
require_relative "cyberarm_engine/ui/container"
|
29
|
+
|
30
|
+
require_relative "cyberarm_engine/ui/flow"
|
31
|
+
require_relative "cyberarm_engine/ui/stack"
|
32
|
+
require_relative "cyberarm_engine/ui/check_box"
|
33
|
+
require_relative "cyberarm_engine/ui/dsl"
|
34
|
+
|
35
|
+
require_relative "cyberarm_engine/game_state"
|
36
|
+
require_relative "cyberarm_engine/ui/gui_state"
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require "gosu"
|
2
|
+
|
3
|
+
module CyberarmEngine
|
4
|
+
class Background
|
5
|
+
attr_accessor :x, :y, :z, :width, :height, :angle, :debug
|
6
|
+
attr_reader :background
|
7
|
+
def initialize(x: 0, y: 0, z: 0, width: 0, height: 0, background: Gosu::Color::BLACK, angle: 0, debug: false)
|
8
|
+
@x,@y,@z = x,y,z
|
9
|
+
@width,@height = width,height
|
10
|
+
@debug = debug
|
11
|
+
|
12
|
+
@paint = Paint.new(background)
|
13
|
+
@angle = angle
|
14
|
+
|
15
|
+
@top_left = Vector.new(@x, @y)
|
16
|
+
@top_right = Vector.new(@x + @width, @y)
|
17
|
+
@bottom_left = Vector.new(@x, @y + @height)
|
18
|
+
@bottom_right = Vector.new(@x + @width, @y + @height)
|
19
|
+
end
|
20
|
+
|
21
|
+
def draw
|
22
|
+
Gosu.clip_to(@x, @y, @width, @height) do
|
23
|
+
Gosu.draw_quad(
|
24
|
+
@top_left.x, @top_left.y, @paint.top_left,
|
25
|
+
@top_right.x, @top_right.y, @paint.top_right,
|
26
|
+
@bottom_right.x, @bottom_right.y, @paint.bottom_right,
|
27
|
+
@bottom_left.x, @bottom_left.y, @paint.bottom_left,
|
28
|
+
@z
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
debug_outline if @debug
|
33
|
+
end
|
34
|
+
|
35
|
+
def update
|
36
|
+
origin_x = (@x + (@width/2))
|
37
|
+
origin_y = (@y + (@height/2))
|
38
|
+
|
39
|
+
points = [
|
40
|
+
@top_left = Vector.new(@x, @y),
|
41
|
+
@top_right = Vector.new(@x + @width, @y),
|
42
|
+
@bottom_left = Vector.new(@x, @y + @height),
|
43
|
+
@bottom_right = Vector.new(@x + @width, @y + @height)
|
44
|
+
]
|
45
|
+
|
46
|
+
[@top_left, @top_right, @bottom_left, @bottom_right].each do |vector|
|
47
|
+
temp_x = vector.x - origin_x
|
48
|
+
temp_y = vector.y - origin_y
|
49
|
+
|
50
|
+
# 90 is up here, while gosu uses 0 for up.
|
51
|
+
radians = (@angle + 90).gosu_to_radians
|
52
|
+
vector.x = (@x + (@width/2)) + ((temp_x * Math.cos(radians)) - (temp_y * Math.sin(radians)))
|
53
|
+
vector.y = (@y + (@height/2)) + ((temp_x * Math.sin(radians)) + (temp_y * Math.cos(radians)))
|
54
|
+
end
|
55
|
+
|
56
|
+
# [
|
57
|
+
# [:top, @top_left, @top_right],
|
58
|
+
# [:right, @top_right, @bottom_right],
|
59
|
+
# [:bottom, @bottom_right, @bottom_left],
|
60
|
+
# [:left, @bottom_left, @top_left]
|
61
|
+
# ].each do |edge|
|
62
|
+
# points.each do |point|
|
63
|
+
# puts "#{edge.first} -> #{shortest_distance(point, edge[1], edge[2])}"
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
end
|
67
|
+
|
68
|
+
def shortest_distance(point, la, lb)
|
69
|
+
a = la.x - lb.x
|
70
|
+
b = la.y - lb.y
|
71
|
+
c = Gosu.distance(la.x, la.y, lb.x, lb.y)
|
72
|
+
p a,b,c
|
73
|
+
d = (a * point.x + b * point.y + c).abs / (Math.sqrt(a * a + b * b))
|
74
|
+
puts "Distance: #{d}"
|
75
|
+
exit!
|
76
|
+
return d
|
77
|
+
end
|
78
|
+
|
79
|
+
def debug_outline
|
80
|
+
# Top
|
81
|
+
Gosu.draw_line(
|
82
|
+
@x, @y, Gosu::Color::RED,
|
83
|
+
@x + @width, @y, Gosu::Color::RED,
|
84
|
+
@z
|
85
|
+
)
|
86
|
+
|
87
|
+
# Right
|
88
|
+
Gosu.draw_line(
|
89
|
+
@x + @width, @y, Gosu::Color::RED,
|
90
|
+
@x + @width, @y + @height, Gosu::Color::RED,
|
91
|
+
@z
|
92
|
+
)
|
93
|
+
|
94
|
+
# Bottom
|
95
|
+
Gosu.draw_line(
|
96
|
+
@x + @width, @y + @height, Gosu::Color::RED,
|
97
|
+
@x, @y + @height, Gosu::Color::RED,
|
98
|
+
@z
|
99
|
+
)
|
100
|
+
|
101
|
+
# Left
|
102
|
+
Gosu.draw_line(
|
103
|
+
@x, @y + @height, Gosu::Color::RED,
|
104
|
+
@x, @y, Gosu::Color::RED,
|
105
|
+
@z
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
def background=(_background)
|
110
|
+
@paint.set(_background)
|
111
|
+
update
|
112
|
+
end
|
113
|
+
|
114
|
+
def angle=(n)
|
115
|
+
@angle = n
|
116
|
+
update
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class Paint
|
121
|
+
attr_accessor :top_left, :top_right, :bottom_left, :bottom_right
|
122
|
+
def initialize(background)
|
123
|
+
set(background)
|
124
|
+
end
|
125
|
+
|
126
|
+
def set(background)
|
127
|
+
@background = background
|
128
|
+
|
129
|
+
|
130
|
+
if background.is_a?(Numeric)
|
131
|
+
@top_left = background
|
132
|
+
@top_right = background
|
133
|
+
@bottom_left = background
|
134
|
+
@bottom_right = background
|
135
|
+
elsif background.is_a?(Gosu::Color)
|
136
|
+
@top_left = background
|
137
|
+
@top_right = background
|
138
|
+
@bottom_left = background
|
139
|
+
@bottom_right = background
|
140
|
+
elsif background.is_a?(Array)
|
141
|
+
if background.size == 1
|
142
|
+
set(background.first)
|
143
|
+
elsif background.size == 2
|
144
|
+
@top_left = background.first
|
145
|
+
@top_right = background.last
|
146
|
+
@bottom_left = background.first
|
147
|
+
@bottom_right = background.last
|
148
|
+
elsif background.size == 4
|
149
|
+
@top_left = background[0]
|
150
|
+
@top_right = background[1]
|
151
|
+
@bottom_left = background[2]
|
152
|
+
@bottom_right = background[3]
|
153
|
+
else
|
154
|
+
raise ArgumentError, "background array was empty or had wrong number of elements (expected 2 or 4 elements)"
|
155
|
+
end
|
156
|
+
elsif background.is_a?(Hash)
|
157
|
+
@top_left = background[:top_left]
|
158
|
+
@top_right = background[:top_right]
|
159
|
+
@bottom_left = background[:bottom_left]
|
160
|
+
@bottom_right = background[:bottom_right]
|
161
|
+
else
|
162
|
+
raise ArgumentError, "background '#{background}' of type '#{background.class}' was not able to be processed"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module CyberarmEngine
|
2
|
+
module Common
|
3
|
+
def push_state(klass, options={})
|
4
|
+
$window.push_state(klass, options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def current_state
|
8
|
+
$window.current_state
|
9
|
+
end
|
10
|
+
|
11
|
+
def previous_state
|
12
|
+
$window.previous_state
|
13
|
+
end
|
14
|
+
|
15
|
+
def pop_state
|
16
|
+
$window.pop_state
|
17
|
+
end
|
18
|
+
|
19
|
+
def show_cursor
|
20
|
+
$window.show_cursor
|
21
|
+
end
|
22
|
+
|
23
|
+
def show_cursor=boolean
|
24
|
+
$window.show_cursor = boolean
|
25
|
+
end
|
26
|
+
|
27
|
+
def draw_rect(x, y, width, height, color, z = 0)
|
28
|
+
$window.draw_rect(x,y,width,height,color,z)
|
29
|
+
end
|
30
|
+
|
31
|
+
def fill(color, z = 0)
|
32
|
+
draw_rect(0, 0, $window.width, $window.height, color, z)
|
33
|
+
end
|
34
|
+
|
35
|
+
def lighten(color, amount = 25)
|
36
|
+
if defined?(color.alpha)
|
37
|
+
return Gosu::Color.rgba(color.red+amount, color.green+amount, color.blue+amount, color.alpha)
|
38
|
+
else
|
39
|
+
return Gosu::Color.rgb(color.red+amount, color.green+amount, color.blue+amount)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def darken(color, amount = 25)
|
44
|
+
if defined?(color.alpha)
|
45
|
+
return Gosu::Color.rgba(color.red-amount, color.green-amount, color.blue-amount, color.alpha)
|
46
|
+
else
|
47
|
+
return Gosu::Color.rgb(color.red-amount, color.green-amount, color.blue-amount)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_asset(path, hash, klass)
|
52
|
+
asset = nil
|
53
|
+
hash.detect do |_asset, instance|
|
54
|
+
if _asset == path
|
55
|
+
asset = instance
|
56
|
+
true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
unless asset
|
61
|
+
instance = klass.new(path)
|
62
|
+
hash[path] = instance
|
63
|
+
asset = instance
|
64
|
+
end
|
65
|
+
|
66
|
+
return asset
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_image(path)
|
70
|
+
get_asset(path, Engine::IMAGES, Gosu::Image)
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_sample(path)
|
74
|
+
get_asset(path, Engine::SAMPLES, Gosu::Sample)
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_song(path)
|
78
|
+
get_asset(path, Engine::SONGS, Gosu::Song)
|
79
|
+
end
|
80
|
+
|
81
|
+
def window
|
82
|
+
$window
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|