Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » MinorHack Attack!

This thread is locked; no one can reply to it. rss feed Print
MinorHack Attack!
BAF
Member #2,981
December 2002
avatar

1#include <math.h>
2#include <allegro.h>
3#include <vector>
4 
5using namespace std;
6 
7struct Point
8{
9 int x, y;
10};
11 
12class Mouse
13{
14 public: // Types
15 static const int spacing = 8;
16 static const int radius = 4;
17 
18 public: // Public variables
19 int pressed_x, pressed_y;
20 vector<Point> snake;
21 int countdown;
22 Point next;
23 int score;
24 bool dead;
25 
26 public: // Public functions
27 Mouse()
28 {
29 Restart();
30 }
31 
32 bool Logic()
33 {
34 bool pressed = !(pressed_x == -1);
35 if(!pressed)
36 {
37 if(mouse_b & 1)
38 {
39 pressed_x = mouse_x;
40 pressed_y = mouse_y;
41 
42 if(countdown == -1 && !dead)
43 countdown = 15;
44 }
45 }
46 if(pressed)
47 {
48 if(!(mouse_b & 1))
49 {
50 if(mouse_x < 100 && pressed_x < 100 && mouse_y > SCREEN_H - 25 && pressed_y > SCREEN_H - 25)
51 return false;
52 if(mouse_x < 200 && pressed_x < 200 && mouse_y > SCREEN_H - 25 && pressed_y > SCREEN_H - 25)
53 {
54 Restart();
55 }
56 pressed_x = -1;
57 pressed_y = -1;
58 }
59 }
60 
61 if(countdown >= 0)
62 {
63 countdown--;
64 if(countdown == -1)
65 {
66 snake.push_back(next);
67 if(!Dead())
68 {
69 countdown = 15;
70 score++;
71 }
72 else
73 dead = true;
74 }
75 next.x = snake.back().x;
76 next.y = snake.back().y;
77 double angle = atan2((double) mouse_y - next.y, mouse_x - next.x);
78 next.x += cos(angle) * spacing;
79 next.y += sin(angle) * spacing;
80 }
81 return true;
82 }
83 
84 void Draw(BITMAP* buffer)
85 {
86 if(!dead)
87 clear_to_color(buffer, makecol(255, 255, 0));
88 else
89 clear_to_color(buffer, makecol(255, 0, 0));
90 hline(buffer, 0, SCREEN_H - 25, 200, makecol(0, 0, 0));
91 vline(buffer, 100, SCREEN_H - 25, SCREEN_H, makecol(0, 0, 0));
92 textprintf_centre_ex(buffer, font, 50, SCREEN_H - 14, makecol(0, 0, 0), -1, "Quit");
93 vline(buffer, 200, SCREEN_H - 25, SCREEN_H, makecol(0, 0, 0));
94 textprintf_centre_ex(buffer, font, 150, SCREEN_H - 14, makecol(0, 0, 0), -1, "Restart");
95 textprintf_right_ex(buffer, font, SCREEN_W - 6, SCREEN_H - 14, makecol(0, 0, 0), -1, "Score: %02d", score);
96 
97 for(vector<Point>::iterator i = snake.begin(); i != snake.end(); i++)
98 {
99 circle(buffer, i->x, i->y, radius, makecol(0, 0, 0));
100 }
101 if(countdown != -1)
102 circle(buffer, next.x, next.y, radius, makecol(0, 0, 128));
103 if(dead)
104 textprintf_centre_ex(buffer, font, SCREEN_W / 2, SCREEN_H / 2, makecol(255, 255, 255), -1, "Game over");
105 }
106 
107 bool Dead()
108 {
109 for(vector<Point>::iterator i = snake.begin(); i != snake.end() - 2; i++)
110 {
111 double dist = sqrt(pow((double) i->x - next.x, 2) + pow((double) i->y - next.y, 2));
112 if(dist < 2 * radius)
113 return true;
114 }
115 return false;
116 }
117 
118 void Restart()
119 {
120 pressed_x = -1;
121 pressed_y = -1;
122 countdown = -1;
123 score = 0;
124 dead = false;
125 snake.clear();
126 Point p;
127 p.y = SCREEN_H / 2;
128 p.x = SCREEN_W / 2 - (5 * spacing);
129 for(int i = 0; i < 5; i++)
130 {
131 snake.push_back(p);
132 p.x += spacing;
133 }
134 }
135};
136 
137volatile int tick = 0;
138 
139void tock()
140{
141 ++tick;
142}
143 
144int main(int argc, char* argv[])
145{
146 allegro_init();
147 
148 set_color_depth(32);
149 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
150
151 install_mouse();
152 install_timer();
153 
154 install_int_ex(tock, BPS_TO_TIMER(30));
155 
156 bool quit = false;
157 Mouse m;
158 BITMAP* buffer = create_bitmap(SCREEN_W, SCREEN_H);
159 show_mouse(screen);
160 
161 while(!quit)
162 {
163 while(tick > 0)
164 {
165 if(!m.Logic())
166 quit = true;
167 --tick;
168 }
169 m.Draw(buffer);
170 scare_mouse();
171 blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
172 unscare_mouse();
173 }
174 
175 destroy_bitmap(buffer);
176 
177 return 0;
178}
179END_OF_MAIN()
180// The end

