red_bird-demo 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.
@@ -0,0 +1,4 @@
1
+ ---
2
+ num_hor_tiles: 12
3
+ num_ver_tiles: 12
4
+ tiles: "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x03\0\x02\0\x01\0\x01\0\x01\0\x03\0\x02\0\x02\0\x02\0\x01\0\x03\0\x02\0\x02\0\x01\0\x02\0\x02\0\x01\0\x01\0\x03\0\x01\0\x01\0\x01\0\x01\0\x03\0\x03\0\x01\0\x02\0\x02\0\x03\0\x02\0\x01\0\x03\0\x02\0\x02\0\x01\0\x03\0\x02\0\x02\0\x01\0\x01\0\x03\0\x03\0\x03\0\x01\0\x01\0\x01\0\x01\0\x03\0\x02\0\x02\0\x03\0\x02\0\x03\0\x01\0\x03\0\x03\0\x01\0\x03\0\x03\0\x03\0\x03\0\x01\0\x02\0\x02\0\x02\0\x03\0\x02\0\x03\0\x01\0\x01\0\x01\0\x02\0\x02\0\x01\0\x01\0\x03\0\x01\0\x01\0\x02\0\x02\0\x02\0\x03\0\x03\0\x03\0\x01\0\x02\0\x02\0\x02\0\x02\0\x01\0\x03\0\x03\0\x01\0\x02\0\x02\0\x01\0\x01\0\x03\0\x02\0\x03\0\x03\0\x01\0\x02\0\x01\0\x03\0\x01\0\x02\0\x02\0\x03\0\x03\0\x03\0\x01\0\x01\0\x02\0\x01\0\x02\0\x02\0\x02\0\x03\0\x01\0\x02\0\x03\0\x02\0\x02\0\x01\0\x02\0\x01\0\x01\0\x01\0\x02\0\x02\0\x02\0"
@@ -0,0 +1,4 @@
1
+ ---
2
+ texture: "/img/tileset.pgm"
3
+ width: 32
4
+ height: 32
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "red_bird/demo"
4
+
5
+ RedBird::Demo.run
@@ -0,0 +1,36 @@
1
+ # SPDX-License-Identifier: MIT
2
+ require "red_bird"
3
+ require "red_bird/demo/version"
4
+
5
+ module RedBird
6
+ module Demo
7
+ require_relative "demo/stage_main"
8
+ require_relative "demo/stage_move_on_tiles"
9
+ require_relative "demo/stage_resolution"
10
+ require_relative "demo/version"
11
+
12
+ class Error < StandardError; end
13
+
14
+ def self.run
15
+ RedBird::Engine.debug = true
16
+ RedBird::Engine.set_pixel_quantity(256, 240)
17
+ RedBird::Engine.set_screen_resolution(256, 240)
18
+
19
+ gb = {
20
+ stage: :main,
21
+ palette: nil
22
+ }
23
+ RedBird::Engine.run(gb) do |global_data|
24
+ case global_data[:stage]
25
+ when :main then
26
+ Demo::Stage::Main.new(global_data)
27
+ when :move_on_tiles then
28
+ Demo::Stage::MoveOnTiles.new(global_data)
29
+ when :resolution then
30
+ Demo::Stage::Resolution.new(global_data)
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ # SPDX-License-Identifier: MIT
2
+ module RedBird::Demo
3
+ module Controller
4
+ class MoveOnTiles < RedBird::Controller
5
+ def initialize(entity)
6
+ super()
7
+ @entity = entity
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,131 @@
1
+ # SPDX-License-Identifier: MIT
2
+ require 'red_bird/animation'
3
+ require 'red_bird/relative_entity'
4
+
5
+ module RedBird::Demo
6
+ module Entity
7
+ class MoveOnTiles < RedBird::RelativeEntity
8
+
9
+ def initialize(relative_pos_x, relative_pos_y, palette)
10
+ super(relative_pos_x, relative_pos_y, 32, 32)
11
+
12
+ texture = RedBird::Texture.new(
13
+ Gem.datadir("red_bird-demo") + "/img/player.pgm", palette)
14
+
15
+ vertical_sprites = 1
16
+ horizontal_sprites = 3
17
+ @sprites = {
18
+ walking_down: RedBird::Sprite.grid(
19
+ texture, 0, 0,
20
+ horizontal_sprites, vertical_sprites,
21
+ @collision_box.width, @collision_box.height),
22
+ walking_left: RedBird::Sprite.grid(
23
+ texture, 0, 1 * @collision_box.height,
24
+ horizontal_sprites, vertical_sprites,
25
+ @collision_box.width, @collision_box.height),
26
+ walking_right: RedBird::Sprite.grid(
27
+ texture, 0, 2 * @collision_box.height,
28
+ horizontal_sprites, vertical_sprites,
29
+ @collision_box.width, @collision_box.height),
30
+ walking_up: RedBird::Sprite.grid(
31
+ texture, 0, 3 * @collision_box.height,
32
+ horizontal_sprites, vertical_sprites,
33
+ @collision_box.width, @collision_box.height)
34
+ }
35
+
36
+ @animations = {
37
+ walking_down: RedBird::Animation::Loop.new(
38
+ RedBird::Animation::Frame.sequence(
39
+ [
40
+ [7, @sprites[:walking_down][0]],
41
+ [7, @sprites[:walking_down][1]],
42
+ [7, @sprites[:walking_down][2]]
43
+ ])),
44
+ walking_left: RedBird::Animation::Loop.new(
45
+ RedBird::Animation::Frame.sequence(
46
+ [
47
+ [7, @sprites[:walking_left][0]],
48
+ [7, @sprites[:walking_left][1]],
49
+ [7, @sprites[:walking_left][2]]
50
+ ])),
51
+ walking_right: RedBird::Animation::Loop.new(
52
+ RedBird::Animation::Frame.sequence(
53
+ [
54
+ [7, @sprites[:walking_right][0]],
55
+ [7, @sprites[:walking_right][1]],
56
+ [7, @sprites[:walking_right][2]]
57
+ ])),
58
+ walking_up: RedBird::Animation::Loop.new(
59
+ RedBird::Animation::Frame.sequence(
60
+ [
61
+ [7, @sprites[:walking_up][0]],
62
+ [7, @sprites[:walking_up][1]],
63
+ [7, @sprites[:walking_up][2]]
64
+ ])),
65
+ }
66
+
67
+ @current_animation = :walking_right
68
+
69
+ # Make entity move in circles.
70
+ @walk_count = 0
71
+ @number_hor_steps = 72
72
+ @number_ver_steps = 64
73
+
74
+ @walk_right = Proc.new do
75
+ @collision_box.x += 4
76
+ @walk_count += 1
77
+
78
+ if @walk_count >= @number_hor_steps then
79
+ @walk_count = 0
80
+ @current_animation = :walking_down
81
+ @walk_algorithm = @walk_down
82
+ end
83
+ end
84
+
85
+ @walk_down = Proc.new do
86
+ @collision_box.y += 4
87
+ @walk_count += 1
88
+
89
+ if @walk_count >= @number_ver_steps then
90
+ @walk_count = 0
91
+ @current_animation = :walking_left
92
+ @walk_algorithm = @walk_left
93
+ end
94
+ end
95
+
96
+ @walk_left = Proc.new do
97
+ @collision_box.x -= 4
98
+ @walk_count += 1
99
+
100
+ if @walk_count >= @number_hor_steps then
101
+ @walk_count = 0
102
+ @current_animation = :walking_up
103
+ @walk_algorithm = @walk_up
104
+ end
105
+ end
106
+
107
+ @walk_up = Proc.new do
108
+ @collision_box.y -= 4
109
+ @walk_count += 1
110
+
111
+ if @walk_count >= @number_ver_steps then
112
+ @walk_count = 0
113
+ @current_animation = :walking_right
114
+ @walk_algorithm = @walk_right
115
+ end
116
+ end
117
+
118
+ @walk_algorithm = @walk_right
119
+ end
120
+
121
+ def current_sprite
122
+ return @animations[@current_animation].current_sprite
123
+ end
124
+
125
+ def tick
126
+ @walk_algorithm.call
127
+ @animations[@current_animation].animate
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,70 @@
1
+ # SPDX-License-Identifier: MIT
2
+ require 'red_bird/stage'
3
+ require "red_bird/vertical_menu"
4
+
5
+ module RedBird::Demo
6
+ module Stage
7
+ class Main < RedBird::Stage
8
+
9
+ def initialize(global_data)
10
+ super(global_data)
11
+
12
+ if global_data[:palette].nil? then
13
+ global_data[:palette] = RedBird::Palette.from_yml(
14
+ Gem.datadir("red_bird-demo") + "/palette/palette.yml")
15
+ global_data[:color] = {
16
+ white: RedBird::Color.new(255, 255, 255, 255),
17
+ black: RedBird::Color.new(0, 0, 0, 255),
18
+ }
19
+ end
20
+
21
+ font = RedBird::Font.new(
22
+ Gem.datadir("red_bird-demo") + "/font/connection.ttf", 18)
23
+
24
+ box_style = RedBird::UIBox::Style.new(
25
+ Gem.datadir("red_bird-demo") + "/img/text_box.pgm",
26
+ global_data[:palette], global_data[:color][:black], 16, 16)
27
+
28
+ main_menu = RedBird::VerticalMenu.new(
29
+ box_style, 20, 20,
30
+ [RedBird::VerticalMenu::Option.new(
31
+ RedBird::Text.new(
32
+ "Move on Tiles", font, global_data[:color][:white],
33
+ global_data[:color][:black])
34
+ ) { global_data[:stage] = :move_on_tiles
35
+ RedBird::Engine::quit_stage },
36
+ RedBird::VerticalMenu::Option.new(
37
+ RedBird::Text.new(
38
+ "Resolution", font, global_data[:color][:white],
39
+ global_data[:color][:black])
40
+ ) { global_data[:stage] = :resolution
41
+ RedBird::Engine::quit_stage },
42
+ RedBird::VerticalMenu::Option.new(
43
+ RedBird::Text.new(
44
+ "Exit", font, global_data[:color][:white],
45
+ global_data[:color][:black])
46
+ ) { RedBird::Engine::quit_game }
47
+ ])
48
+
49
+ self.add_entities(main_menu)
50
+
51
+ @controller = RedBird::Controller.new
52
+ @controller.add_command(:press_up) do
53
+ main_menu.pred_opt
54
+ end
55
+ @controller.add_command(:press_down) do
56
+ main_menu.next_opt
57
+ end
58
+ @controller.add_command(:press_confirm) do
59
+ main_menu.activate
60
+ end
61
+
62
+ @input_device = RedBird::InputDevice.new(@controller)
63
+ @input_device.add_keydown(RedBird::Keycode::W, :press_up)
64
+ @input_device.add_keydown(RedBird::Keycode::S, :press_down)
65
+ @input_device.add_keydown(RedBird::Keycode::F, :press_confirm)
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,34 @@
1
+ # SPDX-License-Identifier: MIT
2
+ require 'red_bird/camera'
3
+ require 'red_bird/stage'
4
+
5
+ module RedBird::Demo
6
+ require_relative 'controller_move_on_tiles'
7
+ require_relative 'entity_move_on_tiles'
8
+ require_relative 'tile_maps'
9
+
10
+ module Stage
11
+ class MoveOnTiles < RedBird::Stage
12
+ def initialize(global_data)
13
+ super(global_data)
14
+
15
+ @tile_map = RedBird::Demo::TileMaps.move_on_tiles(
16
+ global_data[:palette])
17
+ RedBird::RelativeEntity.scenario = @tile_map
18
+
19
+ @player = Entity::MoveOnTiles.new(32, 64, global_data[:palette])
20
+ @camera = RedBird::Camera.new(@player, @tile_map)
21
+
22
+ self.add_entities([@tile_map, @player])
23
+ @interactions = [@camera]
24
+
25
+ @controller = Controller::MoveOnTiles.new(@player)
26
+ @input_device = RedBird::InputDevice.new(@controller)
27
+ end
28
+
29
+ def post_tick
30
+ @interactions.each { |i| i.call }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,63 @@
1
+ # SPDX-License-Identifier: MIT
2
+ require 'red_bird/stage'
3
+ require "red_bird/vertical_menu"
4
+
5
+ module RedBird::Demo
6
+ module Stage
7
+ class Resolution < RedBird::Stage
8
+
9
+ def initialize(global_data)
10
+ super(global_data)
11
+
12
+ font = RedBird::Font.new(
13
+ Gem.datadir("red_bird-demo") + "/font/connection.ttf", 18)
14
+
15
+ box_style = RedBird::UIBox::Style.new(
16
+ Gem.datadir("red_bird-demo") + "/img/text_box.pgm",
17
+ global_data[:palette], global_data[:color][:black], 16, 16)
18
+
19
+ resolution_menu = RedBird::VerticalMenu.new(
20
+ box_style, 20, 20,
21
+ [RedBird::VerticalMenu::Option.new(
22
+ RedBird::Text.new("256x240", font, global_data[:color][:white],
23
+ global_data[:color][:black])
24
+ ) { RedBird::Engine.set_screen_resolution(256, 240) },
25
+ RedBird::VerticalMenu::Option.new(
26
+ RedBird::Text.new("512x480", font, global_data[:color][:white],
27
+ global_data[:color][:black])
28
+ ) { RedBird::Engine.set_screen_resolution(512, 480) },
29
+ RedBird::VerticalMenu::Option.new(
30
+ RedBird::Text.new("800x600", font, global_data[:color][:white],
31
+ global_data[:color][:black])
32
+ ) { RedBird::Engine.set_screen_resolution(800, 600) },
33
+ RedBird::VerticalMenu::Option.new(
34
+ RedBird::Text.new("600x800", font, global_data[:color][:white],
35
+ global_data[:color][:black])
36
+ ) { RedBird::Engine.set_screen_resolution(600, 800) },
37
+ RedBird::VerticalMenu::Option.new(
38
+ RedBird::Text.new("Back", font, global_data[:color][:white],
39
+ global_data[:color][:black])
40
+ ) { global_data[:stage] = :main; RedBird::Engine::quit_stage }
41
+ ])
42
+
43
+ self.add_entities(resolution_menu)
44
+
45
+ @controller = RedBird::Controller.new
46
+ @controller.add_command(:press_up) do
47
+ resolution_menu.pred_opt
48
+ end
49
+ @controller.add_command(:press_down) do
50
+ resolution_menu.next_opt
51
+ end
52
+ @controller.add_command(:press_confirm) do
53
+ resolution_menu.activate
54
+ end
55
+
56
+ @input_device = RedBird::InputDevice.new(@controller)
57
+ @input_device.add_keydown(RedBird::Keycode::W, :press_up)
58
+ @input_device.add_keydown(RedBird::Keycode::S, :press_down)
59
+ @input_device.add_keydown(RedBird::Keycode::F, :press_confirm)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,14 @@
1
+ # SPDX-License-Identifier: MIT
2
+ require "red_bird/tile_map"
3
+
4
+ require_relative "tile_sets.rb"
5
+
6
+ module RedBird::Demo
7
+ module TileMaps
8
+ def self.move_on_tiles(palette)
9
+ return RedBird::TileMap.from_yml(
10
+ Gem.datadir("red_bird-demo"), "/tile_map/move_on_tiles.yml",
11
+ TileSets.move_on_tiles(palette), 0, 0, 256, 240)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # SPDX-License-Identifier: MIT
2
+ require "red_bird/tile_set"
3
+
4
+ module RedBird::Demo
5
+ module TileSets
6
+ def self.move_on_tiles(palette)
7
+ return RedBird::TileSet.from_yml(
8
+ Gem.datadir("red_bird-demo"), "/tile_set/move_on_tiles.yml",
9
+ palette)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module RedBird
2
+ module Demo
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'lib/red_bird/demo/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "red_bird-demo"
5
+ spec.version = RedBird::Demo::VERSION
6
+ spec.authors = ["Frederico Linhares"]
7
+ spec.email = ["fred@linhares.blue"]
8
+
9
+ spec.summary = %q{RedBird demonstration.}
10
+ spec.homepage = "http://projects.linhares.blue/red_bid"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] =
16
+ "https://bitbucket.org/fredlinhares/red_bird"
17
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added
21
+ # into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: red_bird-demo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Frederico Linhares
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-08-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - fred@linhares.blue
16
+ executables:
17
+ - red_bird-demo
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE.txt
25
+ - MIT.txt
26
+ - README.md
27
+ - Rakefile
28
+ - SIL_CONNECTION.txt
29
+ - bin/setup
30
+ - data/red_bird-demo/font/connection.ttf
31
+ - data/red_bird-demo/img/player.pgm
32
+ - data/red_bird-demo/img/text_box.pgm
33
+ - data/red_bird-demo/img/tileset.pgm
34
+ - data/red_bird-demo/palette/palette.yml
35
+ - data/red_bird-demo/tile_map/move_on_tiles.yml
36
+ - data/red_bird-demo/tile_set/move_on_tiles.yml
37
+ - exe/red_bird-demo
38
+ - lib/red_bird/demo.rb
39
+ - lib/red_bird/demo/controller_move_on_tiles.rb
40
+ - lib/red_bird/demo/entity_move_on_tiles.rb
41
+ - lib/red_bird/demo/stage_main.rb
42
+ - lib/red_bird/demo/stage_move_on_tiles.rb
43
+ - lib/red_bird/demo/stage_resolution.rb
44
+ - lib/red_bird/demo/tile_maps.rb
45
+ - lib/red_bird/demo/tile_sets.rb
46
+ - lib/red_bird/demo/version.rb
47
+ - red_bird-demo.gemspec
48
+ homepage: http://projects.linhares.blue/red_bid
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: http://projects.linhares.blue/red_bid
53
+ source_code_uri: https://bitbucket.org/fredlinhares/red_bird
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.3.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.1.4
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: RedBird demonstration.
73
+ test_files: []