This commit is contained in:
olikraus 2017-07-14 21:59:15 +02:00
parent 6d0c9fea11
commit 4a0981d818
6 changed files with 71 additions and 12 deletions

View File

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

5
sys/sdl/gm2/info.txt Normal file
View File

@ -0,0 +1,5 @@
14 Jul 17
- introduce position struct (rewrite pos.h/c)
- use position struct in the code itself
- write hero movement code

View File

@ -67,6 +67,14 @@ void setupLevel(uint8_t level)
/* build the pool */
pool_Clear();
/* first item always is our hero (index 0) */
item = pool_GetItem(pool_NewItem());
item->x = 0;
item->y = 0;
item->tile = 0x04e;
item->template_index = 0; /* not used, but still template index should be reserverd then */
onmap_ptr = map_list[level].onmap_list;
for( i = 0; i < cnt; i++ )
{
@ -99,4 +107,5 @@ uint8_t getMapTile(uint8_t x, uint8_t y)
offset += x;
return map_list[current_level].data[offset];
}
}

View File

@ -231,16 +231,15 @@ const uint8_t scrollosprites[6642] U8G2_FONT_SECTION("scrollosprites") =
/*===============================================*/
u8g2_t u8g2;
/*===============================================*/
u8g2_t u8g2;
void map_draw(uint8_t map_idx, uint8_t x0, uint8_t y0)
{
uint8_t x, y;
uint16_t offset;
for( y = 0; y < MAP_DISPLAY_HEIGHT; y++ )
{
for( x = 0; x < MAP_DISPLAY_WIDTH; x++ )
@ -249,10 +248,7 @@ void map_draw(uint8_t map_idx, uint8_t x0, uint8_t y0)
{
if ( (uint8_t)(y+y0) < (uint8_t)map_list[map_idx].height )
{
offset = (y+y0) & 255;
offset *= map_list[map_idx].width;
offset += (x+x0) & 255;
u8g2_DrawGlyph(&u8g2, x*16, 16+y*16, map_list[map_idx].data[offset]);
u8g2_DrawGlyph(&u8g2, x*16, 16+y*16, getMapTile(x+x0, y+y0));
}
}
}
@ -261,6 +257,8 @@ void map_draw(uint8_t map_idx, uint8_t x0, uint8_t y0)
int main(void)
{
int k;

View File

@ -45,7 +45,7 @@
# itemstep <iname>
# executed every step
# - moving items can move towards hero or others
# enditemstep
# endproc
#
#
# map <name> <width> <height>
@ -138,7 +138,6 @@ tile '. $6a # stone 2
tile ': $6b # stone 3
thing 'f $74 # fire
#thing 'x $72 # door closed
thing '^ $73 # door open
thing 'C $79 # cupboard
thing 'S $7a # bookshelf
@ -150,8 +149,8 @@ thing 'h $9c # chest
thing 'H $92 # hut
thing 'K $93 # kingdom
item normal_door $73 # $73 = door open
itemkey normal_door 'x $72 # $72 = door closed
item normal_door $72 # $72 = door closed --> inital tile
itemkey normal_door 'x $73 # $73 = door open --> this will be placed on the map, the item can destroy itself, but this tile will stay
iteminit normal_door
print(add(1,2))
@ -159,6 +158,13 @@ iteminit normal_door
print(add(1234,5678))
endproc
itemhit normal_door
endproc
itemstep normal_door
endproc
map test 20 9

View File

@ -902,6 +902,46 @@ int map_read_line(const char **s)
is_inside_proc = 1;
return 1;
}
else if ( strcmp(id, "itemhit") == 0 )
{
const char *id;
int idx;
uint16_t code_pos;
id = get_identifier(s);
idx = item_get_idx_by_name(id);
code_pos = uglStartNamelessProc(0);
if ( idx < 0 )
{
printf("code line %d, item '%s' not found.\n", ugl_current_input_line, id);
}
else
{
item_list[idx].hit_proc= code_pos;
}
is_inside_proc = 1;
return 1;
}
else if ( strcmp(id, "itemstep") == 0 )
{
const char *id;
int idx;
uint16_t code_pos;
id = get_identifier(s);
idx = item_get_idx_by_name(id);
code_pos = uglStartNamelessProc(0);
if ( idx < 0 )
{
printf("code line %d, item '%s' not found.\n", ugl_current_input_line, id);
}
else
{
item_list[idx].step_proc= code_pos;
}
is_inside_proc = 1;
return 1;
}
else if ( strcmp(id, "map") == 0 )
{
is_inside_map = 1;