summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrexim <reximkut@gmail.com>2024-03-11 00:02:15 +0700
committerrexim <reximkut@gmail.com>2024-03-11 00:02:15 +0700
commitce6c3bf08a4c9d5eb5e64808943412c69f85f349 (patch)
treeac6b4555198a0b1c96ec2d1e02a94e67af9fceed
parent5a89655e5a6e0d91eb6dcb1968ffc99b5fe0f7c5 (diff)
Implement bomb regeneration
-rw-r--r--game.adb72
-rw-r--r--map.txt71
-rw-r--r--raylib.ads5
-rw-r--r--test.adb14
4 files changed, 99 insertions, 63 deletions
diff --git a/game.adb b/game.adb
index d20f166..f246454 100644
--- a/game.adb
+++ b/game.adb
@@ -66,10 +66,15 @@ procedure Game is
type Item_Kind is (Key, Bomb);
+ type Item is record
+ Kind: Item_Kind;
+ Cooldown: Integer;
+ end record;
+
package Hashed_Map_Items is new
Ada.Containers.Hashed_Maps(
Key_Type => IVector2,
- Element_Type => Item_Kind,
+ Element_Type => Item,
Hash => Hash_IVector2,
Equivalent_Keys => Equivalent_IVector2);
@@ -163,12 +168,12 @@ procedure Game is
when '=' => Game.Map(Row, Column) := Door;
when '*' =>
Game.Map(Row, Column) := Floor;
- Game.Items.Insert((Column, Row), Bomb);
+ Game.Items.Insert((Column, Row), (Kind => Bomb, Cooldown => 0));
when '&' =>
Game.Map(Row, Column) := Barricade;
when '%' =>
Game.Map(Row, Column) := Floor;
- Game.Items.Insert((Column, Row), Key);
+ Game.Items.Insert((Column, Row), (Kind => Key, Cooldown => 0));
when '@' =>
Game.Map(Row, Column) := Floor;
if Update_Player then
@@ -185,9 +190,9 @@ procedure Game is
end loop;
end;
- procedure Draw_Bomb(Position: IVector2) is
+ procedure Draw_Bomb(Position: IVector2; C: Color) is
begin
- Draw_Circle_V(To_Vector2(Position)*Cell_Size + Cell_Size*0.5, Cell_Size.X*0.5, COLOR_RED);
+ Draw_Circle_V(To_Vector2(Position)*Cell_Size + Cell_Size*0.5, Cell_Size.X*0.5, C);
end;
procedure Draw_Key(Position: IVector2) is
@@ -208,13 +213,29 @@ procedure Game is
end loop;
end;
+ procedure Draw_Number(Cell_Position: IVector2; N: Integer) is
+ Label: Char_Array := To_C(Trim(Integer'Image(N), Ada.Strings.Left));
+ Label_Height: Integer := 32;
+ Label_Width: Integer := Integer(Measure_Text(Label, Int(Label_Height)));
+ Text_Size: Vector2 := To_Vector2((Label_Width, Label_Height));
+ Position: Vector2 := To_Vector2(Cell_Position)*Cell_Size + Cell_Size*0.5 - Text_Size*0.5;
+ begin
+ Draw_Text(Label, Int(Position.X), Int(Position.Y), Int(Label_Height), COLOR_LABEL);
+ end;
+
procedure Game_Items(Game: in Game_State) is
use Hashed_Map_Items;
begin
for C in Game.Items.Iterate loop
- case Element(C) is
+ case Element(C).Kind is
when Key => Draw_Key(Key(C));
- when Bomb => Draw_Bomb(Key(C));
+ when Bomb =>
+ if Element(C).Cooldown > 0 then
+ Draw_Bomb(Key(C), Color_Brightness(COLOR_RED, -0.5));
+ Draw_Number(Key(C), Element(C).Cooldown);
+ else
+ Draw_Bomb(Key(C), COLOR_RED);
+ end if;
end case;
end loop;
end;
@@ -253,13 +274,15 @@ procedure Game is
C: Cursor := Game.Items.Find(Game.Player.Position);
begin
if Has_Element(C) then
- case Element(C) is
+ case Element(C).Kind is
when Key =>
Game.Player.Keys := Game.Player.Keys + 1;
- when Bomb =>
+ Game.Items.Delete(C);
+ when Bomb => if Element(C).Cooldown <= 0 then
Game.Player.Bombs := Game.Player.Bombs + 1;
+ Game.Items.Replace_Element(C, (Kind => Bomb, Cooldown => 30));
+ end if;
end case;
- Game.Items.Delete(C);
end if;
end;
when Door =>
@@ -278,7 +301,7 @@ procedure Game is
procedure Explode_Line(Dir: Direction) is
New_Position: IVector2 := Position;
begin
- Line: loop
+ Line: for I in 1..10 loop
if New_Position = Game.Player.Position then
Game.Player.Dead := True;
end if;
@@ -362,7 +385,7 @@ procedure Game is
begin
Step(Dir, Position);
if Game.Map(Position.Y, Position.X) = Floor then
- Draw_Bomb(Position);
+ Draw_Bomb(Position, COLOR_RED);
if Is_Key_Pressed(Keys(Dir)) then
for Bomb of Game.Bombs loop
if Bomb.Countdown <= 0 then
@@ -388,6 +411,7 @@ procedure Game is
end loop;
Player_Step(Game, Dir);
+
for Bomb of Game.Bombs loop
if Bomb.Countdown > 0 then
Bomb.Countdown := Bomb.Countdown - 1;
@@ -396,6 +420,18 @@ procedure Game is
end if;
end if;
end loop;
+
+ declare
+ use Hashed_Map_Items;
+ begin
+ for C in Game.Items.Iterate loop
+ if Element(C).Kind = Bomb then
+ if Element(C).Cooldown > 0 then
+ Game.Items.Replace_Element(C, (Kind => Bomb, Cooldown => Element(C).Cooldown - 1));
+ end if;
+ end if;
+ end loop;
+ end;
end if;
end loop;
end if;
@@ -405,16 +441,8 @@ procedure Game is
begin
for Bomb of Game.Bombs loop
if Bomb.Countdown > 0 then
- Draw_Bomb(Bomb.Position);
- declare
- Label: Char_Array := To_C(Trim(Integer'Image(Bomb.Countdown), Ada.Strings.Left));
- Label_Height: Integer := 32;
- Label_Width: Integer := Integer(Measure_Text(Label, Int(Label_Height)));
- Text_Size: Vector2 := To_Vector2((Label_Width, Label_Height));
- Position: Vector2 := To_Vector2(Bomb.Position)*Cell_Size + Cell_Size*0.5 - Text_Size*0.5;
- begin
- Draw_Text(Label, Int(Position.X), Int(Position.Y), Int(Label_Height), COLOR_LABEL);
- end;
+ Draw_Bomb(Bomb.Position, COLOR_RED);
+ Draw_Number(Bomb.Position, Bomb.Countdown);
end if;
end loop;
end;
diff --git a/map.txt b/map.txt
index bc7fb1d..d213bae 100644
--- a/map.txt
+++ b/map.txt
@@ -1,35 +1,36 @@
- #########
- #.......#
- #.......#
- #...*...#
- #.......#
- #.......#
- ########### #######=#######
- #.........# #.............#
-#######.........# #.............#########
-#.....#.........# #.............#.......#
-#.....#.........######################....B........#.......#
-#..*..=....@....&..................................&...%...#
-#.....#.........######################.............#.......#
-#.....#.........# #.............#.......#
-#######.........# #.............#########
- #.........# #.............#
- #####.##### ######...######
- #.# #...#
- #.# #...#
- #.# #...#
- #####.##### #...#
- #.........# #...#
- #.........# #...#
- #.........# #...#
- #....%....# #...#
- #.........# #...#
- #.........# #...#
- #.........# #...#
- ########### #...#
- #...#
- #...#
- #...#
- #...#
- #...#
- #####
+ #########
+ #.......#
+ #.......#
+ #...*...#
+ #.......#
+ #.......#
+ ########### #######=#######
+ #.........# #.............#
+#######.........# #.............#########
+#.....#.........# #.............#.......#
+#.....#.........############################################....B........#.......#
+#..*..=....@....&........................................................&...%...#
+#.....#.........############################################.............#.......#
+#.....#.........# #.............#.......#
+#######.........# #.............#########
+ #.........# #.............#
+ #####.##### ######...######
+ #.# #...#
+ #.# #...#
+ #.# #...#
+ #####.##### #...#
+ #.........# #...#
+ #.........# #...#
+ #.........# #...#
+ #....%....# #...#
+ #.........# #...#
+ #.........# #...#
+ #.........# #...#
+ ########### #...#
+ #...#
+ #...#
+ #...#
+ #...#
+ #...#
+ #####
+
diff --git a/raylib.ads b/raylib.ads
index 2beab5e..9b3d65a 100644
--- a/raylib.ads
+++ b/raylib.ads
@@ -141,4 +141,9 @@ package Raylib is
Import => True,
Convention => C,
External_Name => "DrawFPS";
+ function Color_Brightness(C: Color; Factor: C_Float) return Color
+ with
+ Import => True,
+ Convention => C,
+ External_Name => "ColorBrightness";
end Raylib;
diff --git a/test.adb b/test.adb
index f757eb4..3501009 100644
--- a/test.adb
+++ b/test.adb
@@ -3,13 +3,15 @@ with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings; use Ada.Strings;
procedure Test is
- type IVector2 is record
- X, Y: Integer;
- end record;
- type Ten_Numbers is array(IVector2) of Integer;
+ type Item_Kind is (Key, Bomb);
- Position: IVector2;
- Xs: Ten_Numbers;
+ type Item(Kind: Item_Kind) is record
+ case Kind is
+ when Key => null;
+ when Bomb =>
+ Cooldown: Integer;
+ end case;
+ end record;
begin
null;
end;