return NULL;
}
-tower_base_t *setup_tower_base(engine_t *self, int type, int cost) {
- tower_base_t *base = engine_get_tower_base(self, type);
- if (base) // already configured
- return NULL;
-
- base = array_new(self->tbases);
- init_tower_base(base, type);
- base->cost = cost;
- return base;
-}
-
-int setup_wave(engine_t *self, int start_tick, int bits) {
- wave_t *wave = array_new(self->waves);
- if (!wave)
- return 0;
-
- init_wave(wave, start_tick);
- wave->bits = bits;
-
- return 1;
-}
-
-enemy_t *setup_enemy(engine_t *self, int type, int id, size_t start_tick) {
- if (!self->waves->count)
- if (!setup_wave(self, 0, 0))
- return 0;
-
- //TODO: type and eney_base_t
-
- wave_t *wave = array_last(self->waves);
- return wave_add_enemy(wave, id, start_tick);
-}
-
-int setup_path(engine_t *self, int x, int y) {
- if (x < 0 || y < 0)
- return 0;
- if (x >= self->map->width || y >= self->map->height)
- return 0;
- if (self->map->data[y * self->map->width + x])
- return 0;
-
- path_t *loc = array_new(self->map->paths);
- init_path(loc, x, y);
- loc->index = self->map->paths->count - 1;
-
- self->map->data[y * self->map->width + x] = path2any(loc);
- return 1;
-}
-
tower_base_t *engine_get_tower_base(engine_t *self, int type);
-tower_base_t *setup_tower_base(engine_t *self, int type, int cost);
-
-int setup_wave(engine_t *self, int start_tick, int bits);
-
-enemy_t *setup_enemy(engine_t *self, int type, int id, size_t start_tick);
-
-int setup_path(engine_t *self, int x, int y);
-
#endif /* ENGINE_H */
}
}
+int map_add_path(map_t *self, int x, int y) {
+ if (x < 0 || y < 0)
+ return 0;
+ if (x >= self->width || y >= self->height)
+ return 0;
+ if (self->data[y * self->width + x])
+ return 0;
+
+ path_t *loc = array_new(self->paths);
+ if (!loc)
+ return 0;
+
+ init_path(loc, x, y);
+ loc->index = self->paths->count - 1;
+
+ self->data[y * self->width + x] = path2any(loc);
+ return 1;
+}
+
void map_enemy_enters(map_t *self, enemy_t *enemy, array_t *events) {
enemy->alive = 1;
array_push(self->alive, &enemy);
*/
void uninit_map(map_t *self);
+int map_add_path(map_t *self, int x, int y);
+
void map_enemy_enters(map_t *self, enemy_t *enemy, array_t *events);
void map_move_1(map_t *self, array_t *events);
--- /dev/null
+/*
+ * TDef: small tower defense game
+ *
+ * Copyright (C) 2025 Niki Roo
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "setup.h"
+
+tower_base_t *setup_tower_base(engine_t *self, int type, int cost) {
+ tower_base_t *base = engine_get_tower_base(self, type);
+ if (base) // already configured
+ return NULL;
+
+ base = array_new(self->tbases);
+ init_tower_base(base, type);
+ base->cost = cost;
+
+ return base;
+}
+
+int setup_wave(engine_t *self, int start_tick, int bits) {
+ wave_t *wave = array_new(self->waves);
+ if (!wave)
+ return 0;
+
+ init_wave(wave, start_tick);
+ wave->bits = bits;
+
+ return 1;
+}
+
+enemy_t *setup_enemy(engine_t *self, int type, int id, size_t start_tick) {
+ if (!self->waves->count)
+ if (!setup_wave(self, 0, 0))
+ return 0;
+
+ //TODO: type and eney_base_t
+
+ wave_t *wave = array_last(self->waves);
+ return wave_add_enemy(wave, id, start_tick);
+}
+
+int setup_path(engine_t *self, int x, int y) {
+ return map_add_path(self->map, x, y);
+}
+
--- /dev/null
+/**
+ * @file setup.h
+ * @author Niki
+ * @date 2025
+ *
+ * @brief bla
+ *
+ * blablabla
+ *
+ */
+
+#ifndef SETUP_H
+#define SETUP_H
+
+#include "engine.h"
+
+tower_base_t *setup_tower_base(engine_t *self, int type, int cost);
+
+int setup_wave(engine_t *self, int start_tick, int bits);
+
+enemy_t *setup_enemy(engine_t *self, int type, int id, size_t start_tick);
+
+int setup_path(engine_t *self, int x, int y);
+
+#endif /* SETUP_H */
#include "engine.h"
#include "reader.h"
#include "event.h"
+#include "command.h"
+#include "setup.h"
int displayMode = 0;