--- /dev/null
+#include "board.h"
+#include <stdlib.h>
+
+typedef struct {
+ Tile ***tiles;
+ Point2i dimensions;
+} Board_t;
+
+Board *board_init(int sizex, int sizey)
+{
+ Board *ret = NULL;
+ Board_t *b = malloc(sizeof(Board_t));
+ int sizet = sizex * sizey;
+
+ b->dimensions.x = sizex;
+ b->dimensions.y = sizey;
+ b->tiles = malloc(sizet * sizeof(Tile));
+
+ for(int i = 0; i < sizey; ++i){
+ b->tiles[i] = malloc(sizex * sizeof(Tile));
+ for(int j = 0; j < sizex; ++j){
+ b->tiles[i][j] = tile_init(point3i(i,j,1), PLAINS);
+ }
+ }
+
+ return ret;
+}
+
+void board_cleanup(Board *b)
+{
+ Board_t *bt = (Board_t *) b;
+
+ for(int i = 0; i < bt->dimensions.x; ++i){
+ for(int j = 0; j < bt->dimensions.y; ++j){
+ tile_cleanup(bt->tiles[i][j]);
+ }
+ }
+
+ for(int j = 0; j < bt->dimensions.y; ++j){
+ free(bt->tiles[j]);
+ }
+ free(bt->tiles);
+}
+
+Tile* board_tile_at(Board* b, Point2i point)
+{
+ Board_t *bt = (Board_t *) b;
+ if (point.x > bt->dimensions.x || point.x < 0 ||
+ point.y > bt->dimensions.y || point.y < 0 ){
+ return NULL;
+ }
+
+ return bt->tiles[point.x][point.y];
+}
--- /dev/null
+#ifndef BOARD_H
+#define BOARD_H
+#include "point.h"
+#include "tile.h"
+
+typedef struct {} Board;
+
+Board *board_init(int sizex, int sizey);
+void board_cleanup(Board* b);
+Tile* board_tile_at(Board* b, Point2i point);
+#endif//BOARD_H
--- /dev/null
+#include "point.h"
+
+Point2i point2i(int x, int y)
+{
+ Point2i p;
+ p.x = x;
+ p.y = y;
+ return p;
+}
+Point3i point3i(int x, int y, int z)
+{
+ Point3i p;
+ p.x = x;
+ p.y = y;
+ p.z = z;
+ return p;
+}
+Point4i point4i(int w, int x, int y, int z)
+{
+ Point4i p;
+ p.w = w;
+ p.x = x;
+ p.y = y;
+ p.z = z;
+ return p;
+}
+
+Point2f point2f(int x, int y)
+{
+ Point2f p;
+ p.x = x;
+ p.y = y;
+ return p;
+}
+Point3f point3f(int x, int y, int z)
+{
+ Point3f p;
+ p.x = x;
+ p.y = y;
+ p.z = z;
+ return p;
+}
+Point4f point4f(int w, int x, int y, int z)
+{
+ Point4f p;
+ p.w = w;
+ p.x = x;
+ p.y = y;
+ p.z = z;
+ return p;
+}
typedef struct { float x, y; } Point2f;
typedef struct { float x, y, z; } Point3f;
typedef struct { float w, x, y, z; } Point4f;
+
+Point2i point2i(int x, int y);
+Point3i point3i(int x, int y, int z);
+Point4i point4i(int w, int x, int y, int z);
+
+Point2f point2f(float x, float y);
+Point3f point3f(float x, float y, float z);
+Point4f point4f(float w, float x, float y, float z);
#endif//POINT_H
#include <stdio.h>
#include <stdbool.h>
#include <SDL2/SDL.h>
-#include "tile.h"
+#include "board.h"
#include "point.h"
-
-static Tile *tile = NULL;
-static Point3i pos;
+static Board* board = NULL;
bool init()
{
return false;
}
- pos.x = 1;
- pos.y = 2;
- pos.z = 3;
-
- tile = tile_init(pos, D_WATER);
-
- pos.x = pos.y = pos.z = 0;
- pos = tile_position(tile);
-
- if(tile == NULL){
- printf("ERROR: tile null!");
+ board = board_init(5,3);
+ if(board == NULL){
+ printf("ERROR: board null!");
return false;
}
return true;
Uint32 itime = SDL_GetTicks();
Uint32 ctime = 0;
int i = 0;
+ Point2i loc;
+ Tile* sel = NULL;
+
+ for(int i = 0; i < 5; ++i){
+ for(int j = 0; j < 3; ++j){
+ loc.x = i;
+ loc.y = j;
+ sel = board_tile_at(board, loc);
+ if(sel == NULL){
+ printf("N");
+ } else {
+ printf("#");
+ }
+ }
+ }
- printf("Tile pos - (%d,%d,%d), ter - %d\n",
- pos.x, pos.y, pos.z, tile_terrain(tile));
strcpy(str, "Hello... |");
strcpy(rot, "|/-\\");
printf("%s", str);