Merge branch 'master' of ssh://kettek.exoss.net:4422/srv/eureka/timesynk

master
Vex 2014-04-07 19:40:52 -07:00
commit 543e714c86
9 changed files with 87 additions and 15 deletions

View File

@ -133,3 +133,40 @@ int moveTile(struct Map *map, struct Tile *tile, float x, float y, float z) {
tile->z = target_z;
return 0;
}
int addTileToMap(struct Map *map, struct Tile *tile, float x, float y, float z) {
if (map == NULL)
return -1;
if (tile == NULL)
return -2;
int tile_x = (int)x;
int tile_y = (int)y;
int tile_z = (int)z;
// if out of bounds, add to nearest cell
if (tile_x >= map->width) {
tile_x = map->width-1;
} else if (tile_x < 0) {
tile_x = 0;
}
if (tile_y >= map->height) {
tile_y = map->height-1;
} else if (tile_y < 0) {
tile_y = 0;
}
if (tile_z >= map->depth) {
tile_z = map->depth-1;
} else if (tile_z < 0) {
tile_z = 0;
}
// set tile's x, y, and z params
tile->x = tile_x;
tile->y = tile_y;
tile->z = tile_z;
if (map->tiles[tile_x][tile_y][tile_z] == NULL) {
map->tiles[tile_x][tile_y][tile_z] = tile;
return 0;
}
// if existing, append to tile linked list there
appendTile(map->tiles[tile_x][tile_y][tile_z], tile);
return 0;
}

View File

@ -13,6 +13,6 @@ struct Map *newMap(int width, int height, int depth);
int nullMap(struct Map *map);
void freeMap(struct Map *map, int flags);
int moveTile(struct Map *map, struct Tile *tile, float x, float y, float z);
int addTileToMap(struct Map *map, struct Tile *tile, float x, float y, float z);
#endif

View File

@ -14,7 +14,7 @@ Called once when switching to this state. Used to load whatever data used during
================================
*/
void initTestState() {
if ((test_map = newMap(32, 32, 2)) == NULL) {
if ((test_map = newMap(32, 32, 4)) == NULL) {
printf("ERROR: failed to allocate map!\n");
stopRunning();
return;
@ -22,17 +22,29 @@ void initTestState() {
int x,y,z;
for (x=0;x < test_map->width;x++) {
for (y=0;y < test_map->height;y++) {
test_map->tiles[x][y][0] = newTile(x, y, 0, getTileDataById(g_tile_data, 2, 0));
addTileToMap(test_map, newTile(getTileDataById(g_tile_data, 2, 0)), x, y, 0);
}
}
for (x=8;x < 9;x++) {
for (y=0;y < test_map->height;y++) {
test_map->tiles[x][y][1] = newTile(x, y, 1, getTileDataById(g_tile_data, 3, 0));
addTileToMap(test_map, newTile(getTileDataById(g_tile_data, 3, 0)), x, y, 1);
}
}
test_player_tile = newTile(2, 2, 1, getTileDataById(g_tile_data, 0, 0));
int i = 0;
z = 0;
x = 0;
for (i=0;i < 3;i++) {
for (z = 0; z < 8;z++) {
//for(x = 12;x < 16;x++) {
//test_map->tiles[x][9][0]->next = newTile(getTileDataById(g_tile_data, 7, i));
addTileToMap(test_map, newTile(getTileDataById(g_tile_data, 8, i)), x+i, 9, z);
//}
}
}
test_player_tile = newTile(getTileDataById(g_tile_data, 0, 0));
test_map->tiles[2][2][1] = test_player_tile;
key_press[0] = 0;
@ -72,22 +84,22 @@ void processTestState(int delta) {
while(s_accumulator >= g_tick_time.n) {
if (key_press[0] == 1) {
test_player_tile->set = 4;
moveTile(test_map, test_player_tile, -0.1f, 0.0f, 0.0f);
moveTile(test_map, test_player_tile, -0.5f, 0.0f, 0.0f);
//moveTile(test_map, test_player_tile, -1.0f, 0.0f, 0.0f);
}
if (key_press[1] == 1) {
test_player_tile->set = 5;
moveTile(test_map, test_player_tile, 0.0f, 0.1f, 0.0f);
moveTile(test_map, test_player_tile, 0.0f, 0.5f, 0.0f);
//moveTile(test_map, test_player_tile, 0.0f, 1.0f, 0.0f);
}
if (key_press[2] == 1) {
test_player_tile->set = 6;
moveTile(test_map, test_player_tile, 0.1f, 0.0f, 0.0f);
moveTile(test_map, test_player_tile, 0.5f, 0.0f, 0.0f);
//moveTile(test_map, test_player_tile, 1.0f, 0.0f, 0.0f);
}
if (key_press[3] == 1) {
test_player_tile->set = 7;
moveTile(test_map, test_player_tile, 0.0f, -0.1f, 0.0f);
moveTile(test_map, test_player_tile, 0.0f, -0.5f, 0.0f);
//moveTile(test_map, test_player_tile, 0.0f, -1.0f, 0.0f);
}
@ -123,6 +135,7 @@ void renderTestState() {
int id = tile->data->id;
int pix_x = tile->x * g_module_spritesheets[tile->data->tid]->s_width;
int pix_y = (tile->y * g_module_spritesheets[tile->data->tid]->s_height)/2;
pix_y -= (tile->z * (g_module_spritesheets[tile->data->tid]->s_height/4));
g_renderSprite(g_module_spritesheets[tile->data->tid], g_screen, id, pix_x, pix_y);
tile = tile->next;

View File

@ -1,12 +1,11 @@
#include <stdlib.h>
#include "tile.h"
struct Tile *newTile(float x, float y, float z, struct TileData *data) {
struct Tile *newTile(struct TileData *data) {
struct Tile *tile = malloc(sizeof(struct Tile));
//printf("%fx%fx%f\n", x, y, z);
tile->x = x;
tile->y = y;
tile->z = z;
tile->x = 0.0f;
tile->y = 0.0f;
tile->z = 0.0f;
tile->set = 0;
tile->frame = 0;
tile->data = duplicateTileData(data);
@ -23,7 +22,10 @@ void freeTile(struct Tile *tile) {
free(tile);
}
// TODO: return non-VOID and check for NULL tile_target and new_tile
void appendTile(struct Tile *tile_target, struct Tile *new_tile) {
if (tile_target == NULL)
return;
if (new_tile == tile_target)
return;
struct Tile *current_tile = tile_target;

View File

@ -13,7 +13,7 @@ struct Tile {
struct Tile *prev;
};
struct Tile *newTile(float x, float y, float z, struct TileData *data);
struct Tile *newTile(struct TileData *data);
void freeTile(struct Tile *tile);
void appendTile(struct Tile *tile_target, struct Tile *new_tile);

View File

@ -19,6 +19,7 @@ sprites {
5 items
6 materials
7 spells
8 shapes
}
; list of playable characters for character creation
chars {

View File

@ -85,3 +85,11 @@ spells {
set 1
frame 1
}
shapes {
width 16
height 32
columns 4
set 1
frame 1
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

View File

@ -118,3 +118,14 @@ name stone wall
name wood wall
}
}
8 {
0 {
name box
}
1 {
name sphere
}
2 {
name pyramid
}
}