summaryrefslogtreecommitdiffhomepage
path: root/samples/99_genre_rpg_roguelike/roguelike_line_of_sight
diff options
context:
space:
mode:
Diffstat (limited to 'samples/99_genre_rpg_roguelike/roguelike_line_of_sight')
-rw-r--r--samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/constants.rb8
-rw-r--r--samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/legend.rb65
-rw-r--r--samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/main.rb97
-rw-r--r--samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/sprite_lookup.rb124
-rw-r--r--samples/99_genre_rpg_roguelike/roguelike_line_of_sight/license-for-sample.txt9
-rw-r--r--samples/99_genre_rpg_roguelike/roguelike_line_of_sight/sprites/simple-mood-16x16.pngbin14424 -> 0 bytes
6 files changed, 0 insertions, 303 deletions
diff --git a/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/constants.rb b/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/constants.rb
deleted file mode 100644
index 37dd493..0000000
--- a/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/constants.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-SHOW_LEGEND = true
-SOURCE_TILE_SIZE = 16
-DESTINATION_TILE_SIZE = 16
-TILE_SHEET_SIZE = 256
-TILE_R = 0
-TILE_G = 0
-TILE_B = 0
-TILE_A = 255
diff --git a/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/legend.rb b/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/legend.rb
deleted file mode 100644
index 4d07b79..0000000
--- a/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/legend.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-def tick_legend args
- return unless SHOW_LEGEND
-
- legend_padding = 16
- legend_x = 1280 - TILE_SHEET_SIZE - legend_padding
- legend_y = 720 - TILE_SHEET_SIZE - legend_padding
- tile_sheet_sprite = [legend_x,
- legend_y,
- TILE_SHEET_SIZE,
- TILE_SHEET_SIZE,
- 'sprites/simple-mood-16x16.png', 0,
- TILE_A,
- TILE_R,
- TILE_G,
- TILE_B]
-
- if args.inputs.mouse.point.inside_rect? tile_sheet_sprite
- mouse_row = args.inputs.mouse.point.y.idiv(SOURCE_TILE_SIZE)
- tile_row = 15 - (mouse_row - legend_y.idiv(SOURCE_TILE_SIZE))
-
- mouse_col = args.inputs.mouse.point.x.idiv(SOURCE_TILE_SIZE)
- tile_col = (mouse_col - legend_x.idiv(SOURCE_TILE_SIZE))
-
- args.outputs.primitives << [legend_x - legend_padding * 2,
- mouse_row * SOURCE_TILE_SIZE, 256 + legend_padding * 2, 16, 128, 128, 128, 64].solid
-
- args.outputs.primitives << [mouse_col * SOURCE_TILE_SIZE,
- legend_y - legend_padding * 2, 16, 256 + legend_padding * 2, 128, 128, 128, 64].solid
-
- sprite_key = sprite_lookup.find { |k, v| v == [tile_row, tile_col] }
- if sprite_key
- member_name, _ = sprite_key
- member_name = member_name_as_code member_name
- args.outputs.labels << [660, 70, "# CODE SAMPLE (place in the tick_game method located in main.rb)", -1, 0]
- args.outputs.labels << [660, 50, "# GRID_X, GRID_Y, TILE_KEY", -1, 0]
- args.outputs.labels << [660, 30, "args.outputs.sprites << tile_in_game( 5, 6, #{member_name} )", -1, 0]
- else
- args.outputs.labels << [660, 50, "Tile [#{tile_row}, #{tile_col}] not found. Add a key and value to app/sprite_lookup.rb:", -1, 0]
- args.outputs.labels << [660, 30, "{ \"some_string\" => [#{tile_row}, #{tile_col}] } OR { some_symbol: [#{tile_row}, #{tile_col}] }.", -1, 0]
- end
-
- end
-
- # render the sprite in the top right with a padding to the top and right so it's
- # not flush against the edge
- args.outputs.sprites << tile_sheet_sprite
-
- # carefully place some ascii arrows to show the legend labels
- args.outputs.labels << [895, 707, "ROW --->"]
- args.outputs.labels << [943, 412, " ^"]
- args.outputs.labels << [943, 412, " |"]
- args.outputs.labels << [943, 394, "COL ---+"]
-
- # use the tile sheet to print out row and column numbers
- args.outputs.sprites << 16.map_with_index do |i|
- sprite_key = i % 10
- [
- tile(1280 - TILE_SHEET_SIZE - legend_padding * 2 - SOURCE_TILE_SIZE,
- 720 - legend_padding * 2 - (SOURCE_TILE_SIZE * i),
- sprite(sprite_key)),
- tile(1280 - TILE_SHEET_SIZE - SOURCE_TILE_SIZE + (SOURCE_TILE_SIZE * i),
- 720 - TILE_SHEET_SIZE - legend_padding * 3, sprite(sprite_key))
- ]
- end
-end
diff --git a/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/main.rb b/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/main.rb
deleted file mode 100644
index bd5f521..0000000
--- a/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/main.rb
+++ /dev/null
@@ -1,97 +0,0 @@
-require 'app/constants.rb'
-require 'app/sprite_lookup.rb'
-require 'app/legend.rb'
-
-def tick args
- tick_game args
- tick_legend args
-end
-
-def tick_game args
- # setup the grid
- args.state.grid.padding = 104
- args.state.grid.size = 512
-
- # set up your game
- # initialize the game/game defaults. ||= means that you only initialize it if
- # the value isn't alread initialized
- args.state.player.x ||= 0
- args.state.player.y ||= 0
-
- args.state.enemies ||= [
- { x: 10, y: 10, type: :goblin, tile_key: :G },
- { x: 15, y: 30, type: :rat, tile_key: :R }
- ]
-
- args.state.info_message ||= "Use arrow keys to move around."
-
- # handle keyboard input
- # keyboard input (arrow keys to move player)
- new_player_x = args.state.player.x
- new_player_y = args.state.player.y
- player_direction = ""
- player_moved = false
- if args.inputs.keyboard.key_down.up
- new_player_y += 1
- player_direction = "north"
- player_moved = true
- elsif args.inputs.keyboard.key_down.down
- new_player_y -= 1
- player_direction = "south"
- player_moved = true
- elsif args.inputs.keyboard.key_down.right
- new_player_x += 1
- player_direction = "east"
- player_moved = true
- elsif args.inputs.keyboard.key_down.left
- new_player_x -= 1
- player_direction = "west"
- player_moved = true
- end
-
- #handle game logic
- # determine if there is an enemy on that square,
- # if so, don't let the player move there
- if player_moved
- found_enemy = args.state.enemies.find do |e|
- e[:x] == new_player_x && e[:y] == new_player_y
- end
-
- if !found_enemy
- args.state.player.x = new_player_x
- args.state.player.y = new_player_y
- args.state.info_message = "You moved #{player_direction}."
- else
- args.state.info_message = "You cannot move into a square an enemy occupies."
- end
- end
-
- args.outputs.sprites << tile_in_game(args.state.player.x,
- args.state.player.y, '@')
-
- # render game
- # render enemies at locations
- args.outputs.sprites << args.state.enemies.map do |e|
- tile_in_game(e[:x], e[:y], e[:tile_key])
- end
-
- # render the border
- border_x = args.state.grid.padding - DESTINATION_TILE_SIZE
- border_y = args.state.grid.padding - DESTINATION_TILE_SIZE
- border_size = args.state.grid.size + DESTINATION_TILE_SIZE * 2
-
- args.outputs.borders << [border_x,
- border_y,
- border_size,
- border_size]
-
- # render label stuff
- args.outputs.labels << [border_x, border_y - 10, "Current player location is: #{args.state.player.x}, #{args.state.player.y}"]
- args.outputs.labels << [border_x, border_y + 25 + border_size, args.state.info_message]
-end
-
-def tile_in_game x, y, tile_key
- tile($gtk.args.state.grid.padding + x * DESTINATION_TILE_SIZE,
- $gtk.args.state.grid.padding + y * DESTINATION_TILE_SIZE,
- tile_key)
-end
diff --git a/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/sprite_lookup.rb b/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/sprite_lookup.rb
deleted file mode 100644
index f129e25..0000000
--- a/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/app/sprite_lookup.rb
+++ /dev/null
@@ -1,124 +0,0 @@
-def sprite_lookup
- {
- 0 => [3, 0],
- 1 => [3, 1],
- 2 => [3, 2],
- 3 => [3, 3],
- 4 => [3, 4],
- 5 => [3, 5],
- 6 => [3, 6],
- 7 => [3, 7],
- 8 => [3, 8],
- 9 => [3, 9],
- '@' => [4, 0],
- A: [ 4, 1],
- B: [ 4, 2],
- C: [ 4, 3],
- D: [ 4, 4],
- E: [ 4, 5],
- F: [ 4, 6],
- G: [ 4, 7],
- H: [ 4, 8],
- I: [ 4, 9],
- J: [ 4, 10],
- K: [ 4, 11],
- L: [ 4, 12],
- M: [ 4, 13],
- N: [ 4, 14],
- O: [ 4, 15],
- P: [ 5, 0],
- Q: [ 5, 1],
- R: [ 5, 2],
- S: [ 5, 3],
- T: [ 5, 4],
- U: [ 5, 5],
- V: [ 5, 6],
- W: [ 5, 7],
- X: [ 5, 8],
- Y: [ 5, 9],
- Z: [ 5, 10],
- a: [ 6, 1],
- b: [ 6, 2],
- c: [ 6, 3],
- d: [ 6, 4],
- e: [ 6, 5],
- f: [ 6, 6],
- g: [ 6, 7],
- h: [ 6, 8],
- i: [ 6, 9],
- j: [ 6, 10],
- k: [ 6, 11],
- l: [ 6, 12],
- m: [ 6, 13],
- n: [ 6, 14],
- o: [ 6, 15],
- p: [ 7, 0],
- q: [ 7, 1],
- r: [ 7, 2],
- s: [ 7, 3],
- t: [ 7, 4],
- u: [ 7, 5],
- v: [ 7, 6],
- w: [ 7, 7],
- x: [ 7, 8],
- y: [ 7, 9],
- z: [ 7, 10],
- '|' => [ 7, 12]
- }
-end
-
-def sprite key
- $gtk.args.state.reserved.sprite_lookup[key]
-end
-
-def member_name_as_code raw_member_name
- if raw_member_name.is_a? Symbol
- ":#{raw_member_name}"
- elsif raw_member_name.is_a? String
- "'#{raw_member_name}'"
- elsif raw_member_name.is_a? Fixnum
- "#{raw_member_name}"
- else
- "UNKNOWN: #{raw_member_name}"
- end
-end
-
-def tile x, y, tile_row_column_or_key
- tile_extended x, y, DESTINATION_TILE_SIZE, DESTINATION_TILE_SIZE, TILE_R, TILE_G, TILE_B, TILE_A, tile_row_column_or_key
-end
-
-def tile_extended x, y, w, h, r, g, b, a, tile_row_column_or_key
- row_or_key, column = tile_row_column_or_key
- if !column
- row, column = sprite row_or_key
- else
- row, column = row_or_key, column
- end
-
- if !row
- member_name = member_name_as_code tile_row_column_or_key
- raise "Unabled to find a sprite for #{member_name}. Make sure the value exists in app/sprite_lookup.rb."
- end
-
- # Sprite provided by Rogue Yun
- # http://www.bay12forums.com/smf/index.php?topic=144897.0
- # License: Public Domain
-
- {
- x: x,
- y: y,
- w: w,
- h: h,
- tile_x: column * 16,
- tile_y: (row * 16),
- tile_w: 16,
- tile_h: 16,
- r: r,
- g: g,
- b: b,
- a: a,
- path: 'sprites/simple-mood-16x16.png'
- }
-end
-
-$gtk.args.state.reserved.sprite_lookup = sprite_lookup
diff --git a/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/license-for-sample.txt b/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/license-for-sample.txt
deleted file mode 100644
index 100dcec..0000000
--- a/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/license-for-sample.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-Copyright 2019 DragonRuby LLC
-
-MIT License
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/sprites/simple-mood-16x16.png b/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/sprites/simple-mood-16x16.png
deleted file mode 100644
index 0eca11e..0000000
--- a/samples/99_genre_rpg_roguelike/roguelike_line_of_sight/sprites/simple-mood-16x16.png
+++ /dev/null
Binary files differ