94 lines
2.3 KiB
C
94 lines
2.3 KiB
C
/****
|
|
|
|
***/
|
|
#include <stdlib.h>
|
|
#include "main.h"
|
|
#include "common.h"
|
|
#include "game.h"
|
|
#include "map.h"
|
|
#include "wall.h"
|
|
#include "display.h"
|
|
#include "tile.h"
|
|
#include "context.h"
|
|
#include "player.h"
|
|
|
|
int gameInit() {
|
|
null_tile.tid = 0;
|
|
player.tid = 1;
|
|
player.id = 12;
|
|
current_context = &walkContext;
|
|
allocateMap(¤t_map, 32, 16);
|
|
floodMap(¤t_map, TILE_REPLACE, FLOOR, STONE);
|
|
gameMoveTile(&player, 2, 2);
|
|
|
|
drawPath(¤t_map, TILE_APPEND, WALL, STONE, 6, 1, 8, 12);
|
|
drawPath(¤t_map, TILE_APPEND, WALL, STONE, 12, 4, 7, 13);
|
|
|
|
drawLine(¤t_map, TILE_APPEND, WALL, STONE, 0, 0, 31, 0);
|
|
drawLine(¤t_map, TILE_APPEND, WALL, STONE, 0, 15, 31, 15);
|
|
drawLine(¤t_map, TILE_APPEND, WALL, STONE, 0, 0, 0, 15);
|
|
drawLine(¤t_map, TILE_APPEND, WALL, STONE, 31, 0, 31, 15);
|
|
return SUCCESS;
|
|
}
|
|
|
|
void gameLoop() {
|
|
}
|
|
|
|
void gameClose() {
|
|
// FIXME: breaks on SDL OS X
|
|
freeMap(¤t_map);
|
|
}
|
|
|
|
int gameCollision(target_x, target_y) {
|
|
if (target_x < 0 || target_y < 0 || target_y > current_map->height-1 || target_x > current_map->width-1)
|
|
return 1; // don't go off the map, bb
|
|
struct Tile *debug_tile;
|
|
debug_tile = &(current_map->matrix[target_x][target_y]);
|
|
// TODO: call collision functions for each tile type
|
|
while(debug_tile) {
|
|
switch(debug_tile->tid) {
|
|
case WALL:
|
|
return 1;
|
|
break;
|
|
case FLOOR:
|
|
// return 0;
|
|
break;
|
|
}
|
|
debug_tile = debug_tile->next;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void gameMoveTile(struct Tile *tile, int target_x, int target_y) {
|
|
// remove tile from chain and connect tile's neighbors to each other
|
|
if (tile->prev != NULL) {
|
|
if (tile->next != NULL) {
|
|
tile->prev->next = tile->next;
|
|
} else {
|
|
tile->prev->next = NULL;
|
|
}
|
|
}
|
|
if (tile->next != NULL) {
|
|
tile->next->prev = tile->prev;
|
|
}
|
|
// now add tile to the end of the target chain
|
|
struct Tile *target_loc;
|
|
target_loc = &(current_map->matrix[target_x][target_y]);
|
|
while (target_loc) {
|
|
if (!target_loc->next) { // last element
|
|
target_loc->next = tile;
|
|
tile->prev = target_loc;
|
|
tile->next = NULL;
|
|
break;
|
|
}
|
|
target_loc = target_loc->next;
|
|
}
|
|
// finally, update tile's x and y props
|
|
tile->x = target_x;
|
|
tile->y = target_y;
|
|
}
|
|
|
|
void gameUpdateTile(int x, int y) {
|
|
display_map[x][y] = 2;
|
|
}
|