flonkerton 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +115 -0
- data/Rakefile +11 -0
- data/TODO +12 -0
- data/config/defaults.yml +39 -0
- data/examples/clip.rb +16 -0
- data/examples/config/defaults.yml +39 -0
- data/examples/extras/actor.rb +47 -0
- data/examples/extras/fill.rb +5 -0
- data/examples/extras/input_handler.rb +9 -0
- data/examples/extras/mouse_border.rb +21 -0
- data/examples/extras/random_color.rb +27 -0
- data/examples/extras/scrollable.rb +80 -0
- data/examples/font.rb +25 -0
- data/examples/input.rb +63 -0
- data/examples/screen.rb +38 -0
- data/examples/scroll.rb +72 -0
- data/examples/sound.rb +43 -0
- data/examples/tiles.rb +30 -0
- data/flonkerton.gemspec +16 -0
- data/games/gosu_demo/config/defaults.yml +39 -0
- data/games/gosu_demo/media/Space.png +0 -0
- data/games/gosu_demo/media/beep.wav +0 -0
- data/games/gosu_demo/media/star_25x25.png +0 -0
- data/games/gosu_demo/media/starfighter.png +0 -0
- data/games/gosu_demo/original.rb +137 -0
- data/games/gosu_demo/play.rb +135 -0
- data/lib/flonkerton.rb +241 -0
- data/media/ArcadeClassic.ttf +0 -0
- data/media/CREDITS +4 -0
- data/media/background.png +0 -0
- data/media/catch_me_song.ogg +0 -0
- data/media/cursor.png +0 -0
- data/media/gosu_logo.png +0 -0
- data/media/select.wav +0 -0
- data/media/tiles_32x32.png +0 -0
- data/test/integration_test.rb +115 -0
- data/test/test_helper.rb +9 -0
- data/test/unit_tests.rb +386 -0
- data/watchmen.rb +7 -0
- metadata +168 -0
data/README.md
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# Flonkerton
|
2
|
+
|
3
|
+
Gosu toys for the bored rubyist.
|
4
|
+
|
5
|
+
## Requisites
|
6
|
+
|
7
|
+
You'll need [Gosu](http://www.libgosu.org/).
|
8
|
+
|
9
|
+
Also [Protest](http://github.com/matflores/protest), [RR](http://github.com/btakita/rr) and [Watchr](http://github.com/mynyml/watchr) for test awesomeness.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
$ sudo gem install flonkerton
|
14
|
+
|
15
|
+
## Features
|
16
|
+
|
17
|
+
* Screens Handling
|
18
|
+
* Auto-loads Resources
|
19
|
+
* YAML Configuration
|
20
|
+
* Some conventions and default values
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
require 'flonkerton'
|
25
|
+
Flonkerton::Game.start
|
26
|
+
|
27
|
+
### Hello World
|
28
|
+
|
29
|
+
require 'flonkerton'
|
30
|
+
include Flonkerton
|
31
|
+
|
32
|
+
class HelloWorld < Screen
|
33
|
+
def draw
|
34
|
+
Fonts[:default].draw(:text => 'Hello World!')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
Game.start(HelloWorld)
|
39
|
+
|
40
|
+
### Basic Example
|
41
|
+
|
42
|
+
require 'flonkerton'
|
43
|
+
include Flonkerton
|
44
|
+
|
45
|
+
class GameScreen < Screen
|
46
|
+
def setup
|
47
|
+
@x = 0
|
48
|
+
@song = Songs[:intro]
|
49
|
+
@image = Images[:gosu_logo]
|
50
|
+
@sample = Samples[:beep]
|
51
|
+
end
|
52
|
+
|
53
|
+
def button_down(id)
|
54
|
+
close if id == Gosu::KbEscape # or super
|
55
|
+
@song.play if id == Gosu::KbSpace
|
56
|
+
@sample.play if id == Gosu::KbReturn
|
57
|
+
end
|
58
|
+
|
59
|
+
def update
|
60
|
+
@x += 10 if button_down?(Gosu::KbRight)
|
61
|
+
end
|
62
|
+
|
63
|
+
def draw
|
64
|
+
@image.draw(:x => @x)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
Game.start(GameScreen)
|
69
|
+
|
70
|
+
See [examples](/apillet/flonkerton/tree/master/examples/).
|
71
|
+
|
72
|
+
## Related Projects
|
73
|
+
|
74
|
+
* [Chingu](http://github.com/ippa/chingu)
|
75
|
+
* [Exuberant](http://github.com/adamsanderson/lexery/tree/master/lib/exuberant)
|
76
|
+
* [FWD](http://github.com/walski/FWD)
|
77
|
+
* [Lotu](http://github.com/lobo-tuerto/lotu)
|
78
|
+
* [Nimo](http://github.com/moonpxi/nimo)
|
79
|
+
* [PuitUniverse](http://github.com/oneup/puituniverse)
|
80
|
+
* [Ramverk](http://github.com/deps/Ramverk)
|
81
|
+
* [Space Shooter Engine](http://github.com/belen-albeza/space-shooter/tree/master/engine/)
|
82
|
+
* [SpriteJam](http://github.com/richardeden/spritejam)
|
83
|
+
* [UrDoinItRite](http://github.com/actsasbuffoon/UrDoinItRite)
|
84
|
+
|
85
|
+
The following projects are not based on Gosu, but worth looking into:
|
86
|
+
|
87
|
+
* [Ruby Warrior](http://github.com/ryanb/ruby-warrior)
|
88
|
+
* [Gamebox](http://github.com/shawn42/gamebox)
|
89
|
+
* [Jemini](http://github.com/jemini/jemini-core)
|
90
|
+
* [Zyps](http://github.com/jaymcgavren/zyps)
|
91
|
+
|
92
|
+
## License
|
93
|
+
|
94
|
+
Copyright (c) 2010 Ariel H. Pillet
|
95
|
+
|
96
|
+
Permission is hereby granted, free of charge, to any person
|
97
|
+
obtaining a copy of this software and associated documentation
|
98
|
+
files (the "Software"), to deal in the Software without
|
99
|
+
restriction, including without limitation the rights to use,
|
100
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
101
|
+
copies of the Software, and to permit persons to whom the
|
102
|
+
Software is furnished to do so, subject to the following
|
103
|
+
conditions:
|
104
|
+
|
105
|
+
The above copyright notice and this permission notice shall be
|
106
|
+
included in all copies or substantial portions of the Software.
|
107
|
+
|
108
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
109
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
110
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
111
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
112
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
113
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
114
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
115
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/TODO
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
TODO
|
2
|
+
|
3
|
+
- Document.
|
4
|
+
- Clean up tests.
|
5
|
+
- Add basic instructions to WelcomeScreen.
|
6
|
+
- Add Font#draw_rot
|
7
|
+
- Add Font#draw_rel
|
8
|
+
- Add Image#draw_rot
|
9
|
+
- Add Window#text_input
|
10
|
+
- Add Window#update_interval
|
11
|
+
- Add Screen#gl
|
12
|
+
- Write some mini-games.
|
data/config/defaults.yml
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Window
|
2
|
+
#
|
3
|
+
:width: 800
|
4
|
+
:height: 600
|
5
|
+
:caption: Flonkerton Example
|
6
|
+
:font_size: 20
|
7
|
+
:fullscreen: false
|
8
|
+
:initial_screen: WelcomeScreen
|
9
|
+
|
10
|
+
# Resources
|
11
|
+
#
|
12
|
+
:media_path: media
|
13
|
+
:fonts_ext: *.ttf
|
14
|
+
:songs_ext: *.ogg
|
15
|
+
:tiles_ext: *.png
|
16
|
+
:images_ext: *.png
|
17
|
+
:samples_ext: *.wav
|
18
|
+
|
19
|
+
# Defaults
|
20
|
+
#
|
21
|
+
:image:
|
22
|
+
:x: 0
|
23
|
+
:y: 0
|
24
|
+
:z: 0
|
25
|
+
:factor_x: 1
|
26
|
+
:factor_y: 1
|
27
|
+
:color: 0xffffffff
|
28
|
+
:mode: :default
|
29
|
+
:order: [:x, :y, :z, :factor_x, :factor_y, :color, :mode] # For 1.8.6 - Don't change this
|
30
|
+
:font:
|
31
|
+
:text: ''
|
32
|
+
:x: 0
|
33
|
+
:y: 0
|
34
|
+
:z: 0
|
35
|
+
:factor_x: 1
|
36
|
+
:factor_y: 1
|
37
|
+
:color: 0xffffffff
|
38
|
+
:mode: :default
|
39
|
+
:order: [:text, :x, :y, :z, :factor_x, :factor_y, :color, :mode] # For 1.8.6 - Don't change this
|
data/examples/clip.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require '../lib/flonkerton'
|
2
|
+
include Flonkerton
|
3
|
+
|
4
|
+
module Example
|
5
|
+
class GameScreen < Screen
|
6
|
+
def setup
|
7
|
+
@background = Images[:background]
|
8
|
+
end
|
9
|
+
|
10
|
+
def draw
|
11
|
+
clip_to(10, 10, 320, 200) { @background.draw }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Game.start
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Window
|
2
|
+
#
|
3
|
+
:width: 800
|
4
|
+
:height: 600
|
5
|
+
:caption: Flonkerton Example
|
6
|
+
:font_size: 20
|
7
|
+
:fullscreen: false
|
8
|
+
:initial_screen: Example::GameScreen
|
9
|
+
|
10
|
+
# Resources
|
11
|
+
#
|
12
|
+
:media_path: ../media
|
13
|
+
:fonts_ext: *.ttf
|
14
|
+
:songs_ext: *.ogg
|
15
|
+
:tiles_ext: *.png
|
16
|
+
:images_ext: *.png
|
17
|
+
:samples_ext: *.wav
|
18
|
+
|
19
|
+
# Defaults
|
20
|
+
#
|
21
|
+
:image:
|
22
|
+
:x: 0
|
23
|
+
:y: 0
|
24
|
+
:z: 0
|
25
|
+
:factor_x: 1
|
26
|
+
:factor_y: 1
|
27
|
+
:color: 0xffffffff
|
28
|
+
:mode: :default
|
29
|
+
:order: [:x, :y, :z, :factor_x, :factor_y, :color, :mode] # For 1.8.6 - Don't change this
|
30
|
+
:font:
|
31
|
+
:text: ''
|
32
|
+
:x: 0
|
33
|
+
:y: 0
|
34
|
+
:z: 0
|
35
|
+
:factor_x: 1
|
36
|
+
:factor_y: 1
|
37
|
+
:color: 0xffffffff
|
38
|
+
:mode: :default
|
39
|
+
:order: [:text, :x, :y, :z, :factor_x, :factor_y, :color, :mode] # For 1.8.6 - Don't change this
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Actor
|
2
|
+
attr_accessor :x, :y, :zorder, :scale_x, :scale_y, :color, :mode
|
3
|
+
|
4
|
+
DEFAULTS = { :x => 0,
|
5
|
+
:y => 0,
|
6
|
+
:zorder => 0,
|
7
|
+
:scale => 1,
|
8
|
+
:color => Gosu::Color::WHITE,
|
9
|
+
:mode => :default }
|
10
|
+
|
11
|
+
def initialize options = {}
|
12
|
+
options = DEFAULTS.merge(options)
|
13
|
+
@x = options[:x]
|
14
|
+
@y = options[:y]
|
15
|
+
@zorder = options[:zorder]
|
16
|
+
scale = options[:scale]
|
17
|
+
@scale_x = options[:scale_x] || scale
|
18
|
+
@scale_y = options[:scale_y] || scale
|
19
|
+
@color = options[:color]
|
20
|
+
@mode = options[:mode]
|
21
|
+
end
|
22
|
+
|
23
|
+
def scale= value
|
24
|
+
@scale_x = value
|
25
|
+
@scale_y = value
|
26
|
+
end
|
27
|
+
|
28
|
+
def image
|
29
|
+
@image ||= Images[label]
|
30
|
+
end
|
31
|
+
|
32
|
+
def draw offset_x = 0, offset_y = 0
|
33
|
+
image.draw :x => @x - offset_x,
|
34
|
+
:y => @y - offset_y,
|
35
|
+
:z => @zorder,
|
36
|
+
:factor_x => @scale_x,
|
37
|
+
:factor_y => @scale_y,
|
38
|
+
:color => @color,
|
39
|
+
:mode => @mode
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def label
|
45
|
+
self.class.to_s[/\w+$/].scan(/([A-Z]+[a-z]+)/).flatten.join('_').downcase.intern
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module MouseBorder
|
2
|
+
def border
|
3
|
+
40
|
4
|
+
end
|
5
|
+
|
6
|
+
def mouse_on_left?
|
7
|
+
mouse_x <= border
|
8
|
+
end
|
9
|
+
|
10
|
+
def mouse_on_top?
|
11
|
+
mouse_y <= border
|
12
|
+
end
|
13
|
+
|
14
|
+
def mouse_on_right?
|
15
|
+
mouse_x >= width - border
|
16
|
+
end
|
17
|
+
|
18
|
+
def mouse_on_bottom?
|
19
|
+
mouse_y >= height - border
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Ruby 1.8.6 compatibility
|
2
|
+
#
|
3
|
+
unless Array.new.respond_to?(:sample)
|
4
|
+
class Array
|
5
|
+
def sample
|
6
|
+
self.sort_by{ Kernel.rand }.pop
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Range
|
12
|
+
def rand
|
13
|
+
self.to_a.sample
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module Gosu
|
18
|
+
class Color
|
19
|
+
def self.random red = (0..255), green = (0..255), blue = (0..255)
|
20
|
+
color = Color.new(0xff000000)
|
21
|
+
color.red = red.rand
|
22
|
+
color.green = green.rand
|
23
|
+
color.blue = blue.rand
|
24
|
+
color
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Scrollable
|
2
|
+
class Viewport
|
3
|
+
|
4
|
+
DEFAULTS = { :x => 0,
|
5
|
+
:y => 0,
|
6
|
+
:width => 800,
|
7
|
+
:height => 600,
|
8
|
+
:max_width => 1600,
|
9
|
+
:max_height => 1200,
|
10
|
+
:speed => 5 }
|
11
|
+
|
12
|
+
attr_reader :width, :height
|
13
|
+
attr_accessor :x, :y, :speed, :max_width, :max_height
|
14
|
+
|
15
|
+
def initialize options = {}
|
16
|
+
options = DEFAULTS.merge(options)
|
17
|
+
@x = options[:x]
|
18
|
+
@y = options[:y]
|
19
|
+
@speed = options[:speed]
|
20
|
+
@width = options[:width]
|
21
|
+
@height = options[:height]
|
22
|
+
@max_width = options[:max_width]
|
23
|
+
@max_height = options[:max_height]
|
24
|
+
end
|
25
|
+
|
26
|
+
def move_left
|
27
|
+
@x -= @speed if left_allowed?
|
28
|
+
end
|
29
|
+
|
30
|
+
def move_right
|
31
|
+
@x += @speed if right_allowed?
|
32
|
+
end
|
33
|
+
|
34
|
+
def move_up
|
35
|
+
@y -= @speed if up_allowed?
|
36
|
+
end
|
37
|
+
|
38
|
+
def move_down
|
39
|
+
@y += @speed if down_allowed?
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def left_allowed?
|
45
|
+
@x >= @speed
|
46
|
+
end
|
47
|
+
|
48
|
+
def right_allowed?
|
49
|
+
@x + @width + @speed <= @max_width
|
50
|
+
end
|
51
|
+
|
52
|
+
def down_allowed?
|
53
|
+
@y + @height + @speed <= @max_height
|
54
|
+
end
|
55
|
+
|
56
|
+
def up_allowed?
|
57
|
+
@y >= @speed
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def viewport
|
62
|
+
@viewport ||= Viewport.new
|
63
|
+
end
|
64
|
+
|
65
|
+
def scroll_down
|
66
|
+
viewport.move_down
|
67
|
+
end
|
68
|
+
|
69
|
+
def scroll_up
|
70
|
+
viewport.move_up
|
71
|
+
end
|
72
|
+
|
73
|
+
def scroll_left
|
74
|
+
viewport.move_left
|
75
|
+
end
|
76
|
+
|
77
|
+
def scroll_right
|
78
|
+
viewport.move_right
|
79
|
+
end
|
80
|
+
end
|
data/examples/font.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require '../lib/flonkerton'
|
2
|
+
include Flonkerton
|
3
|
+
|
4
|
+
module Example
|
5
|
+
class GameScreen < Screen
|
6
|
+
def setup
|
7
|
+
@default = Fonts[:default]
|
8
|
+
@arcade = Fonts[:arcade_classic]
|
9
|
+
end
|
10
|
+
|
11
|
+
def draw
|
12
|
+
@arcade.draw :x => 10,
|
13
|
+
:text => 'Flonkerton',
|
14
|
+
:color => Gosu::Color::GREEN,
|
15
|
+
:factor_x => 2,
|
16
|
+
:factor_y => 2
|
17
|
+
|
18
|
+
@default.draw :x => 30,
|
19
|
+
:y => 40,
|
20
|
+
:text => 'default font is ' + Gosu::default_font_name
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Game.start
|