summaryrefslogtreecommitdiffhomepage
path: root/samples/99_genre_dungeon_crawl
diff options
context:
space:
mode:
author_Tradam <[email protected]>2021-12-16 19:22:26 -0500
committerGitHub <[email protected]>2021-12-16 19:22:26 -0500
commit5954b9beb4d4a3b4f248d72d1851195f030558a8 (patch)
treefecd8aa840a25afdb502915b0fdb4d03b7ed339a /samples/99_genre_dungeon_crawl
parent2f845281f133849256b57bb08fd3e9ae57600784 (diff)
parenteaa29e72939f5edf61735ccbb73c36ee89369f65 (diff)
downloaddragonruby-game-toolkit-contrib-master.tar.gz
dragonruby-game-toolkit-contrib-master.zip
Merge branch 'DragonRuby:master' into masterHEADmaster
Diffstat (limited to 'samples/99_genre_dungeon_crawl')
-rw-r--r--samples/99_genre_dungeon_crawl/classics_jam/app/main.rb213
-rw-r--r--samples/99_genre_dungeon_crawl/classics_jam/replay.txt197
-rw-r--r--samples/99_genre_dungeon_crawl/classics_jam/sprites/circle/green.pngbin0 -> 2887 bytes
-rw-r--r--samples/99_genre_dungeon_crawl/classics_jam/sprites/square/blue.pngbin0 -> 283 bytes
-rw-r--r--samples/99_genre_dungeon_crawl/classics_jam/sprites/square/gray.pngbin0 -> 251 bytes
-rw-r--r--samples/99_genre_dungeon_crawl/classics_jam/sprites/square/red.pngbin0 -> 274 bytes
6 files changed, 410 insertions, 0 deletions
diff --git a/samples/99_genre_dungeon_crawl/classics_jam/app/main.rb b/samples/99_genre_dungeon_crawl/classics_jam/app/main.rb
new file mode 100644
index 0000000..d14b50e
--- /dev/null
+++ b/samples/99_genre_dungeon_crawl/classics_jam/app/main.rb
@@ -0,0 +1,213 @@
+class Game
+ attr_gtk
+
+ def tick
+ defaults
+ render
+ input
+ calc
+ end
+
+ def defaults
+ player.x ||= 640
+ player.y ||= 360
+ player.w ||= 16
+ player.h ||= 16
+ player.attacked_at ||= -1
+ player.angle ||= 0
+ player.future_player ||= future_player_position 0, 0
+ player.projectiles ||= []
+ player.damage ||= 0
+ state.level ||= create_level level_one_template
+ end
+
+ def render
+ outputs.sprites << level.walls.map do |w|
+ w.merge(path: 'sprites/square/gray.png')
+ end
+
+ outputs.sprites << level.spawn_locations.map do |s|
+ s.merge(path: 'sprites/square/blue.png')
+ end
+
+ outputs.sprites << player.projectiles.map do |p|
+ p.merge(path: 'sprites/square/blue.png')
+ end
+
+ outputs.sprites << level.enemies.map do |e|
+ e.merge(path: 'sprites/square/red.png')
+ end
+
+ outputs.sprites << player.merge(path: 'sprites/circle/green.png', angle: player.angle)
+
+ outputs.labels << { x: 30, y: 30.from_top, text: "damage: #{player.damage || 0}" }
+ end
+
+ def input
+ player.angle = inputs.directional_angle || player.angle
+ if inputs.controller_one.key_down.a || inputs.keyboard.key_down.space
+ player.attacked_at = state.tick_count
+ end
+ end
+
+ def calc
+ calc_player
+ calc_projectiles
+ calc_enemies
+ calc_spawn_locations
+ end
+
+ def calc_player
+ if player.attacked_at == state.tick_count
+ player.projectiles << { at: state.tick_count,
+ x: player.x,
+ y: player.y,
+ angle: player.angle,
+ w: 4,
+ h: 4 }.center_inside_rect(player)
+ end
+
+ if player.attacked_at.elapsed_time > 5
+ future_player = future_player_position inputs.left_right * 2, inputs.up_down * 2
+ future_player_collision = future_collision player, future_player, level.walls
+ player.x = future_player_collision.x if !future_player_collision.dx_collision
+ player.y = future_player_collision.y if !future_player_collision.dy_collision
+ end
+ end
+
+ def calc_projectile_collisions entities
+ entities.each do |e|
+ e.damage ||= 0
+ player.projectiles.each do |p|
+ if !p.collided && (p.intersect_rect? e)
+ p.collided = true
+ e.damage += 1
+ end
+ end
+ end
+ end
+
+ def calc_projectiles
+ player.projectiles.map! do |p|
+ dx, dy = p.angle.vector 10
+ p.merge(x: p.x + dx, y: p.y + dy)
+ end
+
+ calc_projectile_collisions level.walls + level.enemies + level.spawn_locations
+ player.projectiles.reject! { |p| p.at.elapsed_time > 10000 }
+ player.projectiles.reject! { |p| p.collided }
+ level.enemies.reject! { |e| e.damage > e.hp }
+ level.spawn_locations.reject! { |s| s.damage > s.hp }
+ end
+
+ def calc_enemies
+ level.enemies.map! do |e|
+ dx = 0
+ dx = 1 if e.x < player.x
+ dx = -1 if e.x > player.x
+ dy = 0
+ dy = 1 if e.y < player.y
+ dy = -1 if e.y > player.y
+ future_e = future_entity_position dx, dy, e
+ future_e_collision = future_collision e, future_e, level.enemies + level.walls
+ e.next_x = e.x
+ e.next_y = e.y
+ e.next_x = future_e_collision.x if !future_e_collision.dx_collision
+ e.next_y = future_e_collision.y if !future_e_collision.dy_collision
+ e
+ end
+
+ level.enemies.map! do |e|
+ e.x = e.next_x
+ e.y = e.next_y
+ e
+ end
+
+ level.enemies.each do |e|
+ player.damage += 1 if e.intersect_rect? player
+ end
+ end
+
+ def calc_spawn_locations
+ level.spawn_locations.map! do |s|
+ s.merge(countdown: s.countdown - 1)
+ end
+ level.spawn_locations
+ .find_all { |s| s.countdown.neg? }
+ .each do |s|
+ s.countdown = s.rate
+ s.merge(countdown: s.rate)
+ new_enemy = create_enemy s
+ if !(level.enemies.find { |e| e.intersect_rect? new_enemy })
+ level.enemies << new_enemy
+ end
+ end
+ end
+
+ def create_enemy spawn_location
+ to_cell(spawn_location.ordinal_x, spawn_location.ordinal_y).merge hp: 2
+ end
+
+ def create_level level_template
+ {
+ walls: level_template.walls.map { |w| to_cell(w.ordinal_x, w.ordinal_y).merge(w) },
+ enemies: [],
+ spawn_locations: level_template.spawn_locations.map { |s| to_cell(s.ordinal_x, s.ordinal_y).merge(s) }
+ }
+ end
+
+ def level_one_template
+ {
+ walls: [{ ordinal_x: 25, ordinal_y: 20},
+ { ordinal_x: 25, ordinal_y: 21},
+ { ordinal_x: 25, ordinal_y: 22},
+ { ordinal_x: 25, ordinal_y: 23}],
+ spawn_locations: [{ ordinal_x: 10, ordinal_y: 10, rate: 120, countdown: 0, hp: 5 }]
+ }
+ end
+
+ def player
+ state.player ||= {}
+ end
+
+ def level
+ state.level ||= {}
+ end
+
+ def future_collision entity, future_entity, others
+ dx_collision = others.find { |o| o != entity && (o.intersect_rect? future_entity.dx) }
+ dy_collision = others.find { |o| o != entity && (o.intersect_rect? future_entity.dy) }
+
+ {
+ dx_collision: dx_collision,
+ x: future_entity.dx.x,
+ dy_collision: dy_collision,
+ y: future_entity.dy.y
+ }
+ end
+
+ def future_entity_position dx, dy, entity
+ {
+ dx: entity.merge(x: entity.x + dx),
+ dy: entity.merge(y: entity.y + dy),
+ both: entity.merge(x: entity.x + dx, y: entity.y + dy)
+ }
+ end
+
+ def future_player_position dx, dy
+ future_entity_position dx, dy, player
+ end
+
+ def to_cell ordinal_x, ordinal_y
+ { x: ordinal_x * 16, y: ordinal_y * 16, w: 16, h: 16 }
+ end
+end
+
+def tick args
+ $game ||= Game.new
+ $game.args = args
+ $game.tick
+end
+
+$gtk.reset
+$game = nil
diff --git a/samples/99_genre_dungeon_crawl/classics_jam/replay.txt b/samples/99_genre_dungeon_crawl/classics_jam/replay.txt
new file mode 100644
index 0000000..eab6ec5
--- /dev/null
+++ b/samples/99_genre_dungeon_crawl/classics_jam/replay.txt
@@ -0,0 +1,197 @@
+replay_version 2.0
+stopped_at 873
+seed 100
+recorded_at 2021-11-20 11:38:43 -0600
+[:mouse_button_up, 1, 0, 1, 1, 4]
+[:key_down_raw, 1073741905, 0, 2, 2, 99]
+[:key_down_raw, 1073741905, 0, 2, 3, 113]
+[:key_down_raw, 1073741905, 0, 2, 4, 115]
+[:key_down_raw, 1073741905, 0, 2, 5, 117]
+[:key_down_raw, 1073741905, 0, 2, 6, 119]
+[:key_down_raw, 1073741905, 0, 2, 7, 121]
+[:key_down_raw, 1073741905, 0, 2, 8, 123]
+[:key_down_raw, 1073741905, 0, 2, 9, 125]
+[:key_down_raw, 1073741905, 0, 2, 10, 127]
+[:key_down_raw, 1073741905, 0, 2, 11, 129]
+[:key_down_raw, 1073741905, 0, 2, 12, 131]
+[:key_down_raw, 1073741905, 0, 2, 13, 133]
+[:key_down_raw, 1073741905, 0, 2, 14, 135]
+[:key_down_raw, 1073741905, 0, 2, 15, 137]
+[:key_down_raw, 1073741905, 0, 2, 16, 139]
+[:key_down_raw, 1073741905, 0, 2, 17, 141]
+[:key_down_raw, 1073741905, 0, 2, 18, 143]
+[:key_down_raw, 1073741905, 0, 2, 19, 145]
+[:key_down_raw, 1073741905, 0, 2, 20, 147]
+[:key_down_raw, 1073741905, 0, 2, 21, 149]
+[:key_down_raw, 1073741905, 0, 2, 22, 151]
+[:key_down_raw, 1073741905, 0, 2, 23, 153]
+[:key_down_raw, 1073741905, 0, 2, 24, 155]
+[:key_down_raw, 1073741905, 0, 2, 25, 157]
+[:key_down_raw, 1073741905, 0, 2, 26, 159]
+[:key_down_raw, 1073741905, 0, 2, 27, 161]
+[:key_down_raw, 1073741905, 0, 2, 28, 163]
+[:key_down_raw, 1073741905, 0, 2, 29, 165]
+[:key_down_raw, 1073741905, 0, 2, 30, 167]
+[:key_down_raw, 1073741905, 0, 2, 31, 169]
+[:key_down_raw, 1073741905, 0, 2, 32, 171]
+[:key_down_raw, 1073741905, 0, 2, 33, 173]
+[:key_down_raw, 1073741905, 0, 2, 34, 175]
+[:key_down_raw, 1073741905, 0, 2, 35, 177]
+[:key_down_raw, 1073741905, 0, 2, 36, 179]
+[:key_down_raw, 1073741905, 0, 2, 37, 181]
+[:key_down_raw, 1073741905, 0, 2, 38, 183]
+[:key_down_raw, 1073741905, 0, 2, 39, 185]
+[:key_down_raw, 1073741905, 0, 2, 40, 187]
+[:key_down_raw, 1073741905, 0, 2, 41, 189]
+[:key_down_raw, 1073741905, 0, 2, 42, 191]
+[:key_down_raw, 1073741905, 0, 2, 43, 193]
+[:key_down_raw, 1073741905, 0, 2, 44, 195]
+[:key_down_raw, 1073741904, 0, 2, 45, 196]
+[:key_up_raw, 1073741905, 0, 2, 46, 196]
+[:key_up_raw, 1073741904, 0, 2, 47, 205]
+[:key_down_raw, 32, 0, 2, 48, 206]
+[:key_up_raw, 32, 0, 2, 49, 212]
+[:key_down_raw, 32, 0, 2, 50, 217]
+[:key_up_raw, 32, 0, 2, 51, 222]
+[:key_down_raw, 32, 0, 2, 52, 227]
+[:key_up_raw, 32, 0, 2, 53, 233]
+[:key_down_raw, 32, 0, 2, 54, 237]
+[:key_up_raw, 32, 0, 2, 55, 243]
+[:key_down_raw, 32, 0, 2, 56, 266]
+[:key_up_raw, 32, 0, 2, 57, 271]
+[:key_down_raw, 32, 0, 2, 58, 276]
+[:key_up_raw, 32, 0, 2, 59, 282]
+[:key_down_raw, 32, 0, 2, 60, 294]
+[:key_up_raw, 32, 0, 2, 61, 300]
+[:key_down_raw, 32, 0, 2, 62, 305]
+[:key_down_raw, 1073741904, 0, 2, 63, 306]
+[:key_up_raw, 32, 0, 2, 64, 310]
+[: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, 1073741904, 0, 2, 68, 328]
+[:key_down_raw, 1073741904, 0, 2, 69, 330]
+[:key_down_raw, 1073741904, 0, 2, 70, 332]
+[:key_down_raw, 1073741904, 0, 2, 71, 334]
+[:key_down_raw, 1073741904, 0, 2, 72, 336]
+[:key_down_raw, 1073741904, 0, 2, 73, 338]
+[:key_down_raw, 1073741904, 0, 2, 74, 340]
+[:key_down_raw, 1073741904, 0, 2, 75, 342]
+[:key_down_raw, 1073741904, 0, 2, 76, 344]
+[:key_down_raw, 1073741904, 0, 2, 77, 346]
+[:key_down_raw, 1073741904, 0, 2, 78, 348]
+[:key_down_raw, 1073741904, 0, 2, 79, 350]
+[:key_down_raw, 1073741904, 0, 2, 80, 352]
+[:key_down_raw, 1073741904, 0, 2, 81, 354]
+[:key_down_raw, 1073741904, 0, 2, 82, 356]
+[:key_down_raw, 1073741904, 0, 2, 83, 358]
+[:key_down_raw, 1073741904, 0, 2, 84, 360]
+[:key_down_raw, 1073741904, 0, 2, 85, 362]
+[:key_down_raw, 1073741904, 0, 2, 86, 364]
+[:key_down_raw, 1073741904, 0, 2, 87, 366]
+[:key_down_raw, 1073741904, 0, 2, 88, 368]
+[:key_down_raw, 1073741904, 0, 2, 89, 370]
+[:key_down_raw, 1073741904, 0, 2, 90, 372]
+[:key_down_raw, 1073741904, 0, 2, 91, 374]
+[:key_down_raw, 1073741904, 0, 2, 92, 376]
+[:key_down_raw, 1073741904, 0, 2, 93, 378]
+[:key_down_raw, 1073741904, 0, 2, 94, 380]
+[:key_down_raw, 1073741904, 0, 2, 95, 382]
+[:key_down_raw, 1073741904, 0, 2, 96, 384]
+[:key_down_raw, 1073741904, 0, 2, 97, 386]
+[:key_down_raw, 1073741904, 0, 2, 98, 388]
+[:key_down_raw, 1073741904, 0, 2, 99, 390]
+[:key_down_raw, 1073741904, 0, 2, 100, 392]
+[:key_down_raw, 1073741904, 0, 2, 101, 394]
+[:key_down_raw, 1073741904, 0, 2, 102, 396]
+[:key_down_raw, 1073741904, 0, 2, 103, 398]
+[:key_down_raw, 1073741904, 0, 2, 104, 400]
+[:key_down_raw, 1073741904, 0, 2, 105, 402]
+[:key_down_raw, 1073741904, 0, 2, 106, 404]
+[:key_down_raw, 1073741904, 0, 2, 107, 406]
+[:key_down_raw, 1073741904, 0, 2, 108, 408]
+[:key_down_raw, 1073741904, 0, 2, 109, 410]
+[:key_down_raw, 1073741904, 0, 2, 110, 412]
+[:key_down_raw, 1073741904, 0, 2, 111, 414]
+[:key_down_raw, 1073741904, 0, 2, 112, 416]
+[:key_down_raw, 1073741904, 0, 2, 113, 418]
+[:key_down_raw, 1073741904, 0, 2, 114, 420]
+[:key_down_raw, 1073741904, 0, 2, 115, 422]
+[:key_down_raw, 1073741904, 0, 2, 116, 424]
+[:key_down_raw, 1073741904, 0, 2, 117, 426]
+[:key_down_raw, 1073741904, 0, 2, 118, 428]
+[:key_down_raw, 1073741904, 0, 2, 119, 430]
+[:key_down_raw, 1073741904, 0, 2, 120, 432]
+[:key_down_raw, 1073741904, 0, 2, 121, 434]
+[:key_down_raw, 1073741904, 0, 2, 122, 436]
+[:key_down_raw, 1073741904, 0, 2, 123, 438]
+[:key_down_raw, 1073741904, 0, 2, 124, 440]
+[:key_up_raw, 1073741904, 0, 2, 125, 442]
+[:key_down_raw, 1073741903, 0, 2, 126, 461]
+[:key_down_raw, 1073741903, 0, 2, 127, 476]
+[:key_down_raw, 1073741903, 0, 2, 128, 478]
+[:key_down_raw, 1073741903, 0, 2, 129, 480]
+[:key_down_raw, 1073741903, 0, 2, 130, 482]
+[:key_down_raw, 1073741903, 0, 2, 131, 484]
+[:key_down_raw, 1073741903, 0, 2, 132, 486]
+[:key_down_raw, 1073741903, 0, 2, 133, 488]
+[:key_down_raw, 1073741903, 0, 2, 134, 490]
+[:key_down_raw, 1073741903, 0, 2, 135, 492]
+[:key_down_raw, 1073741903, 0, 2, 136, 494]
+[:key_down_raw, 1073741903, 0, 2, 137, 496]
+[:key_down_raw, 1073741903, 0, 2, 138, 498]
+[:key_down_raw, 1073741903, 0, 2, 139, 500]
+[:key_down_raw, 1073741903, 0, 2, 140, 502]
+[:key_down_raw, 1073741903, 0, 2, 141, 504]
+[:key_down_raw, 1073741903, 0, 2, 142, 506]
+[:key_down_raw, 1073741903, 0, 2, 143, 508]
+[:key_down_raw, 1073741903, 0, 2, 144, 510]
+[:key_down_raw, 1073741903, 0, 2, 145, 512]
+[:key_down_raw, 1073741903, 0, 2, 146, 514]
+[:key_down_raw, 1073741903, 0, 2, 147, 516]
+[:key_down_raw, 1073741903, 0, 2, 148, 518]
+[:key_down_raw, 1073741903, 0, 2, 149, 520]
+[:key_down_raw, 1073741903, 0, 2, 150, 522]
+[:key_down_raw, 1073741903, 0, 2, 151, 524]
+[:key_down_raw, 1073741903, 0, 2, 152, 526]
+[:key_down_raw, 1073741903, 0, 2, 153, 528]
+[:key_down_raw, 1073741904, 0, 2, 154, 528]
+[:key_up_raw, 1073741903, 0, 2, 155, 528]
+[:key_down_raw, 32, 0, 2, 156, 534]
+[:key_up_raw, 32, 0, 2, 157, 539]
+[:key_down_raw, 32, 0, 2, 158, 545]
+[:key_up_raw, 32, 0, 2, 159, 549]
+[:key_down_raw, 32, 0, 2, 160, 554]
+[:key_up_raw, 32, 0, 2, 161, 560]
+[:key_down_raw, 32, 0, 2, 162, 564]
+[:key_up_raw, 32, 0, 2, 163, 570]
+[:key_down_raw, 32, 0, 2, 164, 575]
+[:key_up_raw, 32, 0, 2, 165, 581]
+[:key_down_raw, 32, 0, 2, 166, 585]
+[:key_up_raw, 32, 0, 2, 167, 590]
+[:key_down_raw, 32, 0, 2, 168, 594]
+[:key_up_raw, 32, 0, 2, 169, 600]
+[:key_down_raw, 32, 0, 2, 170, 605]
+[:key_up_raw, 32, 0, 2, 171, 610]
+[:key_down_raw, 32, 0, 2, 172, 615]
+[:key_up_raw, 32, 0, 2, 173, 620]
+[:key_down_raw, 32, 0, 2, 174, 624]
+[:key_up_raw, 32, 0, 2, 175, 630]
+[:key_up_raw, 1073741904, 0, 2, 176, 631]
+[:key_down_raw, 32, 0, 2, 177, 634]
+[:key_up_raw, 32, 0, 2, 178, 639]
+[:key_down_raw, 32, 0, 2, 179, 644]
+[:key_up_raw, 32, 0, 2, 180, 649]
+[:key_down_raw, 32, 0, 2, 181, 654]
+[:key_up_raw, 32, 0, 2, 182, 659]
+[:key_down_raw, 32, 0, 2, 183, 664]
+[:key_up_raw, 32, 0, 2, 184, 669]
+[:key_down_raw, 32, 0, 2, 185, 674]
+[:key_up_raw, 32, 0, 2, 186, 679]
+[:key_down_raw, 32, 0, 2, 187, 684]
+[:key_up_raw, 32, 0, 2, 188, 689]
+[:key_down_raw, 32, 0, 2, 189, 694]
+[:key_up_raw, 32, 0, 2, 190, 699]
+[:key_down_raw, 96, 0, 2, 191, 823]
+[:key_up_raw, 96, 0, 2, 192, 828]
+[:key_down_raw, 13, 0, 2, 193, 873]
diff --git a/samples/99_genre_dungeon_crawl/classics_jam/sprites/circle/green.png b/samples/99_genre_dungeon_crawl/classics_jam/sprites/circle/green.png
new file mode 100644
index 0000000..43cf7ee
--- /dev/null
+++ b/samples/99_genre_dungeon_crawl/classics_jam/sprites/circle/green.png
Binary files differ
diff --git a/samples/99_genre_dungeon_crawl/classics_jam/sprites/square/blue.png b/samples/99_genre_dungeon_crawl/classics_jam/sprites/square/blue.png
new file mode 100644
index 0000000..b840849
--- /dev/null
+++ b/samples/99_genre_dungeon_crawl/classics_jam/sprites/square/blue.png
Binary files differ
diff --git a/samples/99_genre_dungeon_crawl/classics_jam/sprites/square/gray.png b/samples/99_genre_dungeon_crawl/classics_jam/sprites/square/gray.png
new file mode 100644
index 0000000..2142b30
--- /dev/null
+++ b/samples/99_genre_dungeon_crawl/classics_jam/sprites/square/gray.png
Binary files differ
diff --git a/samples/99_genre_dungeon_crawl/classics_jam/sprites/square/red.png b/samples/99_genre_dungeon_crawl/classics_jam/sprites/square/red.png
new file mode 100644
index 0000000..3ed5f13
--- /dev/null
+++ b/samples/99_genre_dungeon_crawl/classics_jam/sprites/square/red.png
Binary files differ