1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
25 #include "bogoman_debug.h"
26 #include "bogoman_map.h"
27 #include "bogoman_loader.h"
28 #include "bogoman_render.h"
32 static void save_png(struct bogoman_map
*map
, unsigned int elem_size
,
38 rx
= elem_size
* map
->w
;
39 ry
= elem_size
* map
->h
;
41 ctx
= GP_ContextAlloc(rx
, ry
, GP_PIXEL_RGB888
);
46 struct bogoman_render render
= {
51 .map_elem_size
= elem_size
,
54 bogoman_render(&render
, BOGOMAN_RENDER_ALL
);
56 GP_SavePNG(ctx
, filename
, NULL
);
60 static struct GP_Backend
*backend
;
62 static void event_loop(struct bogoman_map
*map
)
64 while (GP_BackendEventsQueued(backend
)) {
67 GP_BackendGetEvent(backend
, &ev
);
71 if (ev
.code
!= GP_EV_KEY_DOWN
)
76 GP_BackendExit(backend
);
80 bogoman_map_player_move(map
, 1, 0);
83 bogoman_map_player_move(map
, -1, 0);
86 bogoman_map_player_move(map
, 0, -1);
89 bogoman_map_player_move(map
, 0, 1);
99 int main(int argc
, char *argv
[])
101 struct bogoman_map
*map
;
103 bogoman_set_dbg_level(10);
106 map
= bogoman_load(argv
[1]);
108 map
= bogoman_load("map.txt");
111 fprintf(stderr
, "Failed to load map");
115 bogoman_map_dump(map
);
117 unsigned int cw
= map
->w
* ELEM_SIZE
;
118 unsigned int ch
= map
->h
* ELEM_SIZE
;
120 backend
= GP_BackendX11Init(NULL
, 0, 0, cw
, ch
, "Bogoman", 0);
122 if (backend
== NULL
) {
123 fprintf(stderr
, "Failed to initialize backend");
127 struct bogoman_render render
= {
131 .ctx
= backend
->context
,
132 .map_elem_size
= ELEM_SIZE
,
135 bogoman_render(&render
, BOGOMAN_RENDER_ALL
);
136 GP_BackendFlip(backend
);
139 GP_BackendPoll(backend
);
142 bogoman_render(&render
, BOGOMAN_RENDER_DIRTY
);
143 GP_BackendFlip(backend
);