There is CGames's entry.

Krzysztof Kluczek
Member #4,191
January 2004
avatar

Quote:

Can't get any of the source codes to compile. :o I keep getting errors like "textout_ex undeclared," or "invalid conversion from int to float," and even "confilcting definitions of BITMAP". More recent version of Allegro should fix the 'textout_ex' error though.

As you've said, textout_ex in newer Allegro version. "invalid conversion" is just a warning and you should be able to get rid of "conflicting definitions of BITMAP" by adding "-DNOGDI" to compiler parameters (it prevents <windows.h> from defining it's own BITMAP type). :)

Quote:

KK said:
Done.

Late :P.

On time. :) The code you've got in my post is a snapshot taken just before the compo ended. I've spent additional time before posting it playing it a bit with different settings, so I could make the suggestion, but the code you've got is pure compo version. :)

Victor Williams Stafusa da Silva
Member #4,212
January 2004
avatar

Off-topic:

Jakub Wasilewski said:

(...) without the gov (...)

Nice way to fool e-mail harvesters. :o

[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
avatar

The binary package is attached.

Steven Silvey's code is patched with the change he mentioned to remove a bug.
My code is patched with the two-constant tweak I mentioned.
Kikaru's is corrected with the "doline"=>"do_line" change.

The rest is left untouched. All exe's require alleg42.dll.

---------------------------
[ ChristmasHack! | My games ] :::: One CSS to style them all, One Javascript to script them, / One HTML to bring them all and in the browser bind them / In the Land of Fantasy where Standards mean something.

CGamesPlay
Member #2,559
July 2002
avatar

Okay, now that I am not so worried about getting my entry up:

Click to start the game. The blue circle is where the next node will appear. Make the snake as long as possible without crossing itself. I had no time to experiment with different difficulties, but the magic number 15 in the code can be lowered to make the game harder. (countdown is 15 at the beginning of adding a node.

I had fun doing this one, finished with about a minute to spare, so I'm happy that I did better than last time.

I'm going out for a few hours now. If Jakub gets his binary pack together, I can play tonight, otherwise, probably not till Tuesday (when I am back at home).

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Kikaru
Member #7,616
August 2006
avatar

I need the alleg42.dll. Anyone have it handy?

All in all, the competition was fun! When is the next one?

Jakub Wasilewski
Member #3,653
June 2003
avatar

---------------------------
[ ChristmasHack! | My games ] :::: One CSS to style them all, One Javascript to script them, / One HTML to bring them all and in the browser bind them / In the Land of Fantasy where Standards mean something.

CGamesPlay
Member #2,559
July 2002
avatar

The next one will be after the judging for this one is over :) Just put them in your favorite order, from first to last.

Let me know what weekend would be best for everyone, and I can schedule another.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Onewing
Member #6,152
August 2005
avatar

Wow, some nice entries. I'd say either Jakub or Johnathan for my first vote.

@KK: I couldn't get it to compile. timeGetTime couldn't be found (linking error) and M_PI was undefined.

------------
Solo-Games.org | My Tech Blog: The Digital Helm

CursedTyrant
Member #7,080
April 2006
avatar

Unfortunately, I could not attend. There was a really vehement thunderstorm, and I didn't want to push my luck, so I unplugged my PC.

---------
Signature.
----
[My Website] | [My YouTube Channel]

Jakub Wasilewski
Member #3,653
June 2003
avatar

Quote:

I couldn't get it to compile. timeGetTime couldn't be found (linking error) and M_PI was undefined.

For the first thing, link with the winmm lib (-lwinmm for MinGW), for the second, I don't know. Maybe try including <cmath> instead of "math.h"? It should be defined there. If that doesn't help, just add #define M_PI 3.141592 and be done with it ;).

---------------------------
[ ChristmasHack! | My games ] :::: One CSS to style them all, One Javascript to script them, / One HTML to bring them all and in the browser bind them / In the Land of Fantasy where Standards mean something.

Krzysztof Kluczek
Member #4,191
January 2004
avatar

Quote:

@KK: I couldn't get it to compile. timeGetTime couldn't be found (linking error) and M_PI was undefined.

M_PI should be defined in <math.h>, but if it isn't, you can define it yourself. timeGetTime() is Windows high-frequency timer, which declaration is in <windows.h> (included indirectly via <winalleg.h> (you may also have to pass "-lwinmm" linker option if it doesn't include this library by default). If you are running Linux, try compatibility timeGetTime() Linux replacement I've posted together with my code. :)

