From a988bdea8a3d332fb88b185930cac6b7078a42dd Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Wed, 8 Apr 2020 15:53:42 +1000 Subject: [PATCH] Implemented pickups and fixed several other lingering errors --- assets/entities/door.symtres | 8 +- assets/entities/door_blue.symtres | 115 +++++++++++++++ assets/entities/door_green.symtres | 115 +++++++++++++++ assets/entities/door_red.symtres | 115 +++++++++++++++ assets/entities/door_rgb.symtres | 115 +++++++++++++++ assets/entities/pickup_health.symtres | 44 ++++++ assets/entities/pickup_key_blue.symtres | 44 ++++++ assets/entities/pickup_key_green.symtres | 44 ++++++ assets/entities/pickup_key_red.symtres | 41 ++++++ assets/models/pickup_health.symbres | Bin 0 -> 2608 bytes assets/models/pickup_key.symbres | Bin 0 -> 1312 bytes assets/scenes/scene_1.symtres | 42 +++++- src/common/limits.h | 3 + src/common/version.h | 2 +- src/game/door.c | 26 ---- src/game/entity.c | 25 +++- src/game/entity.h | 26 +++- src/game/event.c | 2 +- src/game/event.h | 1 + src/game/pickup.c | 122 ++++++++++++++++ src/game/pickup.h | 15 ++ src/game/player.c | 16 ++- src/game/player.h | 2 + src/game/scene.c | 170 ++++++++++++++++++++--- src/game/scene.h | 5 +- src/game/trigger.c | 7 +- todo.txt | 6 +- 27 files changed, 1043 insertions(+), 68 deletions(-) create mode 100644 assets/entities/door_blue.symtres create mode 100644 assets/entities/door_green.symtres create mode 100644 assets/entities/door_red.symtres create mode 100644 assets/entities/door_rgb.symtres create mode 100644 assets/entities/pickup_health.symtres create mode 100644 assets/entities/pickup_key_blue.symtres create mode 100644 assets/entities/pickup_key_green.symtres create mode 100644 assets/entities/pickup_key_red.symtres create mode 100644 assets/models/pickup_health.symbres create mode 100644 assets/models/pickup_key.symbres create mode 100644 src/game/pickup.c create mode 100644 src/game/pickup.h diff --git a/assets/entities/door.symtres b/assets/entities/door.symtres index 8f5383c..4705f6a 100644 --- a/assets/entities/door.symtres +++ b/assets/entities/door.symtres @@ -62,7 +62,7 @@ Entity active : true diffuse_texture : default.tga diffuse : 1.0000 - position : 0.006 4.500 0.000 + position : 0.000 4.500 0.000 specular_strength : 62.0000 name : Door_Mesh uv_scale : 0.300 0.200 @@ -78,7 +78,7 @@ Entity geometry : cube.symbres active : true diffuse_texture : white.tga - position : -2.000 9.500 0.000 + position : 4.000 7.500 0.000 name : Door_Key_Indicator_Red uv_scale : 0.300 0.200 } @@ -93,7 +93,7 @@ Entity geometry : cube.symbres active : true diffuse_texture : white.tga - position : -0.250 9.500 0.000 + position : 4.000 5.500 0.000 name : Door_Key_Indicator_Green uv_scale : 0.300 0.200 } @@ -108,7 +108,7 @@ Entity geometry : cube.symbres active : true diffuse_texture : white.tga - position : 1.500 9.500 0.000 + position : 4.000 3.500 0.000 name : Door_Key_Indicator_Blue uv_scale : 0.300 0.200 } diff --git a/assets/entities/door_blue.symtres b/assets/entities/door_blue.symtres new file mode 100644 index 0000000..cc86b74 --- /dev/null +++ b/assets/entities/door_blue.symtres @@ -0,0 +1,115 @@ +Entity +{ + type : 10 + scale : 1.000 1.000 1.000 + door_state : 0 + door_open_position : -7.0000 + rotation : 0.000 0.000 0.000 1.000 + door_close_position : 0.0000 + active : true + door_speed : 6.0000 + position : -18.500 1.000 -30.000 + door_mask : 4 + name : Door + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 9 + scale : 7.000 11.000 14.000 + rotation : 0.000 0.000 0.000 1.000 + trigger_mask : 1 + active : true + position : 0.000 5.000 0.000 + trigger_type : 1 + name : Door_Trigger + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 7 + scale : 1.000 1.000 1.000 + volume : 1.0000 + rolloff_factor : 0.9500 + rotation : 0.000 0.000 0.000 1.000 + loop : false + sound_min_distance : 0.0000 + active : true + position : 0.000 0.000 0.000 + source_filename : sounds/door_locked.wav + sound_type : 1 + sound_max_distance : 30.0000 + name : Door_Sound + bounding_box_min : -0.500 -0.500 -0.500 + sound_attenuation_type : 2 + paused : true + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 6 + scale : 7.000 12.000 0.200 + material : 0 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.055 0.863 0.839 1.000 + geometry : cube.symbres + specular : 0.4000 + active : true + diffuse_texture : default.tga + diffuse : 1.0000 + position : 0.012 4.500 0.000 + specular_strength : 62.0000 + name : Door_Mesh + uv_scale : 0.300 0.200 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.100 0.100 0.100 + geometry : cube.symbres + active : true + diffuse_texture : white.tga + position : 4.000 7.500 0.000 + name : Door_Key_Indicator_Red + uv_scale : 0.300 0.200 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.100 0.100 0.100 + geometry : cube.symbres + active : true + diffuse_texture : white.tga + position : 4.000 5.500 0.000 + name : Door_Key_Indicator_Green + uv_scale : 0.300 0.200 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.470 0.670 0.890 + geometry : cube.symbres + active : true + diffuse_texture : white.tga + position : 4.000 3.500 0.000 + name : Door_Key_Indicator_Blue + uv_scale : 0.300 0.200 +} + diff --git a/assets/entities/door_green.symtres b/assets/entities/door_green.symtres new file mode 100644 index 0000000..d92f1fa --- /dev/null +++ b/assets/entities/door_green.symtres @@ -0,0 +1,115 @@ +Entity +{ + type : 10 + scale : 1.000 1.000 1.000 + door_state : 0 + door_open_position : -7.0000 + rotation : 0.000 0.000 0.000 1.000 + door_close_position : 0.0000 + active : true + door_speed : 6.0000 + position : -18.500 1.000 -30.000 + door_mask : 2 + name : Door + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 9 + scale : 7.000 11.000 14.000 + rotation : 0.000 0.000 0.000 1.000 + trigger_mask : 1 + active : true + position : 0.000 5.000 0.000 + trigger_type : 1 + name : Door_Trigger + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 7 + scale : 1.000 1.000 1.000 + volume : 1.0000 + rolloff_factor : 0.9500 + rotation : 0.000 0.000 0.000 1.000 + loop : false + sound_min_distance : 0.0000 + active : true + position : 0.000 0.000 0.000 + source_filename : sounds/door_locked.wav + sound_type : 1 + sound_max_distance : 30.0000 + name : Door_Sound + bounding_box_min : -0.500 -0.500 -0.500 + sound_attenuation_type : 2 + paused : true + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 6 + scale : 7.000 12.000 0.200 + material : 0 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.055 0.863 0.839 1.000 + geometry : cube.symbres + specular : 0.4000 + active : true + diffuse_texture : default.tga + diffuse : 1.0000 + position : 0.012 4.500 0.000 + specular_strength : 62.0000 + name : Door_Mesh + uv_scale : 0.300 0.200 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.100 0.100 0.100 + geometry : cube.symbres + active : true + diffuse_texture : white.tga + position : 4.000 7.500 0.000 + name : Door_Key_Indicator_Red + uv_scale : 0.300 0.200 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.530 0.670 0.280 + geometry : cube.symbres + active : true + diffuse_texture : white.tga + position : 4.000 5.500 0.000 + name : Door_Key_Indicator_Green + uv_scale : 0.300 0.200 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.100 0.100 0.100 + geometry : cube.symbres + active : true + diffuse_texture : white.tga + position : 4.000 3.500 0.000 + name : Door_Key_Indicator_Blue + uv_scale : 0.300 0.200 +} + diff --git a/assets/entities/door_red.symtres b/assets/entities/door_red.symtres new file mode 100644 index 0000000..bc9cf39 --- /dev/null +++ b/assets/entities/door_red.symtres @@ -0,0 +1,115 @@ +Entity +{ + type : 10 + scale : 1.000 1.000 1.000 + door_state : 0 + door_open_position : -7.0000 + rotation : 0.000 0.000 0.000 1.000 + door_close_position : 0.0000 + active : true + door_speed : 6.0000 + position : -18.500 1.000 -30.000 + door_mask : 1 + name : Door + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 9 + scale : 7.000 11.000 14.000 + rotation : 0.000 0.000 0.000 1.000 + trigger_mask : 1 + active : true + position : 0.000 5.000 0.000 + trigger_type : 1 + name : Door_Trigger + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 7 + scale : 1.000 1.000 1.000 + volume : 1.0000 + rolloff_factor : 0.9500 + rotation : 0.000 0.000 0.000 1.000 + loop : false + sound_min_distance : 0.0000 + active : true + position : 0.000 0.000 0.000 + source_filename : sounds/door_locked.wav + sound_type : 1 + sound_max_distance : 30.0000 + name : Door_Sound + bounding_box_min : -0.500 -0.500 -0.500 + sound_attenuation_type : 2 + paused : true + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 6 + scale : 7.000 12.000 0.200 + material : 0 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.055 0.863 0.839 1.000 + geometry : cube.symbres + specular : 0.4000 + active : true + diffuse_texture : default.tga + diffuse : 1.0000 + position : 0.012 4.500 0.000 + specular_strength : 62.0000 + name : Door_Mesh + uv_scale : 0.300 0.200 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.870 0.320 0.400 + geometry : cube.symbres + active : true + diffuse_texture : white.tga + position : 4.000 7.500 0.000 + name : Door_Key_Indicator_Red + uv_scale : 0.300 0.200 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.100 0.100 0.100 + geometry : cube.symbres + active : true + diffuse_texture : white.tga + position : 4.000 5.500 0.000 + name : Door_Key_Indicator_Green + uv_scale : 0.300 0.200 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.100 0.100 0.100 + geometry : cube.symbres + active : true + diffuse_texture : white.tga + position : 4.000 3.500 0.000 + name : Door_Key_Indicator_Blue + uv_scale : 0.300 0.200 +} + diff --git a/assets/entities/door_rgb.symtres b/assets/entities/door_rgb.symtres new file mode 100644 index 0000000..84fd54d --- /dev/null +++ b/assets/entities/door_rgb.symtres @@ -0,0 +1,115 @@ +Entity +{ + type : 10 + scale : 1.000 1.000 1.000 + door_state : 0 + door_open_position : -7.0000 + rotation : 0.000 0.000 0.000 1.000 + door_close_position : 0.0000 + active : true + door_speed : 6.0000 + position : -18.500 1.000 -30.000 + door_mask : 7 + name : Door + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 9 + scale : 7.000 11.000 14.000 + rotation : 0.000 0.000 0.000 1.000 + trigger_mask : 1 + active : true + position : 0.000 5.000 0.000 + trigger_type : 1 + name : Door_Trigger + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 7 + scale : 1.000 1.000 1.000 + volume : 1.0000 + rolloff_factor : 0.9500 + rotation : 0.000 0.000 0.000 1.000 + loop : false + sound_min_distance : 0.0000 + active : true + position : 0.000 0.000 0.000 + source_filename : sounds/door_locked.wav + sound_type : 1 + sound_max_distance : 30.0000 + name : Door_Sound + bounding_box_min : -0.500 -0.500 -0.500 + sound_attenuation_type : 2 + paused : true + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 6 + scale : 7.000 12.000 0.200 + material : 0 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.055 0.863 0.839 1.000 + geometry : cube.symbres + specular : 0.4000 + active : true + diffuse_texture : default.tga + diffuse : 1.0000 + position : 0.012 4.500 0.000 + specular_strength : 62.0000 + name : Door_Mesh + uv_scale : 0.300 0.200 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.870 0.320 0.400 + geometry : cube.symbres + active : true + diffuse_texture : white.tga + position : 4.000 7.500 0.000 + name : Door_Key_Indicator_Red + uv_scale : 0.300 0.200 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.530 0.670 0.280 + geometry : cube.symbres + active : true + diffuse_texture : white.tga + position : 4.000 5.500 0.000 + name : Door_Key_Indicator_Green + uv_scale : 0.300 0.200 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.470 0.670 0.890 + geometry : cube.symbres + active : true + diffuse_texture : white.tga + position : 4.000 3.500 0.000 + name : Door_Key_Indicator_Blue + uv_scale : 0.300 0.200 +} + diff --git a/assets/entities/pickup_health.symtres b/assets/entities/pickup_health.symtres new file mode 100644 index 0000000..e5282c8 --- /dev/null +++ b/assets/entities/pickup_health.symtres @@ -0,0 +1,44 @@ +Entity +{ + type : 11 + scale : 1.000 1.000 1.000 + rotation : 0.000 0.000 0.000 1.000 + pickup_spin_speed : 45.0000 + active : true + position : 13.000 3.000 -13.000 + pickup_type : 1 + pickup_health : 25 + name : Pickup_Health + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 9 + scale : 3.000 3.000 2.000 + rotation : 0.000 0.000 0.000 1.000 + trigger_mask : 1 + active : true + position : 0.000 0.000 0.000 + trigger_type : 0 + name : Pickup_Health_Trigger + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.686 0.000 0.027 1.000 + geometry : pickup_health.symbres + active : true + diffuse_texture : white.tga + position : 0.000 0.000 0.000 + name : Pickup_Health_Mesh + uv_scale : 1.000 1.000 +} + diff --git a/assets/entities/pickup_key_blue.symtres b/assets/entities/pickup_key_blue.symtres new file mode 100644 index 0000000..4eac7bf --- /dev/null +++ b/assets/entities/pickup_key_blue.symtres @@ -0,0 +1,44 @@ +Entity +{ + type : 11 + scale : 1.000 1.000 1.000 + pickup_key_type : 4 + rotation : 0.000 0.000 0.000 1.000 + pickup_spin_speed : 40.0000 + active : true + position : -39.000 2.000 -56.000 + pickup_type : 0 + name : Pickup_Key_Blue + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 9 + scale : 3.00 3 3 + rotation : 0.000 0.000 0.000 1.000 + trigger_mask : 1 + active : true + position : 0.000 0.000 0.000 + trigger_type : 0 + name : Pickup_Key_Blue_Trigger + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.530 0.670 0.280 1.000 + geometry : pickup_key.symbres + active : true + diffuse_texture : white.tga + position : 0.000 0.000 0.000 + name : Pickup_Key_Blue_Mesh + uv_scale : 1.000 1.000 +} + diff --git a/assets/entities/pickup_key_green.symtres b/assets/entities/pickup_key_green.symtres new file mode 100644 index 0000000..d3a08b6 --- /dev/null +++ b/assets/entities/pickup_key_green.symtres @@ -0,0 +1,44 @@ +Entity +{ + type : 11 + scale : 1.000 1.000 1.000 + pickup_key_type : 2 + rotation : 0.000 0.000 0.000 1.000 + pickup_spin_speed : 5.0000 + active : true + position : -37.000 2.000 -74.000 + pickup_type : 0 + name : Pickup_Key_Green + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 9 + scale : 1.000 1.000 1.000 + rotation : 0.000 0.000 0.000 1.000 + trigger_mask : 1 + active : true + position : 0.000 0.000 0.000 + trigger_type : 0 + name : Pickup_Key_Green_Trigger + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 0.870 0.320 0.400 1.000 + geometry : pickup_key.symbres + active : true + diffuse_texture : white.tga + position : 0.000 0.000 0.000 + name : Pickup_Key_Green_Mesh + uv_scale : 1.000 1.000 +} + diff --git a/assets/entities/pickup_key_red.symtres b/assets/entities/pickup_key_red.symtres new file mode 100644 index 0000000..a447b0a --- /dev/null +++ b/assets/entities/pickup_key_red.symtres @@ -0,0 +1,41 @@ +Entity +{ + type : 11 + scale : 1.000 1.000 1.000 + rotation : 0.000 0.000 0.000 1.000 + active : true + position : 0.000 0.000 0.000 + name : Pickup_Key_Red + pickup_type : 0 + pickup_key_type : 1 + pickup_spin_speed : 5.000 +} + +Entity +{ + type : 9 + scale : 1.000 1.000 1.000 + rotation : 0.000 0.000 0.000 1.000 + trigger_mask : 1 + active : true + position : 0.000 0.000 0.000 + trigger_type : 0 + name : Pickup_Key_Red_Trigger + bounding_box_min : -0.500 -0.500 -0.500 + bounding_box_max : 0.500 0.500 0.500 +} + +Entity +{ + type : 6 + scale : 1.000 1.000 1.000 + material : 1 + rotation : 0.000 0.000 0.000 1.000 + diffuse_color : 1.000 1.000 1.000 1.000 + geometry : pickup_key.symbres + active : true + diffuse_texture : white.tga + position : 0.000 0.000 0.000 + name : Pickup_Key_Red_Mesh + uv_scale : 1.000 1.000 +} \ No newline at end of file diff --git a/assets/models/pickup_health.symbres b/assets/models/pickup_health.symbres new file mode 100644 index 0000000000000000000000000000000000000000..89f6b367716cbb3ebe5db492b8bc9909d34493b1 GIT binary patch literal 2608 zcmaKtS9aS#3`LpVtJAB~dv9(LmF{I|C($kvrEG=t2C^pSJ_s1YBOQO-gPF&NLeR%r zZ<=O3!Liu|yI~LPg?+Fe4!}V;1c%`W9ED?W98SPVI0dI+0nWf#I0xt90$hYka2c+^ zRk#M%VG(Y?O}GWO;SSt|dvG5fz(aThkKqYCg=g>_UcgIu1+U=^yoGnL1k11jtFQ*| zVE`=*;RAexPw*MOz*qPNlgR|@xcxPmbib$P{wLA({?C>!kMs_IuXE*>-r|=Yp04tn zhx*b7s^j(N`YVt5HJkUfdAwKaHLbp8*xdZC+Jhg{S@c|I)v)v5SzYhlp(|JK(Yb#{ zSMEGd?v*|HyweOZvu4n4G>_LTGx$#O_liA4&bIyd{_VT?*}h%Y^A7X3%X;qXXZv=! zX3otXblbcC{lvM;_2b?3zH#iTXSEZNK#lUPEZKU-ebRbO?a`An)~?-P3Tkyq~(-teh^&dna5E#{86t$utb z#k>dauYQ)NC@N3PD^EFV9{1VIdM2`-`)W?jt>@m)@}#BQ;>j~qb(Ckl_=V+XZVVgz zUm1GTU3%P`^jvz}$K)tacj@JhB)!~~<99{*N75kj6w95n@`oPB=^j2k55J=BW5{~B zW38Vz?pIX)2%?_y7W196?n6)=#keart}Dh}QFY{xdJ)N(&Kc43^}KQa2u<}ABd k)gQtJ{v1PBY}^-7`SO=KoXr<=MD)7yHSQmIJ;km3|3STGJ^%m! literal 0 HcmV?d00001 diff --git a/assets/models/pickup_key.symbres b/assets/models/pickup_key.symbres new file mode 100644 index 0000000000000000000000000000000000000000..252594ad6ea58815a1b3c386e59a76299c4001a7 GIT binary patch literal 1312 zcma)*J5Iwu5QdjGBoGL12oD1(0}a%+8-(aUTp%|gH3vum5*&gOk)=c&AZ;Y>0p=TL z*BTZp!qTUi9se`?kDN4(F---j8G~_{fJvBwX_$don1c#bVICHs28*x+by$WKScNrM zhYi?-E!c(z?7%MU!9GNA0Ech{Us=}6vfIR%4j3Ovjg{KT>&vOm(Z}fJon;T}^PpGe zSbCqe-p!#mzqgp_e*`YrV{5zI_bpTCX+QgT71a1OIw{u@}7wK4W~2+OgO@@LbgO9PL4S);@zd zrQY<8dZxZh@5nz+eml^XZyOKKI=)epM`BS&E9cb3j*BwKIGsc}i%wz$9dbGQn7VqX rlXDw<6n*6SCCVdnspeed = 0.f; struct Event_Manager* event_manager = game_state_get()->event_manager; - event_manager_unsubscribe_with_subscriber(event_manager, EVT_TRIGGER, &door_on_trigger, (void*)door); event_manager_unsubscribe_with_subscriber(event_manager, EVT_SCENE_LOADED, &door_on_scene_loaded, (void*)door); } @@ -168,31 +166,7 @@ void door_on_scene_loaded(struct Event* event, void* door_ptr) log_error("door:on_scene_load", "Could not find sound entity for door %s", door->base.name); if(entity_get_num_children_of_type(door, ET_TRIGGER, &door_trigger, 1) == 1) - { door->trigger = door_trigger[0]; - struct Event_Manager* event_manager = game_state_get()->event_manager; - event_manager_subscribe_with_subscriber(event_manager, EVT_TRIGGER, &door_on_trigger, (void*)door); - } else - { log_error("door:on_scene_load", "Could not find trigger entity for door %s", door->base.name); - } - } - -void door_on_trigger(struct Event* event, void* door_ptr) -{ - struct Game_State* game_state = game_state_get(); - struct Door* door = (struct Door*)door_ptr; - //log_message("Trigger %s triggered for door %s", door->trigger->base.name, door->base.name); - switch(door->state) - { - case DOOR_CLOSED: - break; - case DOOR_OPEN: - break; - case DOOR_OPENING: - case DOOR_CLOSING: - break; - } -} \ No newline at end of file diff --git a/src/game/entity.c b/src/game/entity.c index 48eb2ca..9d42372 100755 --- a/src/game/entity.c +++ b/src/game/entity.c @@ -21,6 +21,7 @@ #include "event.h" #include "sound_source.h" #include "door.h" +#include "pickup.h" #include #include @@ -172,7 +173,7 @@ bool entity_write(struct Entity* entity, struct Parser_Object* object, bool writ hashmap_vec2_set(entity_data, "uv_scale", &model->material_params[MMP_UV_SCALE].val_vec2); break; case MAT_UNSHADED: - hashmap_vec3_set(entity_data, "diffuse_color", &model->material_params[MMP_DIFFUSE_COL].val_vec3); + hashmap_vec4_set(entity_data, "diffuse_color", &model->material_params[MMP_DIFFUSE_COL].val_vec4); hashmap_str_set(entity_data, "diffuse_texture", model->material_params[MMP_DIFFUSE_TEX].val_int == -1 ? "default.tga" : texture_get_name(model->material_params[MMP_DIFFUSE_TEX].val_int)); hashmap_vec2_set(entity_data, "uv_scale", &model->material_params[MMP_UV_SCALE].val_vec2); break; @@ -217,17 +218,23 @@ bool entity_write(struct Entity* entity, struct Parser_Object* object, bool writ enemy_write(enemy, entity_data); } break; + case ET_TRIGGER: + { + struct Trigger* trigger = (struct Trigger*)entity; + hashmap_int_set(entity_data, "trigger_type", trigger->type); + hashmap_int_set(entity_data, "trigger_mask", trigger->trigger_mask); + } + break; case ET_DOOR: { struct Door* door = (struct Door*)entity; door_write(door, entity_data); } break; - case ET_TRIGGER: + case ET_PICKUP: { - struct Trigger* trigger = (struct Trigger*)entity; - hashmap_int_set(entity_data, "trigger_type", trigger->type); - hashmap_int_set(entity_data, "trigger_mask", trigger->trigger_mask); + struct Pickup* pickup = (struct Pickup*)entity; + pickup_write(pickup, entity_data); } break; }; @@ -491,6 +498,13 @@ struct Entity* entity_read(struct Parser_Object* object, struct Entity* parent_e return new_entity; } break; + case ET_PICKUP: + { + new_entity = &pickup_read(object, name, parent_entity)->base; + if(!new_entity) + return new_entity; + } + break; default: log_warning("Unhandled Entity type '%d' detected", type); break; @@ -610,6 +624,7 @@ const char* entity_type_name_get(struct Entity* entity) case ET_ENEMY: typename = "Enemy"; break; case ET_TRIGGER: typename = "Trigger"; break; case ET_DOOR: typename = "Door"; break; + case ET_PICKUP: typename = "Pickup"; break; default: typename = "Unknown"; break; }; return typename; diff --git a/src/game/entity.h b/src/game/entity.h index 5d49457..b47866f 100755 --- a/src/game/entity.h +++ b/src/game/entity.h @@ -28,6 +28,7 @@ enum Entity_Type ET_ENEMY, ET_TRIGGER, ET_DOOR, + ET_PICKUP, ET_MAX }; @@ -65,6 +66,13 @@ enum Entity_Flags EF_IGNORE_RAYCAST = 1 << 6 }; +enum Pickup_Type +{ + PICKUP_KEY = 0, + PICKUP_HEALTH, + PICKUP_MAX +}; + enum Entity_Ray_Mask { ERM_NONE = 0, @@ -76,7 +84,9 @@ enum Entity_Ray_Mask ERM_SOUND_SOURCE = 1 << 5, ERM_ENEMY = 1 << 6, ERM_TRIGGER = 1 << 7, - ERM_ALL = ERM_DEFAULT | ERM_PLAYER | ERM_CAMERA | ERM_LIGHT | ERM_STATIC_MESH | ERM_SOUND_SOURCE | ERM_ENEMY | ERM_TRIGGER + ERM_DOOR = 1 << 8, + ERM_PICKUP = 1 << 9, + ERM_ALL = ERM_DEFAULT | ERM_PLAYER | ERM_CAMERA | ERM_LIGHT | ERM_STATIC_MESH | ERM_SOUND_SOURCE | ERM_ENEMY | ERM_TRIGGER | ERM_DOOR | ERM_PICKUP }; enum Trigger_Mask @@ -274,6 +284,20 @@ struct Door struct Trigger* trigger; }; +struct Pickup +{ + struct Entity base; + int type; + union + { + int health; + int key_type; + }; + float spin_speed; + struct Static_Mesh* mesh; + struct Trigger* trigger; +}; + void entity_init(struct Entity* entity, const char* name, struct Entity* parent); void entity_reset(struct Entity* entity, int id); bool entity_save(struct Entity* entity, const char* filename, int directory_type); diff --git a/src/game/event.c b/src/game/event.c index 15b006a..eb2c39b 100644 --- a/src/game/event.c +++ b/src/game/event.c @@ -489,7 +489,7 @@ void event_manager_unsubscribe_with_subscriber_sender(struct Event_Manager* even for(int i = 0; i < MAX_EVENT_SUBSCRIPTIONS; i++) { struct Event_Subscription* subscription = &event_manager->event_subsciptions[i]; - if(subscription->type != EST_SUBSCRIBER) continue; + if(subscription->type != EST_SUBSCRIBER_SENDER) continue; if(subscription->event_type == event_type && subscription->Subscription_Subscriber_Sender.handler == handler_func && subscription->Subscription_Subscriber_Sender.subscriber == subscriber && diff --git a/src/game/event.h b/src/game/event.h index 653ee1a..8054507 100755 --- a/src/game/event.h +++ b/src/game/event.h @@ -101,6 +101,7 @@ struct Scene_Loaded_Event struct Trigger_Event { struct Trigger* sender; + struct Entity* triggering_entity; }; struct Player_Death_Event diff --git a/src/game/pickup.c b/src/game/pickup.c new file mode 100644 index 0000000..6e94865 --- /dev/null +++ b/src/game/pickup.c @@ -0,0 +1,122 @@ +#include "pickup.h" +#include "entity.h" +#include "game.h" +#include "event.h" +#include "../common/hashmap.h" +#include "../common/parser.h" +#include "scene.h" +#include "../common/log.h" +#include "material.h" +#include "door.h" +#include "transform.h" + +static void pickup_on_scene_loaded(struct Event* event, void* pickup_ptr); +static void pickup_on_trigger(struct Event* event, void* pickup_ptr, void* trigger_ptr); + +void pickup_init(struct Pickup* pickup, int type) +{ + pickup->base.type = ET_PICKUP; + pickup->type = type; + pickup->spin_speed = 5.f; + switch(type) + { + case PICKUP_KEY: pickup->key_type = DOOR_KEY_MASK_NONE; break; + case PICKUP_HEALTH: pickup->health = 0; break; + } + + struct Game_State* game_state = game_state_get(); + event_manager_subscribe_with_subscriber(game_state->event_manager, EVT_SCENE_LOADED, &pickup_on_scene_loaded, (void*)pickup); +} + +void pickup_reset(struct Pickup* pickup) +{ + struct Game_State* game_state = game_state_get(); + event_manager_unsubscribe_with_subscriber(game_state->event_manager, EVT_SCENE_LOADED, &pickup_on_scene_loaded, (void*)pickup); + event_manager_unsubscribe_with_subscriber_sender(game_state->event_manager, EVT_TRIGGER, &pickup_on_trigger, (void*)pickup, (void*)pickup->trigger); +} + +struct Pickup* pickup_read(struct Parser_Object* parser_object, const char* name, struct Entity* parent_entity) +{ + struct Pickup* new_pickup = NULL; + struct Scene* scene = game_state_get()->scene; + + new_pickup = scene_pickup_create(scene, name, parent_entity, PICKUP_HEALTH); + if(hashmap_value_exists(parser_object->data, "pickup_type")) new_pickup->type = hashmap_int_get(parser_object->data, "pickup_type"); + if(hashmap_value_exists(parser_object->data, "pickup_spin_speed")) new_pickup->spin_speed = hashmap_float_get(parser_object->data, "pickup_spin_speed"); + switch(new_pickup->type) + { + case PICKUP_KEY: if(hashmap_value_exists(parser_object->data, "pickup_key_type")) new_pickup->key_type = hashmap_int_get(parser_object->data, "pickup_key_type"); break; + case PICKUP_HEALTH: if(hashmap_value_exists(parser_object->data, "pickup_health")) new_pickup->health = hashmap_int_get(parser_object->data, "pickup_health"); break; + } + return new_pickup; +} + +void pickup_write(struct Pickup* pickup, struct Hashmap* pickup_data) +{ + hashmap_int_set(pickup_data, "pickup_type", pickup->type); + hashmap_float_set(pickup_data, "pickup_spin_speed", pickup->spin_speed); + + switch(pickup->type) + { + case PICKUP_KEY: hashmap_int_set(pickup_data, "pickup_key_type", pickup->key_type); break; + case PICKUP_HEALTH: hashmap_int_set(pickup_data, "pickup_health", pickup->health); break; + } +} + +void pickup_on_scene_loaded(struct Event* event, void* pickup_ptr) +{ + struct Pickup* pickup = (struct Pickup*)pickup_ptr; + struct Trigger* pickup_trigger[1] = { NULL }; + struct Static_Mesh* pickup_mesh[1] = { NULL }; + + if(entity_get_num_children_of_type(pickup, ET_TRIGGER, &pickup_trigger, 1) == 1) + { + pickup->trigger = pickup_trigger[0]; + struct Event_Manager* event_manager = game_state_get()->event_manager; + event_manager_subscribe_with_subscriber_sender(event_manager, EVT_TRIGGER, &pickup_on_trigger, (void*)pickup, pickup->trigger); + } + else + { + log_error("pickup:on_scene_loaded", "Could not find trigger for pickup %s", pickup->base.name); + } + + if(entity_get_num_children_of_type(pickup, ET_STATIC_MESH, &pickup_mesh, 1) == 1) + { + pickup->mesh = pickup_mesh[0]; + if(pickup->type == PICKUP_KEY) + { + switch(pickup->key_type) + { + case DOOR_KEY_MASK_RED: vec4_assign(&pickup->mesh->model.material_params[MMP_DIFFUSE_COL].val_vec4, &KEY_INDICATOR_COLOR_RED); break; + case DOOR_KEY_MASK_GREEN: vec4_assign(&pickup->mesh->model.material_params[MMP_DIFFUSE_COL].val_vec4, &KEY_INDICATOR_COLOR_GREEN); break; + case DOOR_KEY_MASK_BLUE: vec4_assign(&pickup->mesh->model.material_params[MMP_DIFFUSE_COL].val_vec4, &KEY_INDICATOR_COLOR_BLUE); break; + } + } + else if(pickup->type == PICKUP_HEALTH) + { + log_message("Break"); + } + } + else + { + log_error("pickup:on_scene_loaded", "Could not find mesh for pickup %s", pickup->base.name); + } +} + +void pickup_update(struct Pickup* pickup, float dt) +{ + transform_rotate(pickup->mesh, &UNIT_Y, pickup->spin_speed * dt, TS_WORLD); +} + +void pickup_on_trigger(struct Event* event, void* pickup_ptr, void* trigger_ptr) +{ + struct Pickup* pickup = (struct Pickup*) pickup_ptr; + switch(event->trigger.triggering_entity->type) + { + case ET_PLAYER: player_on_pickup(event->trigger.triggering_entity, pickup); break; + case ET_ENEMY: + break; + } + + scene_pickup_remove(game_state_get()->scene, pickup); +} \ No newline at end of file diff --git a/src/game/pickup.h b/src/game/pickup.h new file mode 100644 index 0000000..aed8a0d --- /dev/null +++ b/src/game/pickup.h @@ -0,0 +1,15 @@ +#ifndef PICKUP_H +#define PICKUP_H + +struct Pickup; +struct Entity; +struct Parser_Object; +struct Hashmap; + +void pickup_init(struct Pickup* pickup, int type); +void pickup_reset(struct Pickup* pickup); +struct Pickup* pickup_read(struct Parser_Object* parser_object, const char* name, struct Entity* parent_entity); +void pickup_write(struct Pickup* pickup, struct Hashmap* pickup_data); +void pickup_update(struct Pickup* pickup, float dt); + +#endif \ No newline at end of file diff --git a/src/game/player.c b/src/game/player.c index 7e5b7e8..008e5eb 100755 --- a/src/game/player.c +++ b/src/game/player.c @@ -21,6 +21,7 @@ #include #include + static void player_on_mousebutton_released(const struct Event* event); static void player_on_input_map_released(const struct Event* event); @@ -44,7 +45,7 @@ void player_init(struct Player* player, struct Scene* scene) player->min_forward_distance = hashmap_float_get(config, "player_min_forward_distance"); player->grounded = true; player->can_jump = true; - player->health = 100; + player->health = MAX_PLAYER_HEALTH; player->key_mask = 0; player->mesh = scene_static_mesh_create(scene, "Player_Mesh", player, "sphere.symbres", MAT_BLINN); @@ -373,3 +374,16 @@ void player_apply_damage(struct Player* player, struct Enemy* enemy) event_manager_send_event(event_manager, player_death_event); } } + +void player_on_pickup(struct Player* player, struct Pickup* pickup) +{ + switch(pickup->type) + { + case PICKUP_HEALTH: + player->health = min(MAX_PLAYER_HEALTH, player->health + pickup->health); + break; + case PICKUP_KEY: + player->key_mask |= pickup->key_type; + break; + } +} diff --git a/src/game/player.h b/src/game/player.h index bd5b55a..b047b24 100755 --- a/src/game/player.h +++ b/src/game/player.h @@ -3,10 +3,12 @@ struct Player; struct Scene; +struct Pickup; void player_init(struct Player* player, struct Scene* scene); void player_destroy(struct Player* player); void player_apply_damage(struct Player* player, struct Enemy* enemy); +void player_on_pickup(struct Player* player, struct Pickup* pickup); void player_update_physics(struct Player* player, struct Scene* scene, float dt); #endif diff --git a/src/game/scene.c b/src/game/scene.c index 663d32b..f1973fd 100755 --- a/src/game/scene.c +++ b/src/game/scene.c @@ -22,6 +22,7 @@ #include "scene_funcs.h" #include "trigger.h" #include "door.h" +#include "pickup.h" #include #include @@ -78,13 +79,25 @@ void scene_init(struct Scene* scene) for(int i = 0; i < MAX_SCENE_ENEMIES; i++) { entity_reset(&scene->enemies[i], i); - scene->enemies->base.type = ET_ENEMY; + scene->enemies[i].base.type = ET_ENEMY; } for(int i = 0; i < MAX_SCENE_TRIGGERS; i++) { entity_reset(&scene->triggers[i], i); - scene->triggers->base.type = ET_TRIGGER; + scene->triggers[i].base.type = ET_TRIGGER; + } + + for(int i = 0; i < MAX_SCENE_DOORS; i++) + { + entity_reset(&scene->doors[i], i); + scene->doors[i].base.type = ET_DOOR; + } + + for(int i = 0; i < MAX_SCENE_PICKUPS; i++) + { + entity_reset(&scene->pickups[i], i); + scene->pickups[i].base.type = ET_PICKUP; } player_init(&scene->player, scene); @@ -333,6 +346,7 @@ bool scene_save(struct Scene* scene, const char* filename, int directory_type) scene_write_entity_list(scene, ET_ENEMY, parser); scene_write_entity_list(scene, ET_TRIGGER, parser); scene_write_entity_list(scene, ET_DOOR, parser); + scene_write_entity_list(scene, ET_PICKUP, parser); if(parser_write_objects(parser, scene_file, prefixed_filename)) log_message("Scene saved to %s", prefixed_filename); @@ -390,6 +404,11 @@ void scene_write_entity_list(struct Scene* scene, int entity_type, struct Parser entity = &scene->doors[0].base; stride = sizeof(struct Door); break; + case ET_PICKUP: + max_length = MAX_SCENE_PICKUPS; + entity = &scene->pickups[0].base; + stride = sizeof(struct Pickup); + break; default: return; } @@ -441,6 +460,7 @@ void scene_destroy(struct Scene* scene) for(int i = 0; i < MAX_SCENE_ENEMIES; i++) scene_enemy_remove(scene, &scene->enemies[i]); for(int i = 0; i < MAX_SCENE_TRIGGERS; i++) scene_trigger_remove(scene, &scene->triggers[i]); for(int i = 0; i < MAX_SCENE_DOORS; i++) scene_door_remove(scene, &scene->doors[i]); + for(int i = 0; i < MAX_SCENE_PICKUPS; i++) scene_pickup_remove(scene, &scene->pickups[i]); for(int i = 0; i < MAX_SCENE_ENTITY_ARCHETYPES; i++) memset(&scene->entity_archetypes[i][0], '\0', MAX_FILENAME_LEN); player_destroy(&scene->player); entity_reset(&scene->root_entity, 0); @@ -462,6 +482,12 @@ void scene_update(struct Scene* scene, float dt) if(scene->doors[i].base.flags & EF_ACTIVE) door_update(&scene->doors[i], scene, dt); } + + for(int i = 0; i < MAX_SCENE_PICKUPS; i++) + { + if(scene->pickups[i].base.flags & EF_ACTIVE) + pickup_update(&scene->pickups[i], dt); + } } } @@ -602,6 +628,18 @@ void scene_post_update(struct Scene* scene) } } + for(int i = 0; i < MAX_SCENE_PICKUPS; i++) + { + struct Pickup* pickup = &scene->pickups[i]; + if(!(pickup->base.flags & EF_ACTIVE)) continue; + + if(pickup->base.flags & EF_MARKED_FOR_DELETION) + { + scene_pickup_remove(scene, pickup); + continue; + } + } + if(scene->player.base.transform.is_modified) { scene->player.base.transform.is_modified = false; @@ -839,6 +877,33 @@ struct Door* scene_door_create(struct Scene* scene, const char* name, struct Ent return new_door; } +struct Pickup* scene_pickup_create(struct Scene* scene, const char* name, struct Entity* parent, int type) +{ + assert(scene); + struct Pickup* new_pickup = NULL; + for(int i = 0; i < MAX_SCENE_PICKUPS; i++) + { + struct Pickup* pickup = &scene->pickups[i]; + if(!(pickup->base.flags & EF_ACTIVE)) + { + new_pickup = pickup; + break; + } + } + + if(new_pickup) + { + entity_init(&new_pickup->base, name, parent ? parent : &scene->root_entity); + pickup_init(new_pickup, type); + } + else + { + log_error("scene:pickup_create", "Max pickup limit reached!"); + } + + return new_pickup; +} + struct Trigger* scene_trigger_create(struct Scene* scene, const char* name, struct Entity* parent, int type, int mask) { assert(scene); @@ -898,6 +963,13 @@ void scene_door_remove(struct Scene* scene, struct Door* door) scene_entity_base_remove(scene, door); } +void scene_pickup_remove(struct Scene* scene, struct Pickup* pickup) +{ + assert(scene && pickup); + pickup_reset(pickup); + scene_entity_base_remove(scene, pickup); +} + void scene_trigger_remove(struct Scene* scene, struct Trigger* trigger) { assert(scene && trigger); @@ -1048,43 +1120,38 @@ struct Door* scene_door_find(struct Scene* scene, const char* name) return door; } -struct Trigger* scene_trigger_find(struct Scene* scene, const char* name) +struct Pickup* scene_pickup_find(struct Scene* scene, const char* name) { assert(scene && name); - struct Trigger* trigger = NULL; + struct Pickup* pickup = NULL; - for(int i = 0; i < MAX_SCENE_TRIGGERS; i++) + for(int i = 0; i < MAX_SCENE_PICKUPS; i++) { - if(strncmp(name, scene->triggers[i].base.name, MAX_ENTITY_NAME_LEN) == 0) + if(strncmp(name, scene->pickups[i].base.name, MAX_ENTITY_NAME_LEN) == 0) { - trigger = &scene->triggers[i]; + pickup = &scene->pickups[i]; break; } } - return trigger; + return pickup; } -struct Entity* scene_base_entity_get(struct Scene* scene, int id, int type) +struct Trigger* scene_trigger_find(struct Scene* scene, const char* name) { - assert(scene && id != -1 && type < ET_MAX); - - struct Entity* entity = NULL; + assert(scene && name); + struct Trigger* trigger = NULL; - switch(type) + for(int i = 0; i < MAX_SCENE_TRIGGERS; i++) { - case ET_DEFAULT: entity = &scene->entities[id]; break; - case ET_CAMERA: entity = &scene->cameras[id]; break; - case ET_LIGHT: entity = &scene->lights[id]; break; - case ET_STATIC_MESH: entity = &scene->static_meshes[id]; break; - case ET_SOUND_SOURCE: entity = &scene->sound_sources[id]; break; - case ET_ENEMY: entity = &scene->enemies[id]; break; - case ET_TRIGGER: entity = &scene->triggers[id]; break; - case ET_PLAYER: entity = &scene->player; break; - case ET_ROOT: entity = &scene->root_entity; break; + if(strncmp(name, scene->triggers[i].base.name, MAX_ENTITY_NAME_LEN) == 0) + { + trigger = &scene->triggers[i]; + break; + } } - return entity; + return trigger; } void* scene_find(struct Scene* scene, const char* name) @@ -1109,6 +1176,15 @@ void* scene_find(struct Scene* scene, const char* name) entity = scene_enemy_find(scene, name); if(entity) return entity; + entity = scene_trigger_find(scene, name); + if(entity) return entity; + + entity = scene_door_find(scene, name); + if(entity) return entity; + + entity = scene_pickup_find(scene, name); + if(entity) return entity; + return entity; } @@ -1175,6 +1251,30 @@ void scene_ray_intersect(struct Scene* scene, struct Ray* ray, struct Raycast_Re entity = &scene->player; stride = sizeof(struct Player); break; + case ET_ENEMY: + if(!(ray_mask & ERM_ENEMY)) continue; + max_length = MAX_SCENE_ENEMIES; + entity = &scene->enemies[0].base; + stride = sizeof(struct Enemy); + break; + case ET_TRIGGER: + if(!(ray_mask & ERM_TRIGGER)) continue; + max_length = MAX_SCENE_TRIGGERS; + entity = &scene->triggers[0].base; + stride = sizeof(struct Trigger); + break; + case ET_DOOR: + if(!(ray_mask & ERM_DOOR)) continue; + max_length = MAX_SCENE_DOORS; + entity = &scene->doors[0].base; + stride = sizeof(struct Door); + break; + case ET_PICKUP: + if(!(ray_mask & ERM_PICKUP)) continue; + max_length = MAX_SCENE_PICKUPS; + entity = &scene->pickups[0].base; + stride = sizeof(struct Pickup); + break; default: continue; } @@ -1250,6 +1350,30 @@ struct Entity* scene_ray_intersect_closest(struct Scene* scene, struct Ray* ray, entity = &scene->player; stride = sizeof(struct Player); break; + case ET_ENEMY: + if(!(ray_mask & ERM_ENEMY)) continue; + max_length = MAX_SCENE_ENEMIES; + entity = &scene->enemies[0].base; + stride = sizeof(struct Enemy); + break; + case ET_TRIGGER: + if(!(ray_mask & ERM_TRIGGER)) continue; + max_length = MAX_SCENE_TRIGGERS; + entity = &scene->triggers[0].base; + stride = sizeof(struct Trigger); + break; + case ET_DOOR: + if(!(ray_mask & ERM_DOOR)) continue; + max_length = MAX_SCENE_DOORS; + entity = &scene->doors[0].base; + stride = sizeof(struct Door); + break; + case ET_PICKUP: + if(!(ray_mask & ERM_PICKUP)) continue; + max_length = MAX_SCENE_PICKUPS; + entity = &scene->pickups[0].base; + stride = sizeof(struct Pickup); + break; default: continue; } diff --git a/src/game/scene.h b/src/game/scene.h index 1ae0392..80b7614 100755 --- a/src/game/scene.h +++ b/src/game/scene.h @@ -24,6 +24,7 @@ struct Scene struct Enemy enemies[MAX_SCENE_ENEMIES]; struct Trigger triggers[MAX_SCENE_TRIGGERS]; struct Door doors[MAX_SCENE_DOORS]; + struct Pickup pickups[MAX_SCENE_PICKUPS]; char entity_archetypes[MAX_SCENE_ENTITY_ARCHETYPES][MAX_FILENAME_LEN]; int active_camera_index; char init_func_name[MAX_HASH_KEY_LEN]; @@ -51,6 +52,7 @@ struct Sound_Source* scene_sound_source_create(struct Scene* scene, const char* struct Enemy* scene_enemy_create(struct Scene* scene, const char* name, struct Entity* parent, int type); struct Trigger* scene_trigger_create(struct Scene* scene, const char* name, struct Entity* parent, int type, int mask); struct Door* scene_door_create(struct Scene* scene, const char* name, struct Entity* parent, int mask); +struct Pickup* scene_pickup_create(struct Scene* scene, const char* name, struct Entity* parent, int type); void scene_entity_base_remove(struct Scene* scene, struct Entity* entity); void scene_light_remove(struct Scene* scene, struct Light* light); @@ -60,6 +62,7 @@ void scene_sound_source_remove(struct Scene* scene, struct Sound_Source* source) void scene_enemy_remove(struct Scene* scene, struct Enemy* enemy); void scene_trigger_remove(struct Scene* scene, struct Trigger* trigger); void scene_door_remove(struct Scene* scene, struct Door* door); +void scene_pickup_remove(struct Scene* scene, struct Pickup* pickup); void* scene_find(struct Scene* scene, const char* name); // Looks in all entity type arrays and returns the first one found. Result should be cast back to expected type struct Entity* scene_entity_find(struct Scene* scene, const char* name); @@ -67,10 +70,10 @@ struct Light* scene_light_find(struct Scene* scene, const char* name); struct Camera* scene_camera_find(struct Scene* scene, const char* name); struct Static_Mesh* scene_static_mesh_find(struct Scene* scene, const char* name); struct Sound_Source* scene_sound_source_find(struct Scene* scene, const char* name); -struct Entity* scene_base_entity_get(struct Scene* scene, int id, int type); struct Enemy* scene_enemy_find(struct Scene* scene, const char* name); struct Trigger* scene_trigger_find(struct Scene* scene, const char* name); struct Door* scene_door_find(struct Scene* scene, const char* name); +struct Pickup* scene_pickup_find(struct Scene* scene, const char* name); void scene_entity_parent_set(struct Scene* scene, struct Entity* entity, struct Entity* parent); void scene_entity_parent_reset(struct Scene* scene, struct Entity* entity); // Sets root entity as parent diff --git a/src/game/trigger.c b/src/game/trigger.c index 5d4122f..674c1bf 100644 --- a/src/game/trigger.c +++ b/src/game/trigger.c @@ -27,16 +27,18 @@ void trigger_update_physics(struct Trigger* trigger, struct Scene* scene, float { // Check if we're triggered and fire the associated event bool intersecting = false; + struct Entity* triggering_entity = NULL; if(trigger->trigger_mask & TRIGM_PLAYER) { int intersection = bv_intersect_bounding_boxes(&trigger->base.derived_bounding_box, &scene->player.base.derived_bounding_box); if(intersection == IT_INSIDE || intersection == IT_INTERSECT) { intersecting = true; + triggering_entity = &scene->player.base; } } - if(trigger->trigger_mask & TRIGM_ENEMY) + if(!intersecting && trigger->trigger_mask & TRIGM_ENEMY) { for(int i = 0; i < MAX_SCENE_ENEMIES; i++) { @@ -48,6 +50,8 @@ void trigger_update_physics(struct Trigger* trigger, struct Scene* scene, float if(intersection == IT_INTERSECT || intersection == IT_INSIDE) { intersecting = true; + triggering_entity = &enemy->base; + break; } } } @@ -95,6 +99,7 @@ void trigger_update_physics(struct Trigger* trigger, struct Scene* scene, float struct Event* trigger_event = event_manager_create_new_event(event_manager); trigger_event->type = EVT_TRIGGER; trigger_event->trigger.sender = trigger; + trigger_event->trigger.triggering_entity = triggering_entity; trigger_event->sender = trigger; event_manager_send_event(event_manager, trigger_event); if(trigger->type == TRIG_ONE_SHOT) diff --git a/todo.txt b/todo.txt index 81a969c..332ebbc 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,7 @@ Todo: + - Game End + - Pickup sounds + - Don't save parent entity's transform when saving entity archetype. Only save the transformation values for children - Save case sensitive file names when scene entity entries - Disbale all player actions when scene cleared dialog or scene restart dialog are active - Enemies getting hit by bullets @@ -424,4 +427,5 @@ Done: * Audio cues when player does not have the right key combination to open a particular door * Added saving scene init/cleanup funcs if there are any assigned when saving scene * Win/fail States - * In-Game Gui \ No newline at end of file + * In-Game Gui + * Pickups \ No newline at end of file