gm2
This commit is contained in:
parent
17e07322ca
commit
b6d68ea357
|
@ -1,14 +1,30 @@
|
|||
CFLAGS = -g -Wall -Wpointer-arith -I. -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
|
||||
GMSRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c )
|
||||
GMSRC += map.c main.c item.c
|
||||
GMSRC += ../../../tools/ugl/ugl_bc.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
GMOBJ = $(GMSRC:.c=.o)
|
||||
|
||||
gm: $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) `sdl-config --libs` -o gm
|
||||
|
||||
MAPGENSRC = $(shell ls ../../../csrc/*.c) mapgen.c u8g2_d_tga.c
|
||||
MAPGENSRC += ../../../tools/ugl/ugl_arrays.c
|
||||
MAPGENSRC += ../../../tools/ugl/ugl_error.c
|
||||
MAPGENSRC += ../../../tools/ugl/ugl_parse.c
|
||||
#MAPGENSRC += ../../../tools/ugl/ugl_bc.c
|
||||
|
||||
MAPGENOBJ = $(MAPGENSRC:.c=.o)
|
||||
|
||||
|
||||
|
||||
gm: $(GMOBJ) map.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $(GMOBJ) `sdl-config --libs` -o gm
|
||||
|
||||
mapgen: $(MAPGENOBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $(MAPGENOBJ) -o mapgen
|
||||
|
||||
map.c: mapgen gm.map
|
||||
./mapgen -o map.c gm.map
|
||||
|
||||
clean:
|
||||
-rm $(OBJ) u8g2_sdl
|
||||
-rm $(GMOBJ) $(MAPGENOBJ) gm mapgen map.c
|
||||
|
||||
|
|
|
@ -0,0 +1,204 @@
|
|||
#
|
||||
# gm.map
|
||||
#
|
||||
# Syntax:
|
||||
# 'hash' introduces a comment
|
||||
# tile <ascii> <mapto> <top> <right> <bottom> <left>
|
||||
# map the <ascii> code to the specified <mapto> code, if the other for tiles match
|
||||
# If one of the other four tiles is 0, then ignore this tile (wildcard)
|
||||
# thing ... same as tile, but can be redefined at any time, should redefine to char
|
||||
# itemkey <iname> <ascii> <bg-tile> ... similar thing, but will connect to an item and assign the <backgroundmapto> instead
|
||||
#
|
||||
# summery:
|
||||
# tile: static fixed thing for all maps
|
||||
# thing: static thing for some maps
|
||||
# itemkey: dynamic objects like changing doors, boxes or monsters
|
||||
#
|
||||
# item <iname> <foregroundmapto>
|
||||
# defines a global template for an object.
|
||||
# anyting on the map, which might disappear, move or change has to be an item
|
||||
# itemuse <iname> <ascii>
|
||||
# only within active map. <mapto> will be the background tile for the char
|
||||
# the current foreground tile might still be differrent and is set during iteminit
|
||||
# connects the ascii char with the given ascii char on the map to get the xy pos.
|
||||
# iteminit <iname>
|
||||
# <procedure>
|
||||
# endproc
|
||||
# procedure, which is called, when the item is created,
|
||||
# receives position, where it should be created on the map
|
||||
# itemhit <iname>
|
||||
# procedure, which is called, when the item is hit by something
|
||||
# - returns 0 if the item hitting item has to be stopped
|
||||
# - may move itself
|
||||
# - may change its own shape (tile)
|
||||
# - may modify its status
|
||||
# endproc
|
||||
#
|
||||
# example "normal door, status=closed"
|
||||
# 1. hit: status=open, change tile to open door, return 0
|
||||
# 2. hit: return 1 (hero can pass)
|
||||
# example "creature, status=5 life"
|
||||
# 1. hit: get hitting obj attac damage, reduce life --> status=2, apply attack damage hitting object, return 0
|
||||
# 2. hit: get hitting obj attac damage, reduce life --> status=0, remove object from map, return 0
|
||||
# 3. hero can continue
|
||||
#
|
||||
# itemstep <iname>
|
||||
# executed every step
|
||||
# - moving items can move towards hero or others
|
||||
# endproc
|
||||
# mapinit
|
||||
# executed during map init
|
||||
# endproc
|
||||
#
|
||||
#
|
||||
# map <name> <width> <height>
|
||||
# Create a map with the given name and size. this must be followed by :
|
||||
# endmap
|
||||
# Finish the current map
|
||||
#
|
||||
tile 32 32 # map space to space
|
||||
tile '+ $80 0 '- '| 0
|
||||
tile '+ $80 0 '- '+ 0
|
||||
tile '+ $80 0 '+ '| 0
|
||||
tile '+ $80 0 '+ '+ 0
|
||||
|
||||
tile '+ $81 0 0 '| '-
|
||||
tile '+ $81 0 0 '+ '-
|
||||
tile '+ $81 0 0 '| '+
|
||||
tile '+ $81 0 0 '+ '+
|
||||
|
||||
tile '+ $82 '| '- 0 0
|
||||
tile '+ $82 '+ '- 0 0
|
||||
tile '+ $82 '| '+ 0 0
|
||||
tile '+ $82 '+ '+ 0 0
|
||||
|
||||
tile '+ $83 '| 0 0 '-
|
||||
tile '+ $83 '+ 0 0 '-
|
||||
tile '+ $83 '| 0 0 '+
|
||||
tile '+ $83 '+ 0 0 '+
|
||||
|
||||
tile '+ $84 '| '- '| 0
|
||||
tile '+ $84 '+ '- '| 0
|
||||
tile '+ $84 '| '+ '| 0
|
||||
tile '+ $84 '+ '+ '| 0
|
||||
tile '+ $84 '| '- '+ 0
|
||||
tile '+ $84 '+ '- '+ 0
|
||||
tile '+ $84 '| '+ '+ 0
|
||||
tile '+ $84 '+ '+ '+ 0
|
||||
|
||||
|
||||
tile '+ $85 '| 0 '| '-
|
||||
tile '+ $85 '+ 0 '| '-
|
||||
tile '+ $85 '| 0 '+ '-
|
||||
tile '+ $85 '+ 0 '+ '-
|
||||
tile '+ $85 '| 0 '| '+
|
||||
tile '+ $85 '+ 0 '| '+
|
||||
tile '+ $85 '| 0 '+ '+
|
||||
tile '+ $85 '+ 0 '+ '+
|
||||
|
||||
tile '+ $86 0 '- '| '-
|
||||
tile '+ $86 0 '+ '| '-
|
||||
tile '+ $86 0 '- '+ '-
|
||||
tile '+ $86 0 '+ '+ '-
|
||||
tile '+ $86 0 '- '| '+
|
||||
tile '+ $86 0 '+ '| '+
|
||||
tile '+ $86 0 '- '+ '+
|
||||
tile '+ $86 0 '+ '+ '+
|
||||
|
||||
tile '+ $87 '| '- 0 '-
|
||||
tile '+ $87 '+ '- 0 '-
|
||||
tile '+ $87 '| '+ 0 '-
|
||||
tile '+ $87 '+ '+ 0 '-
|
||||
tile '+ $87 '| '- 0 '+
|
||||
tile '+ $87 '+ '- 0 '+
|
||||
tile '+ $87 '| '+ 0 '+
|
||||
tile '+ $87 '+ '+ 0 '+
|
||||
|
||||
tile '+ $88 '| '- '| '-
|
||||
tile '+ $88 '+ '- '| '-
|
||||
tile '+ $88 '| '+ '| '-
|
||||
tile '+ $88 '+ '+ '| '-
|
||||
tile '+ $88 '| '- '+ '-
|
||||
tile '+ $88 '+ '- '+ '-
|
||||
tile '+ $88 '| '+ '+ '-
|
||||
tile '+ $88 '+ '+ '+ '-
|
||||
tile '+ $88 '| '- '| '+
|
||||
tile '+ $88 '+ '- '| '+
|
||||
tile '+ $88 '| '+ '| '+
|
||||
tile '+ $88 '+ '+ '| '+
|
||||
tile '+ $88 '| '- '+ '+
|
||||
tile '+ $88 '+ '- '+ '+
|
||||
tile '+ $88 '| '+ '+ '+
|
||||
tile '+ $88 '+ '+ '+ '+
|
||||
|
||||
|
||||
tile '| $7e 0 0 '| 0
|
||||
tile '| $7e 0 0 '+ 0
|
||||
tile '| $7f 0 0 0 0
|
||||
tile '- $7d 0 0 0 0
|
||||
|
||||
tile '. $6a # stone 2
|
||||
tile ': $6b # stone 3
|
||||
|
||||
thing 'f $74 # fire
|
||||
thing '^ $73 # door open
|
||||
thing 'C $79 # cupboard
|
||||
thing 'S $7a # bookshelf
|
||||
thing 'c $78 # chair
|
||||
thing 't $7b # table
|
||||
thing 'T $7c # throne
|
||||
thing 'h $9c # chest
|
||||
|
||||
thing 'H $92 # hut
|
||||
thing 'K $93 # kingdom
|
||||
|
||||
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))
|
||||
print(add(3,4))
|
||||
print(add(1234,5678))
|
||||
endproc
|
||||
|
||||
itemhit normal_door
|
||||
endproc
|
||||
|
||||
itemstep normal_door
|
||||
endproc
|
||||
|
||||
|
||||
|
||||
map test 20 9
|
||||
mapinit
|
||||
setPos(3,2)
|
||||
setItemPos(0)
|
||||
|
||||
endproc
|
||||
|
||||
: K H
|
||||
: . .
|
||||
: ...........
|
||||
: . .
|
||||
:+-----^--x--C--S---+
|
||||
:| T f|
|
||||
:|ctc h |
|
||||
:| c |
|
||||
:+-----^-----x------+
|
||||
|
||||
endmap
|
||||
|
||||
thing 'S $54 # Spider
|
||||
thing 'k $a0 # key
|
||||
map first 12 12
|
||||
:+---+ +---+
|
||||
:| | | |
|
||||
:+-+ +--+ | |
|
||||
: | +-+ |
|
||||
: | | |
|
||||
: | |
|
||||
: +-+ -----+
|
||||
: | Sk|
|
||||
: +------+
|
||||
endmap
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
|
||||
|
||||
#ifndef _MAP_H
|
||||
#define _MAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
struct _item_onmap_struct
|
||||
{
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t template_index;
|
||||
uint8_t option;
|
||||
};
|
||||
typedef struct _item_onmap_struct item_onmap_t;
|
||||
|
||||
struct _map_struct
|
||||
{
|
||||
unsigned char *data;
|
||||
item_onmap_t *onmap_list;
|
||||
uint16_t init_proc;
|
||||
uint8_t onmap_cnt;
|
||||
uint8_t width;
|
||||
uint8_t height;
|
||||
};
|
||||
typedef struct _map_struct map_t;
|
||||
|
||||
struct _item_template_struct
|
||||
{
|
||||
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 unsigned char map_code[] ;
|
||||
extern item_template_t item_template_list[];
|
||||
extern map_t map_list[];
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,271 @@
|
|||
|
||||
#include "u8g2.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
//#define FACTOR 3
|
||||
//#define XOFFSET (FACTOR*32)
|
||||
//#define YOFFSET (FACTOR*32)
|
||||
#define DEFAULT_WIDTH (512+512)
|
||||
#define DEFAULT_HEIGHT (1024+512+256)
|
||||
|
||||
|
||||
uint16_t tga_max_x;
|
||||
uint16_t tga_max_y;
|
||||
size_t tga_max_offset = 0;
|
||||
|
||||
static uint16_t tga_width;
|
||||
static uint16_t tga_height;
|
||||
static uint8_t *tga_data = NULL;
|
||||
uint8_t tga_r = 0;
|
||||
uint8_t tga_g = 0;
|
||||
uint8_t tga_b = 0;
|
||||
|
||||
uint8_t tga_desc_r = 0;
|
||||
uint8_t tga_desc_g = 0;
|
||||
uint8_t tga_desc_b = 0;
|
||||
|
||||
int tga_init(uint16_t w, uint16_t h)
|
||||
{
|
||||
tga_max_x = 0;
|
||||
tga_max_y = 0;
|
||||
tga_width = 0;
|
||||
tga_height = 0;
|
||||
tga_max_offset = 0;
|
||||
if ( tga_data != NULL )
|
||||
{
|
||||
tga_data = (uint8_t *)realloc(tga_data, w*h*3);
|
||||
}
|
||||
else
|
||||
{
|
||||
tga_data = (uint8_t *)malloc(w*h*3);
|
||||
}
|
||||
if ( tga_data == NULL )
|
||||
return 0;
|
||||
memset(tga_data, 255, (long)w*(long)h*3L);
|
||||
tga_width = w;
|
||||
tga_height = h;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void tga_set_pixel(uint16_t x, uint16_t y, uint16_t f)
|
||||
{
|
||||
uint8_t *p;
|
||||
uint16_t xx,yy;
|
||||
size_t offset;
|
||||
for( yy = y; yy < y+f; yy++ )
|
||||
{
|
||||
for( xx = x; xx < x+f; xx++ )
|
||||
{
|
||||
if ( yy < tga_height && xx < tga_width )
|
||||
{
|
||||
//printf ("(%d %d) ", xx, yy);
|
||||
offset = (tga_height-yy-1)*tga_width*3 + xx*3;
|
||||
p = tga_data + offset;
|
||||
if ( tga_max_offset < offset )
|
||||
tga_max_offset = offset;
|
||||
*p++ = tga_b;
|
||||
*p++ = tga_g;
|
||||
*p++ = tga_r;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tga_clr_pixel(uint16_t x, uint16_t y, uint16_t f)
|
||||
{
|
||||
uint8_t *p;
|
||||
size_t offset;
|
||||
uint16_t xx,yy;
|
||||
for( yy = y; yy < y+f; yy++ )
|
||||
{
|
||||
for( xx = x; xx < x+f; xx++ )
|
||||
{
|
||||
offset = (tga_height-yy-1)*tga_width*3 + xx*3;
|
||||
p = tga_data + offset;
|
||||
*p++ = 255;
|
||||
*p++ = 255;
|
||||
*p++ = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tga_set_8pixel(int x, int y, uint8_t pixel, uint16_t f)
|
||||
{
|
||||
int cnt = 8;
|
||||
while( cnt > 0 )
|
||||
{
|
||||
if ( (pixel & 1) != 0 )
|
||||
{
|
||||
tga_set_pixel(x,y, f);
|
||||
}
|
||||
else
|
||||
{
|
||||
tga_clr_pixel(x,y, f);
|
||||
}
|
||||
pixel >>= 1;
|
||||
y+=f;
|
||||
cnt--;
|
||||
}
|
||||
}
|
||||
|
||||
void tga_set_multiple_8pixel(int x, int y, int cnt, uint8_t *pixel, uint16_t f)
|
||||
{
|
||||
uint8_t b;
|
||||
while( cnt > 0 )
|
||||
{
|
||||
b = *pixel;
|
||||
tga_set_8pixel(x, y, b, f);
|
||||
x+=f;
|
||||
pixel++;
|
||||
cnt--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void tga_write_byte(FILE *fp, uint8_t byte)
|
||||
{
|
||||
fputc(byte, fp);
|
||||
}
|
||||
|
||||
void tga_write_word(FILE *fp, uint16_t word)
|
||||
{
|
||||
tga_write_byte(fp, word&255);
|
||||
tga_write_byte(fp, word>>8);
|
||||
}
|
||||
|
||||
void tga_save(const char *name)
|
||||
{
|
||||
FILE *fp;
|
||||
if ( tga_data == NULL )
|
||||
return;
|
||||
|
||||
//printf("tga_save: File %s with %dx%d pixel\n", name, tga_width, tga_height);
|
||||
|
||||
fp = fopen(name, "wb");
|
||||
if ( fp != NULL )
|
||||
{
|
||||
tga_write_byte(fp, 0); /* no ID */
|
||||
tga_write_byte(fp, 0); /* no color map */
|
||||
tga_write_byte(fp, 2); /* uncompressed true color */
|
||||
tga_write_word(fp, 0);
|
||||
tga_write_word(fp, 0);
|
||||
tga_write_byte(fp, 0);
|
||||
tga_write_word(fp, 0); /* x origin */
|
||||
tga_write_word(fp, 0); /* y origin */
|
||||
tga_write_word(fp, tga_width); /* width */
|
||||
tga_write_word(fp, tga_height); /* height */
|
||||
tga_write_byte(fp, 24); /* color depth */
|
||||
tga_write_byte(fp, 0);
|
||||
fwrite(tga_data, tga_width*tga_height*3, 1, fp);
|
||||
tga_write_word(fp, 0);
|
||||
tga_write_word(fp, 0);
|
||||
tga_write_word(fp, 0);
|
||||
tga_write_word(fp, 0);
|
||||
fwrite("TRUEVISION-XFILE.", 18, 1, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
/*==========================================*/
|
||||
/* tga procedures */
|
||||
|
||||
|
||||
u8x8_display_info_t u8x8_tga_info =
|
||||
{
|
||||
/* chip_enable_level = */ 0,
|
||||
/* chip_disable_level = */ 1,
|
||||
|
||||
/* post_chip_enable_wait_ns = */ 0,
|
||||
/* pre_chip_disable_wait_ns = */ 0,
|
||||
/* reset_pulse_width_ms = */ 0,
|
||||
/* post_reset_wait_ms = */ 0,
|
||||
/* sda_setup_time_ns = */ 0,
|
||||
/* sck_pulse_width_ns = */ 0,
|
||||
/* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
|
||||
/* spi_mode = */ 1,
|
||||
/* i2c_bus_clock_100kHz = */ 0,
|
||||
/* data_setup_time_ns = */ 0,
|
||||
/* write_pulse_width_ns = */ 0,
|
||||
/* tile_width = */ (DEFAULT_WIDTH)/8,
|
||||
/* tile_hight = */ (DEFAULT_HEIGHT)/8,
|
||||
/* default_x_offset = */ 0,
|
||||
/* flipmode_x_offset = */ 0,
|
||||
DEFAULT_WIDTH,
|
||||
DEFAULT_HEIGHT
|
||||
};
|
||||
|
||||
|
||||
uint8_t u8x8_d_tga(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
u8g2_uint_t x, y, c;
|
||||
uint8_t *ptr;
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_DISPLAY_SETUP_MEMORY:
|
||||
u8x8_d_helper_display_setup_memory(u8g2, &u8x8_tga_info);
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_INIT:
|
||||
u8x8_d_helper_display_init(u8g2);
|
||||
//if ( tga_data == NULL )
|
||||
tga_init(u8x8_tga_info.pixel_width, u8x8_tga_info.pixel_height);
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_SET_CONTRAST:
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_DRAW_TILE:
|
||||
|
||||
tga_r = tga_desc_r;
|
||||
tga_g = tga_desc_g;
|
||||
tga_b = tga_desc_b;
|
||||
|
||||
x = ((u8x8_tile_t *)arg_ptr)->x_pos;
|
||||
//printf("U8X8_MSG_DISPLAY_DRAW_TILE x=%d, ", x);
|
||||
x *= 8;
|
||||
x += u8g2->x_offset;
|
||||
|
||||
y = ((u8x8_tile_t *)arg_ptr)->y_pos;
|
||||
//printf("y=%d, c=%d\n", y, ((u8x8_tile_t *)arg_ptr)->cnt);
|
||||
y *= 8;
|
||||
|
||||
do
|
||||
{
|
||||
c = ((u8x8_tile_t *)arg_ptr)->cnt;
|
||||
ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
|
||||
tga_set_multiple_8pixel(x, y, c*8, ptr, 1);
|
||||
arg_int--;
|
||||
} while( arg_int > 0 );
|
||||
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void u8x8_Setup_TGA(u8x8_t *u8x8)
|
||||
{
|
||||
/* setup defaults */
|
||||
u8x8_SetupDefaults(u8x8);
|
||||
|
||||
/* setup specific callbacks */
|
||||
u8x8->display_cb = u8x8_d_tga;
|
||||
|
||||
/* setup display info */
|
||||
u8x8_SetupMemory(u8x8);
|
||||
}
|
||||
|
||||
void u8g2_SetupBuffer_TGA(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb)
|
||||
{
|
||||
static uint8_t buf[(DEFAULT_WIDTH)*8*8];
|
||||
|
||||
u8x8_Setup_TGA(u8g2_GetU8x8(u8g2));
|
||||
u8g2_SetupBuffer(u8g2, buf, 8, u8g2_ll_hvline_vertical_top_lsb, u8g2_cb);
|
||||
}
|
||||
|
|
@ -31,11 +31,13 @@ void ugl_InitBytecode(void)
|
|||
ugl_AddBytecode(BC_CMD_RETURN_FROM_PROCEDURE);
|
||||
}
|
||||
|
||||
/*
|
||||
void ugl_ExecBytecode(void)
|
||||
{
|
||||
bc_t bc;
|
||||
bc_exec(&bc, ugl_bytecode_array, 0);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void ugl_CheckForAllLabelsDefined(void)
|
||||
|
|
|
@ -299,7 +299,6 @@ void bc_exec(bc_t *bc, uint8_t *code, uint16_t pos)
|
|||
}
|
||||
|
||||
|
||||
|
||||
/*======================================================*/
|
||||
|
||||
/* put top of stack into register a, reduce stack */
|
||||
|
|
Loading…
Reference in New Issue