diff --git a/assets/entities/cube_uv.symtres b/assets/entities/cube_uv.symtres index f80eaeb..cecf711 100755 --- a/assets/entities/cube_uv.symtres +++ b/assets/entities/cube_uv.symtres @@ -1,7 +1,7 @@ Entity { type : 6 - scale : 135.000 5.000 1.000 + scale : 60.000 11.000 1.000 material : 0 rotation : 0.000 0.000 0.000 1.000 diffuse_color : 1.000 1.000 1.000 1.000 @@ -10,9 +10,9 @@ Entity active : true diffuse_texture : default.tga diffuse : 1.0000 - position : -17.000 3.000 -87.000 + position : -52.000 6.000 -30.000 specular_strength : 1.0000 name : Cube - uv_scale : 5.000 63.500 + uv_scale : 4.600 16.400 } diff --git a/assets/entities/door.symtres b/assets/entities/door.symtres new file mode 100644 index 0000000..a775f02 --- /dev/null +++ b/assets/entities/door.symtres @@ -0,0 +1,69 @@ +Entity +{ + type : 10 + 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 + bounding_box_min : -0.500 -0.500 -0.500 + name : Door + bounding_box_max : 0.500 0.500 0.500 + door_speed : 6.000 + door_state : 0 + door_mask : 1 + door_open_position : -7.000 + door_close_position : 0.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 + bounding_box_min : -3.000 -3.000 -5.000 + bounding_box_max : 3.000 3.000 5.000 + trigger_type : 1 + name : Door_Trigger +} + +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 + paused : true + position : 0.000 0.000 0.000 + bounding_box_min : -0.500 -0.500 -0.500 + source_filename : sounds/door_close.wav + sound_type : 1 + sound_max_distance : 30.0000 + name : Door_Sound + bounding_box_max : 0.500 0.500 0.500 + sound_attenuation_type : 2 +} + +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.000 4.500 0.000 + specular_strength : 62.0000 + name : Door_Mesh + uv_scale : 0.300 0.200 +} \ No newline at end of file diff --git a/assets/entities/trigger.symtres b/assets/entities/trigger.symtres index bca589f..149f9ff 100644 --- a/assets/entities/trigger.symtres +++ b/assets/entities/trigger.symtres @@ -6,9 +6,9 @@ Entity trigger_mask : 1 active : true position : 0.000 0.000 0.000 - bouding_box_min : -0.500 -0.500 -0.500 + bounding_box_min : -0.500 -0.500 -0.500 trigger_type : 0 name : Trigger - bouding_box_max : 0.500 0.500 0.500 + bounding_box_max : 0.500 0.500 0.500 } diff --git a/assets/entities/turret.symtres b/assets/entities/turret.symtres index bd07cae..db88bcd 100644 --- a/assets/entities/turret.symtres +++ b/assets/entities/turret.symtres @@ -13,13 +13,13 @@ Entity turn_speed_when_targetting : 50.0000 max_yaw : 60.0000 position : 0.000 3.000 0.000 - bouding_box_min : -0.500 -0.500 -0.500 + bounding_box_min : -0.500 -0.500 -0.500 enemy_type : 0 turn_speed_default : 50.0000 turn_direction_positive : true attack_cooldown : 0.0500 name : Turret - bouding_box_max : 0.500 0.500 0.500 + bounding_box_max : 0.500 0.500 0.500 color_default : 0.000 1.000 1.000 1.000 color_attack : 1.000 0.000 0.000 1.000 damage : 10 @@ -37,12 +37,12 @@ Entity active : true paused : true position : 0.000 0.000 0.000 - bouding_box_min : -0.500 -0.500 -0.500 + bounding_box_min : -0.500 -0.500 -0.500 source_filename : sounds/bullet_1.wav sound_type : 1 sound_max_distance : 30.0000 name : Turret_Weapon_Sound - bouding_box_max : 0.500 0.500 0.500 + bounding_box_max : 0.500 0.500 0.500 sound_attenuation_type : 2 } @@ -58,12 +58,12 @@ Entity active : true paused : false position : 0.000 0.000 0.000 - bouding_box_min : -0.500 -0.500 -0.500 + bounding_box_min : -0.500 -0.500 -0.500 source_filename : sounds/windy_ambience.ogg sound_type : 2 sound_max_distance : 30.0000 name : Turret_Ambient_Sound - bouding_box_max : 0.500 0.500 0.500 + bounding_box_max : 0.500 0.500 0.500 sound_attenuation_type : 2 } diff --git a/assets/scenes/scene_1.symtres b/assets/scenes/scene_1.symtres index 3a4caa0..6408617 100755 --- a/assets/scenes/scene_1.symtres +++ b/assets/scenes/scene_1.symtres @@ -16,13 +16,14 @@ Player { type : 2 scale : 1.000 1.000 1.000 - rotation : 0.000 0.953 0.000 -0.304 + rotation : 0.000 -1.000 0.000 -0.033 active : true - position : -33.850 2.459 -24.439 - bouding_box_min : -1.500 -1.500 -1.000 + position : -20.255 2.167 -50.978 + player_health : 100 name : Player - bouding_box_max : 1.500 1.500 1.000 + bounding_box_min : -1.500 -1.500 -1.000 camera_clear_color : 0.310 0.412 0.529 1.000 + bounding_box_max : 1.500 1.500 1.000 } Scene_Entity_Entry @@ -90,9 +91,9 @@ Scene_Entity_Entry Scene_Entity_Entry { - scale : 65.000 5.000 2.000 + scale : 65.000 11.000 2.000 rotation : 0.000 0.000 0.000 1.000 - position : 17.000 3.000 -30.000 + position : 17.000 6.000 -30.000 filename : cube_uv name : Cube } @@ -106,6 +107,15 @@ Scene_Entity_Entry name : Cube } +Scene_Entity_Entry +{ + scale : 60.000 11.000 1.000 + rotation : 0.000 0.000 0.000 1.000 + position : -52.000 6.000 -30.000 + filename : cube_uv + name : Cube +} + Scene_Entity_Entry { scale : 1.000 1.000 1.000 @@ -151,3 +161,12 @@ Scene_Entity_Entry name : Turret } +Scene_Entity_Entry +{ + scale : 1.000 1.000 1.000 + rotation : 0.000 0.000 0.000 1.000 + position : -18.500 1.000 -30.000 + filename : door + name : Door +} + diff --git a/assets/sounds/door_close.wav b/assets/sounds/door_close.wav new file mode 100644 index 0000000..1196b14 Binary files /dev/null and b/assets/sounds/door_close.wav differ diff --git a/assets/sounds/door_open.wav b/assets/sounds/door_open.wav new file mode 100644 index 0000000..e7acbc3 Binary files /dev/null and b/assets/sounds/door_open.wav differ diff --git a/src/common/version.h b/src/common/version.h index ce2e8fb..e73c36b 100755 --- a/src/common/version.h +++ b/src/common/version.h @@ -4,7 +4,7 @@ /* Auto generated version file. DO NOT MODIFY */ #define SYMMETRY_VERSION_MAJOR 0 #define SYMMETRY_VERSION_MINOR 1 -#define SYMMETRY_VERSION_REVISION 338 +#define SYMMETRY_VERSION_REVISION 339 #define SYMMETRY_VERSION_BRANCH "dev" #endif \ No newline at end of file diff --git a/src/game/door.c b/src/game/door.c index 09835e4..7a6425a 100644 --- a/src/game/door.c +++ b/src/game/door.c @@ -5,22 +5,25 @@ #include "transform.h" #include "trigger.h" #include "event.h" +#include "sound_source.h" #include "../common/log.h" #include "../common/parser.h" #include "../common/hashmap.h" static void door_on_scene_loaded(struct Event* event, void* door_ptr); -static void door_on_trigger(struct Event* event, void* trigger_ptr); +static void door_on_trigger(struct Event* event, void* door_ptr); void door_init(struct Door* door, int mask) { struct Game_State* game_state = game_state_get(); struct Event_Manager* event_manager = game_state->event_manager; - door->base.type = ET_DOOR; - door->mask = mask; - door->speed = 20.f; - door->state = DOOR_CLOSED; + door->base.type = ET_DOOR; + door->mask = mask; + door->speed = 20.f; + door->open_position = -5.f; + door->close_position = 0.f; + door->state = DOOR_CLOSED; event_manager_subscribe_with_object(event_manager, EVT_SCENE_LOADED, &door_on_scene_loaded, (void*)door); } @@ -40,10 +43,12 @@ struct Door* door_read(struct Parser_Object* object, const char* name, struct En struct Door* new_door = NULL; struct Scene* scene = game_state_get()->scene; - new_door = scene_door_create(scene, name, parent_entity, DOOR_KEY_NONE); - if(hashmap_value_exists(object->data, "door_speed")) new_door->speed = hashmap_float_get(object->data, "door_speed"); - if(hashmap_value_exists(object->data, "door_state")) new_door->state = hashmap_int_get(object->data, "door_state"); - if(hashmap_value_exists(object->data, "door_mask")) new_door->mask = hashmap_int_get(object->data, "door_mask"); + new_door = scene_door_create(scene, name, parent_entity, DOOR_KEY_MASK_NONE); + if(hashmap_value_exists(object->data, "door_speed")) new_door->speed = hashmap_float_get(object->data, "door_speed"); + if(hashmap_value_exists(object->data, "door_state")) new_door->state = hashmap_int_get(object->data, "door_state"); + if(hashmap_value_exists(object->data, "door_mask")) new_door->mask = hashmap_int_get(object->data, "door_mask"); + if(hashmap_value_exists(object->data, "door_open_position")) new_door->open_position = hashmap_float_get(object->data, "door_open_position"); + if(hashmap_value_exists(object->data, "door_close_position")) new_door->close_position = hashmap_float_get(object->data, "door_close_position"); return new_door; @@ -54,18 +59,42 @@ void door_write(struct Door* door, struct Hashmap* entity_data) hashmap_int_set(entity_data, "door_state", door->state); hashmap_int_set(entity_data, "door_mask", door->mask); hashmap_float_set(entity_data, "door_speed", door->speed); + hashmap_float_set(entity_data, "door_open_position", door->open_position); + hashmap_float_set(entity_data, "door_close_position", door->close_position); } void door_update(struct Door* door, struct Scene* scene, float dt) { + struct Game_State* game_state = game_state_get(); switch(door->state) { case DOOR_CLOSED: + if(door->trigger->triggered) + { + door->state = DOOR_OPENING; + sound_source_buffer_set(game_state->sound, door->sound, "sounds/door_open.wav", ST_WAV); + sound_source_play(game_state->sound, door->sound); + } + break; case DOOR_OPEN: + if(!door->trigger->triggered) + { + door->state = DOOR_CLOSING; + sound_source_buffer_set(game_state->sound, door->sound, "sounds/door_close.wav", ST_WAV); + sound_source_play(game_state->sound, door->sound); + } break; case DOOR_OPENING: + if(door->mesh->base.transform.position.x >= door->open_position) + transform_translate(door->mesh, &(vec3) { door->speed* dt * -1.f, 0.f, 0.f }, TS_LOCAL); + else + door->state = DOOR_OPEN; break; case DOOR_CLOSING: + if(door->mesh->base.transform.position.x <= door->close_position) + transform_translate(door->mesh, &(vec3) { door->speed* dt * 1.f, 0.f, 0.f }, TS_LOCAL); + else + door->state = DOOR_CLOSED; break; } } @@ -100,7 +129,19 @@ void door_on_scene_loaded(struct Event* event, void* door_ptr) } -void door_on_trigger(struct Event* event, void* trigger_ptr) +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; + } } diff --git a/src/game/entity.c b/src/game/entity.c index 7c9d7ee..48eb2ca 100755 --- a/src/game/entity.c +++ b/src/game/entity.c @@ -123,8 +123,8 @@ bool entity_write(struct Entity* entity, struct Parser_Object* object, bool writ if(entity->type != ET_STATIC_MESH) { - hashmap_vec3_set(entity_data, "bouding_box_min", &entity->bounding_box.min); - hashmap_vec3_set(entity_data, "bouding_box_max", &entity->bounding_box.max); + hashmap_vec3_set(entity_data, "bounding_box_min", &entity->bounding_box.min); + hashmap_vec3_set(entity_data, "bounding_box_max", &entity->bounding_box.max); } switch(entity->type) diff --git a/src/game/entity.h b/src/game/entity.h index d1e4189..94fa5e9 100755 --- a/src/game/entity.h +++ b/src/game/entity.h @@ -86,20 +86,20 @@ enum Trigger_Mask TRIGM_ALL = TRIGM_PLAYER | TRIGM_ENEMY }; -enum Door_Mask +enum Door_Key_Mask { - DOOR_KEY_NONE = 0, - DOOR_KEY_RED = 1 << 0, - DOOR_KEY_GREEN = 1 << 1, - DOOR_KEY_BLUE = 1 << 2, - DOOR_KEY_ALL = DOOR_KEY_RED | DOOR_KEY_GREEN | DOOR_KEY_BLUE + DOOR_KEY_MASK_NONE = 0, + DOOR_KEY_MASK_RED = 1 << 0, + DOOR_KEY_MASK_GREEN = 1 << 1, + DOOR_KEY_MASK_BLUE = 1 << 2, + DOOR_KEY_MASK_ALL = DOOR_KEY_MASK_RED | DOOR_KEY_MASK_GREEN | DOOR_KEY_MASK_BLUE }; enum Trigger_Type { TRIG_TOGGLE = 0, // Toggled on once and fires event then wont fire event until it is deactivated and activated again TRIG_CONTINUOUS, // Continuously fire events while the trigger is active - TRIG_ONE_SHOT, // Fire event once when triggerd and then get deleted + TRIG_ONE_SHOT, // Fire event once when triggered and then get deleted TRIG_MAX }; @@ -259,6 +259,8 @@ struct Door int mask; int state; float speed; + float open_position; + float close_position; struct Static_Mesh* mesh; struct Sound_Source* sound; struct Trigger* trigger; diff --git a/src/game/sound_source.c b/src/game/sound_source.c index 7457a8b..57807e8 100644 --- a/src/game/sound_source.c +++ b/src/game/sound_source.c @@ -56,23 +56,21 @@ void sound_source_update_position(struct Sound* sound, struct Sound_Source* enti void sound_source_buffer_set(struct Sound* sound, struct Sound_Source* entity, const char* filename, int type) { - if(entity->source_buffer) + struct Sound_Source_Buffer* new_buffer = sound_source_buffer_create(sound, filename, type); + if(new_buffer) { - struct Sound_Source_Buffer* new_buffer = sound_source_buffer_create(sound, filename, type); - if(new_buffer) - { - sound_source_instance_destroy(sound, entity->source_instance); + sound_source_instance_destroy(sound, entity->source_instance); + if(entity->source_buffer) sound_source_buffer_destroy(sound, entity->source_buffer); - entity->source_buffer = new_buffer; - entity->type = type; - entity->source_instance = sound_source_instance_create(sound, entity->source_buffer, true); - sound_source_apply_params_to_instance(sound, entity); - } - else - { - log_error("sound_source:buffer_set", "Failed to set buffer for %s", entity->base.name); - } + entity->source_buffer = new_buffer; + entity->type = type; + entity->source_instance = sound_source_instance_create(sound, entity->source_buffer, true); + sound_source_apply_params_to_instance(sound, entity); + } + else + { + log_error("sound_source:buffer_set", "Failed to set buffer for %s", entity->base.name); } } diff --git a/src/game/trigger.c b/src/game/trigger.c index 753f275..b945958 100644 --- a/src/game/trigger.c +++ b/src/game/trigger.c @@ -89,9 +89,6 @@ void trigger_update_physics(struct Trigger* trigger, struct Scene* scene, float break; } - if(fire_event) - log_message("event triggered!"); - if(fire_event) { struct Event_Manager* event_manager = game_state_get()->event_manager; diff --git a/todo.txt b/todo.txt index 8ee95bb..7d49719 100644 --- a/todo.txt +++ b/todo.txt @@ -1,11 +1,17 @@ Todo: - - Composite door entity made up of static mesh, sound entity and trigger. Door might require 0-3 keys in order to be opened. + - Add door properties to property inspector in editor + - Switch transformation in property inspector to show/modify local transform values by default and show absolute transform values as read-only. - Doors that open using the red/green/blue keys only as a way of progressing the level or cordoing off certain sections - RGB keys to progress to next level - Player/enemies getting hit by bullets - Win/fail States - Remove excessive repitition in scene related code that handles multiple entity types - Allow switching to editor mode when game is in pause mode + - Rendering Additions: + - Color grading + - Shadow mapping + - Cube mapping for sky dome etc + - Add event sender along with events - Implement flag for ignoring collisions with certain entities - Implement separate property window for player related variables that can be shown in the editor similar to renderer settings etc - Implement game gui either with a separate nuklear context or as part of existing context @@ -412,4 +418,5 @@ Done: * Add "Select Parent" button to property inspector * Remove ODE completely * Fixed console not working in game mode - * Pause sound when game is in pause mode \ No newline at end of file + * Pause sound when game is in pause mode + * Composite door entity made up of static mesh, sound entity and trigger. Door might require 0-3 keys in order to be opened. \ No newline at end of file