Anybody up for a Minorhack?
I've added the code to schedule competitions, automatically, every other week. If the time it schedules isn't good for you, you can propose one at a different time. Of course, whichever one gets 4 votes first will be scheduled, and if there's a conflict, the other one deleted.
[edit]
Changed link to homepage
Ummmmmm, I see "February 17th at 7:00 pm - 0 votes" listed like ten times and no other times.
Anyway, I'm in. I want to do some fun programming again.
Yes, the site seems a little freaked out right now.
Anyway, I'm in too.
I'm out of town on Saturday, so no luck this time .
Ack! I guess it is proposing a new one every hour
I will fix later today
I have absolutely nothing for Saturday, so I am in.
That's... odd...
Something bad is happening to my site
Something must have happened when it promoted the competition to "scheduled", because it... didn't.
[append]
Site works, competition scheduled. Yay!
[append]
Just over an hour! Don't forget!
I'm in. At the time of writing this post, it is still 17minutes until it starts, I haven't used Allegro for over a year, haven't written C++ or C code for over half a year and I'm currently setting up my VS2005.
I'm armed with a copy of the manual and Allegro 4.2 and am currently writing just basic initialization code (which won't exceed 10 or 20 lines with loads of whitespace).
Yay for participation. I definitely need to code an email reminder (or SMS reminder) of competitions coming up.
Server Error
Sorry, but a server error has occurred. The site administrator has been notified.
I can't join. :'(
I'm in!
Nooooooooo! I don't know what to do with the server error theme!
edit: goes away if I log in? Or it was just fixed.
Was just fixed. I'm still writing init code and have no idea yet, how to fit in the bonus rule into my non-existant game.
Can't submit my entry.
CGames, I think your site is broken. It gives me a server error when I click submit.
here is my entry: Rings.
The objective of the game is to rotate all of the red rings so the dots on them line up. However, when you move a ring, another ring will move as well. Which one moves which is random, at the beginning of each round. Use left and right to rotate, up and down to change rings.
1 | #include <allegro.h> |
2 | #include "math.h" |
3 | |
4 | #define ALLEGRO_NO_FIX_CLASS |
5 | |
6 | #define MODE GFX_AUTODETECT_WINDOWED |
7 | #define WIDTH 640 |
8 | #define HEIGHT 480 |
9 | #define COLOR_DEPTH 32 |
10 | |
11 | #define WHITE makecol(255, 255, 255) |
12 | #define RED makecol(255, 0, 0) |
13 | #define GOLD makecol(255, 255, 0) |
14 | #define BLACK makecol(0, 0, 0) |
15 | |
16 | #define LOOP_TIME 30 |
17 | |
18 | BITMAP *buffer; |
19 | long start_time; |
20 | long long timer = 0; |
21 | bool end_game = false; |
22 | |
23 | class ring |
24 | { |
25 | public: |
26 | int rot; |
27 | }; |
28 | |
29 | //update the timer |
30 | void update_time(){timer++;} |
31 | |
32 | |
33 | //main function |
34 | void main() |
35 | { |
36 | //setup allegro |
37 | allegro_init(); |
38 | install_keyboard(); |
39 | install_mouse(); |
40 | install_timer(); |
41 | set_color_depth(COLOR_DEPTH); |
42 | set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0); |
43 | |
44 | //setup the timer |
45 | install_int(update_time, 1); |
46 | |
47 | //initialize the buffer |
48 | buffer = create_bitmap(WIDTH, HEIGHT); |
49 | |
50 | srand(time(NULL)); |
51 | |
52 | bool select = false; |
53 | int mode = -1; |
54 | textout_centre_ex(screen, font, "select difficulty:", 320, 180, WHITE, BLACK); |
55 | textout_centre_ex(screen, font, "F1 - easy", 320, 200, WHITE, BLACK); |
56 | textout_centre_ex(screen, font, "F2 - normal", 320, 220, WHITE, BLACK); |
57 | textout_centre_ex(screen, font, "F3 - hard", 320, 240, WHITE, BLACK); |
58 | textout_centre_ex(screen, font, "F4 - insane", 320, 260, WHITE, BLACK); |
59 | while(!select) |
60 | { |
61 | for (int i = KEY_F1; i < KEY_F5; i++) |
62 | { |
63 | if (key<i>) |
64 | { |
65 | select = true; |
66 | mode = i-KEY_F1; |
67 | } |
68 | } |
69 | } |
70 | |
71 | int num_rings = 3+(mode*2); |
72 | int iring = 0; |
73 | int last_hit = 0; |
74 | ring band[num_rings]; |
75 | int aring[num_rings]; |
76 | for (int i = 0; i < num_rings; i++) |
77 | { |
78 | aring<i> = -1; |
79 | } |
80 | int n = 0; |
81 | while (n < num_rings) |
82 | { |
83 | int aranda = rand()%num_rings; |
84 | while ((aranda == n)||(aring[aranda] > -1)) |
85 | aranda = rand()%num_rings; |
86 | aring[aranda] = n; |
87 | n++; |
88 | } |
89 | |
90 | |
91 | //main loop |
92 | while (!end_game) |
93 | { |
94 | //log the start time |
95 | start_time = timer; |
96 | |
97 | if (key[KEY_ESC]) |
98 | end_game = true; |
99 | |
100 | /*game goes here*/ |
101 | if (timer > last_hit+100) |
102 | { |
103 | if (key[KEY_LEFT]) |
104 | { |
105 | band[iring].rot += 5; |
106 | band[iring].rot %= 6; |
107 | band[aring[iring]].rot += 5; |
108 | band[aring[iring]].rot %= 6; |
109 | last_hit = timer; |
110 | } |
111 | if (key[KEY_RIGHT]) |
112 | { |
113 | band[iring].rot ++; |
114 | band[iring].rot %= 6; |
115 | band[aring[iring]].rot ++; |
116 | band[aring[iring]].rot %= 6; |
117 | last_hit = timer; |
118 | } |
119 | if (key[KEY_UP]) |
120 | { |
121 | iring++; |
122 | iring %= num_rings; |
123 | last_hit = timer; |
124 | } |
125 | if (key[KEY_DOWN]) |
126 | { |
127 | iring += num_rings-1; |
128 | iring %= num_rings; |
129 | last_hit = timer; |
130 | } |
131 | } |
132 | int num_good = 1; |
133 | for (int i = 1; i < num_rings; i++) |
134 | { |
135 | if (band<i>.rot == band[0].rot) |
136 | num_good++; |
137 | } |
138 | |
139 | /*drawing goes here*/ |
140 | for (int i = 0; i < num_rings; i++) |
141 | { |
142 | circle(buffer, WIDTH/2, HEIGHT/2, (i*20)+20, RED); |
143 | if (i == iring) |
144 | circlefill(buffer, WIDTH/2+int((i+1)*20*cos(band<i>.rot)), HEIGHT/2+int((i+1)*20*sin(band<i>.rot)), 3, GOLD); |
145 | else |
146 | circlefill(buffer, WIDTH/2+int((i+1)*20*cos(band<i>.rot)), HEIGHT/2+int((i+1)*20*sin(band<i>.rot)), 3, RED); |
147 | } |
148 | |
149 | //draw to the screen |
150 | blit(buffer, screen, 0, 0, 0, 0, WIDTH, HEIGHT); |
151 | |
152 | //victory! |
153 | if (num_good >= num_rings) |
154 | { |
155 | textout_centre_ex(screen, font, "You Win!", 320, 50, WHITE, -1); |
156 | while (!key[KEY_ESC]) |
157 | {} |
158 | } |
159 | |
160 | //clear the buffer |
161 | clear_to_color(buffer, BLACK); |
162 | |
163 | //wait |
164 | while (timer < start_time + LOOP_TIME) |
165 | {} |
166 | } |
167 | remove_int(update_time); |
168 | destroy_bitmap(buffer); |
169 | return; |
170 | } |
171 | END_OF_MAIN() |
Found a bug with the ring-linking. Sometimes makes it impossible to win.
Not planning on submitting my entry.
I can't submit either -- my entry's below. Didn't turn out to be so much fun, but oh well. You're a little blue ball jumping between planets. You can't go off screen or fall in to the sun, or you die.
edit: hmm, submit seemed to work now, although adding notes didn't.
1 | #include <allegro.h> |
2 | #include <cmath> |
3 | #include <list> |
4 | #include <iostream> |
5 | |
6 | using namespace std; |
7 | |
8 | int lt = 0; |
9 | void timer() { |
10 | {lt ++;} |
11 | } END_OF_FUNCTION(timer) |
12 | |
13 | int cx, cy; |
14 | |
15 | struct circ { |
16 | float r, theta; |
17 | float rad; |
18 | int col; |
19 | |
20 | circ(float r, float theta, float rad, int col) : r(r), theta(theta), rad(rad), col(col) {} |
21 | |
22 | void draw(BITMAP *buf) { |
23 | circlefill(buf, cx + cos(theta)*r, cy + sin(theta)*r, rad, col); |
24 | } |
25 | }; |
26 | |
27 | |
28 | int main() { |
29 | allegro_init(); |
30 | install_keyboard(); |
31 | install_timer(); |
32 | LOCK_FUNCTION(timer); |
33 | LOCK_VARIABLE(lt); |
34 | install_int_ex(timer, BPS_TO_TIMER(30)); |
35 | |
36 | set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); |
37 | |
38 | BITMAP *buf = create_bitmap(SCREEN_W, SCREEN_H); |
39 | |
40 | cx = SCREEN_W /2; |
41 | cy = SCREEN_H + 100; |
42 | |
43 | circ sun(0, 0, 300, makecol(255,200,0)); |
44 | list<circ> planets; |
45 | for (int i = 0; i < 10; i++) { |
46 | float r = (rand()%21 - 10) / 10.0; |
47 | planets.push_back(circ(350 + 20*r, .628 * i + .2*r - (3.14/2.0), 20 + 5*r, makecol(r*100,255,r*100))); |
48 | } |
49 | circ me(0, 0, 10, makecol(0,0,255)); |
50 | list<circ>::iterator mine = planets.begin(); |
51 | me.r = mine->rad + me.rad; |
52 | float racc = 0; |
53 | |
54 | while(!key[KEY_ESC]) { |
55 | while (lt> 0) { |
56 | |
57 | if (me.r > mine->rad + me.rad) { |
58 | me.r -= racc; |
59 | racc+=.1; |
60 | } else { |
61 | racc = 0; |
62 | me.r = mine->rad + me.rad; |
63 | me.theta -= (!key[KEY_RIGHT] - !key[KEY_LEFT]) * .1; |
64 | if (key[KEY_SPACE]) { |
65 | me.r += 5; |
66 | racc = -5; |
67 | } |
68 | } |
69 | |
70 | float distToMine = me.r; |
71 | float mex = cx + cos(mine->theta)*mine->r + cos(me.theta)*me.r; |
72 | float mey = cy + sin(mine->theta)*mine->r+sin(me.theta)*me.r; |
73 | |
74 | if ( sqrt( (mex - cx) * (mex -cx) + (mey -cy) * (mey -cy) ) < sun.rad + me.rad) |
75 | { |
76 | return 1; |
77 | } else if (mex > SCREEN_W || mex < 0) { |
78 | return 1; |
79 | } |
80 | |
81 | for (list<circ>::iterator i = planets.begin(); i != planets.end(); ++i){ |
82 | if (i != mine) { |
83 | float youx = cx + cos(i->theta)*i->r; |
84 | float youy = cy + sin(i->theta)*i->r; |
85 | float dist = sqrt( (youx - mex) * (youx - mex) + (youy - mey) * (youy - mey) ); |
86 | if (dist < distToMine) { |
87 | distToMine = dist; |
88 | mine = i; |
89 | me.r = dist; |
90 | me.theta = atan2(mey - youy, mex - youx); |
91 | racc = 0; |
92 | } |
93 | } |
94 | } |
95 | |
96 | for (list<circ>::iterator i = planets.begin(); i != planets.end(); ++i){ |
97 | i->theta += .005; |
98 | } |
99 | |
100 | |
101 | lt--; |
102 | } |
103 | |
104 | for (list<circ>::iterator i = planets.begin(); i != planets.end(); ++i){ |
105 | i->draw(buf); |
106 | } |
107 | circlefill(buf, cx + cos(mine->theta)*mine->r + cos(me.theta)*me.r, |
108 | cy + sin(mine->theta)*mine->r+sin(me.theta)*me.r, me.rad, me.col); |
109 | sun.draw(buf); |
110 | blit(buf, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); |
111 | clear(buf); |
112 | } |
113 | |
114 | return 0; |
115 | } END_OF_MAIN() |
Sorry for the bugs. I've recently switched to a new database backend and a much more pedantic error reporting system. So you can imagine the inconsistencies that come up. Anyways, I've got Kikaru's entry manually added, and Zaphos got his in, as well as Dennis.
Looks like the "entry notes" page won't work either, right now, and that seems to be cause by code that isn't mine, so it will take longer to fix.
In the mean time, let the judging begin!
I'm quite happy with my entry this time around. I had a bunch of spare time, so I added an instructions screen
Well, I submitted my entry though you can't do much besides rotating the players paddle and the collision detection and game logic of the enemy isn't working.
So it's basically a useless piece of crap code.
Fixed Kikaru's entry... I copied too much from my error log
[append]
I had to change line 49 in Zaphos' entry to be this:
planets.push_back(circ(350 + 20*r, .628 * i + .2*r - (3.14/2.0), 20 + 5*r, makecol((int)((10+r)*100)%255,255,(int)((10+r)*100)%255)));
In my game, change line 207 to:
install_int_ex(timer_tick, BPS_TO_TIMER(30));
Dennis: Cute game. I think it would have been cool if the ball bounced off the screen like normal pong but you hit it from the center.
Kikaru: Cool concept, but too often it's impossible to win
Zaphos: Slick. I like the way everything moves. With a little more time, you could probably make something really interesting out of this The graphics put this one ahead of Kikaru's for me, because both games have innovative ideas.
My ranking: Zaphos, Kikaru, Dennis.
Ok, I fixed the bugs and added some flare. For people who like it better.
CGames: the only time you can't win is when 2 rings connect with each other. Fix that by adding ||(aring[n] == aranda) to the while loop that sets the ring links, I think it's line 84.
My updated entry:
1 | #include <allegro.h> |
2 | #include "math.h" |
3 | |
4 | #define ALLEGRO_NO_FIX_CLASS |
5 | |
6 | #define MODE GFX_AUTODETECT_WINDOWED |
7 | #define WIDTH 640 |
8 | #define HEIGHT 480 |
9 | #define COLOR_DEPTH 32 |
10 | |
11 | #define WHITE makecol(255, 255, 255) |
12 | #define RED makecol(255, 0, 0) |
13 | #define GOLD makecol(255, 255, 0) |
14 | #define BLACK makecol(0, 0, 0) |
15 | |
16 | #define LOOP_TIME 30 |
17 | |
18 | BITMAP *buffer; |
19 | long start_time; |
20 | long long timer = 0; |
21 | bool end_game = false; |
22 | |
23 | class ring |
24 | { |
25 | public: |
26 | int rot; |
27 | }; |
28 | |
29 | //update the timer |
30 | void update_time(){timer++;} |
31 | |
32 | |
33 | //main function |
34 | void main() |
35 | { |
36 | //setup allegro |
37 | allegro_init(); |
38 | install_keyboard(); |
39 | install_mouse(); |
40 | install_timer(); |
41 | set_color_depth(COLOR_DEPTH); |
42 | set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0); |
43 | |
44 | //setup the timer |
45 | install_int(update_time, 1); |
46 | |
47 | //initialize the buffer |
48 | buffer = create_bitmap(WIDTH, HEIGHT); |
49 | |
50 | srand(time(NULL)); |
51 | |
52 | bool select = false; |
53 | int mode = -1; |
54 | textout_centre_ex(screen, font, "select difficulty:", 320, 180, WHITE, BLACK); |
55 | textout_centre_ex(screen, font, "F1 - easy", 320, 200, WHITE, BLACK); |
56 | textout_centre_ex(screen, font, "F2 - normal", 320, 220, WHITE, BLACK); |
57 | textout_centre_ex(screen, font, "F3 - hard", 320, 240, WHITE, BLACK); |
58 | textout_centre_ex(screen, font, "F4 - insane", 320, 260, WHITE, BLACK); |
59 | while(!select) |
60 | { |
61 | for (int i = KEY_F1; i < KEY_F5; i++) |
62 | { |
63 | if (key<i>) |
64 | { |
65 | select = true; |
66 | mode = i-KEY_F1; |
67 | } |
68 | } |
69 | } |
70 | |
71 | int num_rings = 3+(mode*2); |
72 | int iring = 0; |
73 | int last_hit = 0; |
74 | ring band[num_rings]; |
75 | int aring[num_rings]; |
76 | for (int i = 0; i < num_rings; i++) |
77 | { |
78 | aring<i> = -1; |
79 | } |
80 | int n = 0; |
81 | while (n < num_rings) |
82 | { |
83 | int aranda = rand()%num_rings; |
84 | while ((aranda == n)||(aring[aranda] > -1)||(aring[n] == aranda)) |
85 | aranda = rand()%num_rings; |
86 | aring[aranda] = n; |
87 | n++; |
88 | } |
89 | |
90 | |
91 | //main loop |
92 | while (!end_game) |
93 | { |
94 | //log the start time |
95 | start_time = timer; |
96 | |
97 | if (key[KEY_ESC]) |
98 | end_game = true; |
99 | |
100 | /*game goes here*/ |
101 | if (timer > last_hit+100) |
102 | { |
103 | if (key[KEY_LEFT]) |
104 | { |
105 | band[iring].rot += 5; |
106 | band[iring].rot %= 6; |
107 | band[aring[iring]].rot += 5; |
108 | band[aring[iring]].rot %= 6; |
109 | last_hit = timer; |
110 | } |
111 | if (key[KEY_RIGHT]) |
112 | { |
113 | band[iring].rot ++; |
114 | band[iring].rot %= 6; |
115 | band[aring[iring]].rot ++; |
116 | band[aring[iring]].rot %= 6; |
117 | last_hit = timer; |
118 | } |
119 | if (key[KEY_UP]) |
120 | { |
121 | iring++; |
122 | iring %= num_rings; |
123 | last_hit = timer; |
124 | } |
125 | if (key[KEY_DOWN]) |
126 | { |
127 | iring += num_rings-1; |
128 | iring %= num_rings; |
129 | last_hit = timer; |
130 | } |
131 | } |
132 | int num_good = 1; |
133 | for (int i = 1; i < num_rings; i++) |
134 | { |
135 | if (band<i>.rot == band[0].rot) |
136 | num_good++; |
137 | } |
138 | |
139 | /*drawing goes here*/ |
140 | for (int i = 0; i < num_rings; i++) |
141 | { |
142 | circle(buffer, WIDTH/2, HEIGHT/2, (i*20)+20, RED); |
143 | if (num_good >= num_rings) |
144 | iring = i; |
145 | if (i == iring) |
146 | circlefill(buffer, WIDTH/2+int((i+1)*20*cos(band<i>.rot)), HEIGHT/2+int((i+1)*20*sin(band<i>.rot)), 3, GOLD); |
147 | else |
148 | circlefill(buffer, WIDTH/2+int((i+1)*20*cos(band<i>.rot)), HEIGHT/2+int((i+1)*20*sin(band<i>.rot)), 3, RED); |
149 | } |
150 | |
151 | //draw to the screen |
152 | blit(buffer, screen, 0, 0, 0, 0, WIDTH, HEIGHT); |
153 | |
154 | //victory! |
155 | if (num_good >= num_rings) |
156 | { |
157 | circlefill(screen, WIDTH/2, HEIGHT/2, 10, GOLD); |
158 | line(screen, WIDTH/2+int(WIDTH*cos(band[num_rings-1].rot)), HEIGHT/2+int(WIDTH*sin(band[num_rings-1].rot)), WIDTH/2, HEIGHT/2, GOLD); |
159 | textout_centre_ex(screen, font, "You Win!", 320, 50, WHITE, -1); |
160 | while (!key[KEY_ESC]) |
161 | {} |
162 | } |
163 | |
164 | //clear the buffer |
165 | clear_to_color(buffer, BLACK); |
166 | |
167 | //wait |
168 | while (timer < start_time + LOOP_TIME) |
169 | {} |
170 | } |
171 | remove_int(update_time); |
172 | destroy_bitmap(buffer); |
173 | return; |
174 | } |
175 | END_OF_MAIN() |
Time to try out the others now!
[EDIT]
Played the others, here is my vote:
CGamesPlay, Zaphos, Dennis Busch
Here are my rankings (ordered from most favourite to least favourite).
Zaphos/CGamesPlay/Kikaru/Dennis
Zaphos: 5 of 5 stars
Nice animations and cool concept. It's challenging and has great replayability value.
CGamesPlay: 4 of 5 stars
-1 one because of two compiler errors, which I had to fix, one was a missing M_PI and the other was no return value in main.
Well, nice graphics and most important of all: it's playable.
Kikaru: 3 of 5 stars
Too bad I couldn't play the game, it always immediately says "You win!" for me. Also I had to fix some ambiguous calls to cos and sin which my compiler didn't like, so maybe I messed up there. But I like the idea of the game.
Dennis: 0 of 5 stars
Better luck next time. Your game isn't even playable. Maybe you should spend some more time practicing speed coding.
Okay, adding revised entries and entry notes will work on the site now.
Dennis: 0 of 5 stars
Better luck next time. Your game isn't even playable. Maybe you should spend some more time practicing speed coding.
Onewing: -1 of 5 Stars (Take one star off next minor hack)
I had basically the same thing as Dennis, only no ball (just a circular paddle which was going to be the cross hair). The game was going to be a bad ripoff of Tempest. Unfortunately, my trig-fu is sloppy and I should've been using atan2 instead of atan.
Sigh...
What were the "ambiguous sin/cos calls?"
The problem with the instant "you win!" is that I forgot to randomize the rotations of the rings.
Kikaru: My compiler said that there were calls to sin and cos which were overloaded and that more than one overloaded version of them would fit, so I casted everything inside these calls to doubles so that the compiler knew to take the cos/sin version that take a double.
Ah, so the instant "you win!" wasn't caused by changing that.
Anyway, I'll probably bugfix my entry tomorrow and add some more game logic to it, but now I have to attend to silly-joy anniversary festivities.:)
Okay, here's my updated version -- the planets bounce, and you have a very erratic flight path. The premise is that you are some sort of space fly, I guess.
1 | #include <allegro.h> |
2 | #include <cmath> |
3 | #include <list> |
4 | #include <iostream> |
5 | |
6 | using namespace std; |
7 | |
8 | int lt = 0; |
9 | void timer() { |
10 | {lt ++;} |
11 | } END_OF_FUNCTION(timer) |
12 | |
13 | int cx, cy; |
14 | |
15 | struct circ { |
16 | float r, theta; |
17 | float rate; |
18 | float rad; |
19 | int col; |
20 | float rvel; |
21 | |
22 | circ(float r, float theta, float rate, float rad, int col) : r(r), theta(theta), rate(rate), rad(rad), col(col), rvel(0) {} |
23 | |
24 | void draw(BITMAP *buf) { |
25 | circlefill(buf, cx + cos(theta)*r, cy + sin(theta)*r, rad, col); |
26 | } |
27 | }; |
28 | |
29 | |
30 | int main() { |
31 | allegro_init(); |
32 | install_keyboard(); |
33 | install_timer(); |
34 | LOCK_FUNCTION(timer); |
35 | LOCK_VARIABLE(lt); |
36 | install_int_ex(timer, BPS_TO_TIMER(30)); |
37 | |
38 | set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); |
39 | |
40 | BITMAP *buf = create_bitmap(SCREEN_W, SCREEN_H); |
41 | |
42 | cx = SCREEN_W /2; |
43 | cy = SCREEN_H + 100; |
44 | |
45 | circ sun(0, 0, 0, 300, makecol(255,200,0)); |
46 | list<circ> planets; |
47 | for (int i = 0; i < 20; i++) { |
48 | float r = (rand()%21 - 10) / 10.0; |
49 | planets.push_back(circ(350 + 20*r, .314 * i + .15*r - (3.5/2.0), .01 + .003*r, 20 + 5*r, makecol(51+r*50,255,51+r*50))); |
50 | } |
51 | circ me(0, -3.14/2.0, 3.14/2.0, 10, makecol(0,0,255)); |
52 | list<circ>::iterator mine = planets.begin(); |
53 | me.r = mine->rad + me.rad; |
54 | float racc = 0; |
55 | int beats = 0; |
56 | |
57 | while(!key[KEY_ESC]) { |
58 | while (lt> 0) { |
59 | me.theta -= (!key[KEY_RIGHT] - !key[KEY_LEFT]) * .06; |
60 | |
61 | if (me.r > mine->rad + me.rad) { |
62 | me.r -= racc; |
63 | racc+=.2; |
64 | beats = 0; |
65 | } else { |
66 | racc = 0; |
67 | me.r = mine->rad + me.rad; |
68 | me.theta -= (!key[KEY_RIGHT] - !key[KEY_LEFT]) * .1; |
69 | beats++; |
70 | if (/*beats > 5 || */key[KEY_SPACE]) { |
71 | me.r += 10; |
72 | racc = -10; |
73 | } |
74 | } |
75 | |
76 | float distToMine = me.r; |
77 | float mex = cx + cos(mine->theta)*mine->r + cos(me.theta)*me.r; |
78 | float mey = cy + sin(mine->theta)*mine->r+sin(me.theta)*me.r; |
79 | |
80 | if ( sqrt( (mex - cx) * (mex -cx) + (mey -cy) * (mey -cy) ) < sun.rad + me.rad) |
81 | { |
82 | return 1; |
83 | } else if (mex > SCREEN_W || mex < 0) { |
84 | return 1; |
85 | } |
86 | |
87 | for (list<circ>::iterator i = planets.begin(); i != planets.end(); ++i){ |
88 | if (i != mine) { |
89 | float youx = cx + cos(i->theta)*i->r; |
90 | float youy = cy + sin(i->theta)*i->r; |
91 | float dist = sqrt( (youx - mex) * (youx - mex) + (youy - mey) * (youy - mey) ); |
92 | if (dist < distToMine) { |
93 | distToMine = dist; |
94 | mine = i; |
95 | me.r = dist; |
96 | me.theta = atan2(mey - youy, mex - youx); |
97 | if (racc < 0) |
98 | racc = -racc; |
99 | } |
100 | } |
101 | } |
102 | |
103 | for (list<circ>::iterator i = planets.begin(); i != planets.end(); ++i){ |
104 | i->theta += i->rate; |
105 | |
106 | i->rvel -= .5; |
107 | i->r += i->rvel; |
108 | if (i->r < 290) { |
109 | i->r = 290; |
110 | float r = (rand()%21 - 10) / 10.0; |
111 | i->rvel = 7 * r*2; |
112 | } |
113 | } |
114 | |
115 | |
116 | lt--; |
117 | } |
118 | |
119 | for (list<circ>::iterator i = planets.begin(); i != planets.end(); ++i){ |
120 | i->draw(buf); |
121 | } |
122 | circlefill(buf, cx + cos(mine->theta)*mine->r + cos(me.theta)*me.r, |
123 | cy + sin(mine->theta)*mine->r+sin(me.theta)*me.r, me.rad, me.col); |
124 | sun.draw(buf); |
125 | blit(buf, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); |
126 | clear(buf); |
127 | } |
128 | |
129 | return 0; |
130 | } END_OF_MAIN() |
edit: And for ranking, I'll go with Kikaru, CGames, Dennis
Kikaru and CGames are both really strong entries imo (I'm impressed you both had time to add intro text things ...) but Kikaru's was more surprising. Dennis's looked like it would have been interesting -- looking forward to the revised entry!
edit2: changed the starting theta to -PI/2 like CGames suggested (below)
Ugh, the revision (the one on the site at least) makes it impossible
Much harder, and I tend to die in the first half second. I change the initial player theta to -pi/2, which helped some, but staying alive 5 seconds is a good record for me
Ok, everyone has voted, so here are the results:
Zaphos: 7 pts.
Kikaru: 5 pts.
Dennis: 3 pts.
CGamesPlay: 7 pts.
It's a tie between Zaphos and CGames. Good games everyone!
Ohmigosh! This is like the second time I've come close to winning I think last time I wasn't tied, though
FYI, the next bi-weekly competition has been scheduled. I won't be able to attend, because I will be in London.
Woo!
Much harder, and I tend to die in the first half second. I change the initial player theta to -pi/2, which helped some, but staying alive 5 seconds is a good record for me
Ah, the rand() I was getting managed to hide some of the problems (and difficulty!) -- note to self: test with different srand()s!
I think I'll go back and mess with the entry some more later. The way the blue guy exists in polar coordinates makes him control really oddly; I think I want to see how it plays if he moves more normally.
edit: also -- hope we can make this a semi-regular event again. Everybody come back to play again in 2 weeks!
I am adding the email support right now, as we speak. I just finished the "send me emails when a competition is proposed."
[append]
The top 3 options on this page work!
I would love to start doing this again. What's funny is that I joined late, finished early, and still had a good game...
Now, to work some more on it!
All of the email options except one are now working.
If I added SMS support, how many of you would use it? (i.e. SMS me 1 hour before competition begins, and SMS me when a competition begins)
I fixed my collision logic and made the paddle shrink after each hit.
There is still no game over condition though, as the only thing bugging me was the collision bug and since that's fixed, I can sleep well now.
1 | // Title: My 1st Minorhack participation |
2 | // Author: Dennis Busch |
3 | // Date: 17th of February 2007 |
4 | // Time spent: 1h + 1h bugfixing the faulty collision logic :P |
5 | |
6 | // didn't finish in time! |
7 | // collision bug fixed, paddle shrinks after every hit |
8 | // (only the center pixel of the enemy is checked for collision) |
9 | // still no game over condition |
10 | |
11 | // Rule: 1 source file, game has to use polar coordinates instead of rect. coords. |
12 | |
13 | // this is quick and dirty code without too much(if any at all) error checking |
14 | |
15 | #include <allegro.h> |
16 | #include <math.h> |
17 | |
18 | // variables |
19 | bool debug_info = true; |
20 | bool game_over = false; |
21 | bool use_screen = false; |
22 | BITMAP *back = NULL; |
23 | const int W = 640; |
24 | const int H = 480; |
25 | const int timing = 60; |
26 | const float PI = 3.14159; |
27 | |
28 | const float to_fix = 128.0/180.0; |
29 | const float to_rad = PI/180.0; |
30 | |
31 | float ply_angle = 0.0; // :P |
32 | float ply_angle_step = 3.0; |
33 | float ply_length = W/6.0; // distance to center |
34 | float ply_size = 60.0; |
35 | float ply_size_min = 5.0; |
36 | float ply_size_step = 5.0; |
37 | float ply_arc_end = ply_angle + ply_size; |
38 | float center_x = W/2.0; |
39 | float center_y = H/2.0; |
40 | |
41 | float enemy_angle = 0.0; |
42 | float enemy_length = W/2; // distance to center |
43 | float enemy_size = W / 100.0; |
44 | float enemy_step = W / 320.0; |
45 | int enemy_state = 0; // 0 incoming, 1 offgoing |
46 | int enemy_reset_delay = 240; |
47 | int enemy_delay = enemy_reset_delay; |
48 | |
49 | void update_display() |
50 | { |
51 | BITMAP *drawto = NULL; |
52 | |
53 | if(use_screen) |
54 | drawto = screen; |
55 | else |
56 | drawto = back; |
57 | |
58 | // drawing |
59 | clear_bitmap(drawto); |
60 | |
61 | // draw debug info |
62 | if(debug_info) |
63 | { |
64 | textprintf_ex(drawto, font, 0, 0, makecol(255,255,255), -1, "player_angle: %f / player_angle+player_size: %f", ply_angle, ply_arc_end); |
65 | textprintf_ex(drawto, font, 0,10, makecol(255,255,255), -1, "enemy_angle: %f / enemy_length: %f", enemy_angle, enemy_length); |
66 | |
67 | } |
68 | |
69 | // draw the player |
70 | circlefill(drawto, center_x, center_y, ply_length / 2, makecol(255,255,255)); |
71 | arc(drawto, center_x,center_y,itofix(int(ply_angle*to_fix)),itofix(int(ply_angle*to_fix+ply_size*to_fix)),ply_length, makecol(255,255,255)); |
72 | |
73 | // draw the enemy |
74 | circlefill(drawto, center_x + cos(enemy_angle*to_rad)*enemy_length |
75 | , center_y - sin(enemy_angle*to_rad)*enemy_length |
76 | , enemy_size, makecol(255,0,0)); |
77 | putpixel(drawto, center_x + cos(enemy_angle*to_rad)*enemy_length |
78 | , center_y - sin(enemy_angle*to_rad)*enemy_length |
79 | , makecol(0,0,0)); |
80 | |
81 | if(!use_screen) |
82 | blit(back, screen, 0,0,0,0,W,H); |
83 | } |
84 | |
85 | void update_game_logic() |
86 | { |
87 | // read input |
88 | if(key[KEY_ESC]) |
89 | game_over = true; |
90 | |
91 | if(key[KEY_LEFT]||key[KEY_UP]) |
92 | ply_angle += ply_angle_step; |
93 | if(key[KEY_RIGHT]||key[KEY_DOWN]) |
94 | ply_angle -= ply_angle_step; |
95 | |
96 | if (ply_angle > 360.0) |
97 | ply_angle -= 360.0; |
98 | if (ply_angle < 0.0) |
99 | ply_angle = 360.0 + ply_angle; |
100 | |
101 | if(ply_angle == 360.0) |
102 | ply_angle = 0.0; |
103 | |
104 | ply_arc_end = ply_angle + ply_size; |
105 | if (ply_arc_end > 360.0) |
106 | ply_arc_end -= 360.0; |
107 | if (ply_arc_end < 0.0) |
108 | ply_arc_end = 360.0 + ply_arc_end; |
109 | |
110 | if(ply_arc_end == 360.0) |
111 | ply_arc_end = 0.0; |
112 | |
113 | // update enemy |
114 | switch(enemy_state) |
115 | { |
116 | case 0: |
117 | enemy_length -= enemy_step; |
118 | if((abs(enemy_length) <= (ply_length + enemy_size)) // in player paddle radius? |
119 | && (abs(enemy_length) >= (ply_length - enemy_size))) |
120 | { |
121 | bool hit = false; |
122 | |
123 | if(ply_angle < ply_arc_end) |
124 | if((enemy_angle >= ply_angle)&&(enemy_angle <= (ply_arc_end))) |
125 | hit = true; |
126 | |
127 | if(ply_angle > ply_arc_end) |
128 | if( ((enemy_angle >= 0.0)&&(enemy_angle<=ply_arc_end)) |
129 | ||((enemy_angle >= ply_angle)&&(enemy_angle <= 360.0))) |
130 | hit = true; |
131 | |
132 | if(hit) |
133 | { |
134 | if(ply_size > ply_size_min) |
135 | { |
136 | ply_size -= ply_size_step; |
137 | ply_angle += ply_size_step / 2.0; |
138 | } |
139 | enemy_state = 1; |
140 | } |
141 | } |
142 | |
143 | if((abs(enemy_length) >= W/2)||(abs(enemy_length) <= ply_length/2 )) |
144 | { |
145 | // reset enemy |
146 | enemy_angle = float(rand()%360); |
147 | enemy_length = W/2; |
148 | } |
149 | break; |
150 | case 1: |
151 | enemy_length += enemy_step; |
152 | |
153 | if((abs(enemy_length) >= W/2)||(abs(enemy_length) <= ply_length/2 )) |
154 | { |
155 | // reset enemy |
156 | enemy_angle = float(rand()%360); |
157 | enemy_length = W/2; |
158 | enemy_state = 0; |
159 | } |
160 | break; |
161 | } |
162 | |
163 | } |
164 | |
165 | // copy/pasted from the FAQ |
166 | volatile int speed_counter = 0; |
167 | void increment_speed_counter() |
168 | {speed_counter++;} |
169 | END_OF_FUNCTION(increment_speed_counter) |
170 | |
171 | void play_the_game() |
172 | { |
173 | |
174 | LOCK_VARIABLE(speed_counter); |
175 | LOCK_FUNCTION(increment_speed_counter); |
176 | |
177 | install_int_ex(increment_speed_counter, BPS_TO_TIMER(timing)); |
178 | |
179 | while(!game_over) |
180 | { |
181 | while (speed_counter > 0) |
182 | { |
183 | update_game_logic(); |
184 | speed_counter--; |
185 | } |
186 | update_display(); |
187 | } |
188 | } |
189 | // END OF copy/pasted from the FAQ |
190 | |
191 | int main(void) |
192 | { |
193 | bool failed = false; |
194 | if(allegro_init() != 0)failed = true; |
195 | if(install_timer() != 0)failed = true; |
196 | if(install_keyboard() != 0)failed = true; |
197 | if(install_mouse() == -1)failed = true; |
198 | |
199 | if(!failed) |
200 | { |
201 | set_color_depth(32); |
202 | if(set_gfx_mode(GFX_AUTODETECT_WINDOWED,W,H,0,0)==0) |
203 | { |
204 | back = create_bitmap(W,H); |
205 | if(back==NULL) |
206 | use_screen = true; |
207 | |
208 | play_the_game(); |
209 | |
210 | } |
211 | } |
212 | allegro_exit(); |
213 | return 0; |
214 | } |
215 | END_OF_MAIN() |
Zaphos: 7 pts.
Kikaru: 5 pts.
Dennis: 3 pts.
CGamesPlay: 7 pts.
Wait ... how did you calculate that? It adds to 22, but 4 * (3+2+1) is 24 ...
edit: Hmm -- also, in admin on the webpage, we can set the "Minimum players for competition"? I thought that was something global, not per user?
Dennis -- nice to see it working! It'd be cool if the same ball bounced around the screen edges and came back, but I guess that's rather hard to do with polar coordinates.
What do you mean? I gave 3 points for first, 2 points for second, and 1 point for third.
I mean that if you have 4 people voting, and each gives out 3 points for first, 2 points for second, and 1 point for third, then the total number of points given out should be 4*(3+2+1) = 24. But 7+5+3+7 = 22.
Zaphos: 8
CGamesPlay: 7
Kikaru: 6
Dennis: 3
I'll get you one day!
[append]
The minimum is 3. He can't give points to himself.
The minimum is 3. He can't give points to himself.
Yeah -- that's referring to an edit that I put in and then quickly removed. Momentary brain failure.
edit: also, hooray!
Maybe you could make it not reuse rules for a certain number of events? Like, 6 or 7? We have enough rules for that.
Maybe you could make it not reuse rules for a certain number of events? Like, 6 or 7? We have enough rules for that.
Does it re-use rules at all? It doesn't seem like it's been a problem, yet, at any rate ...
The rule we just did was... Oh, wait, it was different. Hehe.
Since this was my first participation, I can't judge about the previous rules but this one certainly was challenging.
Anyway, I'm not going to revise my entry again, because it inspired me to something else, which I hope I'll have the time and motivation to start working on someday.:)
For me, this MinorHack turned out to be the most cool thing I did in a while. I will surely participate in the next one as well. It's fun!
Good thing you IRC, or else you wouldn't have heard about it!