flonkerton 0.0.1
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/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/examples/input.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require '../lib/flonkerton'
|
2
|
+
require 'extras/input_handler'
|
3
|
+
require 'extras/fill'
|
4
|
+
require 'extras/random_color'
|
5
|
+
include Gosu
|
6
|
+
include Flonkerton
|
7
|
+
|
8
|
+
module Example
|
9
|
+
class Logo
|
10
|
+
SPEED = 5
|
11
|
+
|
12
|
+
def initialize x = 0, y = 0
|
13
|
+
@image = Images[:gosu_logo]
|
14
|
+
@x = x
|
15
|
+
@y = y
|
16
|
+
end
|
17
|
+
|
18
|
+
def draw
|
19
|
+
@image.draw :x => @x, :y => @y
|
20
|
+
end
|
21
|
+
|
22
|
+
def move_right; @x += SPEED; end
|
23
|
+
def move_left; @x -= SPEED; end
|
24
|
+
def move_up; @y -= SPEED; end
|
25
|
+
def move_down; @y += SPEED; end
|
26
|
+
end
|
27
|
+
|
28
|
+
class GameScreen < Screen
|
29
|
+
include InputHandler
|
30
|
+
include FillScreen
|
31
|
+
|
32
|
+
def setup
|
33
|
+
@color = Color::BLUE
|
34
|
+
@font = Fonts[:default]
|
35
|
+
@logo = Logo.new(20, 30)
|
36
|
+
@input = { :up => [KbUp, KbW],
|
37
|
+
:down => [KbDown, KbS],
|
38
|
+
:left => [KbLeft, KbA],
|
39
|
+
:right => [KbRight, KbD],
|
40
|
+
:color => [KbReturn, KbSpace, KbBackspace] }
|
41
|
+
end
|
42
|
+
|
43
|
+
def button_down(id)
|
44
|
+
super # close
|
45
|
+
@color = Color.random if pressed?(:color)
|
46
|
+
end
|
47
|
+
|
48
|
+
def update
|
49
|
+
@logo.move_up if pressed?(:up)
|
50
|
+
@logo.move_down if pressed?(:down)
|
51
|
+
@logo.move_left if pressed?(:left)
|
52
|
+
@logo.move_right if pressed?(:right)
|
53
|
+
end
|
54
|
+
|
55
|
+
def draw
|
56
|
+
fill @color
|
57
|
+
@font.draw :text => 'Use WASD or Arrow Keys to move logo. SPACE to change color.', :x => 5, :y => 5
|
58
|
+
@logo.draw
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
Game.start
|
data/examples/screen.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require '../lib/flonkerton'
|
2
|
+
require 'extras/fill'
|
3
|
+
include Gosu
|
4
|
+
include Flonkerton
|
5
|
+
|
6
|
+
module Example
|
7
|
+
class LogoScreen < Screen
|
8
|
+
def draw
|
9
|
+
Fonts[:default].draw :text => 'LOGO SCREEN - press Space',
|
10
|
+
:x => 10,
|
11
|
+
:y => 10
|
12
|
+
end
|
13
|
+
|
14
|
+
def button_down(id)
|
15
|
+
super # close
|
16
|
+
go_to(GameScreen) if id == KbSpace
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class GameScreen < Screen
|
21
|
+
include FillScreen
|
22
|
+
|
23
|
+
def draw
|
24
|
+
fill
|
25
|
+
Fonts[:default].draw :text => 'GAME SCREEN - press Space',
|
26
|
+
:color => Color::BLACK,
|
27
|
+
:x => 10,
|
28
|
+
:y => 10
|
29
|
+
end
|
30
|
+
|
31
|
+
def button_down(id)
|
32
|
+
super # close
|
33
|
+
go_to(LogoScreen) if id == KbSpace
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
Game.start(Example::LogoScreen)
|
data/examples/scroll.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require '../lib/flonkerton'
|
2
|
+
require 'extras/actor'
|
3
|
+
require 'extras/mouse_border'
|
4
|
+
require 'extras/scrollable'
|
5
|
+
require 'extras/input_handler'
|
6
|
+
require 'extras/random_color'
|
7
|
+
|
8
|
+
include Gosu
|
9
|
+
include Flonkerton
|
10
|
+
|
11
|
+
module Example
|
12
|
+
Background = Class.new(Actor)
|
13
|
+
GosuLogo = Class.new(Actor)
|
14
|
+
|
15
|
+
class GameScreen < Screen
|
16
|
+
include Scrollable
|
17
|
+
include MouseBorder
|
18
|
+
include InputHandler
|
19
|
+
|
20
|
+
def setup
|
21
|
+
# Resources
|
22
|
+
@font = Fonts[:default]
|
23
|
+
@mouse = Images[:cursor]
|
24
|
+
|
25
|
+
# Configure InputHandler
|
26
|
+
@input = { :left => [KbA, KbLeft, GpLeft],
|
27
|
+
:right => [KbD, KbRight, GpRight],
|
28
|
+
:up => [KbW, KbUp, GpUp],
|
29
|
+
:down => [KbS, KbDown, GpDown] }
|
30
|
+
|
31
|
+
# Actors
|
32
|
+
@background = Background.new :scale => 2
|
33
|
+
@things = Array.new
|
34
|
+
100.times do
|
35
|
+
@things << GosuLogo.new(:x => rand(width * 2),
|
36
|
+
:y => rand(height * 2),
|
37
|
+
:scale => [0.2, 0.4, 0.6, 0.8, 1].sample,
|
38
|
+
:color => Color.random,
|
39
|
+
:mode => [:default, :additive].sample)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def update
|
44
|
+
# Uses Scrollable, MouseBorder and InputHandler
|
45
|
+
scroll_right if mouse_on_right? or pressed?(:right)
|
46
|
+
scroll_left if mouse_on_left? or pressed?(:left)
|
47
|
+
scroll_up if mouse_on_top? or pressed?(:up)
|
48
|
+
scroll_down if mouse_on_bottom? or pressed?(:down)
|
49
|
+
|
50
|
+
# Random Game Logic
|
51
|
+
20.times do
|
52
|
+
npc = @things.sample
|
53
|
+
npc.x += (-5..5).rand
|
54
|
+
npc.y += (-5..5).rand
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def draw
|
59
|
+
# Actors receives viewport coordinates.
|
60
|
+
@background.draw(@viewport.x, @viewport.y)
|
61
|
+
@things.each do |thing|
|
62
|
+
thing.draw(@viewport.x, @viewport.y)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Resources receives screen coordinates.
|
66
|
+
@mouse.draw :x => mouse_x, :y => mouse_y
|
67
|
+
@font.draw :text => 'Use Mouse, WASD or Arrow Keys to scroll...', :x => 5, :y => 5
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
Game.start
|
data/examples/sound.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require '../lib/flonkerton'
|
2
|
+
include Gosu
|
3
|
+
include Flonkerton
|
4
|
+
|
5
|
+
module Example
|
6
|
+
class GameScreen < Screen
|
7
|
+
|
8
|
+
INSTRUCTIONS = ['Press Escape to quit',
|
9
|
+
'Press Space to play Song',
|
10
|
+
'Press Backspace to stop Song',
|
11
|
+
'Press Enter to play Sample']
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@font = Fonts[:default]
|
15
|
+
@song = Songs[:catch_me_song]
|
16
|
+
@beep = Samples[:select]
|
17
|
+
@song.volume = 0.2
|
18
|
+
end
|
19
|
+
|
20
|
+
def button_down(id)
|
21
|
+
super
|
22
|
+
@song.play if id == KbSpace
|
23
|
+
@song.stop if id == KbBackspace
|
24
|
+
@beep.play if id == KbReturn
|
25
|
+
end
|
26
|
+
|
27
|
+
def draw
|
28
|
+
write INSTRUCTIONS
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def write list, left_margin = 5, top_margin = 0, space = 20
|
34
|
+
list.each_with_index do |line, i|
|
35
|
+
@font.draw :text => line,
|
36
|
+
:x => left_margin,
|
37
|
+
:y => top_margin + i * space
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Game.start
|
data/examples/tiles.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require '../lib/flonkerton'
|
2
|
+
include Flonkerton
|
3
|
+
|
4
|
+
module Example
|
5
|
+
class GameScreen < Screen
|
6
|
+
|
7
|
+
TILES = '.RWT' # Plain, Rock, Water, Tree
|
8
|
+
|
9
|
+
MAP = ['.R...TTT',
|
10
|
+
'RR....TT',
|
11
|
+
'........',
|
12
|
+
'....WWWW',
|
13
|
+
'..WWWW..']
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@tiles = Tiles[:tiles]
|
17
|
+
@size = @tiles.first.width
|
18
|
+
end
|
19
|
+
|
20
|
+
def draw
|
21
|
+
MAP.each_with_index do |line, y|
|
22
|
+
line.split('').each_with_index do |char, x|
|
23
|
+
@tiles[TILES.index(char)].draw :x => x * @size, :y => y * @size
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Game.start
|
data/flonkerton.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "flonkerton"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.summary = "Gosu toys for the bored rubyist."
|
5
|
+
s.description = "A simple framework that aims to improve your Gosu experience."
|
6
|
+
s.authors = ["Ariel H. Pillet"]
|
7
|
+
s.email = ["apillet@gmail.com"]
|
8
|
+
s.homepage = "http://github.com/apillet/flonkerton"
|
9
|
+
s.files = ["TODO", "README.md", "media/CREDITS", "Rakefile", "watchmen.rb", "config/defaults.yml", "examples/clip.rb", "examples/config/defaults.yml", "examples/extras/actor.rb", "examples/extras/fill.rb", "examples/extras/input_handler.rb", "examples/extras/mouse_border.rb", "examples/extras/random_color.rb", "examples/extras/scrollable.rb", "examples/font.rb", "examples/input.rb", "examples/screen.rb", "examples/scroll.rb", "examples/sound.rb", "examples/tiles.rb", "games/gosu_demo/config/defaults.yml", "games/gosu_demo/media/beep.wav", "games/gosu_demo/media/Space.png", "games/gosu_demo/media/star_25x25.png", "games/gosu_demo/media/starfighter.png", "games/gosu_demo/original.rb", "games/gosu_demo/play.rb", "lib/flonkerton.rb", "flonkerton.gemspec", "media/ArcadeClassic.ttf", "media/background.png", "media/catch_me_song.ogg", "media/cursor.png", "media/gosu_logo.png", "media/select.wav", "media/tiles_32x32.png", "test/integration_test.rb", "test/test_helper.rb", "test/unit_tests.rb"]
|
10
|
+
|
11
|
+
s.rubyforge_project = "flonkerton"
|
12
|
+
s.add_dependency "gosu", ">= 0.7.19"
|
13
|
+
s.add_development_dependency "protest", ">= 0.3.1"
|
14
|
+
s.add_development_dependency "rr", ">= 0.10.11"
|
15
|
+
s.add_development_dependency "watchr", ">= 0.6"
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Window
|
2
|
+
#
|
3
|
+
:width: 640
|
4
|
+
:height: 480
|
5
|
+
:caption: Gosu Tutorial Game
|
6
|
+
:font_size: 20
|
7
|
+
:fullscreen: false
|
8
|
+
:initial_screen: GosuTutorial::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
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,137 @@
|
|
1
|
+
begin
|
2
|
+
# In case you use Gosu via RubyGems.
|
3
|
+
require 'rubygems'
|
4
|
+
rescue LoadError
|
5
|
+
# In case you don't.
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'gosu'
|
9
|
+
|
10
|
+
module ZOrder
|
11
|
+
Background, Stars, Player, UI = *0..3
|
12
|
+
end
|
13
|
+
|
14
|
+
class Player
|
15
|
+
attr_reader :score
|
16
|
+
|
17
|
+
def initialize(window)
|
18
|
+
@image = Gosu::Image.new(window, "media/starfighter.png", false)
|
19
|
+
@beep = Gosu::Sample.new(window, "media/beep.wav")
|
20
|
+
@x = @y = @vel_x = @vel_y = @angle = 0.0
|
21
|
+
@score = 0
|
22
|
+
end
|
23
|
+
|
24
|
+
def warp(x, y)
|
25
|
+
@x, @y = x, y
|
26
|
+
end
|
27
|
+
|
28
|
+
def turn_left
|
29
|
+
@angle -= 4.5
|
30
|
+
end
|
31
|
+
|
32
|
+
def turn_right
|
33
|
+
@angle += 4.5
|
34
|
+
end
|
35
|
+
|
36
|
+
def accelerate
|
37
|
+
@vel_x += Gosu::offset_x(@angle, 0.5)
|
38
|
+
@vel_y += Gosu::offset_y(@angle, 0.5)
|
39
|
+
end
|
40
|
+
|
41
|
+
def move
|
42
|
+
@x += @vel_x
|
43
|
+
@y += @vel_y
|
44
|
+
@x %= 640
|
45
|
+
@y %= 480
|
46
|
+
|
47
|
+
@vel_x *= 0.95
|
48
|
+
@vel_y *= 0.95
|
49
|
+
end
|
50
|
+
|
51
|
+
def draw
|
52
|
+
@image.draw_rot(@x, @y, ZOrder::Player, @angle)
|
53
|
+
end
|
54
|
+
|
55
|
+
def collect_stars(stars)
|
56
|
+
stars.reject! do |star|
|
57
|
+
if Gosu::distance(@x, @y, star.x, star.y) < 35 then
|
58
|
+
@score += 10
|
59
|
+
@beep.play
|
60
|
+
true
|
61
|
+
else
|
62
|
+
false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class Star
|
69
|
+
attr_reader :x, :y
|
70
|
+
|
71
|
+
def initialize(animation)
|
72
|
+
@animation = animation
|
73
|
+
@color = Gosu::Color.new(0xff000000)
|
74
|
+
@color.red = rand(255 - 40) + 40
|
75
|
+
@color.green = rand(255 - 40) + 40
|
76
|
+
@color.blue = rand(255 - 40) + 40
|
77
|
+
@x = rand * 640
|
78
|
+
@y = rand * 480
|
79
|
+
end
|
80
|
+
|
81
|
+
def draw
|
82
|
+
img = @animation[Gosu::milliseconds / 100 % @animation.size]
|
83
|
+
img.draw(@x - img.width / 2.0, @y - img.height / 2.0,
|
84
|
+
ZOrder::Stars, 1, 1, @color, :additive)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class GameWindow < Gosu::Window
|
89
|
+
def initialize
|
90
|
+
super(640, 480, false)
|
91
|
+
self.caption = "Gosu Tutorial Game"
|
92
|
+
|
93
|
+
@background_image = Gosu::Image.new(self, "media/Space.png", true)
|
94
|
+
|
95
|
+
@player = Player.new(self)
|
96
|
+
@player.warp(320, 240)
|
97
|
+
|
98
|
+
@star_anim = Gosu::Image::load_tiles(self, "media/star_25x25.png", 25, 25, false)
|
99
|
+
@stars = Array.new
|
100
|
+
|
101
|
+
@font = Gosu::Font.new(self, Gosu::default_font_name, 20)
|
102
|
+
end
|
103
|
+
|
104
|
+
def update
|
105
|
+
if button_down? Gosu::KbLeft or button_down? Gosu::GpLeft then
|
106
|
+
@player.turn_left
|
107
|
+
end
|
108
|
+
if button_down? Gosu::KbRight or button_down? Gosu::GpRight then
|
109
|
+
@player.turn_right
|
110
|
+
end
|
111
|
+
if button_down? Gosu::KbUp or button_down? Gosu::GpButton0 then
|
112
|
+
@player.accelerate
|
113
|
+
end
|
114
|
+
@player.move
|
115
|
+
@player.collect_stars(@stars)
|
116
|
+
|
117
|
+
if rand(100) < 4 and @stars.size < 25 then
|
118
|
+
@stars.push(Star.new(@star_anim))
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def draw
|
123
|
+
@background_image.draw(0, 0, ZOrder::Background)
|
124
|
+
@player.draw
|
125
|
+
@stars.each { |star| star.draw }
|
126
|
+
@font.draw("Score: #{@player.score}", 10, 10, ZOrder::UI, 1.0, 1.0, 0xffffff00)
|
127
|
+
end
|
128
|
+
|
129
|
+
def button_down(id)
|
130
|
+
if id == Gosu::KbEscape then
|
131
|
+
close
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
window = GameWindow.new
|
137
|
+
window.show
|