diff options
| author | Amir Rajan <[email protected]> | 2020-09-22 06:27:46 -0500 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2020-09-22 06:27:46 -0500 |
| commit | 20d5b4057b44ffcf92478b2a8e9476ace2fdc0f5 (patch) | |
| tree | b4742e4f9acfd5400a04f314164812606a71df9f /samples/99_genre_rpg_topdown | |
| parent | 5b2311900072cfff9582bb0296140cfb354cb911 (diff) | |
| download | dragonruby-game-toolkit-contrib-20d5b4057b44ffcf92478b2a8e9476ace2fdc0f5.tar.gz dragonruby-game-toolkit-contrib-20d5b4057b44ffcf92478b2a8e9476ace2fdc0f5.zip | |
synced with 1.22
Diffstat (limited to 'samples/99_genre_rpg_topdown')
3 files changed, 304 insertions, 0 deletions
diff --git a/samples/99_genre_rpg_topdown/topdown_starting_point/app/main.rb b/samples/99_genre_rpg_topdown/topdown_starting_point/app/main.rb new file mode 100644 index 0000000..c447940 --- /dev/null +++ b/samples/99_genre_rpg_topdown/topdown_starting_point/app/main.rb @@ -0,0 +1,108 @@ +=begin + + APIs listing that haven't been encountered in previous sample apps: + + - reverse: Returns a new string with the characters from original string in reverse order. + For example, the command + "dragonruby".reverse + would return the string + "yburnogard". + Reverse is not only limited to strings, but can be applied to arrays and other collections. + + Reminders: + + - ARRAY#intersect_rect?: Returns true or false depending on if two rectangles intersect. + + - args.outputs.labels: An array. The values generate a label. + The parameters are [X, Y, TEXT, SIZE, ALIGNMENT, RED, GREEN, BLUE, ALPHA, FONT STYLE] + For more information about labels, go to mygame/documentation/02-labels.md. + +=end + +# This code shows a maze and uses input from the keyboard to move the user around the screen. +# The objective is to reach the goal. + +# Sets values of tile size and player's movement speed +# Also creates tile or box for player and generates map +def tick args + args.state.tile_size = 80 + args.state.player_speed = 4 + args.state.player ||= tile(args, 7, 3, 0, 128, 180) + generate_map args + + # Adds walls, goal, and player to args.outputs.solids so they appear on screen + args.outputs.solids << args.state.walls + args.outputs.solids << args.state.goal + args.outputs.solids << args.state.player + + # If player's box intersects with goal, a label is output onto the screen + if args.state.player.intersect_rect? args.state.goal + args.outputs.labels << [30, 720 - 30, "You're a wizard Harry!!"] # 30 pixels lower than top of screen + end + + move_player args, -1, 0 if args.inputs.keyboard.left # x position decreases by 1 if left key is pressed + move_player args, 1, 0 if args.inputs.keyboard.right # x position increases by 1 if right key is pressed + move_player args, 0, 1 if args.inputs.keyboard.up # y position increases by 1 if up is pressed + move_player args, 0, -1 if args.inputs.keyboard.down # y position decreases by 1 if down is pressed +end + +# Sets position, size, and color of the tile +def tile args, x, y, *color + [x * args.state.tile_size, # sets definition for array using method parameters + y * args.state.tile_size, # multiplying by tile_size sets x and y to correct position using pixel values + args.state.tile_size, + args.state.tile_size, + *color] +end + +# Creates map by adding tiles to the wall, as well as a goal (that the player needs to reach) +def generate_map args + return if args.state.area + + # Creates the area of the map. There are 9 rows running horizontally across the screen + # and 16 columns running vertically on the screen. Any spot with a "1" is not + # open for the player to move into (and is green), and any spot with a "0" is available + # for the player to move in. + args.state.area = [ + [1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1,], + [1, 1, 1, 2, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1,], # the "2" represents the goal + [1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,], + [1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], + [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,], + [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ], + ].reverse # reverses the order of the area collection + + # By reversing the order, the way that the area appears above is how it appears + # on the screen in the game. If we did not reverse, the map would appear inverted. + + #The wall starts off with no tiles. + args.state.walls = [] + + # If v is 1, a green tile is added to args.state.walls. + # If v is 2, a black tile is created as the goal. + args.state.area.map_2d do |y, x, v| + if v == 1 + args.state.walls << tile(args, x, y, 0, 255, 0) # green tile + elsif v == 2 # notice there is only one "2" above because there is only one single goal + args.state.goal = tile(args, x, y, 0, 0, 0) # black tile + end + end +end + +# Allows the player to move their box around the screen +def move_player args, *vector + box = args.state.player.shift_rect(vector) # box is able to move at an angle + + # If the player's box hits a wall, it is not able to move further in that direction + return if args.state.walls + .any_intersect_rect?(box) + + # Player's box is able to move at angles (not just the four general directions) fast + args.state.player = + args.state.player + .shift_rect(vector.x * args.state.player_speed, # if we don't multiply by speed, then + vector.y * args.state.player_speed) # the box will move extremely slow +end diff --git a/samples/99_genre_rpg_topdown/topdown_starting_point/license-for-sample.txt b/samples/99_genre_rpg_topdown/topdown_starting_point/license-for-sample.txt new file mode 100644 index 0000000..100dcec --- /dev/null +++ b/samples/99_genre_rpg_topdown/topdown_starting_point/license-for-sample.txt @@ -0,0 +1,9 @@ +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_topdown/topdown_starting_point/replay.txt b/samples/99_genre_rpg_topdown/topdown_starting_point/replay.txt new file mode 100644 index 0000000..f121bc6 --- /dev/null +++ b/samples/99_genre_rpg_topdown/topdown_starting_point/replay.txt @@ -0,0 +1,187 @@ +replay_version 2.0 +stopped_at 880 +seed 100 +recorded_at Sun Sep 29 22:31:22 2019 +[:key_down_raw, 1073741904, 0, 2, 1, 92] +[:key_down_raw, 1073741904, 0, 2, 2, 117] +[:key_down_raw, 1073741903, 0, 2, 3, 119] +[:key_up_raw, 1073741904, 0, 2, 4, 119] +[:key_down_raw, 1073741903, 0, 2, 5, 144] +[:key_down_raw, 1073741903, 0, 2, 6, 146] +[:key_down_raw, 1073741903, 0, 2, 7, 148] +[:key_down_raw, 1073741903, 0, 2, 8, 150] +[:key_down_raw, 1073741903, 0, 2, 9, 152] +[:key_down_raw, 1073741906, 0, 2, 10, 152] +[:key_down_raw, 1073741906, 0, 2, 11, 177] +[:key_down_raw, 1073741906, 0, 2, 12, 179] +[:key_down_raw, 1073741906, 0, 2, 13, 181] +[:key_down_raw, 1073741906, 0, 2, 14, 183] +[:key_down_raw, 1073741906, 0, 2, 15, 185] +[:key_down_raw, 1073741906, 0, 2, 16, 187] +[:key_down_raw, 1073741906, 0, 2, 17, 189] +[:key_down_raw, 1073741906, 0, 2, 18, 191] +[:key_down_raw, 1073741906, 0, 2, 19, 193] +[:key_down_raw, 1073741906, 0, 2, 20, 195] +[:key_down_raw, 1073741906, 0, 2, 21, 197] +[:key_down_raw, 1073741906, 0, 2, 22, 199] +[:key_down_raw, 1073741906, 0, 2, 23, 201] +[:key_down_raw, 1073741906, 0, 2, 24, 203] +[:key_down_raw, 1073741906, 0, 2, 25, 205] +[:key_down_raw, 1073741906, 0, 2, 26, 207] +[:key_down_raw, 1073741906, 0, 2, 27, 209] +[:key_down_raw, 1073741906, 0, 2, 28, 211] +[:key_down_raw, 1073741906, 0, 2, 29, 213] +[:key_down_raw, 1073741906, 0, 2, 30, 215] +[:key_down_raw, 1073741906, 0, 2, 31, 217] +[:key_down_raw, 1073741906, 0, 2, 32, 219] +[:key_down_raw, 1073741906, 0, 2, 33, 221] +[:key_down_raw, 1073741906, 0, 2, 34, 223] +[:key_down_raw, 1073741906, 0, 2, 35, 225] +[:key_down_raw, 1073741906, 0, 2, 36, 227] +[:key_down_raw, 1073741906, 0, 2, 37, 229] +[:key_down_raw, 1073741906, 0, 2, 38, 231] +[:key_down_raw, 1073741906, 0, 2, 39, 233] +[:key_down_raw, 1073741906, 0, 2, 40, 235] +[:key_down_raw, 1073741906, 0, 2, 41, 237] +[:key_down_raw, 1073741906, 0, 2, 42, 239] +[:key_down_raw, 1073741906, 0, 2, 43, 241] +[:key_down_raw, 1073741906, 0, 2, 44, 243] +[:key_down_raw, 1073741906, 0, 2, 45, 245] +[:key_down_raw, 1073741906, 0, 2, 46, 248] +[:key_down_raw, 1073741906, 0, 2, 47, 250] +[:key_down_raw, 1073741906, 0, 2, 48, 252] +[:key_down_raw, 1073741906, 0, 2, 49, 254] +[:key_down_raw, 1073741906, 0, 2, 50, 256] +[:key_down_raw, 1073741906, 0, 2, 51, 258] +[:key_down_raw, 1073741906, 0, 2, 52, 260] +[:key_down_raw, 1073741906, 0, 2, 53, 262] +[:key_down_raw, 1073741906, 0, 2, 54, 264] +[:key_down_raw, 1073741905, 0, 2, 55, 265] +[:key_up_raw, 1073741906, 0, 2, 56, 266] +[:key_up_raw, 1073741903, 0, 2, 57, 267] +[:key_down_raw, 1073741904, 0, 2, 58, 287] +[:key_up_raw, 1073741905, 0, 2, 59, 289] +[:key_down_raw, 1073741904, 0, 2, 60, 312] +[:key_down_raw, 1073741904, 0, 2, 61, 314] +[:key_down_raw, 1073741904, 0, 2, 62, 316] +[:key_down_raw, 1073741904, 0, 2, 63, 318] +[:key_down_raw, 1073741904, 0, 2, 64, 320] +[:key_down_raw, 1073741904, 0, 2, 65, 322] +[:key_down_raw, 1073741904, 0, 2, 66, 324] +[:key_down_raw, 1073741904, 0, 2, 67, 326] +[:key_down_raw, 1073741905, 0, 2, 68, 328] +[:key_up_raw, 1073741905, 0, 2, 69, 348] +[:key_down_raw, 1073741905, 0, 2, 70, 385] +[:key_down_raw, 1073741906, 0, 2, 71, 395] +[:key_up_raw, 1073741904, 0, 2, 72, 408] +[:key_up_raw, 1073741905, 0, 2, 73, 409] +[:key_down_raw, 1073741906, 0, 2, 74, 420] +[:key_down_raw, 1073741906, 0, 2, 75, 422] +[:key_down_raw, 1073741906, 0, 2, 76, 424] +[:key_down_raw, 1073741906, 0, 2, 77, 426] +[:key_down_raw, 1073741906, 0, 2, 78, 428] +[:key_down_raw, 1073741906, 0, 2, 79, 430] +[:key_down_raw, 1073741906, 0, 2, 80, 432] +[:key_down_raw, 1073741906, 0, 2, 81, 434] +[:key_down_raw, 1073741906, 0, 2, 82, 436] +[:key_down_raw, 1073741906, 0, 2, 83, 438] +[:key_down_raw, 1073741904, 0, 2, 84, 440] +[:key_down_raw, 1073741904, 0, 2, 85, 465] +[:key_down_raw, 1073741904, 0, 2, 86, 467] +[:key_down_raw, 1073741904, 0, 2, 87, 469] +[:key_down_raw, 1073741904, 0, 2, 88, 471] +[:key_down_raw, 1073741904, 0, 2, 89, 473] +[:key_down_raw, 1073741904, 0, 2, 90, 475] +[:key_down_raw, 1073741904, 0, 2, 91, 477] +[:key_down_raw, 1073741904, 0, 2, 92, 479] +[:key_down_raw, 1073741904, 0, 2, 93, 481] +[:key_down_raw, 1073741904, 0, 2, 94, 483] +[:key_down_raw, 1073741904, 0, 2, 95, 485] +[:key_down_raw, 1073741904, 0, 2, 96, 487] +[:key_down_raw, 1073741904, 0, 2, 97, 489] +[:key_down_raw, 1073741904, 0, 2, 98, 491] +[:key_up_raw, 1073741906, 0, 2, 99, 493] +[:key_down_raw, 1073741904, 0, 2, 100, 493] +[:key_down_raw, 1073741904, 0, 2, 101, 495] +[:key_down_raw, 1073741904, 0, 2, 102, 497] +[:key_down_raw, 1073741904, 0, 2, 103, 499] +[:key_down_raw, 1073741904, 0, 2, 104, 501] +[:key_down_raw, 1073741904, 0, 2, 105, 503] +[:key_down_raw, 1073741904, 0, 2, 106, 505] +[:key_down_raw, 1073741904, 0, 2, 107, 507] +[:key_down_raw, 1073741904, 0, 2, 108, 509] +[:key_down_raw, 1073741904, 0, 2, 109, 511] +[:key_down_raw, 1073741904, 0, 2, 110, 513] +[:key_down_raw, 1073741904, 0, 2, 111, 515] +[:key_down_raw, 1073741904, 0, 2, 112, 517] +[:key_down_raw, 1073741904, 0, 2, 113, 519] +[:key_down_raw, 1073741904, 0, 2, 114, 521] +[:key_down_raw, 1073741904, 0, 2, 115, 523] +[:key_down_raw, 1073741904, 0, 2, 116, 526] +[:key_down_raw, 1073741904, 0, 2, 117, 527] +[:key_down_raw, 1073741904, 0, 2, 118, 530] +[:key_down_raw, 1073741904, 0, 2, 119, 532] +[:key_down_raw, 1073741904, 0, 2, 120, 533] +[:key_down_raw, 1073741904, 0, 2, 121, 536] +[:key_up_raw, 1073741904, 0, 2, 122, 537] +[:key_down_raw, 1073741906, 0, 2, 123, 556] +[:key_down_raw, 1073741906, 0, 2, 124, 580] +[:key_down_raw, 1073741906, 0, 2, 125, 583] +[:key_down_raw, 1073741906, 0, 2, 126, 585] +[:key_down_raw, 1073741906, 0, 2, 127, 587] +[:key_down_raw, 1073741906, 0, 2, 128, 589] +[:key_up_raw, 1073741906, 0, 2, 129, 589] +[:key_down_raw, 1073741905, 0, 2, 130, 617] +[:key_down_raw, 1073741905, 0, 2, 131, 642] +[:key_down_raw, 1073741905, 0, 2, 132, 644] +[:key_down_raw, 1073741905, 0, 2, 133, 646] +[:key_down_raw, 1073741905, 0, 2, 134, 648] +[:key_down_raw, 1073741905, 0, 2, 135, 650] +[:key_down_raw, 1073741905, 0, 2, 136, 652] +[:key_down_raw, 1073741905, 0, 2, 137, 654] +[:key_up_raw, 1073741905, 0, 2, 138, 654] +[:key_down_raw, 1073741906, 0, 2, 139, 663] +[:key_down_raw, 1073741906, 0, 2, 140, 688] +[:key_down_raw, 1073741906, 0, 2, 141, 690] +[:key_down_raw, 1073741906, 0, 2, 142, 692] +[:key_down_raw, 1073741906, 0, 2, 143, 695] +[:key_down_raw, 1073741906, 0, 2, 144, 697] +[:key_down_raw, 1073741906, 0, 2, 145, 699] +[:key_down_raw, 1073741906, 0, 2, 146, 701] +[:key_down_raw, 1073741906, 0, 2, 147, 703] +[:key_down_raw, 1073741906, 0, 2, 148, 705] +[:key_down_raw, 1073741906, 0, 2, 149, 707] +[:key_up_raw, 1073741906, 0, 2, 150, 707] +[:key_down_raw, 1073741905, 0, 2, 151, 713] +[:key_down_raw, 1073741905, 0, 2, 152, 738] +[:key_down_raw, 1073741905, 0, 2, 153, 740] +[:key_down_raw, 1073741903, 0, 2, 154, 741] +[:key_down_raw, 1073741903, 0, 2, 155, 766] +[:key_down_raw, 1073741903, 0, 2, 156, 768] +[:key_down_raw, 1073741903, 0, 2, 157, 770] +[:key_down_raw, 1073741903, 0, 2, 158, 772] +[:key_up_raw, 1073741905, 0, 2, 159, 772] +[:key_down_raw, 1073741903, 0, 2, 160, 774] +[:key_down_raw, 1073741903, 0, 2, 161, 776] +[:key_down_raw, 1073741903, 0, 2, 162, 778] +[:key_down_raw, 1073741903, 0, 2, 163, 780] +[:key_down_raw, 1073741903, 0, 2, 164, 782] +[:key_down_raw, 1073741903, 0, 2, 165, 784] +[:key_down_raw, 1073741903, 0, 2, 166, 786] +[:key_down_raw, 1073741903, 0, 2, 167, 788] +[:key_down_raw, 1073741903, 0, 2, 168, 790] +[:key_down_raw, 1073741903, 0, 2, 169, 792] +[:key_down_raw, 1073741903, 0, 2, 170, 794] +[:key_down_raw, 1073741903, 0, 2, 171, 796] +[:key_down_raw, 1073741903, 0, 2, 172, 798] +[:key_down_raw, 1073741903, 0, 2, 173, 800] +[:key_down_raw, 1073741903, 0, 2, 174, 802] +[:key_down_raw, 1073741903, 0, 2, 175, 804] +[:key_down_raw, 1073741903, 0, 2, 176, 806] +[:key_down_raw, 1073741903, 0, 2, 177, 808] +[:key_down_raw, 1073741903, 0, 2, 178, 810] +[:key_down_raw, 1073741903, 0, 2, 179, 812] +[:key_down_raw, 1073741903, 0, 2, 180, 814] +[:key_up_raw, 1073741903, 0, 2, 181, 814] +[:key_down_raw, 1073742051, 1024, 2, 182, 879] +[:key_down_raw, 113, 1024, 2, 183, 879] |
