diff options
author | rexim <reximkut@gmail.com> | 2024-03-13 23:22:18 +0700 |
---|---|---|
committer | rexim <reximkut@gmail.com> | 2024-03-13 23:22:18 +0700 |
commit | 0d6bc4cdc89c98cd37994e9539200d7c009907e5 (patch) | |
tree | 93d9ac3ffe8f282180c13f13d85d0dd752b0123f | |
parent | 29cb48cedb43034355e602d57b73b22fb785f5ca (diff) |
Finally! Useful Unions!
-rw-r--r-- | game.adb | 19 | ||||
-rw-r--r-- | map.txt | 2 | ||||
-rw-r--r-- | test.adb | 25 |
3 files changed, 28 insertions, 18 deletions
@@ -33,6 +33,8 @@ procedure Game is SHREK_EXPLOSION_DAMAGE : constant Float := 0.15; SHREK_TURN_REGENERATION : constant Float := 0.01; BOMB_GENERATOR_COOLDOWN : constant Integer := 20; + SHREK_STEPS_LIMIT : constant Integer := 4; + SHREK_STEP_LENGTH_LIMIT : constant Integer := 100; type IVector2 is record X, Y: Integer; @@ -95,9 +97,12 @@ procedure Game is type Item_Kind is (Key, Bomb, Checkpoint); - type Item is record - Kind: Item_Kind; - Cooldown: Integer; + type Item(Kind: Item_Kind := Key) is record + case Kind is + when Bomb => + Cooldown: Integer; + when others => null; + end case; end record; package Hashed_Map_Items is new @@ -238,8 +243,6 @@ procedure Game is while not Q.Is_Empty loop declare - SHREK_STEPS_LIMIT: constant Integer := 4; - SHREK_STEP_LENGTH_LIMIT: constant Integer := 10; Position: constant IVector2 := Q(0); begin Q.Delete_First; @@ -363,7 +366,7 @@ procedure Game is when '=' => Game.Map(Row, Column) := Door; when '!' => Game.Map(Row, Column) := Floor; - Game.Items.Insert((Column, Row), (Kind => Checkpoint, Cooldown => 0)); + Game.Items.Insert((Column, Row), (Kind => Checkpoint)); when '*' => Game.Map(Row, Column) := Floor; Game.Items.Insert((Column, Row), (Kind => Bomb, Cooldown => 0)); @@ -371,7 +374,7 @@ procedure Game is Game.Map(Row, Column) := Barricade; when '%' => Game.Map(Row, Column) := Floor; - Game.Items.Insert((Column, Row), (Kind => Key, Cooldown => 0)); + Game.Items.Insert((Column, Row), (Kind => Key)); when '@' => Game.Map(Row, Column) := Floor; if Update_Player then @@ -794,3 +797,5 @@ end; -- TODO: count the player's turns towards the final score of the game -- We can even collect different stats, like bombs collected, bombs used, -- times deid etc. +-- TODO: animate key when you pick it up +-- Smoothly move it into the HUD. @@ -9,7 +9,7 @@ #######.........# #.............######### #.....#.........# #.............#.......# #.....#.........#############################.....B.......#.......# -#..*..=.........&......!...............@..................&...%...# +#..*..=....@....&......!..................................&...%...# #.....#.........#############################.............#.......# #.....#.........# #.............#.......# #######.........# #.............######### @@ -4,15 +4,20 @@ with Ada.Strings; use Ada.Strings; with Ada.Containers.Vectors; procedure Test is - package Queue is new - Ada.Containers.Vectors(Index_Type => Natural, Element_Type => Integer); - Q: Queue.Vector; + type Item_Kind is (Key, Bomb, Checkpoint); + type Item(Kind: Item_Kind := Key) is record + case Kind is + when Key | Checkpoint => null; + when Bomb => + Cooldown: Integer; + end case; + end record; + type Map is array (Natural range <>) of Item; + type Map_Access is access Map; + + Items: Map_Access := null; begin - for Index in 1..10 loop - Q.Append(Index); - end loop; - while not Q.Is_Empty loop - Put_Line(Integer'Image(Q(0))); - Q.Delete_First; - end loop; + Items := new Map(1..10); + Items(1) := (Kind => Bomb, Cooldown => 10); + Put_Line(Items.all'Image); end; |