Jonatan Hedborg
Member #4,886
July 2004
avatar

Very well done everyone! 7 entires is not bad i think.

EDIT: fixed

CGamesPlay
Member #2,559
July 2002
avatar

Okay, I got to play all of the games. Here are my notes:

Jakub: good game. No way to restart, and games are really short :) I could quit without the keyboard though.

Jonathan: very creative game. Hard to control the ball though. I can quit and restart without the keyboard :)

Kikaru: cool concept. The score display is broken, though, and there is no end-game screen, either.

Krzysztof: Neat idea. I don't really know how to win, and the game never seems to end, but it was cool. Also demonstrated the ability to make a strategy game in 1 hour. No way to quit or restart with the mouse.

Onewing: good game with some bugs. I eventually found a pocket I was invulnerable in :) My score seemed to restart, too. No way to quit or restart using just the mouse.

Victor: fun game with nice graphics. For some reason, my ship diappeared in a flash of light. No way to quit or restart using the mouse.

I'm not holding the quit/restart issues against anyone. Here is my ranking:

Krzysztof, Kikaru, CGamesPlay, Hedborg, Onewing, Jakub, Victor.

This was hard to rank. I like Krzy's the best, but the rest were all pretty close. I put Kikaru's second because it was a neat idea. Hedborg's had control issues, and was hard. Onewing's had some bugs. Jakub's was like impossible to play for long because I guess you have to shoot ammo to gain ammo :) And Victor's was last, even though it had the best graphics, because there was no score or way to quit.

Good effort participants! I think I may want to switch to a quantitative judging system in future competitions. It was really hard to place my own entry :)

Another thing to note is what rules these entries also followed. For instance Krzy's and strategy. Just think about that before saying a rule is impossible. Okay, now I am out for the day. When I get back, I expect your ratings, guys. I will put up a winners page on the site, too.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Ron Ofir
Member #2,357
May 2002
avatar

Jonatan: You mean good, right?

Other than that, I can't wait for the next one (I hope it will be earlier than this, or on Saturday/Friday evening). Congratulations for those of who did manage to get something done!

