|
Demo game |
Richard Phipps
Member #1,632
November 2001
|
Of course there could also be several demo games (increasing in complexity) for example from pong to tetris to a galaxian style game. The small amount of gfx for some of these games shouldn't make much of a dent in the space allowance. |
Chris Katko
Member #1,881
January 2002
|
Well, if that were the case (and I like the idea), I'd prefer we put them all (except "the Winner") in a Demo Pack instead of the main distro. -----sig: |
spellcaster
Member #1,493
September 2001
|
What about this: I write a "template", something pretty basic containing set-up and shutdown code, maybe hiscore code. Then we create several small games. That would mean that no single game needs to use all of allegro's features. demo The template code would be really generic. Not even sure if it should include menu code, since most games prefer to use their own, personal code for that. What do you guys think? If it's ok for you that I write the template, I'd try to start pretty soon and finish it on the weekend. -- |
Richard Phipps
Member #1,632
November 2001
|
It sounds a great idea to me. How detailed should the template be though? |
Thomas Fjellstrom
Member #476
June 2000
|
Less talk, more action ie: It doesn't matter. Its up to the coder till [s]he releases it. Then it can be tweeked or massaged into what people want. -- |
Chris Katko
Member #1,881
January 2002
|
Quote: If it's ok for you that I write the template, Lemmie guess, C? I don't think I'll be using that, or at least for my next project (the planet one). -----sig: |
HoHo
Member #4,534
April 2004
|
Quote: Lemmie guess, C? I don't think I'll be using that, or at least for my next project (the planet one). YTou could make c++ bindings or c++ alternative of it I guess including several games is a bit too much for allegro. Perhaps it would be good idea to seperate the library and tests, examples and games into two or more seperate packages. An official tutorial with example games/programs would be nice but I don't think it would be done in forseeable future __________ |
Evert
Member #794
November 2000
|
Quote: What about this: I write a "template", something pretty basic containing set-up and shutdown code, maybe hiscore code. Then we create several small games. That would mean that no single game needs to use all of allegro's features.
I like the idea, it's neat. But I don't feel like requiring people to follow this way... if they really want to write their own game independent of a single framework, then I think it should be ok for them to do so. |
james_lohr
Member #1,947
February 2002
|
Spellcaster: I think your idea is great. To me the idea of writing something within a template is quite attractive. I'd also like to prove that I can write legible code with comments .
|
kikabo
Member #3,679
July 2003
|
OT: The template/framework idea would be great for a Bishi-Bashi style game competition. I've always thought that BB was a good framework for a compo, but the result being more substantial and structured for demo purposes. |
David Grace
Member #42
April 2000
|
The template idea does sound like a good idea -- I would do a menu using that, because almost all of my games use a similiar menu that contains options such as "start game", "configure game options/controls", and "exit". (But then again, I tend to work on the same paradigm as console games -- Limited input ability, rarely support the mouse, etc.) The highscore tables code and such rarely change between my games. In fact I tend to just cut-n-paste between my projects. Usually the only thing that changes is what sort of values are being written to the score file, but if you just keep it to score and name, that would be fine for a small subset of games. One more to add: Shooter, like Space Invaders (the current demo, in other words) Whether it's a scrolling shooter is debatable, as tilemaps could be shown in the platformer. If we are VERY creative with resources, I see no reason why we couldn't make several very simple games with just 200k or so of artwork/sound assets. Yeah, sounds like a lot of work but I have fun doing stuff like Game In A Day so I guess it doesn't bother me as much, heh. _______________________________ |
spellcaster
Member #1,493
September 2001
|
I've the basic template ready. It allows you to handle initialisation, switching between windowed and fullscreen mode and has a simple hiscore code. I'll add some simple menu code and make it available for download. Do you think I should add some allegro logo display and a scrolling display of a customizable textfile as well? -- |
tobing
Member #5,213
November 2004
|
Wow, I'd like to see what it looks like... Add the allegro logo, I think that's a good idea. Don't know if a scrolling text is necessary. The logo would be enough to show how to display some sort of splash screen, which is fine for almost all games. |
spellcaster
Member #1,493
September 2001
|
Quote: Wow, I'd like to see what it looks like... Here's my current code, it still contains some testing code and the menu function is missing. 1#include <allegro.h>
2#include <stdio.h>
3#include <stdlib.h>
4
5
6enum {
7 HI_COLOR = -3,
8 TRUE_COLOR,
9 INDEXED_COLOR
10};
11
12enum {
13 MODE_FAILED,
14 WINDOWED,
15 FULLSCREEN,
16 WINDOWED_OR_FULLSCREEN,
17 FULLSCREEN_OR_WINDOWED
18};
19
20typedef struct {
21 int w, h, bpp;
22 int windowed;
23 int preferred_bpp;
24
25 BITMAP* buffer;
26} ScreenInfo;
27
28enum { HISCORE_COUNT = 10 };
29enum { HISCORE_NAME_LENGTH = 16 };
30
31
32typedef struct {
33 int score;
34 char name[HISCORE_NAME_LENGTH];
35 char new_entry;
36} HiscoreEntry;
37
38/* We need one element more than actually used by the game */
39HiscoreEntry hiscores[HISCORE_COUNT +1];
40ScreenInfo screen_info = { 0, 0, 0, 0, 0, NULL };
41
42
43/*
44 * Sets all hiscore table entries to a given name and value.
45 * name - the name to use. If longer than HISCORE_NAME_LENGTH, the name will be truncated.
46 * score - the score
47 */
48void hiscore_init(char *name, int score) {
49 int a;
50 for (a = 0; a < HISCORE_COUNT; ++a) {
51 snprintf(hiscores[a].name, HISCORE_NAME_LENGTH, name);
52 hiscores[a].score = score;
53 hiscores[a].new_entry = 0;
54 }
55}
56
57/*
58 * Compares two hiscore entries. Used by quicksort in the hiscore_add() method
59 */
60int hiscore_compare(const void *lhs, const void *rhs) {
61 return ((HiscoreEntry*) rhs)->score - ((HiscoreEntry*) lhs)->score;
62}
63
64
65/*
66 * Adds a new score to the table. After the call to this function
67 * you can recognize the new element in the table by the state of the
68 * new_entry flag - so if you want to display the latest entry to the table
69 * differently, just check the newly added flag.
70 */
71void hiscore_add(char *name, int score) {
72 int a;
73 for (a=0; a < HISCORE_COUNT; ++a) {
74 hiscores[a].new_entry = 0;
75 }
76
77 /* the table contains one element more than HISCORE_COUNT,
78 * allowing us to add new scores easily
79 */
80 snprintf(hiscores[HISCORE_COUNT].name, HISCORE_NAME_LENGTH, name);
81 hiscores[HISCORE_COUNT].score = score;
82 hiscores[a].new_entry = 1;
83
84 qsort(hiscores, HISCORE_COUNT+1, sizeof(HiscoreEntry), hiscore_compare);
85}
86
87int hiscore_save(const char* filename) {
88 int a;
89 PACKFILE *f = pack_fopen(filename, "w");
90
91 if (f != NULL) {
92 for (a = 0; a < HISCORE_COUNT; ++a) {
93 pack_fwrite(hiscores[a].name, HISCORE_NAME_LENGTH, f);
94 pack_iputw(hiscores[a].score, f);
95 }
96 pack_fclose(f);
97
98 return TRUE;
99 }
100 return FALSE;
101}
102
103int hiscore_load(const char* filename) {
104 int a;
105 PACKFILE *f = pack_fopen(filename, "r");
106
107 if (f != NULL) {
108 for (a = 0; a < HISCORE_COUNT; ++a) {
109 pack_fread(hiscores[a].name, HISCORE_NAME_LENGTH, f);
110 hiscores[a].score = pack_igetw(f);
111 }
112 pack_fclose(f);
113
114 return TRUE;
115 }
116 return FALSE;
117}
118
119
120/*
121 * Sets a gfx mode.
122 * If you pass a literal value for the colordepth (say 16) this
123 * routine will try to set the colordepth and return a failure if
124 * this depth could not be set. If you pass a mode constant the
125 * routine will try several fitting color depths if the preferred
126 * one could not be set.
127 * If you want to force a windowed mode, pass WINDOWED as windowed parameter
128 * If you want to force a fullscreen mode, pass FULLSCREEN as windowed.
129 * If you prefer windowed, but can live with fullscreen use WINDOWE_OR_FULLSCREEN.
130 * If you prefer fullscreen, but windowed is ok as well, pass FULLSCREEN_OR_WINDOWED
131 *
132 * width - screen width
133 * height - screen height
134 * colordepth - either HI_COLOR, TRUE_COLOR, INDEXED_COLOR or the bpp
135 * value you want to use (8, 16, etc..)
136 * windowed - either WINDOWED, FULLSCREEN, WINDOWED_OR_FULLSCREEN or
137 * FULLSCREEN_OR_WINDOWED
138 *
139 * returns TRUE if the mode was set, FALSE otherwise
140 */
141int init_graphics(int width, int height, int colordepth, int windowed) {
142
143 /*
144 * Not all cards support 16 bit color, some require 15
145 * even if they are listed as "HiColor".
146 * In order to set a fitting graphics mode, some
147 * alternatives are defined.
148 * The 24 bit color mode is always tried last, since
149 * the 3 byte alignement makes it a terribly slow mode to
150 * use.
151 */
152 static int hicolor[] = { 16, 15, 32, 24, 0 };
153 static int truecolor[] = { 32, 16, 15, 24, 0 };
154 int *depths = NULL;
155 int bpp = 0;
156 int a;
157 int mode = 0;
158 int result = -1;
159
160 /*
161 * depths is the array containing the bpp values.
162 * We'll iterate over that array (if it is != NULL)
163 * below and set the corresponding mode. If the
164 * array is NULL we'll try to set the colordepth
165 * stored in bpp (if bpp != 0)
166 */
167 switch (colordepth) {
168 case HI_COLOR:
169 depths = hicolor;
170 break;
171 case TRUE_COLOR:
172 depths = truecolor;
173 break;
174 case INDEXED_COLOR:
175 bpp = 8;
176 break;
177 default:
178 bpp = colordepth;
179 }
180
181 /* Set the first mode (windows or fullscreen) to try */
182 if (windowed == WINDOWED || windowed == WINDOWED_OR_FULLSCREEN) {
183 mode = GFX_AUTODETECT_WINDOWED;
184 } else {
185 mode = GFX_AUTODETECT_FULLSCREEN;
186 }
187
188 if (depths) {
189 /* While no mode is set and we have alternative modes */
190 while (result < 0 && windowed != MODE_FAILED) {
191 a = 0;
192 while (depths[a] != 0 && result < 0) {
193 set_color_depth(depths[a]);
194 result = set_gfx_mode(mode, width, height, 0, 0);
195 if (result >= 0) {
196 bpp = depths[a];
197 }
198 ++a;
199 }
200
201 if (result < 0) {
202 if (windowed == WINDOWED_OR_FULLSCREEN && mode == GFX_AUTODETECT_WINDOWED) {
203 mode = GFX_AUTODETECT_FULLSCREEN;
204 } else if (windowed == FULLSCREEN_OR_WINDOWED && mode == GFX_AUTODETECT_FULLSCREEN) {
205 mode = GFX_AUTODETECT_WINDOWED;
206 } else {
207 windowed = MODE_FAILED;
208 }
209 }
210 }
211 } else if (bpp != 0) {
212 /* User has requested a very specific color depth */
213 set_color_depth(bpp);
214 result = set_gfx_mode(mode, width, height, 0, 0);
215
216 if (result < 0) {
217 if (windowed == WINDOWED_OR_FULLSCREEN && mode == GFX_AUTODETECT_WINDOWED) {
218 mode = GFX_AUTODETECT_FULLSCREEN;
219 } else if (windowed == FULLSCREEN_OR_WINDOWED && mode == GFX_AUTODETECT_FULLSCREEN) {
220 mode = GFX_AUTODETECT_WINDOWED;
221 } else {
222 windowed = MODE_FAILED;
223 }
224
225 /* if there is a 2nd mode we can try, try it: */
226 if (windowed !=MODE_FAILED) {
227 result = set_gfx_mode(mode, width, height, 0, 0);
228 }
229 }
230 }
231
232 /* If a mode was set, result is equal to (or greater than) 0.
233 */
234 if (result >= 0) {
235
236 /* If this method was called to change the graphics mode,
237 * we'll try to maintain the contents of the screen
238 */
239 if (screen_info.w == width && screen_info.h == height) {
240 /* screensize was not changed, blit doublebuffer to screen */
241 blit(screen_info.buffer, screen, 0, 0, 0, 0, width, height);
242
243 if (screen_info.bpp != bpp) {
244 /* colordepth has changed, we need a new buffer.
245 * If we destroy the buffer here and set it to NULL,
246 * a new bufer will be created below
247 */
248 destroy_bitmap(screen_info.buffer);
249 screen_info.buffer = NULL;
250 }
251 }
252 screen_info.w = width;
253 screen_info.h = height;
254 screen_info.bpp = bpp;
255 screen_info.preferred_bpp = colordepth;
256 screen_info.windowed = (mode == GFX_AUTODETECT_WINDOWED);
257
258 /* create a doublebuffer if needed */
259 if (screen_info.buffer == NULL) {
260 screen_info.buffer = create_bitmap(width, height);
261 }
262
263 return TRUE;
264 } else {
265 return FALSE;
266 }
267}
268
269/*
270 * Allows you to toggle the fullscreen / windowed aspect of your game.
271 * windowed - set to TRUE if you want to switch to windowed mode,
272 * set to FALSE if you want to switch to fullscreen mode.
273 *
274 * returns TRUE if the switch worked, FALSE otherwise
275 */
276int set_window_mode(int windowed) {
277 if (screen_info.windowed != windowed) {
278 /* if your game uses video BITMAPs make sure to release them here,
279 * and recreate them after the call to init_graphics, kinda like this:
280 *
281 * int result = 0;
282 * unload_all_video_bitmaps();
283 * result = init_graphics(screen_info.w, screen_info.h, screen_info.preferred_bpp, windowed ? WINDOWED : FULLSCREEN);
284 * load_all_video_bitmaps();
285 * return result;
286 */
287 return init_graphics(screen_info.w, screen_info.h, screen_info.preferred_bpp, windowed ? WINDOWED : FULLSCREEN);
288 }
289 return TRUE;
290}
291
292
293void update_screen() {
294 blit(screen_info.buffer, screen, 0, 0, 0, 0, screen_info.w, screen_info.h);
295}
296
297
298int main(int argc, char* argv) {
299 int lastkey = 0;
300 int a;
301
302 FONT *colorFont;
303
304 allegro_init();
305 if (init_graphics(800, 600, HI_COLOR, WINDOWED_OR_FULLSCREEN)) {
306 install_keyboard();
307
308 text_mode(-1);
309
310 clear_keybuf();
311 clear(screen_info.buffer);
312 textprintf(screen_info.buffer, font, 10, 10, makecol(255,255,255), "%ix%ix%i", screen_info.w, screen_info.h, screen_info.bpp);
313
314 update_screen();
315
316 while (!key[KEY_ESC]) {
317
318 if (key[KEY_W] && lastkey != KEY_W) {
319 lastkey = KEY_W;
320 set_window_mode(TRUE);
321 } else if (key[KEY_F] && lastkey != KEY_F) {
322 lastkey = KEY_F;
323 set_window_mode(FALSE);
324 } else {
325 lastkey = 0;
326 }
327
328 rest(1);
329 }
330 }
331
332 hiscore_init("This string is way too long. Way too long", 10);
333 hiscore_add("foo", 20);
334 hiscore_add("bar", 30);
335 hiscore_add("baz", 15);
336 for (a=0; a < HISCORE_COUNT; ++a) {
337 printf("%2i %16s %i\n", (a+1), hiscores[a].name, hiscores[a].score);
338 }
339 hiscore_save("hiscores.bin");
340 hiscore_load("hiscores.bin");
341 for (a=0; a < HISCORE_COUNT; ++a) {
342 printf("%2i %16s %i\n", (a+1), hiscores[a].name, hiscores[a].score);
343 }
344}
345END_OF_MAIN()
-- |
Rick
Member #3,572
June 2003
|
Nothing big, but I would take this out: windowed ? WINDOWED : FULLSCREEN
Like someone said above, any shorthand code I think should be avoided. Not that it's a big deal or anything, but the less questions about something the better. Otherwise I think it look great. ======================================================== |
Matt Smith
Member #783
November 2000
|
Quote: I'd go with a single resolution (with high-color) to avoid the confusion that comes with "customization" The single resolution is a mistake, as it would be better to provide a clear example of using SCREEN_W and SCREEN_H correctly. All the examples use a fixed resolution too and that makes it a pain to port to machines that don't offer a 'safe' 320x200 or 640x480. |
Eradicor
Member #2,992
December 2002
|
Really.. Why is this forum in the forum arena shown as yellow.. It is killing me.. btw: 500'th Post with this profile | Visit The site | |
Evert
Member #794
November 2000
|
It's yellow because it's sticky. As if it's bookmarked for everyone. And its sticky so that everyone can see it and it doesn't get burried and lost among all the other posts. Quote: The single resolution is a mistake, as it would be better to provide a clear example of using SCREEN_W and SCREEN_H correctly.
Thinking more about it, I think this is right. The examples show simple things or single features and there it's ok to use a singlefixed resolution, but the demo game can be a bit more complex than that. |
Eradicor
Member #2,992
December 2002
|
Can i get rid of it? That Yellow is killing my eyes. | Visit The site | |
Evert
Member #794
November 2000
|
Sure. Use a custom stylesheet. Please open a new thread if you need to ask how to use one though. |
Kitty Cat
Member #2,815
October 2002
|
Use the Blue Lotus Blossom style sheet. It's a nice light-blue that blends nicely with the surrounding area. It's enough to be noticeable, but it's not harsh and distracting. -- |
Thomas Fjellstrom
Member #476
June 2000
|
Drumcode, you didn't get my hint earlier did you Oh, you can also "Kill Thread". that should get rid of the yellow. -- |
spellcaster
Member #1,493
September 2001
|
The problem with the variable screen resolution is that get_gfx_mode_list() won't function with meta drivers like GFX_AUTODETECT. So, you'll have to write platform or at least driver specific code to get a list - or you need to show a list of all drivers to the user. I'd say that at GFX_AUTODETECT and GFX_AUTODETECT_FULLSCREEN should work - and return the modes for the first driver in the GFX_AUTODETECT_FULLSCREEN list. I'm also not sure if something like this is really needed for 2d games. If your artwork is pixel based, you'll normally want a specific logical size of the screen. The only 2d games that allow different screen resolutions are normally strategy titles that display more of the map on larger screens or emulators which scale their contents to the size of the screen. In both cases you'll need some extra logic - either to position the elements on the screen or to do the scaling. While I think that we should have a better example for the get_gfx_mode_list() function, I'm not sure if a demo game is the right place for it. -- |
Michael Jensen
Member #2,870
October 2002
|
My plate is fairly full, but I'd like to attempt a demo game for this, I have some ideas that could involve using the joystick/mouse/keyboard for game play; as for c programming, I still haven't learned oop but I practice putting my code into .cpp files so I can evily declare variables anywhere I want -- this will have to change, and I can put off learning oop a few weeks or so... -- Also I could benefit from trying to write clear cut code Also I think some things the demo should DEFINATLEY DO, are be tile based!!! Too many people have trouble building tile based games... Also I think it should be fairly polished, since we are competing with SDL which has hardware accelerated 3D (so I'm against making anything that looks TOO old-style, but then again, I'm a fan of some of the classics so I'm kind of torn...) Anyway SC, I'd love to use your template, I haven't looked at it yet, but your code has always been understandable for me in the past -- as for the ? operator -- I've been programming in C about 5 years now and I still don't know what it does (I know, that what it does do could be accomplished with an if/else block, but off the top of my head w/o looking it's function up, I couldn't tell you what it does...) Anyway, I might get started on my entry sometime next week, update this thread when you get menuing support in your template... I'd love to see alex take a bite out of the SDL logo... Can we do this? or is there some kind of copyright on their logo? Maybe just an alegator that looks like it has an SDL logo in it's mouth but you wouldn't notice unless you knew what it looked like? Anyway...
|
spellcaster
Member #1,493
September 2001
|
The ?: operator is gone. Anything else that should be in the template? I think I'll create a "summer games" like game as a first demo game using the template. Not that many games, just the standards: I plan to allow both hotseat and single screen multiplayer (depending on the event and the number of joypads connected). And with Bryce / Poser it shouldn't even be that hard to create the gfx -- |
|
|