![]() |
|
MinorHack Attack! |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
Quote: Current competition is scheduled for 2100 GMT on September 3. + Quote: The next competition starts in 2 hours and 7 minutes. = NaN Unless I've gone bonkers, the competition starts at 2200 GMT according to the page.
|
Kikaru
Member #7,616
August 2006
![]() |
I have a comment about one of the bonus rules: How would a game be played inside it's own source code? It doesn't make much sense, if any. Also, a quick question: If I submit an executible file, could the source be put in a project so I can use the linker? I don't have a makefile for it yet. |
Lenman
Member #4,522
April 2004
![]() |
Quote: I have a question about one of the bonus rules: How would a game be played inside it's own source code? It doesn't make much sense, if any. You could use the possibility of including your own source file to include some data hidden as comments. -------------------------------------------------------- Perhaps I should let you all in on a little secret. No one likes you in the future. This time period is looked at as being full of lazy, self-centered, civically ignorant sheep. -John Titor |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
It sounds like a silly thing to have in a one hour game... Actually, it sounds like a silly thing period. But so are some other rules (i don't even know how the state of California looks!)
|
Kikaru
Member #7,616
August 2006
![]() |
Get a map of the US. California is on the lower-left. And, I still don't understand the source code thing, just hope it doesn't come up. |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
I realize that it's not a big deal to find out how the state of California looks, but it's so arbitrary. Also quite hard to do without bitmaps (like the banana theme).
|
Krzysztof Kluczek
Member #4,191
January 2004
![]() |
Quote: I realize that it's not a big deal to find out how the state of California looks, but it's so arbitrary. Also quite hard to do without bitmaps (like the banana theme).
You can generate bananas using a pair of circles (one yellow and one transparent) or even just using a single arc. As for shape of California, just draw arbitrary random shape and state that it's post-apocalyptic version of it. ________ |
Michael Faerber
Member #4,800
July 2004
![]() |
Quote: You can generate bananas using a pair of circles (one yellow and one transparent) or even just using a single arc.
Hehe .. I made the bananas with two arcs, and I experimented for about 15 minutes until I got the right radii, positions, angles ... -- |
Kikaru
Member #7,616
August 2006
![]() |
MinorHack starting in 20 min. twitch, twitch |
CGamesPlay
Member #2,559
July 2002
![]() |
Kikaru: for instance, load your source code and render it to a bitmap using textprintf. Then scale this bitmap up and use it as a background image. There are more creative things you can do, but this is the simplest. Okay, I might check this page one more time before the compo, but I doubt it (it's quite a pain). Just put your source in this thread when your entry is done. Good luck Allegroites! -- Ryan Patterson - <http://cgamesplay.com/> |
Zaphos
Member #1,468
August 2001
|
The competition is running, but I don't see the bonus rule listed anywhere ...
|
Jonatan Hedborg
Member #4,886
July 2004
![]() |
I guess i'm "done". The gold ball (you) tries to move towards the mouse, while the big evil ball (the grey one) tries to crush you. If it hits you - game over.
|
Jakub Wasilewski
Member #3,653
June 2003
![]() |
Here is mine. Code here and attached, readme included The game gradually gets harder so try for your high score Also, a little balancing after the contest: replace "randomFloat(0, 48 - level)" with "randomFloat(0, 46 - level * 2)" and "level += 0.0012" with "level += 0.0017" to make it less boring. 1/*
2 BADDIE
3
4 press left mouse button to shoot, right to reload
5 each reload costs 250 points, each baddie scores points, each coin scores mucho points
6
7 each baddie that goes off screen costs HP
8
9 when HP is zero, you're dead
10
11 link with allegro
12*/
13
14#include <iostream>
15#include <cstdlib>
16#include <cmath>
17#include <ctime>
18#include <allegro.h>
19#include <string>
20#include <list>
21#include <vector>
22
23using namespace std;
24
25/**********************************************************/
26
27BITMAP *buffer, *crosshair, *baddie;
28int score = 0, hp = 4, ammo = 6;
29float level;
30
31/**********************************************************/
32/**********************************************************/
33/**********************************************************/
34
35static volatile int ticks = 0;
36
37void incTicks()
38{
39 ticks++;
40}
41
42void resetTicks()
43{
44 ticks = 0;
45}
46
47/**********************************************************/
48
49void initRandom()
50{
51 std::srand(time(NULL));
52}
53
54/************************************************************/
55
56float randomFloat(float min, float max)
57{
58 return min + ((float)std::rand() / (float)RAND_MAX) * (max - min);
59}
60
61/************************************************************/
62
63long randomInt(long min, long max)
64{
65 return rand() % (max - min + 1) + min;
66}
67
68/**********************************************************/
69/**********************************************************/
70/**********************************************************/
71
72/**********************************************************/
73
74void init()
75{
76 allegro_init();
77
78 set_color_depth(desktop_color_depth());
79 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
80
81 install_keyboard();
82 install_timer();
83 install_mouse();
84
85 install_int_ex(incTicks, BPS_TO_TIMER(60));
86
87 initRandom();
88
89 // buffer
90
91 buffer = create_bitmap(640, 480);
92
93 // crosshair
94
95 crosshair = create_bitmap(40, 40);
96 clear_to_color(crosshair, makecol(255, 0, 255));
97 circle(crosshair, 20, 20, 16, makecol(200, 0, 0));
98 line(crosshair, 20, 0, 20, 12, makecol(200, 0, 0));
99 line(crosshair, 20, 40, 20, 28, makecol(200, 0, 0));
100 line(crosshair, 0, 20, 12, 20, makecol(200, 0, 0));
101 line(crosshair, 40, 20, 28, 20, makecol(200, 0, 0));
102
103 // baddie
104
105 baddie = create_bitmap(32, 32);
106 clear_to_color(baddie, makecol(255, 0, 255));
107 rectfill(baddie, 1, 0, 30, 31, makecol(50, 80, 255));
108 rectfill(baddie, 0, 1, 31, 30, makecol(50, 80, 255));
109 rect(baddie, 2, 2, 30, 30, makecol(0, 0, 0));
110 rectfill(baddie, 6, 10, 12, 14, makecol(255, 255, 255));
111 rectfill(baddie, 20, 10, 26, 14, makecol(255, 255, 255));
112 rect(baddie, 6, 10, 12, 14, makecol(0, 0, 0));
113 rect(baddie, 20, 10, 26, 14, makecol(0, 0, 0));
114 rectfill(baddie, 9, 12, 11, 14, makecol(0, 0, 0));
115 rectfill(baddie, 23, 12, 25, 14, makecol(0, 0, 0));
116 line(baddie, 6, 6, 12, 8, makecol(0, 0, 0));
117 line(baddie, 20, 8, 26, 6, makecol(0, 0, 0));
118 line(baddie, 8, 24, 24, 24, makecol(0, 0, 0));
119}
120
121/**********************************************************/
122
123void destroy()
124{
125}
126
127/**********************************************************/
128/**********************************************************/
129/**********************************************************/
130
131
132class Thing
133{
134 public:
135
136 virtual bool isAlive() {return true;};
137
138 virtual void update(){};
139 virtual void draw(){};
140
141 virtual void shootAt(int x, int y){};
142
143};
144
145list<Thing*> world;
146
147class Gun : public Thing
148{
149 int x, y;
150
151 public:
152
153 void update()
154 {
155 x = mouse_x;
156 y = mouse_y;
157 }
158
159 void draw()
160 {
161 draw_sprite(buffer, crosshair, x - 20, y - 20);
162 }
163};
164
165class Particle : public Thing
166{
167 public:
168
169 int color;
170
171 float x, y;
172 float vx, vy;
173
174 Particle(int x, int y, float vx, float vy, int color)
175 : x(x), y(y), vx(vx), vy(vy), color(color)
176 {
177
178 }
179
180 bool isAlive()
181 {
182 return y < 480;
183 }
184
185 void update()
186 {
187 vy += 0.2;
188
189 x += vx;
190 y += vy;
191 }
192
193 void draw()
194 {
195 putpixel(buffer, (int)x, int(y), color);
196 }
197};
198
199class Bonus : public Thing
200{
201 public:
202
203 float x, y;
204 float vy;
205 bool destroyed;
206
207 public:
208
209 Bonus(int x, float vy)
210 : x(x), vy(vy)
211 {
212 y = -20;
213 destroyed = false;
214 }
215
216 bool isAlive()
217 {
218 return (!destroyed);
219 }
220
221 void draw()
222 {
223 circlefill(buffer, (int)x, int(y), 10, makecol(255, 255, 0));
224 }
225
226
227 void update()
228 {
229 y += vy;
230
231 if (y >= 490)
232 {
233 destroyed = true;
234 }
235 }
236
237 void shootAt(int sx, int sy)
238 {
239 if (((sx - x) * (sx - x) + (sy - y) * (sy - y)) < 100)
240 {
241 score += (int)(level * 100);
242 destroyed = true;
243
244 for(int i = 0; i < 20; i++)
245 {
246 world.push_back(new Particle((int)x + randomInt(-5, 5), (int)y + randomInt(-5, 5), randomFloat(-2, 2), randomFloat(-2, 2), makecol(255, 200, 0)));
247 }
248 }
249 }
250};
251
252
253class Baddie : public Thing
254{
255 public:
256
257 float x, y;
258 float vy;
259 bool destroyed;
260
261 public:
262
263 Baddie(int x, float vy)
264 : x(x), vy(vy)
265 {
266 y = -20;
267 destroyed = false;
268 }
269
270 bool isAlive()
271 {
272 return (!destroyed);
273 }
274
275 void draw()
276 {
277 draw_sprite(buffer, baddie, (int)x - 16, (int)y - 16);
278 }
279
280
281 void update()
282 {
283 y += vy;
284
285 if (y >= 490)
286 {
287 hp--;
288 destroyed = true;
289 }
290 }
291
292 void shootAt(int sx, int sy)
293 {
294 if ((std::abs(sx - x) < 15) && (std::abs(sy - y) < 15))
295 {
296 score += (int)(level * 25);
297 destroyed = true;
298
299 for(int i = 0; i < 20; i++)
300 {
301 world.push_back(new Particle((int)x + randomInt(-5, 5), (int)y + randomInt(-5, 5), randomFloat(-2, 2), randomFloat(-2, 2), makecol(0, 50, 255)));
302 }
303 }
304 }
305};
306
307class Scoreboard : public Thing
308{
309 public:
310 void draw()
311 {
312 textprintf_ex(buffer, font, 4, 4, makecol(255, 0, 0), -1, "HP:");
313 for (int i = 0; i < hp; i++)
314 {
315 rectfill(buffer, 30 + i * 10, 4, 30 + i * 10 + 8, 9, makecol(255, 0, 0));
316 }
317 textprintf_ex(buffer, font, 160, 4, makecol(255, 255, 255), -1, "Ammo:");
318 for (int i = 0; i < ammo; i++)
319 {
320 rectfill(buffer, 204 + i * 5, 4, 204 + i * 5 + 3, 9, makecol(255, 255, 255));
321 }
322
323 textprintf_right_ex(buffer, font, 636, 4, makecol(255, 255, 0), -1, "Score: %d", score);
324 }
325};
326
327/**********************************************************/
328/**********************************************************/
329/**********************************************************/
330
331/**********************************************************/
332
333
334int main()
335{
336 init();
337
338 resetTicks();
339
340 bool end = false;
341 list<Thing*>::iterator it;
342
343 Gun *gun = new Gun();
344 Scoreboard *sb = new Scoreboard();
345
346 level = 4.0;
347 int prev_button = 0;
348
349 while(!end)
350 {
351 if (ticks > 0)
352 {
353 while(ticks-- > 0)
354 {
355 if (randomFloat(0, 48 - level) < 1.0)
356 {
357 if (randomInt(0, 15) == 0)
358 world.push_back(new Bonus(randomInt(20, 620), level * randomFloat(0.99, 1.05)));
359 else
360 world.push_back(new Baddie(randomInt(20, 620), level * randomFloat(0.99, 1.05)));
361 }
362
363 for(it = world.begin(); it != world.end(); it++)
364 (*it)->update();
365
366 for(it = world.begin(); it != world.end();)
367 {
368 if (!(*it)->isAlive())
369 {
370 delete (*it);
371 it = world.erase(it);
372 }
373 else
374 {
375 it++;
376 }
377 }
378 gun->update();
379
380 if (key[KEY_ESC])
381 {
382 end = true;
383 }
384 end |= (hp <= 0);
385
386 level += 0.0012;
387
388 if ((mouse_b == 1) && (mouse_b != prev_button) && (ammo > 0))
389 {
390 ammo--;
391 for(it = world.begin(); it != world.end(); it++)
392 (*it)->shootAt(mouse_x, mouse_y);
393 }
394 if ((mouse_b == 2) && (mouse_b != prev_button))
395 {
396 ammo = 6;
397 score -= 250;
398 }
399
400 prev_button = mouse_b;
401 }
402 }
403
404 clear_bitmap(buffer);
405 for(it = world.begin(); it != world.end(); it++)
406 (*it)->draw();
407 gun->draw();
408 sb->draw();
409
410 blit(buffer, screen, 0, 0, 0, 0, 640, 480);
411 }
412
413 clear_bitmap(screen);
414 textprintf_centre_ex(screen, font, 320, 220, makecol(255, 0, 0), -1, "G A M E O V E R");
415 textprintf_centre_ex(screen, font, 320, 240, makecol(255, 255, 255), -1, "Final score: %d", score);
416 textprintf_centre_ex(screen, font, 320, 260, makecol(255, 255, 0), -1, "Press both mouse buttons to exit");
417
418 while (mouse_b);
419 while (mouse_b != 3);
420
421 destroy();
422}
423END_OF_MAIN()
--------------------------- |
Victor Williams Stafusa da Silva
Member #4,212
January 2004
![]() |
here attached [The attack of the space bugs - Speedhack 2005] [Rambananas - Speedhack 2006] [Make clean - Speedhack 2009] [The source god - TINS 2010] |
Onewing
Member #6,152
August 2005
![]() |
Dodge the Blocks!!!!!!!!!!!!!! Scores are formed by where the blocks land. The higher the block, the better the score! 1// Compile with allegro!
2#include "allegro.h"
3#include<stdio.h>
4
5/**************** DEFINES & MACROS *************/
6#define BPP 32
7#define MODE GFX_AUTODETECT_WINDOWED
8#define GFX_W 640
9#define GFX_H 480
10#define MAX_BLOCKS 1000
11
12/*************** CONSTANTS ********************/
13const int MASK = makecol(255, 0, 255);
14const int WHITE = makecol(255, 255, 255);
15
16
17/*************** GLOBAL ********************/
18volatile int system_time;
19volatile int ticks;
20volatile int framerate;
21volatile int draw_ticks;
22PALETTE pal;
23COLOR_MAP trans_table;
24BITMAP *buffer;
25BITMAP *bText;
26BITMAP *bScreen;
27int startpos;
28int iTimer_Speed;
29bool iFrameRate;
30bool quit, over;
31int block_create;
32int dark;
33int score;
34
35void timer1(void)
36{
37 system_time++;
38}END_OF_FUNCTION(timer1);
39
40void frametimer(void)
41{
42 framerate = draw_ticks;
43 draw_ticks = 0;
44}END_OF_FUNCTION(frametimer);
45
46
47
48void init()
49{
50 // Allegro Library
51 if(allegro_init() != 0)
52 {
53 allegro_message("ERROR: Failed to initialize allegro library. Terminating program.\n");
54 allegro_message("REPORT: %s\n", allegro_error);
55 exit(0);
56 }
57
58
59 set_color_depth(BPP) ; // 24 bit colour
60 if (set_gfx_mode(MODE, GFX_W, GFX_H, 0, 0)<0)
61 {
62 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
63 allegro_message("ERROR: Failure to init video mode! Terminating program.\n");
64 allegro_message("REPORT: %s\n", allegro_error);
65 exit(0);
66 }
67
68
69 // Install Timer
70 if(install_timer() != 0)
71 {
72 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
73 allegro_message("ERROR: Failed to install timer. Terminating program.\n");
74 allegro_message("REPORT: %s\n", allegro_error);
75 exit(0);
76 }
77
78
79
80 // Install Keyboard
81 if(install_keyboard() != 0)
82 {
83 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
84 allegro_message("ERROR: Failed to install keyboard. Terminating program.\n");
85 allegro_message("REPORT: %s\n", allegro_error);
86 exit(0);
87 }
88
89 /*install_joystick(JOY_TYPE_AUTODETECT);
90 poll_joystick();
91 if(num_joysticks == 0)
92 {
93 allegro_message("NOTE: No joystick could be found, but you can still use keyboard.");
94 }
95 startpos = joy[0].stick[0].axis[0].pos;*/
96
97
98 // Install Mouse
99 if(install_mouse() < 0)
100 {
101 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
102 allegro_message("ERROR: Failed to install mouse. Terminating program.\n");
103 allegro_message("REPORT: %s\n", allegro_error);
104 exit(0);
105 }
106
107 text_mode(MASK);
108 reserve_voices(32,-1); ///Reserves more channels of sound for us
109
110 // Install Sound
111 if(install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) != 0)
112 {
113 allegro_message("ERROR: Failure to install sound. Attempting to run without sound.\n");
114 allegro_message("REPORT: %s\n", allegro_error);
115 if(install_sound(DIGI_NONE, MIDI_NONE, NULL) != 0)
116 {
117 allegro_message("ERROR: Failed to install sound. Terminating program.\n");
118 allegro_message("REPORT: %s\n", allegro_error);
119 exit(0);
120 }
121 }
122
123 srand( (unsigned) time(NULL));
124
125 // Install Time Handler
126 LOCK_VARIABLE(system_time);
127 LOCK_VARIABLE(ticks);
128 LOCK_VARIABLE(framerate);
129 LOCK_VARIABLE(draw_ticks);
130 LOCK_FUNCTION(timer1);
131 LOCK_FUNCTION(frametimer);
132 iTimer_Speed = 60;
133 install_int_ex(timer1, BPS_TO_TIMER(iTimer_Speed));
134 install_int_ex(frametimer, BPS_TO_TIMER(1));
135 //install_int(timer1, 1000);
136
137 // Setup the buffer
138 buffer = create_bitmap(GFX_W, GFX_H);
139
140 // Setup translucent table
141 create_trans_table(&trans_table, pal, 0, 0, 0, NULL);
142 color_map = &trans_table;
143}
144
145//**************** Classes ***********************
146class BLOCK
147{
148public:
149 BLOCK();
150 ~BLOCK();
151
152 void update();
153 void draw(BITMAP *bDisplay);
154 void set_speed(int v);
155
156private:
157 int speed;
158 int x, y;
159 int col;
160 BITMAP *bImage;
161 int eye_length;
162 int update_timer;
163 int check_timer;
164 bool move;
165 bool scoring;
166};
167
168BLOCK::BLOCK()
169{
170 x = rand() % GFX_W;
171 y = 0;
172 bImage = create_bitmap(20, 20);
173 col = rand() % 255;
174 rectfill(bImage, 0, 0, bImage->w, bImage->h, makecol(rand() % dark,rand() % dark,rand() % dark));
175 eye_length = 4;
176 update_timer = 0;
177 speed = 1;
178 move = true;
179 scoring = true;
180 check_timer = 0;
181
182}
183
184BLOCK::~BLOCK()
185{
186 if(bImage != NULL) {destroy_bitmap(bImage);bImage = NULL;}
187}
188
189void BLOCK::set_speed(int v)
190{
191 speed = v;
192}
193
194void BLOCK::update()
195{
196 int yold = y;
197 if(abs(ticks - update_timer) > 5 && move == true)
198 {
199 y += speed;
200 if(getpixel(bScreen, x + 10, y + 20) != makecol(0,0,0) && y > 100)
201 move = false;
202 if(y > GFX_H)
203 {
204 move = false;
205 y = GFX_H - 20;
206 }
207
208 if(move == false && scoring == true)
209 score += (y - GFX_H) * -1;
210
211 update_timer = ticks;
212 }
213 if(abs(ticks - check_timer) > 30 && move == false)
214 {
215 scoring = false;
216 move = true;
217 check_timer = ticks;
218 }
219
220 //collision
221 if(mouse_x > x && mouse_x < x + 20 && mouse_y > y && mouse_y < y + 20)
222 over = true;
223
224}
225
226void BLOCK::draw(BITMAP *bDisplay)
227{
228 line(bImage, 5, 10 - eye_length, 5, 10 + eye_length, makecol(255, 255, 255));
229 line(bImage, 15, 10 - eye_length, 15, 10 + eye_length, makecol(255, 255, 255));
230
231 draw_sprite(bDisplay, bImage, x, y);
232 putpixel(bDisplay, x + 5, y + 10, makecol(0, 0, 255));
233 putpixel(bDisplay, x + 15, y + 10, makecol(0, 0, 255));
234}
235
236class BLOCKS
237{
238public:
239 BLOCKS();
240 ~BLOCKS();
241
242 void update();
243 void draw(BITMAP *bDisplay);
244
245private:
246 BLOCK *bBlocks[MAX_BLOCKS];
247 int update_timer;
248 int speed_timer;
249 int block_timer;
250 int dark_timer;
251 int gspeed;
252 void create_block();
253} *MyBlocks;
254
255BLOCKS::BLOCKS()
256{
257 for(int i = 0; i < MAX_BLOCKS; i++)
258 bBlocks<i> = NULL;
259 update_timer = 0;
260 gspeed = 5;
261 speed_timer = 0;
262 block_timer = 0;
263 dark_timer = 0;
264}
265
266BLOCKS::~BLOCKS()
267{
268 for(int i = 0; i < MAX_BLOCKS; i++)
269 if(bBlocks<i> != NULL)
270 {
271 delete bBlocks<i>;
272 bBlocks<i> = NULL;
273 }
274}
275
276void BLOCKS::update()
277{
278 if(abs(ticks - update_timer) > block_create)
279 {
280 create_block();
281 update_timer = ticks;
282 }
283 if(abs(ticks - speed_timer) > 1000)
284 {
285 gspeed++;
286 speed_timer = ticks;
287 }
288 if(abs(ticks - block_timer) > 60)
289 {
290 block_create--;
291 if(block_create < 5) block_create = 5;
292 block_timer = ticks;
293 }
294 if(abs(ticks - dark_timer) > 30)
295 {
296 dark--;
297 dark_timer = ticks;
298 }
299 for(int i = 0; i < MAX_BLOCKS; i++)
300 if(bBlocks<i> != NULL)
301 bBlocks<i>->update();
302}
303
304void BLOCKS::create_block()
305{
306 int i = 0;
307 while(i < MAX_BLOCKS && bBlocks<i> != NULL)
308 i++;
309 if(i >= MAX_BLOCKS) return;
310 bBlocks<i> = new BLOCK;
311 bBlocks<i>->set_speed(gspeed);
312}
313
314void BLOCKS::draw(BITMAP *bDisplay)
315{
316 for(int i = 0; i < MAX_BLOCKS; i++)
317 if(bBlocks<i> != NULL)
318 bBlocks<i>->draw(bDisplay);
319}
320
321void game_init()
322{
323 dark = 255;
324 score = 0;
325 quit = false;
326 over = false;
327 bText = create_bitmap(100, 30);
328 bScreen = create_bitmap(GFX_W, GFX_H);
329 clear(bScreen);
330 MyBlocks = new BLOCKS;
331 block_create = 50;
332 show_mouse(screen);
333}
334
335void game_update()
336{
337 MyBlocks->update();
338}
339
340void game_draw()
341{
342 rectfill(bText, 0, 0, bText->w, bText->h, makecol(0,180,0));
343 textprintf(bText, font, 4, 10, makecol(255, 255,255), "SCORE: %d", score);
344 rectfill(bScreen, 0, 0, bScreen->w, bScreen->h, makecol(0,0,0));
345 MyBlocks->draw(bScreen);
346
347 draw_sprite(buffer, bScreen, 0, 0);
348
349 set_trans_blender(0,0,0, 180);
350 draw_trans_sprite(buffer, bText, 10, 10);
351 draw_sprite(screen, buffer, 0, 0);
352
353}
354
355void game_shutdown()
356{
357 destroy_bitmap(buffer);
358 destroy_bitmap(bText);
359}
360
361
362
363void play_game()
364{
365 iFrameRate = false;
366 game_init();
367
368 while(!quit)
369 {
370 while(!key[KEY_ESC] && !over)
371 {
372 while(system_time && !over)
373 {
374 system_time--;
375 ticks++;
376 game_update();
377 }
378
379 draw_ticks++;
380 game_draw();
381
382 if(iFrameRate) textprintf(screen, font, 10, 10, -1, "%d", framerate);
383 }
384 quit = true;
385 system_time = 0;
386 ticks = 0;
387 }
388
389 while(!key[KEY_ENTER])
390 textprintf(screen, font, 100, 100, makecol(255, 255, 255), "GAME OVER! Press ENTER to end game!");
391 game_shutdown();
392}
393
394
395
396int main()
397{
398 init();
399
400
401
402 play_game();
403
404 return 0;
405}
406END_OF_MAIN()
Dodge the Blocks!!!!!!!!!!!!!! ------------ |
Kikaru
Member #7,616
August 2006
![]() |
Finished! Move the blue dot to pick up the gold coins. |
CGamesPlay
Member #2,559
July 2002
![]() |
Well, crappy rule to get on a development environment with only a trackpad, but I have my entry! It's tron, I guess. I finished with about a minute to spare, but uploading this is slow. Oh yay. My phone doesn't support the attachments tab... Emailing my entry to Baf... -- Ryan Patterson - <http://cgamesplay.com/> |
Onewing
Member #6,152
August 2005
![]() |
************ BUG ********************* [edit] Also, the game crashes after so long... ------------ |
Victor Williams Stafusa da Silva
Member #4,212
January 2004
![]() |
About the mine: PS: My crappy dialed internet connection almost made i lose the deadline. I posted in 20:59 (GMT), just a few seconds. [EDIT: It inherited some cool thing from Rambanana (which was inherited from my SH2005 Game: The attack of the space bugs). This include passing "F" as a argc/argv command to make it fullscreen. It inherited other things to handle sound, music and joystick, but doesn't use these. Oh, i found a serious bug: After some time, large white strips start to appear in the game. These are asteroids with something really wrong in their math (and very letal to the player). Maybe some overflow or division by zero bug? ] [The attack of the space bugs - Speedhack 2005] [Rambananas - Speedhack 2006] [Make clean - Speedhack 2009] [The source god - TINS 2010] |
Jakub Wasilewski
Member #3,653
June 2003
![]() |
Okay, I've got all the entries so far compiled, I'll wait for CGamesPlay's if he does post it, and then attach a binary pack for Windows Victor: Hm, I didn't know if code reuse was allowed... I did everything from scratch, but it's OK, it was more fun that way. I felt like my fingers were on fire CGames: BAF doesn't seem to be around, just e-mail it to me at krajzega@kalamburos.gov.net, without the gov. I'll include it with the binaries and post source here. --------------------------- |
Krzysztof Kluczek
Member #4,191
January 2004
![]() |
Done. For Linux people, here is "winalleg.h" compatibility replacement to run this game (also don't forget to change <winalleg.h> to "winalleg.h" in the source code). #include <sys/time.h> unsigned long long timeGetTime() { timeval T; gettimeofday(&T,0); return ((long long)T.tv_sec)*1000+T.tv_usec/1000; }
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <math.h>
5#include <time.h>
6
7#include <allegro.h>
8#include <winalleg.h>
9
10#include <vector>
11#include <string>
12#include <algorithm>
13
14using namespace std;
15
16
17
18#define DIFFICULTY 30
19#define HIVE_HP 10000
20
21
22
23class tUnit {
24public:
25 float xp,yp;
26 float vx,vy;
27 float tx,ty;
28 bool selected;
29 bool hive;
30 int side;
31 int enemy;
32 float timer;
33 int hp;
34
35 tUnit() : selected(false),enemy(-1), timer(0), vx(0), vy(0), hive(false), hp(100) {}
36
37 void Draw(BITMAP *buff);
38 bool Think(float delta);
39 void MoveTo(float x2,float y2);
40};
41
42
43vector<tUnit> units[2];
44int sel_cx,sel_cy;
45float sel_rad;
46int _mb=0;
47float closest_dist;
48
49
50int nearest_unit(int side,float xp,float yp)
51{
52 float md2=100000;
53 int id = -1;
54 for(int i=0;i<units[side].size();i++)
55 {
56 float dx = units[side]<i>.xp - xp;
57 float dy = units[side]<i>.yp - yp;
58 dx=dx*dx+dy*dy;
59 if(units[side]<i>.hive)
60 dx/=9;
61 if(md2>dx)
62 {
63 md2=dx;
64 id=i;
65 }
66 }
67 closest_dist = sqrt(md2);
68 return id;
69}
70
71
72
73void tUnit::Draw(BITMAP *buff)
74{
75 int col = 2;
76 if(selected) col=14;
77 if(side!=0) col=4;
78 circle(buff,int(xp),int(yp),hive?int(13-timer*2):2,col);
79 if(hive)
80 {
81 hline(buff,int(xp)-6,int(yp),int(xp)+6,8);
82 hline(buff,int(xp)-6,int(yp),int(xp)-6+int((13.f*hp)/HIVE_HP),col);
83 }
84}
85
86bool tUnit::Think(float delta)
87{
88 if(hp<=0)
89 return false;
90
91 if(hive)
92 {
93 selected = false;
94 timer-=delta;
95 if(timer<=0)
96 {
97 hp+=10;
98 if(hp>HIVE_HP)
99 hp=HIVE_HP;
100
101 float r = (rand()%360)*M_PI/180.f;
102 tUnit u;
103
104 u.side = side;
105 u.xp = xp;
106 u.yp = yp;
107 u.tx = xp + cos(r)*30;
108 u.ty = yp + sin(r)*30;
109
110 units[side].push_back(u);
111
112 timer+=1+(rand()%1000)/1000.f;
113 }
114
115 return true;
116 }
117
118
119 // AI
120 timer-=delta;
121 if(timer<=0)
122 {
123 int enemy = nearest_unit(!side,xp,yp);
124 if(enemy>=0)
125 {
126 if(closest_dist<5)
127 units[!side][enemy].hp-=rand()%120;
128
129 if(side!=0 && (closest_dist<30 || (rand()%100<DIFFICULTY)))
130 {
131 tx = units[!side][enemy].xp;
132 ty = units[!side][enemy].yp;
133 }
134
135 timer+=0.5+(rand()%500)/1000.f;
136 }
137 }
138
139 float acc = 0.3;
140 float frc = 0.5;
141
142 acc = acc*delta;
143 frc = pow(frc,delta);
144
145 vx+=(tx-xp)*acc; vx*=frc;
146 vy+=(ty-yp)*acc; vy*=frc;
147 xp+=vx*delta;
148 yp+=vy*delta;
149
150 return true;
151}
152
153void tUnit::MoveTo(float x2,float y2)
154{
155 tx=x2+rand()%21-10;
156 ty=y2+rand()%21-10;
157}
158
159
160
161void init_armies()
162{
163 for(int s=0;s<2;s++)
164 {
165 units[s].clear();
166 for(int y=0;y<3;y++)
167 {
168 tUnit u;
169
170 u.side = s;
171 u.xp = 40+560*s;
172 u.yp = 40+200*y;
173 u.hive = true;
174 u.hp = HIVE_HP;
175
176 units[s].push_back(u);
177 }
178 }
179}
180
181
182void think_mouse()
183{
184 int mx = mouse_x;
185 int my = mouse_y;
186 int mb = mouse_b;
187 if(mb&2) mb=2;
188
189 if(mb==1 && _mb!=1)
190 {
191 sel_cx = mx;
192 sel_cy = my;
193 sel_rad=0;
194 }
195
196 if(mb==1)
197 {
198 int dx=mx-sel_cx;
199 int dy=my-sel_cy;
200 sel_rad=sqrt(float(dx*dx+dy*dy));
201 }
202
203 if(mb!=1 && _mb==1)
204 for(int i=0;i<units[0].size();i++)
205 {
206 int dx=units[0]<i>.xp-sel_cx;
207 int dy=units[0]<i>.yp-sel_cy;
208 units[0]<i>.selected = (sqrt(float(dx*dx+dy*dy))<=sel_rad);
209 }
210
211 if(mb==2 && _mb!=2)
212 for(int i=0;i<units[0].size();i++)
213 if(units[0]<i>.selected)
214 units[0]<i>.MoveTo(mx,my);
215
216 _mb = mb;
217}
218
219
220
221int main()
222{
223 allegro_init();
224 install_keyboard();
225 install_timer();
226 install_mouse();
227
228 set_color_depth(8);
229 set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);
230
231 show_mouse(screen);
232
233 BITMAP *buff = create_bitmap(SCREEN_W,SCREEN_H);
234 clear(buff);
235
236 init_armies();
237
238 unsigned int t0,t1;
239 t0=t1=timeGetTime();
240
241 while(!key[KEY_ESC])
242 {
243 clear(buff);
244
245 for(int s=0;s<2;s++)
246 for(int i=0;i<units[s].size();i++)
247 units[s]<i>.Draw(buff);
248
249 if(_mb==1)
250 circle(buff,sel_cx,sel_cy,int(sel_rad),2);
251
252 vsync();
253 blit(buff,screen,0,0,0,0,SCREEN_W,SCREEN_H);
254
255 t1 = timeGetTime();
256 float delta = (t1-t0)/1000.f;
257 t0=t1;
258
259 think_mouse();
260
261 for(int s=0;s<2;s++)
262 for(int i=0;i<units[s].size();i++)
263 if(!units[s]<i>.Think(delta))
264 {
265 units[s]<i> = units[s][units[s].size()-1];
266 units[s].erase(units[s].end()-1);
267 i--;
268 }
269
270 }
271
272 return 0;
273}
274END_OF_MAIN()
________ |
Kikaru
Member #7,616
August 2006
![]() |
Can't get any of the source codes to compile. Maybe attach some .exe files later? |
Jakub Wasilewski
Member #3,653
June 2003
![]() |
Quote: Maybe attach some .exe files later? I'll post the binary pack in my next post, whether CGames makes it or not. KK said: Done.
Late --------------------------- |
CGamesPlay
Member #2,559
July 2002
![]() |
Baf doesn't seem to be available. I can email it to anyone who asks me... PM me, I guess. Oh, I will also email the entry to cgamespla@mailinator.com. Go to http://mailinator.com and log into to cgamespla's mailbox. Not cgamesplay's, but cgamespla's. -- Ryan Patterson - <http://cgamesplay.com/> |
Kikaru
Member #7,616
August 2006
![]() |
Oops. Didn't get to test the final thing, so two changes: replace 'doline' with 'do_line', and on line 98, change 'cointime' to 'score'. |
|
|