Jonatan Hedborg
Member #4,886
July 2004
avatar

Uh yeah. Fixed. I have no idea why that said "bad" :D I think it was suppose to be "not bad"

Also; Are you allowed to vote for your own game?

Victor Williams Stafusa da Silva
Member #4,212
January 2004
avatar

CGamesPlay said:

For some reason, my ship diappeared in a flash of light.

The flash of light is an asteroid distorted by an overflow bug.

Oh, ih got the last place? :(

[The attack of the space bugs - Speedhack 2005] [Rambananas - Speedhack 2006] [Make clean - Speedhack 2009] [The source god - TINS 2010]

Kikaru
Member #7,616
August 2006
avatar

kk, Victor Williams, Onewing, Jonatan Hedborg, CGamesPlay, Jakub Wasilewski.

KK: Your game was awesome! You should consider turning it into a full project.

CGamesPlay: It was good, maybe the most polished of them, but very slow, and a little boring.

Jakub: The reason I rank your game last is that the max score possible is 6, and after you fire 6 times you just wait until you die.

(the score display can be fixed by changing "cointime" to "score" on the textprintf. It was a testing thing, and I guess I hit 'undo' after I fixed it.):P

Jonatan Hedborg
Member #4,886
July 2004
avatar

I will withdraw some internal points for using the keyboard.

From best to less best:
- Krzysztof Kluczek: Very ambitious. No way to win (or score) brings the score down a bit. A bit easy.

- Jakub: Very nice graphics and polish. Gets old kind of quick.

- Jonatan Hedborg: Well, cant really objectively comment this, but i think i did pretty well =) Perhaps i should have made the player-ball a tad faster. But then again, i like it this way - nice and difficult >: )
Note: You cant quit prematurely - but it's not really a problem as you tend to die within a few seconds anyway ;)

CGamesPlay: A neat puzzle-style game with a nice UI. No real challenge in the game however. I can imagine it takes quite some time to die from space-exhaustion.

Steven Silvey: A nice concept, and the graphics are quite good. The blocks seems to fall quite "choppily" however, and they don't seem to stack well all the time (some of them got stuck half-way down the screen). Not much interactivity is needed to stay alive for the first few minutes, then you need to keep alive for a while and after that you can just hide in a "cave" and never die. So it's a bit easy =)

Victor Williams: Beautiful, especially the background. No way to win or compare results. Quite easy as well. Works as a screen-saver after you die.

Kikaru: The graphics are flickering (might just be here) and you can't quit the game early. The score system seems broken.

I think we all did a very nice job with the games! Man did i feel the pressure at the end there :D
One hour is not a lot of time.
Great job all!

EDIT:
Uhm, you reload the gun with the right mouse button in Jakub's game :)
Also, we need a better voting system.

Kikaru
Member #7,616
August 2006
avatar

For my game, I was finishing coding my enty, watching the on-site time limit, and typing a quick description all at the same time, during the last 2 min of the competition, and barely got it submitted. I did not install keybourd or use any mouse buttons, and didn't have time to code hotspots.
However, this was also the first program I ever wrote in under a week of casual programming and testing, so I think I did okay. :)

I am going to make an update to it, showing what it was supposed to be.

Jonatan Hedborg
Member #4,886
July 2004
avatar

Oh yes, don't be offended by my comments :)
Getting anything that runs in one hour is great.

Krzysztof Kluczek
Member #4,191
January 2004
avatar

Comments (ordered by name):
- CGamesPlay: Nice, a bit improved, Snake clone, although gameplay can get boring after a while (adding "beans" instead of continuous growth and increasing the speed could help a lot).

- Jakub: Well done and polished classic. It's sometimes physically impossible to survive some waves, but other than this, it's OK.

- Jonathan: Simple and playable, with some polish.

- Kikaru: The idea is simple, but after some improvements it can be quite nice tool for testing someone's reflex (eg. coin value could decrease over time). Too bad it just quits after time has passed.

