Added simple auto open/close door

dev
Shariq Shah 6 years ago
parent 64dcb37310
commit 833bfecf1d
  1. 6
      assets/entities/cube_uv.symtres
  2. 69
      assets/entities/door.symtres
  3. 4
      assets/entities/trigger.symtres
  4. 12
      assets/entities/turret.symtres
  5. 31
      assets/scenes/scene_1.symtres
  6. BIN
      assets/sounds/door_close.wav
  7. BIN
      assets/sounds/door_open.wav
  8. 2
      src/common/version.h
  9. 49
      src/game/door.c
  10. 4
      src/game/entity.c
  11. 16
      src/game/entity.h
  12. 4
      src/game/sound_source.c
  13. 3
      src/game/trigger.c
  14. 9
      todo.txt

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

Binary file not shown.

Binary file not shown.

@ -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

@ -5,12 +5,13 @@
#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)
{
@ -20,6 +21,8 @@ void door_init(struct Door* door, int mask)
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);
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;
}
}

@ -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)

@ -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;

@ -56,12 +56,11 @@ 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)
{
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;
@ -73,7 +72,6 @@ void sound_source_buffer_set(struct Sound* sound, struct Sound_Source* entity, c
{
log_error("sound_source:buffer_set", "Failed to set buffer for %s", entity->base.name);
}
}
}
bool sound_source_is_paused(struct Sound* sound, struct Sound_Source* entity)

@ -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;

@ -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
@ -413,3 +419,4 @@ Done:
* Remove ODE completely
* Fixed console not working in game mode
* 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.
Loading…
Cancel
Save