Better hashtable destruction. Monsters prepared.
This commit is contained in:
parent
f90a7c735e
commit
17c3b817a0
2
.vimrc
2
.vimrc
|
@ -1,3 +1,3 @@
|
|||
nnoremap <F1> :Make -C build --no-print-directory -l<cr>
|
||||
set makeprg=make\ -C\ build\ --no-print-directory\ -l
|
||||
let g:syntastic_c_include_dirs = [ 'linkedlist' ]
|
||||
let g:syntastic_c_include_dirs = [ 'linkedlist', 'hashtable' ]
|
||||
|
|
|
@ -43,6 +43,7 @@ add_executable(breakhack
|
|||
src/timer
|
||||
src/roommatrix
|
||||
src/position
|
||||
src/monster
|
||||
)
|
||||
|
||||
target_link_libraries(breakhack
|
||||
|
|
10
TODO.txt
10
TODO.txt
|
@ -1,10 +1,14 @@
|
|||
x Add walls and stuff to maps
|
||||
- Implement simple box collisions
|
||||
- Add enemies (generated through lua)
|
||||
- Htting enemies
|
||||
x Implement simple box collisions
|
||||
o Add enemies (generated through lua)
|
||||
x Monster object created
|
||||
- Lua bindings for creation
|
||||
- Hitting enemies
|
||||
- Moving enemies
|
||||
- Lower levels
|
||||
- XP
|
||||
- gui
|
||||
- Items
|
||||
- More gui
|
||||
|
||||
Legend: ( '-' = future) ( 'x' = completed ) ( 'o' = begun )
|
||||
|
|
|
@ -127,6 +127,12 @@ ht_get(Hashtable *table, char *key)
|
|||
|
||||
void
|
||||
ht_destroy(Hashtable *table)
|
||||
{
|
||||
ht_destroy_custom(table, free);
|
||||
}
|
||||
|
||||
void
|
||||
ht_destroy_custom(Hashtable *table, void (*destroy_value)(void *value))
|
||||
{
|
||||
Entry *entry, *next;
|
||||
unsigned int i;
|
||||
|
@ -141,11 +147,12 @@ ht_destroy(Hashtable *table)
|
|||
continue;
|
||||
while (entry) {
|
||||
next = entry->next;
|
||||
free(entry->value);
|
||||
destroy_value(entry->value);
|
||||
entry->value = NULL;
|
||||
free(entry);
|
||||
entry = next;
|
||||
}
|
||||
}
|
||||
free(table->entries);
|
||||
free(table);
|
||||
}
|
||||
|
|
|
@ -20,4 +20,6 @@ void* ht_get(Hashtable*, char *key);
|
|||
|
||||
void ht_destroy(Hashtable*);
|
||||
|
||||
void ht_destroy_custom(Hashtable*, void (*destroy_value)(void*));
|
||||
|
||||
#endif // HASHTABLE_H_
|
||||
|
|
|
@ -24,6 +24,8 @@ Map* map_create()
|
|||
|
||||
Map *map = ec_malloc(sizeof(Map));
|
||||
map->textures = linkedlist_create();
|
||||
map->monsterTextures = ht_create(100);
|
||||
map->monsters = linkedlist_create();
|
||||
map->currentRoom = (Position) { 0, 0 };
|
||||
map->renderTimer = timer_create();
|
||||
map->level = 1;
|
||||
|
@ -191,8 +193,12 @@ void map_destroy(Map *map)
|
|||
}
|
||||
}
|
||||
while (map->textures != NULL) {
|
||||
texture_destroy(linkedlist_poplast(&map->textures));
|
||||
texture_destroy(linkedlist_pop(&map->textures));
|
||||
}
|
||||
while (map->monsters != NULL) {
|
||||
monster_destroy(linkedlist_pop(&map->textures));
|
||||
}
|
||||
ht_destroy_custom(map->monsterTextures, (void (*)(void*)) texture_destroy);
|
||||
timer_destroy(map->renderTimer);
|
||||
free(map);
|
||||
}
|
||||
|
|
|
@ -4,12 +4,14 @@
|
|||
#include <SDL2/SDL.h>
|
||||
#include <stdbool.h>
|
||||
#include <linkedlist.h>
|
||||
#include <hashtable.h>
|
||||
|
||||
#include "sprite.h"
|
||||
#include "camera.h"
|
||||
#include "position.h"
|
||||
#include "timer.h"
|
||||
#include "defines.h"
|
||||
#include "monster.h"
|
||||
|
||||
typedef struct MapTile_t {
|
||||
int textureIndex0;
|
||||
|
@ -28,6 +30,8 @@ typedef struct Room_t {
|
|||
typedef struct Map_t {
|
||||
Room* rooms[MAP_H_ROOM_COUNT][MAP_V_ROOM_COUNT];
|
||||
LinkedList *textures;
|
||||
Hashtable *monsterTextures;
|
||||
LinkedList *monsters;
|
||||
Position currentRoom;
|
||||
Timer *renderTimer;
|
||||
int level;
|
||||
|
@ -35,6 +39,8 @@ typedef struct Map_t {
|
|||
|
||||
Map* map_create();
|
||||
|
||||
void map_add_monster(Map*, Monster*);
|
||||
|
||||
int map_add_texture(Map*, const char *path, SDL_Renderer*);
|
||||
|
||||
void map_add_tile(Map *map, Position *tile_pos, MapTile*);
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#include "monster.h"
|
||||
#include "util.h"
|
||||
|
||||
Monster*
|
||||
monster_create()
|
||||
{
|
||||
Monster *m = ec_malloc(sizeof(Monster));
|
||||
m->sprite = sprite_create();
|
||||
return m;
|
||||
}
|
||||
|
||||
void
|
||||
monster_destroy(Monster *m)
|
||||
{
|
||||
sprite_destroy(m->sprite);
|
||||
free(m);
|
||||
}
|
|
@ -10,4 +10,8 @@ typedef struct {
|
|||
Stats stats;
|
||||
} Monster;
|
||||
|
||||
Monster* monster_create();
|
||||
|
||||
void monster_destroy(Monster*);
|
||||
|
||||
#endif // MONSTER_H_
|
||||
|
|
Loading…
Reference in New Issue