- Steven: Simple idea, which works quite nice, but not without some problems (scores above 9999 are displayed incorrectly, blocks don't collide properly and sometimes stop and hover above the field). There is also a gameplay problem: once some boxes form a kind of "roof", you can hide the mouse there and be completely safe (aligning boxes before dropping them should would solve this problem).

- Victor: Simple idea, but done nicely, but looking at the code makes me really doubt it all was written from scratch during 1 hour.

(on a second thought, I should probably have left all "simple idea" comments) :)

My vote goes as follows:
Jakub, Steven, Victor, Jonathan, CGamesPlay, Kikaru

Quote:

No way to quit or restart with the mouse.

The game itself uses just the mouse. It's just exiting it that doesn't - other games sometimes even don't have this feature. ;)

Quote:

I'm not holding the quit/restart issues against anyone. Here is my ranking:

Krzysztof, Kikaru, CGamesPlay, Hedborg, Onewing, Jakub, Victor.

I find it strange you've included yourself in the ranking. :)

Quote:

I like Krzy's the best, but the rest were all pretty close.

Quote:

Your game was awesome! You should consider turning it into a full project.

Thanks! ;D (you can just call me KK)

Quote:

- Krzysztof Kluczek: Very ambitious. No way to win (or score) brings the score down a bit. A bit easy.

You can destroy enemy "hives" with your units. Destroying all enemy activity in the zone while saving at least one "hive" can be considered complete victory. Destroying all enemy activity while loosing all own "hives" can be considered partial victory. Loosing own "hives" while allowing enemy "hives" to continue spawning is clear failure. I don't think achieving complete victory is too easy (it's doable, although it probably requires more luck than strategy). :)

Jakub Wasilewski
Member #3,653
June 2003
avatar

People who ranked my game last because of "only 6 rounds of ammo", please do read the source file. There it is clearly on the top of the file - "press RMB to reload, each reload costs 200 points" or something like this :). Just in case you want to change your mind ;).

Well, here is my order:

Jonatan, Krzysiek, Steven, Victor, CGamesPlay, Kikaru.

Jonatan - original concept, challenging controls, simple gameplay. Nice touch with the graphics, they look almost acceptable :). Most fun factor earns this entry a win.

Krzysiek - a strategy game in 1 hour is always impressive, even if as simple as that one. It's nicely executed, the display is clear, and it takes some skill to win (I was able to rescue 2 hives after a bit of practice, default settings). Pretty fun.

Steven - pretty complete, somewhat original. The bugs ruin it though, and there is ga gameplay flaw where you can find a closed pocket and wait there until your score... well, restarts from 0 :).

Victor - well, pretty complete, though dull - at first it's nearly impossible to die, and then some sort of ray usually kills you without a chance of avoiding it.

CGamesPlay - somewhat original concept, though it actually doesn't turn out to be all that fun.

That's my take.

---------------------------
[ ChristmasHack! | My games ] :::: One CSS to style them all, One Javascript to script them, / One HTML to bring them all and in the browser bind them / In the Land of Fantasy where Standards mean something.

Jonatan Hedborg
Member #4,886
July 2004
avatar

Thanks for the vote there =)

Also, feel free to remove my name from my own list. I just added it in there because CGP did.

KK: Oh yeah, i "won" it two out of three times, once with one surviving hive and once with two. It's quite fun (but would be more suitable as a "real" game. Please make it one :)). I just meant that it would have been nice with a "Yay, you crushed the enemy ants/xenomorphs/bees like a melon shot by a gun!" screen.

Kikaru
Member #7,616
August 2006
avatar

Here is what my game was supposed to look like. Requires alleg40.dll. Not to be used for judging. :)

[edit]
Jakub: game is ok, a little wierd though. My vote now goes:kk, Victor Williams, Onewing, Jonatan Hedborg, Jakub Wasilewski, CGamesPlay.



Go to: