kawaii 0.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.
- data/.DS_Store +0 -0
- data/.gitignore +2 -0
- data/.yardoc/checksums +19 -0
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +28 -0
- data/LICENSE +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/backlog.md +26 -0
- data/bin/kawaii +13 -0
- data/doc/Kawaii/Animation.html +120 -0
- data/doc/Kawaii/AudioManager.html +202 -0
- data/doc/Kawaii/ContentManager.html +487 -0
- data/doc/Kawaii/Entity.html +604 -0
- data/doc/Kawaii/Game.html +1141 -0
- data/doc/Kawaii/InputManager.html +120 -0
- data/doc/Kawaii/Intro.html +120 -0
- data/doc/Kawaii/Math.html +105 -0
- data/doc/Kawaii/Node.html +1030 -0
- data/doc/Kawaii/NodeManager.html +512 -0
- data/doc/Kawaii/Scene.html +120 -0
- data/doc/Kawaii/SceneManager.html +200 -0
- data/doc/Kawaii/TextField.html +538 -0
- data/doc/Kawaii/TmxLayer.html +836 -0
- data/doc/Kawaii/TmxTileMap.html +972 -0
- data/doc/Kawaii/Tweening.html +120 -0
- data/doc/Kawaii/UnsupportedFormatError.html +123 -0
- data/doc/Kawaii/Vector2.html +514 -0
- data/doc/Kawaii.html +136 -0
- data/doc/_index.html +327 -0
- data/doc/class_list.html +53 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +328 -0
- data/doc/file.README.html +130 -0
- data/doc/file_list.html +55 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +130 -0
- data/doc/js/app.js +214 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +708 -0
- data/doc/top-level-namespace.html +112 -0
- data/kawaii.gemspec +27 -0
- data/lib/kawaii/animation.rb +4 -0
- data/lib/kawaii/audio_manager.rb +7 -0
- data/lib/kawaii/command.rb +96 -0
- data/lib/kawaii/constants.rb +5 -0
- data/lib/kawaii/content_manager.rb +34 -0
- data/lib/kawaii/entity.rb +25 -0
- data/lib/kawaii/errors.rb +6 -0
- data/lib/kawaii/game.rb +89 -0
- data/lib/kawaii/helpers.rb +22 -0
- data/lib/kawaii/input_manager.rb +51 -0
- data/lib/kawaii/intro.rb +4 -0
- data/lib/kawaii/math.rb +5 -0
- data/lib/kawaii/node.rb +62 -0
- data/lib/kawaii/node_manager.rb +35 -0
- data/lib/kawaii/physics_entity.rb +32 -0
- data/lib/kawaii/physics_manager.rb +27 -0
- data/lib/kawaii/scene.rb +21 -0
- data/lib/kawaii/scene_manager.rb +50 -0
- data/lib/kawaii/text_field.rb +22 -0
- data/lib/kawaii/tmx_layer.rb +44 -0
- data/lib/kawaii/tmx_tile_map.rb +70 -0
- data/lib/kawaii/tweening.rb +4 -0
- data/lib/kawaii/vector2.rb +26 -0
- data/lib/kawaii/version.rb +3 -0
- data/lib/kawaii.rb +22 -0
- data/samples/.DS_Store +0 -0
- data/samples/content/gfx/ball.png +0 -0
- data/samples/content/maps/test_map.json +39 -0
- data/samples/content/maps/test_map.xml +12 -0
- data/samples/sample.rb +25 -0
- data/samples/sample_1/.DS_Store +0 -0
- data/samples/sample_1/content/gfx/ball.png +0 -0
- data/samples/sample_1/content/gfx/map1.png +0 -0
- data/samples/sample_1/content/maps/map1.json +50 -0
- data/samples/sample_1/content/maps/map1.tmx +16 -0
- data/samples/sample_1/content/maps/test_map.json +39 -0
- data/samples/sample_1/content/maps/test_map.xml +12 -0
- data/samples/sample_1/enemy.rb +11 -0
- data/samples/sample_1/sample_game.rb +51 -0
- data/samples/sample_chipmunk/sample.rb +0 -0
- data/spec/kawaii/audio_manager_spec.rb +9 -0
- data/spec/kawaii/content/gfx/ball.png +0 -0
- data/spec/kawaii/content/maps/test_map.json +39 -0
- data/spec/kawaii/content/maps/test_map.xml +12 -0
- data/spec/kawaii/content_manager_spec.rb +33 -0
- data/spec/kawaii/entity_spec.rb +38 -0
- data/spec/kawaii/game_spec.rb +23 -0
- data/spec/kawaii/helpers_spec.rb +31 -0
- data/spec/kawaii/input_manager_spec.rb +29 -0
- data/spec/kawaii/node_manager_spec.rb +36 -0
- data/spec/kawaii/node_spec.rb +81 -0
- data/spec/kawaii/physics_entity_spec.rb +37 -0
- data/spec/kawaii/physics_manager_spec.rb +45 -0
- data/spec/kawaii/scene_manager_spec.rb +34 -0
- data/spec/kawaii/scene_spec.rb +31 -0
- data/spec/kawaii/text_field_spec.rb +17 -0
- data/spec/kawaii/tmx_layer_spec.rb +21 -0
- data/spec/kawaii/tmx_tile_map_spec.rb +38 -0
- data/spec/kawaii/vector2_spec.rb +34 -0
- data/spec/spec_helper.rb +1 -0
- metadata +205 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
6
|
+
<title>
|
|
7
|
+
Top Level Namespace
|
|
8
|
+
|
|
9
|
+
— Documentation by YARD 0.8.2.1
|
|
10
|
+
|
|
11
|
+
</title>
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
|
|
14
|
+
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
|
16
|
+
|
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
|
19
|
+
relpath = '';
|
|
20
|
+
framesUrl = "frames.html#!" + escape(window.location.href);
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
25
|
+
|
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
</head>
|
|
30
|
+
<body>
|
|
31
|
+
<div id="header">
|
|
32
|
+
<div id="menu">
|
|
33
|
+
|
|
34
|
+
<a href="_index.html">Index</a> »
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
<span class="title">Top Level Namespace</span>
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<div id="search">
|
|
44
|
+
|
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
|
46
|
+
href="class_list.html">
|
|
47
|
+
Class List
|
|
48
|
+
</a>
|
|
49
|
+
|
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
|
51
|
+
href="method_list.html">
|
|
52
|
+
Method List
|
|
53
|
+
</a>
|
|
54
|
+
|
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
|
56
|
+
href="file_list.html">
|
|
57
|
+
File List
|
|
58
|
+
</a>
|
|
59
|
+
|
|
60
|
+
</div>
|
|
61
|
+
<div class="clear"></div>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<iframe id="search_frame"></iframe>
|
|
65
|
+
|
|
66
|
+
<div id="content"><h1>Top Level Namespace
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
</h1>
|
|
71
|
+
|
|
72
|
+
<dl class="box">
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
</dl>
|
|
82
|
+
<div class="clear"></div>
|
|
83
|
+
|
|
84
|
+
<h2>Defined Under Namespace</h2>
|
|
85
|
+
<p class="children">
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Kawaii.html" title="Kawaii (module)">Kawaii</a></span>
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
</p>
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<div id="footer">
|
|
106
|
+
Generated on Wed Jul 11 13:46:34 2012 by
|
|
107
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
108
|
+
0.8.2.1 (ruby-1.9.3).
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
</body>
|
|
112
|
+
</html>
|
data/kawaii.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
2
|
+
require 'kawaii/version'
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.version = Kawaii::VERSION
|
|
6
|
+
|
|
7
|
+
gem.name = "kawaii"
|
|
8
|
+
gem.date = %q[2012-07-11]
|
|
9
|
+
gem.authors = ["Erik Skoglund"]
|
|
10
|
+
gem.platform = Gem::Platform::RUBY
|
|
11
|
+
gem.email = "erikskoglund88@gmail.com"
|
|
12
|
+
gem.summary = "game library that extends gosu"
|
|
13
|
+
gem.homepage = "https://github.com/eriksk/kawaii"
|
|
14
|
+
gem.description = "kawaii provides a tiny game library that extends gosu"
|
|
15
|
+
|
|
16
|
+
gem.files = `git ls-files`.split($\)
|
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
18
|
+
gem.require_paths = ["lib"]
|
|
19
|
+
|
|
20
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
21
|
+
|
|
22
|
+
gem.default_executable = 'kawaii'
|
|
23
|
+
|
|
24
|
+
gem.add_dependency('gosu', '>= 0.7.43')
|
|
25
|
+
gem.add_dependency('chipmunk', '>= 5.3.4.5')
|
|
26
|
+
gem.add_development_dependency('rspec')
|
|
27
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
class String
|
|
2
|
+
# colorization
|
|
3
|
+
def colorize(text, color_code)
|
|
4
|
+
"\e[#{color_code}m#{text}\e[0m"
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def red
|
|
8
|
+
colorize(self, 31)
|
|
9
|
+
end
|
|
10
|
+
def green
|
|
11
|
+
colorize(self, 32)
|
|
12
|
+
end
|
|
13
|
+
def yellow
|
|
14
|
+
colorize(self, 33)
|
|
15
|
+
end
|
|
16
|
+
def pink
|
|
17
|
+
colorize(self, 35)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
module Kawaii
|
|
22
|
+
class Command
|
|
23
|
+
def self.run command, args
|
|
24
|
+
puts ""
|
|
25
|
+
case command
|
|
26
|
+
when "new"
|
|
27
|
+
new_game_template(args)
|
|
28
|
+
when "help"
|
|
29
|
+
print_help()
|
|
30
|
+
else
|
|
31
|
+
end
|
|
32
|
+
puts ""
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
def self.new_game_template args
|
|
37
|
+
width = 800
|
|
38
|
+
height = 600
|
|
39
|
+
fullscreen = false
|
|
40
|
+
game_class_name = args.first.capitalize
|
|
41
|
+
File.open(args.first + ".rb", "w+") do |f|
|
|
42
|
+
f.write <<-EOF
|
|
43
|
+
require 'kawaii'
|
|
44
|
+
|
|
45
|
+
class #{game_class_name} < Kawaii::Game
|
|
46
|
+
|
|
47
|
+
WIDTH = #{width}
|
|
48
|
+
HEIGHT = #{height}
|
|
49
|
+
FULLSCREEN = #{fullscreen}
|
|
50
|
+
CONTENT_ROOT = "content"
|
|
51
|
+
|
|
52
|
+
def initialize
|
|
53
|
+
super WIDTH, HEIGHT, FULLSCREEN, CONTENT_ROOT
|
|
54
|
+
load_game
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def load_game
|
|
58
|
+
# TODO: load code goes here
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def input
|
|
62
|
+
# TODO: input goes here
|
|
63
|
+
if button_down?Gosu::KbEscape
|
|
64
|
+
exit
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def before_update
|
|
69
|
+
# TODO: game logic goes here
|
|
70
|
+
input
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def after_update
|
|
74
|
+
# TODO: game logic goes here
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# entry point
|
|
79
|
+
game = #{game_class_name}.new
|
|
80
|
+
game.show
|
|
81
|
+
EOF
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
puts "Successfully created new game '#{game_class_name}'".green
|
|
85
|
+
puts "Run it with the command: " + "ruby #{args.first}.rb".yellow
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def self.print_help
|
|
89
|
+
puts "Kawaii <3".pink
|
|
90
|
+
puts <<-EOF
|
|
91
|
+
Commands:
|
|
92
|
+
new [name] # create new game template
|
|
93
|
+
EOF
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'gosu'
|
|
2
|
+
|
|
3
|
+
module Kawaii
|
|
4
|
+
class ContentManager
|
|
5
|
+
|
|
6
|
+
attr_accessor :root, :images
|
|
7
|
+
|
|
8
|
+
def initialize window, root
|
|
9
|
+
@window = window
|
|
10
|
+
@root = root
|
|
11
|
+
@images = {}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def clear
|
|
15
|
+
@images.clear
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# loads an image and caches it for further use
|
|
19
|
+
# if an image has been loaded it is just being returned
|
|
20
|
+
def load_image(path, tileable = false)
|
|
21
|
+
if !@images[path]
|
|
22
|
+
@images[path] = Gosu::Image.new(@window, "#{@root}/#{path}", tileable)
|
|
23
|
+
end
|
|
24
|
+
@images[path]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def load_tiled_images(path, cell_size)
|
|
28
|
+
if !@images[path]
|
|
29
|
+
@images[path] = Gosu::Image.load_tiles(@window, "#{@root}/#{path}", cell_size, cell_size, true)
|
|
30
|
+
end
|
|
31
|
+
@images[path]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require_relative 'node'
|
|
2
|
+
|
|
3
|
+
module Kawaii
|
|
4
|
+
class Entity < Kawaii::Node
|
|
5
|
+
|
|
6
|
+
attr_accessor :flipped_h, :flipped_v, :texture
|
|
7
|
+
|
|
8
|
+
def initialize texture
|
|
9
|
+
super()
|
|
10
|
+
@flipped_v, @flipped_h = false, false
|
|
11
|
+
@texture = texture
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def before_update dt
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def after_update dt
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def draw
|
|
21
|
+
# TODO: draw flipped v & h
|
|
22
|
+
@texture.draw_rot(self.position.x, self.position.y, 0, 0) # TODO: rotation
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/kawaii/game.rb
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require 'gosu'
|
|
2
|
+
|
|
3
|
+
module Kawaii
|
|
4
|
+
class Game < Gosu::Window
|
|
5
|
+
|
|
6
|
+
attr_accessor :width, :height, :fullscreen, :show_fps, :font, :node_manager, :content_manager, :physics_manager
|
|
7
|
+
|
|
8
|
+
def initialize width = 800, height = 600, fullscreen = false, content_root = "content", debug = true
|
|
9
|
+
super width, height, fullscreen
|
|
10
|
+
@width, @height, @fullscreen = width, height, fullscreen
|
|
11
|
+
|
|
12
|
+
# managers
|
|
13
|
+
@node_manager = Kawaii::NodeManager.new
|
|
14
|
+
@content_manager = Kawaii::ContentManager.new(self, content_root)
|
|
15
|
+
@audio_manager = Kawaii::AudioManager.new(self)
|
|
16
|
+
@input_manager = Kawaii::InputManager.new(self)
|
|
17
|
+
@physics_manager = Kawaii::PhysicsManager.new
|
|
18
|
+
|
|
19
|
+
# stats
|
|
20
|
+
@top_color = Gosu::Color.new(0xFF1EB1FA)
|
|
21
|
+
@bottom_color = Gosu::Color.new(0xFF1D4DB5)
|
|
22
|
+
@font = Gosu::Font.new(self, Gosu::default_font_name, 18)
|
|
23
|
+
@debug = debug
|
|
24
|
+
|
|
25
|
+
if @debug
|
|
26
|
+
puts "Game settings:"
|
|
27
|
+
puts "\tResolution: #{width}:#{height}"
|
|
28
|
+
puts "\tFullscreen: #{fullscreen}"
|
|
29
|
+
puts "\tContent root: #{content_root}"
|
|
30
|
+
print_stats
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def add_child node
|
|
35
|
+
@node_manager.nodes.push node
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def remove_child node
|
|
39
|
+
@node_manager.nodes.delete node
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def print_stats
|
|
43
|
+
puts "Statistics:"
|
|
44
|
+
puts "Nodes: #{node_manager.count}"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def update
|
|
48
|
+
if self.class.method_defined? :before_update
|
|
49
|
+
before_update
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
@dt = delta()
|
|
53
|
+
@node_manager.update @dt
|
|
54
|
+
|
|
55
|
+
if self.class.method_defined? :after_update
|
|
56
|
+
after_update
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def delta
|
|
61
|
+
16.0 # TODO: real delta
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def get_fps
|
|
65
|
+
1000.0 / delta
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def before_draw
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def after_draw
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def draw
|
|
75
|
+
draw_quad(
|
|
76
|
+
0, 0, @top_color,
|
|
77
|
+
@width, 0, @top_color,
|
|
78
|
+
@width, @height, @bottom_color,
|
|
79
|
+
0, @height, @bottom_color,
|
|
80
|
+
)
|
|
81
|
+
before_draw
|
|
82
|
+
@node_manager.draw
|
|
83
|
+
if @debug
|
|
84
|
+
@font.draw("FPS: #{get_fps}", 14, 14, 0)
|
|
85
|
+
end
|
|
86
|
+
after_draw
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Kawaii
|
|
2
|
+
|
|
3
|
+
def self.lerp min, max, weight
|
|
4
|
+
min + (max - min) * weight
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.clerp min, max, weight
|
|
8
|
+
weight2 = (1.0 - Math::cos(weight * Math::PI)) / 2.0
|
|
9
|
+
min * (1.0 - weight2) + max * weight2
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.smooth_step y0, y1, y2, y3, mu
|
|
13
|
+
|
|
14
|
+
mu2 = mu*mu
|
|
15
|
+
a0 = y3 - y2 - y0 + y1
|
|
16
|
+
a1 = y0 - y1 - a0
|
|
17
|
+
a2 = y2 - y0
|
|
18
|
+
a3 = y1
|
|
19
|
+
|
|
20
|
+
(a0*mu*mu2+a1*mu2+a2*mu+a3)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Kawaii
|
|
2
|
+
class InputManager
|
|
3
|
+
|
|
4
|
+
attr_accessor :game
|
|
5
|
+
|
|
6
|
+
def initialize game, bound_buttons = []
|
|
7
|
+
@game = game
|
|
8
|
+
@buttons = []
|
|
9
|
+
@bound_buttons = bound_buttons
|
|
10
|
+
|
|
11
|
+
@old_mouse_x = 0.0
|
|
12
|
+
@old_mouse_y = 0.0
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def update
|
|
16
|
+
@buttons.clear
|
|
17
|
+
@bound_buttons.each do |btn|
|
|
18
|
+
@buttons.push btn if button_down? btn
|
|
19
|
+
end
|
|
20
|
+
@old_mouse_x = mouse_x
|
|
21
|
+
@old_mouse_y = mouse_y
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def button_down? button
|
|
25
|
+
@game.button_down?(button)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def button_clicked? button
|
|
29
|
+
@buttons.include?(button) && !@game.button_down?(button)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def mouse_x
|
|
33
|
+
@game.mouse_x
|
|
34
|
+
end
|
|
35
|
+
def mouse_y
|
|
36
|
+
@game.mouse_y
|
|
37
|
+
end
|
|
38
|
+
def old_mouse_x
|
|
39
|
+
@old_mouse_x
|
|
40
|
+
end
|
|
41
|
+
def old_mouse_y
|
|
42
|
+
@old_mouse_y
|
|
43
|
+
end
|
|
44
|
+
def mouse_dif_x
|
|
45
|
+
mouse_x - old_mouse_x
|
|
46
|
+
end
|
|
47
|
+
def mouse_dif_y
|
|
48
|
+
mouse_y - old_mouse_y
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
data/lib/kawaii/intro.rb
ADDED
data/lib/kawaii/node.rb
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
|
|
2
|
+
module Kawaii
|
|
3
|
+
class Node
|
|
4
|
+
attr_accessor :position, :velocity, :rotation, :gravity, :static, :children
|
|
5
|
+
|
|
6
|
+
def initialize static = false, position = Vector2.new, velocity = Vector2.new, gravity = Kawaii::Vector2.new(0, Kawaii::GRAVITY)
|
|
7
|
+
@children = []
|
|
8
|
+
@rotation = 0.0
|
|
9
|
+
@position = position
|
|
10
|
+
@velocity = velocity
|
|
11
|
+
@gravity = gravity
|
|
12
|
+
@static = static
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def count
|
|
16
|
+
sum = 1
|
|
17
|
+
@children.each do |child|
|
|
18
|
+
sum += child.count
|
|
19
|
+
end
|
|
20
|
+
sum
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def add_child node
|
|
24
|
+
@children.push(node)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def remove_child node
|
|
28
|
+
@children.delete(node)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def has_children?
|
|
32
|
+
@children.size > 0
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def update dt
|
|
36
|
+
if self.class.method_defined? :before_update
|
|
37
|
+
before_update dt
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
if !@static
|
|
41
|
+
@velocity.x += @gravity.x * dt
|
|
42
|
+
@velocity.y += @gravity.y * dt
|
|
43
|
+
@position.x += @velocity.x * dt
|
|
44
|
+
@position.y += @velocity.y * dt
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
@children.each do |child|
|
|
48
|
+
child.update dt
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
if self.class.method_defined? :after_update
|
|
52
|
+
after_update dt
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def draw
|
|
57
|
+
@children.each do |child|
|
|
58
|
+
child.draw
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
module Kawaii
|
|
3
|
+
class NodeManager
|
|
4
|
+
|
|
5
|
+
attr_accessor :nodes
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
@nodes = []
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def count
|
|
12
|
+
sum = 0
|
|
13
|
+
nodes.each do |node|
|
|
14
|
+
sum += node.count
|
|
15
|
+
end
|
|
16
|
+
sum
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def update dt
|
|
20
|
+
nodes.each do |node|
|
|
21
|
+
node.update dt
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def draw
|
|
26
|
+
nodes.each do |node|
|
|
27
|
+
node.draw
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def clear
|
|
32
|
+
nodes.clear
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'chipmunk'
|
|
2
|
+
|
|
3
|
+
module Kawaii
|
|
4
|
+
class PhysicsEntity < Entity
|
|
5
|
+
|
|
6
|
+
attr_accessor :shape, :body, :geom
|
|
7
|
+
|
|
8
|
+
def initialize geom, args
|
|
9
|
+
@geom = geom
|
|
10
|
+
case geom
|
|
11
|
+
when :circle
|
|
12
|
+
create_circle(args[:radius])
|
|
13
|
+
when :rectangle
|
|
14
|
+
create_rectangle(args[:width], args[:height])
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_to_space chipmunk_space
|
|
19
|
+
# TODO: check if body is static etc...
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def remove_from_space chipmunk_space
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
protected
|
|
26
|
+
def create_circle radius
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def create_rectangle width, height
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'chipmunk'
|
|
2
|
+
|
|
3
|
+
module Kawaii
|
|
4
|
+
class PhysicsManager
|
|
5
|
+
|
|
6
|
+
attr_accessor :space, :entities
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@space = CP::Space.new
|
|
10
|
+
@entities = []
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def add_physics_entity entity
|
|
14
|
+
if entity.class == PhysicsEntity
|
|
15
|
+
@entities.push entity
|
|
16
|
+
entity.add_to_space @space
|
|
17
|
+
else
|
|
18
|
+
raise WrongTypeError, "Only PhysicsEntity and derivatives are accepted"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def remove_physics_entity entity
|
|
23
|
+
@entities.delete entity
|
|
24
|
+
entity.remove_from_space @space
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/kawaii/scene.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Kawaii
|
|
2
|
+
class Scene
|
|
3
|
+
attr_accessor :name, :scene_manager
|
|
4
|
+
|
|
5
|
+
def initialize scene_manager
|
|
6
|
+
@scene_manager = scene_manager
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def transition_in current, duration
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def transition_out current, duration
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def update dt
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def draw
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|