Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » [MinorHack] This Saturday?

This thread is locked; no one can reply to it. rss feed Print
 1   2 
[MinorHack] This Saturday?
CGamesPlay
Member #2,559
July 2002
avatar

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 :D

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

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

Onewing
Member #6,152
August 2005
avatar

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.

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

Zaphos
Member #1,468
August 2001

Yes, the site seems a little freaked out right now.

Anyway, I'm in too.

Jakub Wasilewski
Member #3,653
June 2003
avatar

I'm out of town on Saturday, so no luck this time :(.

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

Ack! I guess it is proposing a new one every hour :P

I will fix later today :)

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

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

BAF
Member #2,981
December 2002
avatar

I have absolutely nothing for Saturday, so I am in.

CGamesPlay
Member #2,559
July 2002
avatar

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!

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

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

Dennis
Member #1,090
July 2003
avatar

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).

CGamesPlay
Member #2,559
July 2002
avatar

:)

Yay for participation. I definitely need to code an email reminder (or SMS reminder) of competitions coming up.

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

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

Onewing
Member #6,152
August 2005
avatar

Quote:

Server Error

Sorry, but a server error has occurred. The site administrator has been notified.

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

Kikaru
Member #7,616
August 2006
avatar

I can't join. :'(
I'm in! :D

Zaphos
Member #1,468
August 2001

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.

Dennis
Member #1,090
July 2003
avatar

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. :D

Kikaru
Member #7,616
August 2006
avatar

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 
18BITMAP *buffer;
19long start_time;
20long long timer = 0;
21bool end_game = false;
22 
23class ring
24{
25public:
26int rot;
27};
28 
29//update the timer
30void update_time(){timer++;}
31 
32 
33//main function
34void 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}
171END_OF_MAIN()

Found a bug with the ring-linking. Sometimes makes it impossible to win. :-/

Onewing
Member #6,152
August 2005
avatar

Not planning on submitting my entry. :'(

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

Zaphos
Member #1,468
August 2001

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 
6using namespace std;
7 
8int lt = 0;
9void timer() {
10 {lt ++;}
11} END_OF_FUNCTION(timer)
12 
13int cx, cy;
14 
15struct 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 
28int 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()

CGamesPlay
Member #2,559
July 2002
avatar

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 :)

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

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

Dennis
Member #1,090
July 2003
avatar

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. :D

CGamesPlay
Member #2,559
July 2002
avatar

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.

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

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

Kikaru
Member #7,616
August 2006
avatar

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 
18BITMAP *buffer;
19long start_time;
20long long timer = 0;
21bool end_game = false;
22 
23class ring
24{
25public:
26int rot;
27};
28 
29//update the timer
30void update_time(){timer++;}
31 
32 
33//main function
34void 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}
175END_OF_MAIN()

Time to try out the others now! :D

[EDIT]
Played the others, here is my vote:
CGamesPlay, Zaphos, Dennis Busch

Dennis
Member #1,090
July 2003
avatar

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. ;D

CGamesPlay
Member #2,559
July 2002
avatar

Okay, adding revised entries and entry notes will work on the site now.

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

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

Onewing
Member #6,152
August 2005
avatar

Quote:

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...

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

Kikaru
Member #7,616
August 2006
avatar

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. :P

Dennis
Member #1,090
July 2003
avatar

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.:)

 1   2 


Go to: