From 54959be6241f6fe85a39f72e9ba88e3d42d06835 Mon Sep 17 00:00:00 2001 From: Cyril Hrubis Date: Fri, 2 Jan 2015 11:35:18 +0100 Subject: [PATCH] demos: bogoman: Many improvements. * New type of blocks * Rendering optimalizations * Fixed window resize handling Signed-off-by: Cyril Hrubis --- demos/bogoman/bogoman.c | 35 ++++++--- demos/bogoman/bogoman_loader.c | 51 +++++++++++-- demos/bogoman/bogoman_map.c | 138 ++++++++++++++++++++++++++++++----- demos/bogoman/bogoman_map.h | 57 +++++++++++---- demos/bogoman/bogoman_render.c | 115 +++++++++++++++++++++++++---- demos/bogoman/bogoman_render.h | 9 ++- demos/bogoman/levels/02-paticles.txt | 10 +++ demos/bogoman/map.txt | 4 +- 8 files changed, 350 insertions(+), 69 deletions(-) create mode 100644 demos/bogoman/levels/02-paticles.txt diff --git a/demos/bogoman/bogoman.c b/demos/bogoman/bogoman.c index 0f745847..a83cba38 100644 --- a/demos/bogoman/bogoman.c +++ b/demos/bogoman/bogoman.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis * + * Copyright (C) 2009-2015 Cyril Hrubis * * * *****************************************************************************/ @@ -27,7 +27,7 @@ #include "bogoman_loader.h" #include "bogoman_render.h" -#define ELEM_SIZE 33 +#define ELEM_SIZE 27 static void save_png(struct bogoman_map *map, unsigned int elem_size, const char *filename) @@ -59,8 +59,10 @@ static void save_png(struct bogoman_map *map, unsigned int elem_size, static struct GP_Backend *backend; -static void event_loop(struct bogoman_map *map) +static void event_loop(struct bogoman_render *render, GP_Backend *backend) { + struct bogoman_map *map = render->map; + while (GP_BackendEventsQueued(backend)) { GP_Event ev; @@ -89,6 +91,19 @@ static void event_loop(struct bogoman_map *map) bogoman_map_player_move(map, 0, 1); break; } + bogoman_render(render, BOGOMAN_RENDER_DIRTY); + break; + case GP_EV_SYS: + switch (ev.code) { + case GP_EV_SYS_RESIZE: + GP_BackendResizeAck(backend); + bogoman_render(render, BOGOMAN_RENDER_ALL); + break; + } + break; + case GP_EV_TMR: + bogoman_map_timer_tick(render->map); + bogoman_render(render, BOGOMAN_RENDER_DIRTY); break; } } @@ -99,6 +114,7 @@ static void event_loop(struct bogoman_map *map) int main(int argc, char *argv[]) { struct bogoman_map *map; + GP_TIMER_DECLARE(timer, 0, 300, "Refresh", NULL, NULL); bogoman_set_dbg_level(10); @@ -129,20 +145,17 @@ int main(int argc, char *argv[]) .map_x_offset = 0, .map_y_offset = 0, .ctx = backend->context, + .backend = backend, .map_elem_size = ELEM_SIZE, }; bogoman_render(&render, BOGOMAN_RENDER_ALL); - GP_BackendFlip(backend); - - for (;;) { - GP_BackendPoll(backend); - event_loop(map); - bogoman_render(&render, BOGOMAN_RENDER_DIRTY); - GP_BackendFlip(backend); + GP_BackendAddTimer(backend, &timer); - usleep(50000); + for (;;) { + GP_BackendWait(backend); + event_loop(&render, backend); } return 0; diff --git a/demos/bogoman/bogoman_loader.c b/demos/bogoman/bogoman_loader.c index 935bc3e3..e4e17c1d 100644 --- a/demos/bogoman/bogoman_loader.c +++ b/demos/bogoman/bogoman_loader.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis * + * Copyright (C) 2009-2015 Cyril Hrubis * * * *****************************************************************************/ @@ -81,6 +81,15 @@ static enum bogoman_map_elem_id id_from_char(const char ch) return BOGOMAN_MOVEABLE; case 'E': return BOGOMAN_EDIBLE; + case '(': + case ')': + case 'O': + case 'o': + case '<': + case '>': + case '^': + case 'v': + return BOGOMAN_PARTICLE; } WARN("Unknown map character '%c'", ch); @@ -93,6 +102,7 @@ static enum bogoman_map_elem_id id_from_char(const char ch) struct line { unsigned int len; unsigned char line[LINE_MAX]; + unsigned char input[LINE_MAX]; }; static void get_line(FILE *f, struct line *l) @@ -106,6 +116,7 @@ static void get_line(FILE *f, struct line *l) case '\n': return; default: + l->input[l->len] = ch; l->line[l->len++] = id_from_char(ch); break; } @@ -140,19 +151,19 @@ static void load_map(FILE *f, struct bogoman_map *map) case BOGOMAN_WALL: if (x > 0 && line_cur->line[x - 1] == BOGOMAN_WALL) - elem->flags |= BOGOMAN_WALL_LEFT; + elem->flags |= BOGOMAN_LEFT; if (x + 1 < line_cur->len && line_cur->line[x + 1] == BOGOMAN_WALL) - elem->flags |= BOGOMAN_WALL_RIGHT; + elem->flags |= BOGOMAN_RIGHT; if (y > 0 && - bogoman_map_is_id(map, x, y-1, BOGOMAN_WALL)) - elem->flags |= BOGOMAN_WALL_UP; + bogoman_map_elem_id(map, x, y-1) == BOGOMAN_WALL) + elem->flags |= BOGOMAN_UP; if (x < line_next->len && line_next->line[x] == BOGOMAN_WALL) - elem->flags |= BOGOMAN_WALL_DOWN; + elem->flags |= BOGOMAN_DOWN; break; case BOGOMAN_PLAYER: @@ -168,6 +179,34 @@ static void load_map(FILE *f, struct bogoman_map *map) case BOGOMAN_DIAMOND: map->diamonds_total++; break; + case BOGOMAN_PARTICLE: + switch (line_cur->input[x]) { + case '(': + elem->flags = BOGOMAN_LEFT | BOGOMAN_PARTICLE_ROUND; + break; + case ')': + elem->flags = BOGOMAN_RIGHT | BOGOMAN_PARTICLE_ROUND; + break; + case 'O': + elem->flags = BOGOMAN_UP | BOGOMAN_PARTICLE_ROUND; + break; + case 'o': + elem->flags = BOGOMAN_DOWN | BOGOMAN_PARTICLE_ROUND; + break; + case '<': + elem->flags = BOGOMAN_LEFT | BOGOMAN_PARTICLE_SQUARE; + break; + case '>': + elem->flags = BOGOMAN_RIGHT | BOGOMAN_PARTICLE_SQUARE; + break; + case '^': + elem->flags = BOGOMAN_UP | BOGOMAN_PARTICLE_SQUARE; + break; + case 'v': + elem->flags = BOGOMAN_DOWN | BOGOMAN_PARTICLE_SQUARE; + break; + } + break; default: break; } diff --git a/demos/bogoman/bogoman_map.c b/demos/bogoman/bogoman_map.c index b9117441..2919fc00 100644 --- a/demos/bogoman/bogoman_map.c +++ b/demos/bogoman/bogoman_map.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis * + * Copyright (C) 2009-2015 Cyril Hrubis * * * *****************************************************************************/ @@ -30,22 +30,22 @@ static void print_wall(struct bogoman_map_elem *elem) { switch (elem->flags) { - case BOGOMAN_WALL_LEFT: - case BOGOMAN_WALL_RIGHT: - case BOGOMAN_WALL_LEFT | BOGOMAN_WALL_RIGHT: + case BOGOMAN_LEFT: + case BOGOMAN_RIGHT: + case BOGOMAN_LEFT | BOGOMAN_RIGHT: printf("-"); break; - case BOGOMAN_WALL_UP: - case BOGOMAN_WALL_DOWN: - case BOGOMAN_WALL_UP | BOGOMAN_WALL_DOWN: + case BOGOMAN_UP: + case BOGOMAN_DOWN: + case BOGOMAN_UP | BOGOMAN_DOWN: printf("|"); break; - case BOGOMAN_WALL_UP | BOGOMAN_WALL_RIGHT: - case BOGOMAN_WALL_DOWN | BOGOMAN_WALL_LEFT: + case BOGOMAN_UP | BOGOMAN_RIGHT: + case BOGOMAN_DOWN | BOGOMAN_LEFT: printf("\\"); break; - case BOGOMAN_WALL_UP | BOGOMAN_WALL_LEFT: - case BOGOMAN_WALL_DOWN | BOGOMAN_WALL_RIGHT: + case BOGOMAN_UP | BOGOMAN_LEFT: + case BOGOMAN_DOWN | BOGOMAN_RIGHT: printf("/"); break; default: @@ -54,6 +54,48 @@ static void print_wall(struct bogoman_map_elem *elem) } } +static void print_particle(struct bogoman_map_elem *elem) +{ + char c = '?'; + int dir = elem->flags & BOGOMAN_DIRECTION_MASK; + + if (elem->flags & BOGOMAN_PARTICLE_ROUND) { + switch (dir) { + case BOGOMAN_LEFT: + c = '('; + break; + case BOGOMAN_RIGHT: + c = ')'; + break; + case BOGOMAN_UP: + c = 'O'; + break; + case BOGOMAN_DOWN: + c = 'o'; + break; + } + } + + if (elem->flags & BOGOMAN_PARTICLE_SQUARE) { + switch (dir) { + case BOGOMAN_LEFT: + c = '<'; + break; + case BOGOMAN_RIGHT: + c = '>'; + break; + case BOGOMAN_UP: + c = '^'; + break; + case BOGOMAN_DOWN: + c = 'v'; + break; + } + } + + putchar(c); +} + void bogoman_map_dump(struct bogoman_map *map) { unsigned int x, y; @@ -83,6 +125,9 @@ void bogoman_map_dump(struct bogoman_map *map) case BOGOMAN_WALL: print_wall(elem); break; + case BOGOMAN_PARTICLE: + print_particle(elem); + break; } } @@ -139,8 +184,6 @@ static void move_get_diamond(struct bogoman_map *map, static int try_move_block(struct bogoman_map *map, int x, int y, int dx, int dy) { - struct bogoman_map_elem *elem = bogoman_get_map_elem(map, x, y); - int new_x = (int)x + dx; int new_y = (int)y + dy; @@ -194,6 +237,7 @@ void bogoman_map_player_move(struct bogoman_map *map, int x, int y) case BOGOMAN_DIAMOND: move_get_diamond(map, px, py); break; + case BOGOMAN_PARTICLE: case BOGOMAN_MOVEABLE: if (!try_move_block(map, px, py, dx, dy)) goto finish_move; @@ -231,15 +275,75 @@ finish_move: void bogoman_map_timer_tick(struct bogoman_map *map) { - unsigned int x, y; + unsigned int x, y, moved; + struct bogoman_map_elem *elem; for (y = 0; y < map->h; y++) { for (x = 0; x < map->w; x++) { struct bogoman_map_elem *elem; - elem = bogoman_get_map_elem(map, x, y); - - //TODO + elem->moved = 0; } } + + do { + moved = 0; + + for (y = 0; y < map->h; y++) { + for (x = 0; x < map->w; x++) { + int dir_x = 0, dir_y = 0; + elem = bogoman_get_map_elem(map, x, y); + + if (elem->id != BOGOMAN_PARTICLE) + continue; + + if (elem->moved) + continue; + + switch (elem->flags & BOGOMAN_DIRECTION_MASK) { + case BOGOMAN_LEFT: + dir_x = -1; + break; + case BOGOMAN_RIGHT: + dir_x = 1; + break; + case BOGOMAN_UP: + dir_y = -1; + break; + case BOGOMAN_DOWN: + dir_y = +1; + break; + default: + continue; + } + + if (!bogoman_is_empty(map, x + dir_x, y + dir_y)) { + if (!(elem->flags & BOGOMAN_PARTICLE_ROUND)) + continue; + + if (dir_x) { + //TODO randomly choose direction + if (bogoman_is_empty(map, x+dir_x, y-1)) + dir_y = -1; + if (bogoman_is_empty(map, x+dir_x, y+1)) + dir_y = 1; + } + + if (dir_y) { + if (bogoman_is_empty(map, x-1, y+dir_y)) + dir_x = -1; + if (bogoman_is_empty(map, x+1, y+dir_y)) + dir_x = 1; + } + + if (!dir_x || !dir_y) + continue; + } + + elem->moved = 1; + bogoman_switch(map, x, y, x + dir_x, y + dir_y); + moved++; + } + } + } while (moved); } diff --git a/demos/bogoman/bogoman_map.h b/demos/bogoman/bogoman_map.h index fe7c1f14..e4d3c096 100644 --- a/demos/bogoman/bogoman_map.h +++ b/demos/bogoman/bogoman_map.h @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis * + * Copyright (C) 2009-2015 Cyril Hrubis * * * *****************************************************************************/ @@ -36,19 +36,27 @@ enum bogoman_map_elem_id { BOGOMAN_MOVEABLE = 0x04, /* like a diamond but doesn't counts to points */ BOGOMAN_EDIBLE = 0x05, + /* particles, move in defined direction unless stoppend by objects */ + BOGOMAN_PARTICLE = 0x06, - BOGOMAN_MAX = BOGOMAN_EDIBLE, + BOGOMAN_MAX = BOGOMAN_PARTICLE, }; /* - * Wall cal be applied as bitflags. Each bitflag determines wall continuation - * in particular direction. + * Lower 8 bits defines continuation for walls, direction for particles, etc. */ -enum bogoman_wall_flags { - BOGOMAN_WALL_LEFT = 0x01, - BOGOMAN_WALL_RIGHT = 0x02, - BOGOMAN_WALL_UP = 0x04, - BOGOMAN_WALL_DOWN = 0x08, +enum bogoman_direction_flags { + BOGOMAN_LEFT = 0x01, + BOGOMAN_RIGHT = 0x02, + BOGOMAN_UP = 0x04, + BOGOMAN_DOWN = 0x08, + + BOGOMAN_DIRECTION_MASK = 0x0f, +}; + +enum bogoman_particle_flags { + BOGOMAN_PARTICLE_ROUND = 0x10, + BOGOMAN_PARTICLE_SQUARE = 0x20, }; struct bogoman_map_elem { @@ -57,6 +65,7 @@ struct bogoman_map_elem { /* the element changed, needs to be redrawn */ unsigned char dirty:1; + unsigned char moved:1; }; struct bogoman_map { @@ -91,13 +100,13 @@ static inline enum bogoman_map_elem_id return elem->id; } -static inline int bogoman_map_is_id(struct bogoman_map *map, - unsigned int x, unsigned int y, - enum bogoman_map_elem_id id) +static inline enum bogoman_map_elem_id + bogoman_map_elem_id(struct bogoman_map *map, + unsigned int x, unsigned int y) { struct bogoman_map_elem *elem = bogoman_get_map_elem(map, x, y); - return elem->id == id; + return elem->id; } static inline int bogoman_coord_in_map(struct bogoman_map *map, int x, int y) @@ -106,12 +115,30 @@ static inline int bogoman_coord_in_map(struct bogoman_map *map, int x, int y) (y >= 0) && ((unsigned)y < map->w); } -static inline int bogoman_is_empty(struct bogoman_map *map, - unsigned int x, unsigned int y) +static inline int bogoman_is_empty(struct bogoman_map *map, int x, int y) { + if (!bogoman_coord_in_map(map, x, y)) + return 0; + return bogoman_get_map_elem_id(map, x, y) == BOGOMAN_NONE; } +static inline void bogoman_switch(struct bogoman_map *map, + int x1, int y1, int x2, int y2) +{ + struct bogoman_map_elem *i, *j, tmp; + + i = bogoman_get_map_elem(map, x1, y1); + j = bogoman_get_map_elem(map, x2, y2); + + tmp = *i; + *i = *j; + *j = tmp; + + i->dirty = 1; + j->dirty = 1; +} + void bogoman_map_player_move(struct bogoman_map *map, int x, int y); void bogoman_map_timer_tick(struct bogoman_map *map); diff --git a/demos/bogoman/bogoman_render.c b/demos/bogoman/bogoman_render.c index c2ebc10b..bc47f7d2 100644 --- a/demos/bogoman/bogoman_render.c +++ b/demos/bogoman/bogoman_render.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis * + * Copyright (C) 2009-2015 Cyril Hrubis * * * *****************************************************************************/ @@ -48,19 +48,25 @@ struct render_colors { /* edible color */ GP_Pixel edible; + + /* particle colors */ + GP_Pixel particle; + GP_Pixel particle_dir; }; static struct render_colors colors; static void init_colors(GP_Context *ctx, struct render_colors *colors) { - colors->bg = GP_RGBToContextPixel(0xee, 0xee, 0xee, ctx); - colors->player = GP_RGBToContextPixel(0x00, 0xee, 0x00, ctx); - colors->frames = GP_RGBToContextPixel(0x00, 0x00, 0x00, ctx); - colors->diamond = GP_RGBToContextPixel(0x00, 0x00, 0xee, ctx); - colors->wall = GP_RGBToContextPixel(0x66, 0x66, 0x66, ctx); - colors->moveable = GP_RGBToContextPixel(0xff, 0xff, 0x60, ctx); - colors->edible = GP_RGBToContextPixel(0xff, 0x7f, 0x50, ctx); + colors->bg = GP_RGBToContextPixel(0xee, 0xee, 0xee, ctx); + colors->player = GP_RGBToContextPixel(0x00, 0xee, 0x00, ctx); + colors->frames = GP_RGBToContextPixel(0x00, 0x00, 0x00, ctx); + colors->diamond = GP_RGBToContextPixel(0x00, 0x00, 0xee, ctx); + colors->wall = GP_RGBToContextPixel(0x66, 0x66, 0x66, ctx); + colors->moveable = GP_RGBToContextPixel(0xff, 0xff, 0x60, ctx); + colors->edible = GP_RGBToContextPixel(0xff, 0x7f, 0x50, ctx); + colors->particle = GP_RGBToContextPixel(0xff, 0xff, 0x00, ctx); + colors->particle_dir = GP_RGBToContextPixel(0xff, 0x44, 0x00, ctx); } static void render_none(struct bogoman_render *render, @@ -83,8 +89,9 @@ static void render_player(struct bogoman_render *render, (void) elem; GP_FillRectXYWH(render->ctx, x, y, w, w, colors.bg); + GP_FillCircle(render->ctx, x + w/2, y + w/2, w/2 - 1, colors.player); - GP_Circle(render->ctx, x + w/2, y + w/2, w/2 - 1, colors.frames); + GP_FillRing(render->ctx, x + w/2, y + w/2, w/2 - 1, w/2 - 2, colors.frames); } static void render_wall(struct bogoman_render *render, @@ -95,17 +102,25 @@ static void render_wall(struct bogoman_render *render, GP_FillRectXYWH(render->ctx, x, y, w, w, colors.wall); - if (!(elem->flags & BOGOMAN_WALL_LEFT)) + if (!(elem->flags & BOGOMAN_LEFT)) { GP_VLineXYH(render->ctx, x, y, w, colors.frames); + GP_VLineXYH(render->ctx, x+1, y, w, colors.frames); + } - if (!(elem->flags & BOGOMAN_WALL_RIGHT)) + if (!(elem->flags & BOGOMAN_RIGHT)) { GP_VLineXYH(render->ctx, x + w - 1, y, w, colors.frames); + GP_VLineXYH(render->ctx, x + w - 2, y, w, colors.frames); + } - if (!(elem->flags & BOGOMAN_WALL_UP)) + if (!(elem->flags & BOGOMAN_UP)) { GP_HLineXYW(render->ctx, x, y, w, colors.frames); + GP_HLineXYW(render->ctx, x, y+1, w, colors.frames); + } - if (!(elem->flags & BOGOMAN_WALL_DOWN)) + if (!(elem->flags & BOGOMAN_DOWN)) { GP_HLineXYW(render->ctx, x, y + w - 1, w, colors.frames); + GP_HLineXYW(render->ctx, x, y + w - 2, w, colors.frames); + } } static void render_diamond(struct bogoman_render *render, @@ -116,11 +131,15 @@ static void render_diamond(struct bogoman_render *render, GP_FillRectXYWH(render->ctx, x, y, w, w, colors.bg); + (void) elem; + GP_FillTetragon(render->ctx, x + w/2, y, x + w - 1, y + w/2, x + w/2, y + w - 1, x, y + w/2, colors.diamond); GP_Tetragon(render->ctx, x + w/2, y, x + w - 1, y + w/2, x + w/2, y + w - 1, x, y + w/2, colors.frames); + GP_Tetragon(render->ctx, x + w/2, y+1, x + w - 2, y + w/2, + x + w/2, y + w - 2, x+1, y + w/2, colors.frames); } static void render_moveable(struct bogoman_render *render, @@ -129,10 +148,13 @@ static void render_moveable(struct bogoman_render *render, { unsigned int w = render->map_elem_size; + (void) elem; + GP_FillRectXYWH(render->ctx, x, y, w, w, colors.bg); GP_FillRectXYWH(render->ctx, x + 1, y + 1, w - 2, w - 2, colors.moveable); GP_RectXYWH(render->ctx, x + 1, y + 1, w - 2, w - 2, colors.frames); + GP_RectXYWH(render->ctx, x + 2, y + 2, w - 4, w - 4, colors.frames); } static void render_edible(struct bogoman_render *render, @@ -141,11 +163,62 @@ static void render_edible(struct bogoman_render *render, { unsigned int w = render->map_elem_size; + (void) elem; + GP_FillRectXYWH(render->ctx, x, y, w, w, colors.bg); GP_FillRectXYWH(render->ctx, x + 1, y + 1, w - 2, w - 2, colors.edible); } +static void render_particle(struct bogoman_render *render, + unsigned int x, unsigned int y, + struct bogoman_map_elem *elem) +{ + unsigned int w = render->map_elem_size; + int dir = elem->flags & BOGOMAN_DIRECTION_MASK; + + GP_FillRectXYWH(render->ctx, x, y, w, w, colors.bg); + + switch (elem->flags & ~BOGOMAN_DIRECTION_MASK) { + case BOGOMAN_PARTICLE_ROUND: + GP_FillCircle(render->ctx, x + w/2, y + w/2, w/2-1, colors.particle); + GP_FillRing(render->ctx, x + w/2, y + w/2, w/2 - 1, w/2 - 2, colors.frames); + break; + case BOGOMAN_PARTICLE_SQUARE: + GP_FillRectXYWH(render->ctx, x+1, y+1, w-2, w-2, colors.particle); + GP_RectXYWH(render->ctx, x+1, y+1, w-2, w-2, colors.frames); + GP_RectXYWH(render->ctx, x+2, y+2, w-4, w-4, colors.frames); + break; + } + + switch (dir) { + case BOGOMAN_LEFT: + GP_FillTriangle(render->ctx, x + w/4, y + w/2, + x + 5*w/8, y + w/4, x + 5*w/8, y + 3*w/4, colors.particle_dir); + GP_Triangle(render->ctx, x + w/4, y + w/2, + x + 5*w/8, y + w/4, x + 5*w/8, y + 3*w/4, colors.frames); + break; + case BOGOMAN_RIGHT: + GP_FillTriangle(render->ctx, x + 3*w/4, y + w/2, + x + 3*w/8, y + w/4, x + 3*w/8, y + 3*w/4, colors.particle_dir); + GP_Triangle(render->ctx, x + 3*w/4, y + w/2, + x + 3*w/8, y + w/4, x + 3*w/8, y + 3*w/4, colors.frames); + break; + case BOGOMAN_UP: + GP_FillTriangle(render->ctx, x + w/2, y + w/4, + x + w/4, y + 5*w/8, x + 3*w/4, y + 5*w/8, colors.particle_dir); + GP_Triangle(render->ctx, x + w/2, y + w/4, + x + w/4, y + 5*w/8, x + 3*w/4, y + 5*w/8, colors.frames); + break; + case BOGOMAN_DOWN: + GP_FillTriangle(render->ctx, x + w/2, y + 3*w/4, + x + w/4, y + 3*w/8, x + 3*w/4, y + 3*w/8, colors.particle_dir); + GP_Triangle(render->ctx, x + w/2, y + 3*w/4, + x + w/4, y + 3*w/8, x + 3*w/4, y + 3*w/8, colors.frames); + break; + } +} + static void (*renders[])(struct bogoman_render *render, unsigned int x, unsigned int y, struct bogoman_map_elem *elem) = @@ -156,6 +229,7 @@ static void (*renders[])(struct bogoman_render *render, render_diamond, render_moveable, render_edible, + render_particle, }; static void render_elem(struct bogoman_render *render, @@ -181,6 +255,12 @@ static void render_elem(struct bogoman_render *render, WARN("Invalid elem ID %u at %ux%u\n", elem->id, x, y); else renders[elem->id](render, cx, cy, elem); + + if (flags & BOGOMAN_RENDER_DIRTY && render->backend) { + GP_BackendUpdateRect(render->backend, cx, cy, + cx + render->map_elem_size, + cy + render->map_elem_size); + } } void bogoman_render(struct bogoman_render *render, int flags) @@ -190,9 +270,14 @@ void bogoman_render(struct bogoman_render *render, int flags) //TODO: Hack init_colors(render->ctx, &colors); + if (flags & BOGOMAN_RENDER_ALL) + GP_Fill(render->ctx, colors.bg); + for (y = render->map_x_offset; y < render->map->h; y++) { - for (x = render->map_x_offset; x < render->map->w; x++) { + for (x = render->map_x_offset; x < render->map->w; x++) render_elem(render, x, y, flags); - } } + + if (flags & BOGOMAN_RENDER_ALL && render->backend) + GP_BackendFlip(render->backend); } diff --git a/demos/bogoman/bogoman_render.h b/demos/bogoman/bogoman_render.h index f813cdc1..e27744e2 100644 --- a/demos/bogoman/bogoman_render.h +++ b/demos/bogoman/bogoman_render.h @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis * + * Copyright (C) 2009-2015 Cyril Hrubis * * * *****************************************************************************/ @@ -37,14 +37,17 @@ struct bogoman_render { /* context to be used for rendering */ struct GP_Context *ctx; + /* if not NULL is used to update screen */ + struct GP_Backend *backend; + /* elem size in pixels */ unsigned int map_elem_size; }; enum bogonam_render_flags { /* renders all map elements, not only dirty ones */ - BOGOMAN_RENDER_ALL = 0x00, - BOGOMAN_RENDER_DIRTY = 0x01, + BOGOMAN_RENDER_ALL = 0x01, + BOGOMAN_RENDER_DIRTY = 0x02, }; void bogoman_render(struct bogoman_render *render, int flags); diff --git a/demos/bogoman/levels/02-paticles.txt b/demos/bogoman/levels/02-paticles.txt new file mode 100644 index 00000000..1c1dbf15 --- /dev/null +++ b/demos/bogoman/levels/02-paticles.txt @@ -0,0 +1,10 @@ +/------------\ +|$))))E @| +|)))))E | ++------ | +| | +++++-E-++\ | ++++/OOO\++ | +++/OOOOO\+ | +++$$$$$$$| | +\+-------+---/ diff --git a/demos/bogoman/map.txt b/demos/bogoman/map.txt index 337d07ca..3e360f91 100644 --- a/demos/bogoman/map.txt +++ b/demos/bogoman/map.txt @@ -1,8 +1,8 @@ +---------+ +----+ | | | | | $ | | +----+ | -| E @ | +|> E @ (<| +--M----------------+ | M | -| |$|$|$| | +|^v |$|$|$| | +----------+-+-+-+--+ -- 2.11.4.GIT