t
This commit is contained in:
		
							
								
								
									
										17
									
								
								src/dawn/rpg/cutscene/cutscene.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/dawn/rpg/cutscene/cutscene.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| /** | ||||
|  * Copyright (c) 2024 Dominic Masters | ||||
|  *  | ||||
|  * This software is released under the MIT License. | ||||
|  * https://opensource.org/licenses/MIT | ||||
|  */ | ||||
|  | ||||
| #pragma once | ||||
| #include "dusk.h" | ||||
|  | ||||
| typedef struct { | ||||
|  | ||||
| } cutsceneevent_t; | ||||
|  | ||||
| typedef struct { | ||||
|    | ||||
| } cutscene_t; | ||||
| @@ -9,6 +9,7 @@ | ||||
| #include "entitydirection.h" | ||||
| #include "rpg/world/map.h" | ||||
| #include "assert/assert.h" | ||||
| #include "time.h" | ||||
|  | ||||
| void entityInit( | ||||
|   entity_t *entity, | ||||
| @@ -42,20 +43,36 @@ void entityInit( | ||||
| void entityUpdate(entity_t *entity) { | ||||
|   assertNotNull(entity, "Entity cannot be NULL."); | ||||
|  | ||||
|   switch(entity->type) { | ||||
|     case ENTITY_TYPE_NULL: | ||||
|       assertUnreachable("Should not be updating a NULL entity."); | ||||
|   switch(entity->state) { | ||||
|     case ENTITY_STATE_IDLE: | ||||
|       switch(entity->type) { | ||||
|         case ENTITY_TYPE_NULL: | ||||
|           assertUnreachable("Should not be updating a NULL entity."); | ||||
|           break; | ||||
|  | ||||
|         case ENTITY_TYPE_PLAYER: | ||||
|           playerUpdate(entity); | ||||
|           break; | ||||
|  | ||||
|         case ENTITY_TYPE_NPC: | ||||
|           break; | ||||
|  | ||||
|         default: | ||||
|           assertUnreachable("Unknown entity type."); | ||||
|       } | ||||
|       break; | ||||
|  | ||||
|     case ENTITY_TYPE_PLAYER: | ||||
|       playerUpdate(entity); | ||||
|     case ENTITY_STATE_WALKING: | ||||
|       entity->walk.time -= TIME.delta; | ||||
|       if(entity->walk.time > 0.0f) return; | ||||
|       entity->state = ENTITY_STATE_IDLE; | ||||
|       break; | ||||
|  | ||||
|     case ENTITY_TYPE_NPC: | ||||
|     case ENTITY_STATE_TALKING: | ||||
|       break; | ||||
|  | ||||
|     default: | ||||
|       assertUnreachable("Unknown entity type."); | ||||
|       assertUnreachable("Unknown entity state."); | ||||
|   } | ||||
| } | ||||
|  | ||||
| @@ -93,6 +110,9 @@ void entityWalk(entity_t *entity, const uint8_t dir) { | ||||
|   // Commit to move | ||||
|   entity->x = newX; | ||||
|   entity->y = newY; | ||||
|  | ||||
|   entity->state = ENTITY_STATE_WALKING; | ||||
|   entity->walk.time = 0.0f; | ||||
| } | ||||
|  | ||||
| void entityPositionSet(entity_t *entity, const uint16_t x, const uint16_t y) { | ||||
|   | ||||
| @@ -12,8 +12,16 @@ | ||||
| #define ENTITY_TYPE_PLAYER 1 | ||||
| #define ENTITY_TYPE_NPC 2 | ||||
|  | ||||
| #define ENTITY_STATE_IDLE 0 | ||||
| #define ENTITY_STATE_WALKING 1 | ||||
| #define ENTITY_STATE_TALKING 2 | ||||
|  | ||||
| typedef struct _map_t map_t; | ||||
|  | ||||
| typedef struct { | ||||
|   float_t time; | ||||
| } entitywalkstate_t; | ||||
|  | ||||
| typedef struct _entity_t { | ||||
|   map_t *map; | ||||
|   uint8_t type; | ||||
| @@ -21,7 +29,14 @@ typedef struct _entity_t { | ||||
|   uint16_t y; | ||||
|   uint8_t layer; | ||||
|   uint8_t direction; | ||||
|   uint8_t state; | ||||
|  | ||||
|   // State | ||||
|   union { | ||||
|     entitywalkstate_t walk; | ||||
|   }; | ||||
|  | ||||
|   // Type | ||||
|   union { | ||||
|     player_t player; | ||||
|   }; | ||||
|   | ||||
| @@ -41,6 +41,9 @@ void playerUpdate(entity_t *entity) { | ||||
|         target->x, target->y, | ||||
|         entity->x, entity->y | ||||
|       ); | ||||
|  | ||||
|       target->state = ENTITY_STATE_TALKING; | ||||
|       entity->state = ENTITY_STATE_TALKING; | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user