This commit is contained in:
olikraus 2017-07-14 13:52:01 +02:00
parent faa2783201
commit c7886ecc01
5 changed files with 134 additions and 5 deletions

View File

@ -1,6 +1,6 @@
CFLAGS = -g -Wall -Wpointer-arith -I../../../csrc/. -I../../tga/mapgen/. `sdl-config --cflags`
SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c ) ../../tga/mapgen/map.c main.c
SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c ) ../../tga/mapgen/map.c main.c item.c
OBJ = $(SRC:.c=.o)

102
sys/sdl/gm2/item.c Normal file
View File

@ -0,0 +1,102 @@
/*
item.c
during level setup, the item pool is filled with items from the
onmap list.
*/
#include "item.h"
#include "map.h"
/* max number of items in the pool */
#define ITEM_MAX 32
/* current number of items in the pool */
uint8_t item_cnt;
/* current level */
uint8_t current_level;
/* the pool with all dynamic created items */
item_t item_pool[ITEM_MAX];
void pool_Clear(void)
{
item_cnt = 0;
}
uint8_t pool_NewItem(void)
{
if ( item_cnt >= ITEM_MAX )
return ITEM_MAX;
item_cnt++;
return item_cnt-1;
}
item_t *pool_GetItem(uint8_t idx)
{
return item_pool+idx;
}
/*===============================================*/
/*
void item_SetDefaultTile(uint8_t idx)
{
item_t *item = pool_GetItem((idx);
item->tile = item_template_list[item->template_index].fg_tile;
}
*/
/*===============================================*/
void setupLevel(uint8_t level)
{
uint8_t i, cnt;
item_t *item;
item_onmap_t *onmap_ptr;
current_level = level;
cnt = map_list[level].onmap_cnt;
/* build the pool */
pool_Clear();
onmap_ptr = map_list[level].onmap_list;
for( i = 0; i < cnt; i++ )
{
/* no check of pool_NewItem() here, this should always succeed */
item = pool_GetItem(pool_NewItem());
item->x = onmap_ptr->x;
item->y = onmap_ptr->y;
item->template_index = onmap_ptr->template_index;
item->tile = item_template_list[item->template_index].fg_tile;
onmap_ptr++;
}
}
uint8_t getMapTile(uint8_t x, uint8_t y)
{
item_t *item;
uint16_t offset;
uint8_t i, cnt;
cnt = item_cnt;
for( i = 0; i < cnt; i++ )
{
item = pool_GetItem(i);
if ( item->x == x && item->y == y )
return item->tile;
}
offset = y;
offset *= map_list[current_level].width;
offset += x;
return map_list[current_level].data[offset];
}

26
sys/sdl/gm2/item.h Normal file
View File

@ -0,0 +1,26 @@
/*
item.h
*/
#ifndef _ITEM_H
#define _ITEM_H
#include <stdint.h>
struct _item_struct
{
uint8_t x;
uint8_t y;
uint8_t tile; /* current foreground tile, defaults to the value from the template list */
uint8_t template_index; /* index into item_template_list[] */
};
typedef struct _item_struct item_t;
void setupLevel(uint8_t level);
uint8_t getMapTile(uint8_t x, uint8_t y);
#endif /* _ITEM_H */

View File

@ -10,6 +10,7 @@
#include "u8g2.h"
#include "map.h"
#include "item.h"
#include <stdio.h>
#include <unistd.h>
@ -273,7 +274,8 @@ int main(void)
u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
u8g2_SetFont(&u8g2, scrollosprites);
setupLevel(0);
for(;;)

View File

@ -28,15 +28,14 @@ typedef struct _map_struct map_t;
struct _item_template_struct
{
uint8_t fg_tile; /* for tga output and inital tile */
uint8_t bg_tile; /* for the internal map */
uint16_t init_proc;
uint16_t hit_proc;
uint16_t step_proc;
uint8_t fg_tile; /* for tga output and inital tile */
};
typedef struct _item_template_struct item_template_t;
extern item_template_t item_template_list[];
extern map_t map_list[];
#endif