conjuration 0.1.2
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/.rspec +3 -0
- data/.rubocop.yml +28 -0
- data/.rubocop_todo.yml +21 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +82 -0
- data/Rakefile +12 -0
- data/lib/conjuration/concerns/attributes.rb +59 -0
- data/lib/conjuration/game.rb +37 -0
- data/lib/conjuration/game_object.rb +96 -0
- data/lib/conjuration/managers/asset_manager.rb +9 -0
- data/lib/conjuration/managers/debug_manager.rb +93 -0
- data/lib/conjuration/managers/input_manager.rb +47 -0
- data/lib/conjuration/managers/scene_manager.rb +38 -0
- data/lib/conjuration/scene.rb +48 -0
- data/lib/conjuration/version.rb +5 -0
- data/lib/conjuration.rb +12 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1a2cd4153fd1fe67cf858245a3337a12f28e3bf0383a14c4ca5a98021eb446e6
|
4
|
+
data.tar.gz: 0b1975cf3fb9baf67802f204faaef6a91e71a2d080064eb922d22cee2ffc78ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f655cf37edfa05b1ab4b6256a19486b31c3a406ae68c8447f02683b1b946fc13a34266c88017f6c5c332b4603187b2346e58e5988ffde8f41f8009aef4064446
|
7
|
+
data.tar.gz: cecba3e7696c57a11662dce317652bae03b6be7c0addd4d71ac0a2c11a1875de083709305eba38df6a22e3343f4a09fa4a44fa40841e3c0679e4668a2e823364
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
require:
|
4
|
+
- rubocop-rake
|
5
|
+
- rubocop-rspec
|
6
|
+
|
7
|
+
AllCops:
|
8
|
+
NewCops: disable
|
9
|
+
TargetRubyVersion: 3.3.0
|
10
|
+
|
11
|
+
Metrics/AbcSize:
|
12
|
+
AllowedPatterns:
|
13
|
+
- draw_
|
14
|
+
|
15
|
+
Naming/AccessorMethodName:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Naming/MethodParameterName:
|
19
|
+
AllowedNames:
|
20
|
+
- x
|
21
|
+
- y
|
22
|
+
- id
|
23
|
+
|
24
|
+
Style/StringLiterals:
|
25
|
+
EnforcedStyle: double_quotes
|
26
|
+
|
27
|
+
Style/StringLiteralsInInterpolation:
|
28
|
+
EnforcedStyle: double_quotes
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2024-05-16 10:06:07 UTC using RuboCop version 1.63.5.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 7
|
10
|
+
# Configuration parameters: AllowedConstants.
|
11
|
+
Style/Documentation:
|
12
|
+
Exclude:
|
13
|
+
- 'spec/**/*'
|
14
|
+
- 'test/**/*'
|
15
|
+
- 'lib/conjuration/concerns/attributes.rb'
|
16
|
+
- 'lib/conjuration/game.rb'
|
17
|
+
- 'lib/conjuration/game_object.rb'
|
18
|
+
- 'lib/conjuration/managers/asset_manager.rb'
|
19
|
+
- 'lib/conjuration/managers/debug_manager.rb'
|
20
|
+
- 'lib/conjuration/managers/input_manager.rb'
|
21
|
+
- 'lib/conjuration/managers/scene_manager.rb'
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Daniel Dye
|
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,82 @@
|
|
1
|
+
# Conjuration
|
2
|
+
|
3
|
+
A Ruby 2d game engine built on [gosu/gosu](https://github.com/gosu/gosu).
|
4
|
+
|
5
|
+
## Inspiration & Goals
|
6
|
+
|
7
|
+
As a Ruby developer, I want a toolset that allows me to prototype games quickly and easily. I want to be able to experiment with game mechanics and ideas without having to worry about the complexities of a full game engine.
|
8
|
+
|
9
|
+
- Provide a opinionated set of tools to build 2d games in Ruby.
|
10
|
+
- Focus on simplicity and ease of experimentation.
|
11
|
+
- Provide clear examples and documentation to help new developers get started.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
As the gem is based on gosu, you will need to install the gosu dependencies.
|
16
|
+
|
17
|
+
- [Gosu: Getting Started on OS X](https://github.com/gosu/gosu/wiki/Getting-Started-on-OS-X)
|
18
|
+
- [Gosu: Getting Started on Windows](https://github.com/gosu/gosu/wiki/Getting-Started-on-Windows)
|
19
|
+
- [Gosu: Getting Started on Linux](https://github.com/gosu/gosu/wiki/Getting-Started-on-Linux)
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem "conjuration"
|
25
|
+
```
|
26
|
+
|
27
|
+
> TODO: Add project generator. `conjuration new my_game`
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
You should setup your project with the following file structure:
|
32
|
+
|
33
|
+
```
|
34
|
+
.
|
35
|
+
├── src/
|
36
|
+
│ ├── assets
|
37
|
+
│ ├── game_objects
|
38
|
+
│ ├── scenes
|
39
|
+
│ └── game.rb
|
40
|
+
└── main.rb
|
41
|
+
```
|
42
|
+
|
43
|
+
- `main.rb`
|
44
|
+
|
45
|
+
The entrypoint for your game. This is where you require the game file and start the game.
|
46
|
+
|
47
|
+
> TODO: Pull this into a bin script. `conjuration run`
|
48
|
+
|
49
|
+
- `src/game.rb`
|
50
|
+
|
51
|
+
The main game class. This is where you add your initial scene.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
class Game < Conjuration::Game
|
55
|
+
def initialize
|
56
|
+
super(title: "My Game")
|
57
|
+
|
58
|
+
scene_manager.add_scene(:main_menu, MainMenuScene)
|
59
|
+
scene_manager.set_scene(:main_menu)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
- `src/scenes`
|
65
|
+
|
66
|
+
This is where you define each of your game scenes. Each scene should inherit from `Conjuration::Scene`.
|
67
|
+
|
68
|
+
- `src/game_objects`
|
69
|
+
|
70
|
+
This is where you define your game objects. Each game object should inherit from `Conjuration::GameObject`.
|
71
|
+
|
72
|
+
- `src/assets`
|
73
|
+
|
74
|
+
This is where you store your game assets. This can include images, sounds, and other resources.
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Nitemaeric/conjuration.
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Attributes
|
4
|
+
#
|
5
|
+
# This module provides a way to define inspectable attributes for a class.
|
6
|
+
# It provides readers and writers for each attribute, and an inspect method that
|
7
|
+
# displays only defined attributes.
|
8
|
+
#
|
9
|
+
# Instance variables are not added to the inspect output.
|
10
|
+
#
|
11
|
+
# Usage:
|
12
|
+
#
|
13
|
+
# class Person
|
14
|
+
# include Attributes
|
15
|
+
#
|
16
|
+
# attribute :name
|
17
|
+
# attribute :age
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# person = Person.new
|
21
|
+
# person.name = "Alice"
|
22
|
+
# person.age = 30
|
23
|
+
# person.inspect # => "<Person name: \"Alice\", age: 30>"
|
24
|
+
#
|
25
|
+
module Attributes
|
26
|
+
def self.included(base)
|
27
|
+
base.extend(ClassMethods)
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(...)
|
31
|
+
super()
|
32
|
+
|
33
|
+
@attributes = {}
|
34
|
+
end
|
35
|
+
|
36
|
+
def inspect
|
37
|
+
"<#{self.class} #{@attributes.map { |attribute_name, value| "#{attribute_name}: #{value.inspect}" }.join(", ")}>"
|
38
|
+
end
|
39
|
+
|
40
|
+
module ClassMethods
|
41
|
+
def attribute(attribute_name)
|
42
|
+
define_method(attribute_name) do
|
43
|
+
@attributes[attribute_name]
|
44
|
+
end
|
45
|
+
|
46
|
+
define_method("#{attribute_name}=") do |value|
|
47
|
+
@attributes[attribute_name] = value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def boolean_attribute(attribute_name)
|
52
|
+
attribute(attribute_name)
|
53
|
+
|
54
|
+
define_method("#{attribute_name}?") do
|
55
|
+
!!@attributes[attribute_name]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Conjuration
|
4
|
+
class Game < ::Gosu::Window
|
5
|
+
attr_reader :debug_manager, :scene_manager, :input_manager, :target_fps
|
6
|
+
|
7
|
+
def initialize(title:, target_fps: 120, **options)
|
8
|
+
super(1920, 1080, update_interval: 1000.0 / target_fps, **options)
|
9
|
+
|
10
|
+
self.caption = title
|
11
|
+
|
12
|
+
@debug_manager = DebugManager.new
|
13
|
+
@scene_manager = SceneManager.new(self)
|
14
|
+
@input_manager = InputManager.new
|
15
|
+
|
16
|
+
@target_fps = target_fps
|
17
|
+
end
|
18
|
+
|
19
|
+
def update
|
20
|
+
@scene_manager.update(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def draw
|
24
|
+
@scene_manager.draw(self)
|
25
|
+
@debug_manager.draw(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
def button_down(id)
|
29
|
+
@scene_manager.button_down(self, @input_manager.map_button(id))
|
30
|
+
@debug_manager.button_down(self, id)
|
31
|
+
end
|
32
|
+
|
33
|
+
def button_up(id)
|
34
|
+
@scene_manager.button_up(self, @input_manager.map_button(id))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Conjuration
|
4
|
+
class GameObject
|
5
|
+
include Attributes
|
6
|
+
|
7
|
+
attribute :name
|
8
|
+
attribute :x
|
9
|
+
attribute :y
|
10
|
+
attribute :width
|
11
|
+
attribute :height
|
12
|
+
|
13
|
+
boolean_attribute :hovering
|
14
|
+
attribute :clicking
|
15
|
+
|
16
|
+
boolean_attribute :visible
|
17
|
+
|
18
|
+
def initialize(x:, y:, width:, height:)
|
19
|
+
super
|
20
|
+
|
21
|
+
self.x = x
|
22
|
+
self.y = y
|
23
|
+
self.width = width
|
24
|
+
self.height = height
|
25
|
+
self.hovering = false
|
26
|
+
self.clicking = Hash.new(false)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.create(*args, scene:, **kwargs, &block)
|
30
|
+
game_object = new(*args, **kwargs, &block)
|
31
|
+
scene.add_object(game_object)
|
32
|
+
game_object
|
33
|
+
end
|
34
|
+
|
35
|
+
def mouse_position(context)
|
36
|
+
mouse_exited(context)
|
37
|
+
mouse_entered(context)
|
38
|
+
end
|
39
|
+
|
40
|
+
# =====
|
41
|
+
# Helpers
|
42
|
+
# =====
|
43
|
+
|
44
|
+
def in_bounds?(context)
|
45
|
+
context.mouse_x >= x &&
|
46
|
+
context.mouse_x <= x + width &&
|
47
|
+
context.mouse_y >= y &&
|
48
|
+
context.mouse_y <= y + height
|
49
|
+
end
|
50
|
+
|
51
|
+
# ==========
|
52
|
+
# Abstract Methods
|
53
|
+
# ==========
|
54
|
+
|
55
|
+
def draw(context); end
|
56
|
+
def on_click(context, key); end
|
57
|
+
def on_mouse_down(context, key); end
|
58
|
+
def on_mouse_up(context, key); end
|
59
|
+
|
60
|
+
# ==========
|
61
|
+
# Hovering
|
62
|
+
# ==========
|
63
|
+
|
64
|
+
def mouse_exited(context)
|
65
|
+
return unless hovering && !in_bounds?(context)
|
66
|
+
|
67
|
+
self.hovering = false
|
68
|
+
end
|
69
|
+
|
70
|
+
def mouse_entered(context)
|
71
|
+
return unless !hovering && in_bounds?(context)
|
72
|
+
|
73
|
+
self.hovering = true
|
74
|
+
end
|
75
|
+
|
76
|
+
# ==========
|
77
|
+
# Clicking
|
78
|
+
# ==========
|
79
|
+
|
80
|
+
def mouse_down(context, key)
|
81
|
+
on_mouse_down(context, key)
|
82
|
+
|
83
|
+
return unless !clicking[key] && context.input_manager.button_down?(key) && in_bounds?(context)
|
84
|
+
|
85
|
+
clicking[key] = true
|
86
|
+
end
|
87
|
+
|
88
|
+
def mouse_up(context, key)
|
89
|
+
on_mouse_up(context, key)
|
90
|
+
|
91
|
+
on_click(context, key) if clicking[key] && !context.input_manager.button_down?(key) && in_bounds?(context)
|
92
|
+
|
93
|
+
clicking[key] = false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Conjuration
|
4
|
+
class DebugManager
|
5
|
+
include Attributes
|
6
|
+
|
7
|
+
boolean_attribute :enabled
|
8
|
+
|
9
|
+
boolean_attribute :show_fps
|
10
|
+
boolean_attribute :show_grid
|
11
|
+
boolean_attribute :show_coordinates
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super
|
15
|
+
|
16
|
+
self.enabled = false
|
17
|
+
|
18
|
+
self.show_fps = false
|
19
|
+
self.show_grid = false
|
20
|
+
self.show_coordinates = false
|
21
|
+
end
|
22
|
+
|
23
|
+
def draw(window)
|
24
|
+
return unless enabled?
|
25
|
+
|
26
|
+
draw_menu(window)
|
27
|
+
|
28
|
+
draw_fps(window) if show_fps?
|
29
|
+
draw_grid(window) if show_grid?
|
30
|
+
draw_coordinates(window) if show_coordinates?
|
31
|
+
end
|
32
|
+
|
33
|
+
def button_down(_window, id)
|
34
|
+
self.enabled = !enabled if id == Gosu::KB_F12
|
35
|
+
|
36
|
+
return unless enabled?
|
37
|
+
|
38
|
+
case id
|
39
|
+
when Gosu::KB_F1
|
40
|
+
self.show_fps = !show_fps
|
41
|
+
when Gosu::KB_F2
|
42
|
+
self.show_grid = !show_grid
|
43
|
+
when Gosu::KB_F3
|
44
|
+
self.show_coordinates = !show_coordinates
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def font
|
51
|
+
@font ||= Gosu::Font.new(12)
|
52
|
+
end
|
53
|
+
|
54
|
+
def draw_menu(window)
|
55
|
+
font.draw_text("Debug Menu", window.width - 5 - font.text_width("Debug Menu"), 20, 1, 1, 1, Gosu::Color::GREEN)
|
56
|
+
font.draw_text("F1: Toggle FPS", window.width - 5 - font.text_width("F1: Toggle FPS"), 35, 1, 1, 1,
|
57
|
+
Gosu::Color::GREEN)
|
58
|
+
font.draw_text("F2: Toggle Grid", window.width - 5 - font.text_width("F2: Toggle Grid"), 50, 1, 1, 1,
|
59
|
+
Gosu::Color::GREEN)
|
60
|
+
font.draw_text("F3: Toggle Coordinates", window.width - 5 - font.text_width("F3: Toggle Coordinates"), 65, 1, 1,
|
61
|
+
1, Gosu::Color::GREEN)
|
62
|
+
end
|
63
|
+
|
64
|
+
def draw_fps(window)
|
65
|
+
font.draw_text(Gosu.fps, window.width - 5 - font.text_width(Gosu.fps), 5, 1, 1, 1, Gosu::Color::GREEN)
|
66
|
+
end
|
67
|
+
|
68
|
+
def draw_grid(window)
|
69
|
+
(window.width / 20).times do |column|
|
70
|
+
window.draw_line(column * 20, 0, Gosu::Color::GREEN, column * 20, window.height, Gosu::Color::GREEN)
|
71
|
+
end
|
72
|
+
|
73
|
+
(window.height / 20).times do |row|
|
74
|
+
window.draw_line(0, row * 20, Gosu::Color::GREEN, window.width, row * 20, Gosu::Color::GREEN)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def draw_coordinates(window)
|
79
|
+
label = "#{window.mouse_x.to_i}, #{window.mouse_y.to_i}"
|
80
|
+
label_width = font.text_width(label)
|
81
|
+
|
82
|
+
label_x = if window.mouse_x + 5 + label_width > window.width
|
83
|
+
window.mouse_x - 5 - label_width
|
84
|
+
else
|
85
|
+
window.mouse_x + 5
|
86
|
+
end
|
87
|
+
|
88
|
+
label_y = window.mouse_y - 5
|
89
|
+
|
90
|
+
font.draw_text(label, label_x, label_y, 1, 1, 1, Gosu::Color::GREEN)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Conjuration
|
4
|
+
class InputManager
|
5
|
+
LEFT_CLICK = :left_click
|
6
|
+
RIGHT_CLICK = :right_click
|
7
|
+
|
8
|
+
UP = :up
|
9
|
+
LEFT = :left
|
10
|
+
DOWN = :down
|
11
|
+
RIGHT = :right
|
12
|
+
|
13
|
+
def map_button(key_id)
|
14
|
+
input_map[key_id]
|
15
|
+
end
|
16
|
+
|
17
|
+
def button_down?(action)
|
18
|
+
action_map[action].any? { |key_id| Gosu.button_down?(key_id) }
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns a hash of actions mapped to key bindings.
|
22
|
+
#
|
23
|
+
# { action => [key_id] }
|
24
|
+
def action_map
|
25
|
+
@action_map ||= {
|
26
|
+
LEFT_CLICK => [Gosu::MsLeft],
|
27
|
+
RIGHT_CLICK => [Gosu::MsRight],
|
28
|
+
|
29
|
+
UP => [Gosu::KbUp, Gosu::GpUp, Gosu::KB_W],
|
30
|
+
LEFT => [Gosu::KbLeft, Gosu::GpLeft, Gosu::KB_A],
|
31
|
+
DOWN => [Gosu::KbDown, Gosu::GpDown, Gosu::KB_S],
|
32
|
+
RIGHT => [Gosu::KbRight, Gosu::GpRight, Gosu::KB_D]
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns a hash of key bindings mapped to actions.
|
37
|
+
#
|
38
|
+
# { key_id => action }
|
39
|
+
def input_map
|
40
|
+
@input_map ||= action_map.each_with_object({}) do |(action, key_ids), hash|
|
41
|
+
key_ids.each do |key_id|
|
42
|
+
hash[key_id] = action
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Conjuration
|
4
|
+
class SceneManager
|
5
|
+
def initialize(window)
|
6
|
+
@scenes = {}
|
7
|
+
@window = window
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_scene(key, scene_class)
|
11
|
+
@scenes[key] = scene_class
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_scene(_scene_class, options = {})
|
15
|
+
@current_scene = @scenes[key].new(@window, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :current_scene
|
19
|
+
|
20
|
+
# ====================
|
21
|
+
|
22
|
+
def update(window)
|
23
|
+
current_scene.update(window)
|
24
|
+
end
|
25
|
+
|
26
|
+
def draw(window)
|
27
|
+
current_scene.draw(window)
|
28
|
+
end
|
29
|
+
|
30
|
+
def button_down(window, id)
|
31
|
+
current_scene.button_down(window, id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def button_up(window, id)
|
35
|
+
current_scene.button_up(window, id)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Conjuration
|
4
|
+
# Keeps track of game objects and manages their updates, draws, mouse, and keyboard events.
|
5
|
+
class Scene
|
6
|
+
include Attributes
|
7
|
+
|
8
|
+
attr_reader :window
|
9
|
+
|
10
|
+
def initialize(window, options = {})
|
11
|
+
super
|
12
|
+
|
13
|
+
@window = window
|
14
|
+
@game_objects = []
|
15
|
+
@asset_manager = AssetManager.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_object(game_object)
|
19
|
+
@game_objects << game_object
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_background(asset_path)
|
23
|
+
@background_image = AssetManager.load_image(asset_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
# ==========
|
27
|
+
# Abstract Methods
|
28
|
+
# ==========
|
29
|
+
|
30
|
+
def update(context)
|
31
|
+
@game_objects.each { |game_object| game_object.mouse_position(context) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def draw(context)
|
35
|
+
@background_image&.draw(0, 0, 0, context.width.to_f / @background_image.width,
|
36
|
+
context.height.to_f / @background_image.height)
|
37
|
+
@game_objects.each { |game_object| game_object.draw(context) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def button_down(context, key)
|
41
|
+
@game_objects.each { |game_object| game_object.mouse_down(context, key) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def button_up(context, key)
|
45
|
+
@game_objects.each { |game_object| game_object.mouse_up(context, key) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/conjuration.rb
ADDED
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: conjuration
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Dye
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gosu
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.4.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.4.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: zeitwerk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.6.14
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.6.14
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- dnitemaeric@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".rspec"
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- ".rubocop_todo.yml"
|
51
|
+
- CHANGELOG.md
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/conjuration.rb
|
56
|
+
- lib/conjuration/concerns/attributes.rb
|
57
|
+
- lib/conjuration/game.rb
|
58
|
+
- lib/conjuration/game_object.rb
|
59
|
+
- lib/conjuration/managers/asset_manager.rb
|
60
|
+
- lib/conjuration/managers/debug_manager.rb
|
61
|
+
- lib/conjuration/managers/input_manager.rb
|
62
|
+
- lib/conjuration/managers/scene_manager.rb
|
63
|
+
- lib/conjuration/scene.rb
|
64
|
+
- lib/conjuration/version.rb
|
65
|
+
homepage: https://github.com/nitemaeric/conjuration
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata:
|
69
|
+
homepage_uri: https://github.com/nitemaeric/conjuration
|
70
|
+
source_code_uri: https://github.com/nitemaeric/conjuration
|
71
|
+
changelog_uri: https://github.com/nitemaeric/conjuration/blob/main/CHANGELOG.md
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 3.3.0
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubygems_version: 3.5.9
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: A Ruby game engine built on top of Gosu.
|
91
|
+
test_files: []
|