|
MicroHack |
Todd Cope
Member #998
November 2000
|
My game is done. Do I post the source as an attachment? |
CGamesPlay
Member #2,559
July 2002
|
Yeah, please do. Here is my incomplete entry. Maybe I will have it finished soon:
-- Ryan Patterson - <http://cgamesplay.com/> |
Onewing
Member #6,152
August 2005
|
Hmmm...gotta figure out how to attach my file...
------------ |
Todd Cope
Member #998
November 2000
|
Okay, attached. |
FMC
Member #4,431
March 2004
|
ahh.. too late to start [FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites] |
BAF
Member #2,981
December 2002
|
1#include <allegro.h>
2#include <stdlib.h>
3#include <time.h>
4#include <vector>
5#include <list>
6#include <iostream>
7
8volatile int GameTicker = 0;
9void Ticker()
10{
11 ++GameTicker;
12}
13END_OF_FUNCTION(Ticker);
14
15
16std::vector<int> RandomData;
17
18void LoadExeData()
19{
20 char ThisFile[512];
21 get_executable_name(ThisFile, 512);
22 PACKFILE *Self = pack_fopen(ThisFile, "rb");
23
24 int RandAmt = file_size(ThisFile) / 16;
25
26 for(int i = 0; i < RandAmt; ++i)
27 RandomData.push_back(pack_igetw(Self));
28
29 pack_fclose(Self);
30}
31
32int GetRand()
33{
34 if(RandomData.size() <= 0)
35 LoadExeData();
36
37 int Rand = rand() % RandomData.size();
38 int Ret = RandomData[Rand];
39 RandomData.erase(RandomData.begin() + Rand);
40 return Ret;
41}
42
43struct SnakePixel
44{
45 int x, y;
46
47 SnakePixel(int X, int Y) : x(X), y(Y) { }
48};
49
50
51int main(int argc, char *argv[])
52{
53 srand(time(NULL));
54
55 allegro_init();
56 install_keyboard();
57 install_timer();
58
59 LOCK_VARIABLE(GameTicker);
60 LOCK_FUNCTION(Ticker);
61 install_int_ex(Ticker, BPS_TO_TIMER(60));
62
63 set_color_depth(desktop_color_depth());
64 if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0))
65 if(set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0))
66 return -1;
67
68 LoadExeData();
69
70 BITMAP *buffer = create_bitmap(SCREEN_W, SCREEN_H);
71 enum eSD
72 {
73 NORTH = 0,
74 WEST,
75 EAST,
76 SOUTH
77 } SnakeDirection;
78
79
80 // set up board
81 int BoardWidth = SCREEN_W / 5;
82 int BoardHeight = SCREEN_H / 5;
83 char **Board = new char*[BoardWidth];
84 for(int i = 0; i < BoardWidth; ++i)
85 Board<i> = new char[BoardHeight];
86
87 // board edge barriers
88 for(int x = 0; x < BoardWidth; ++x)
89 Board[x][0] = Board[x][BoardHeight - 1] = 1;
90 for(int y = 0; y < BoardHeight; ++y)
91 Board[0][y] = Board[BoardWidth - 1][y] = 1;
92
93 for(int x = 1; x < BoardWidth - 1; ++x)
94 for(int y = 1; y < BoardHeight - 1; ++y)
95 Board[x][y] = 0;
96
97 for(int i = 0; i < 15; ++i)
98 Board[(GetRand() % (BoardWidth - 2)) + 1][(GetRand() % (BoardHeight - 2)) + 1] = 2;
99
100 for(int i = 0; i < 30; ++i)
101 Board[(GetRand() % (BoardWidth - 2)) + 1][(GetRand() % (BoardHeight - 2)) + 1] = 1;
102
103
104 // set up snake
105 std::list<SnakePixel*> Snake;
106 //Snake.push_back(new SnakePixel((GetRand() % (BoardWidth - 6)) + 3, (GetRand() % (BoardWidth - 6)) + 3));
107 Snake.push_back(new SnakePixel(BoardWidth / 2, BoardHeight / 2));
108 SnakeDirection = (eSD)(GetRand() % 4);
109 switch(SnakeDirection)
110 {
111 case NORTH:
112 Snake.push_back(new SnakePixel(Snake.back()->x, Snake.back()->y + 1));
113 Snake.push_back(new SnakePixel(Snake.back()->x, Snake.back()->y + 1));
114 break;
115
116 case WEST:
117 Snake.push_back(new SnakePixel(Snake.back()->x + 1, Snake.back()->y));
118 Snake.push_back(new SnakePixel(Snake.back()->x + 1, Snake.back()->y));
119 break;
120
121 case EAST:
122 Snake.push_back(new SnakePixel(Snake.back()->x - 1, Snake.back()->y));
123 Snake.push_back(new SnakePixel(Snake.back()->x - 1, Snake.back()->y));
124 break;
125
126 case SOUTH:
127 Snake.push_back(new SnakePixel(Snake.back()->x, Snake.back()->y - 1));
128 Snake.push_back(new SnakePixel(Snake.back()->x, Snake.back()->y - 1));
129 break;
130 }
131
132 int DoSnake = 0;
133 int Score = 0;
134 while(!key[KEY_ESC])
135 {
136 while(GameTicker > 0)
137 {
138 poll_keyboard();
139
140 if(key[KEY_LEFT] && SnakeDirection != EAST)
141 SnakeDirection = WEST;
142 else if(key[KEY_RIGHT] && SnakeDirection != WEST)
143 SnakeDirection = EAST;
144 else if(key[KEY_UP] && SnakeDirection != SOUTH)
145 SnakeDirection = NORTH;
146 else if(key[KEY_DOWN] && SnakeDirection != NORTH)
147 SnakeDirection = SOUTH;
148
149 if((DoSnake % 8) == 0)
150 {
151 switch(SnakeDirection)
152 {
153 case NORTH:
154 Snake.push_front(new SnakePixel(Snake.front()->x, Snake.front()->y - 1));
155 break;
156
157 case WEST:
158 Snake.push_front(new SnakePixel(Snake.front()->x - 1, Snake.front()->y));
159 break;
160
161 case EAST:
162 Snake.push_front(new SnakePixel(Snake.front()->x + 1, Snake.front()->y));
163 break;
164
165 case SOUTH:
166 Snake.push_front(new SnakePixel(Snake.front()->x, Snake.front()->y + 1));
167 break;
168 }
169 Snake.pop_back();
170
171 if(Board[Snake.front()->x][Snake.front()->y] == 1) // Hit Barrier
172 {
173 std::cout << "\nGame Over! Score: " << Score << "\n\n";
174 return 0;
175 }
176 else if(Board[Snake.front()->x][Snake.front()->y] == 2) // FOOD!
177 {
178 ++Score;
179 Board[Snake.front()->x][Snake.front()->y] = 0;
180 Board[(GetRand() % (BoardWidth - 2)) + 1][(GetRand() % (BoardHeight - 2)) + 1] = 2; // new food
181
182 switch(SnakeDirection) // Make snake longer \o/
183 {
184 case NORTH:
185 Snake.push_front(new SnakePixel(Snake.front()->x, Snake.front()->y - 1));
186 break;
187
188 case WEST:
189 Snake.push_front(new SnakePixel(Snake.front()->x - 1, Snake.front()->y));
190 break;
191
192 case EAST:
193 Snake.push_front(new SnakePixel(Snake.front()->x + 1, Snake.front()->y));
194 break;
195
196 case SOUTH:
197 Snake.push_front(new SnakePixel(Snake.front()->x, Snake.front()->y + 1));
198 break;
199 }
200 }
201
202 DoSnake = 0;
203 }
204
205 ++DoSnake;
206 --GameTicker;
207 }
208
209 while(GameTicker < 0)
210 {
211 rest(1);
212 }
213
214 clear_bitmap(buffer);
215
216 /*rectfill(buffer, 0, 0, SCREEN_W, 5, makecol(255, 255, 0)); // Top
217 rectfill(buffer, 0, 0, 5, SCREEN_H, makecol(255, 255, 0)); // Left
218 rectfill(buffer, 0, SCREEN_H - 5, SCREEN_W, SCREEN_H, makecol(255, 255, 0)); // Bottom
219 rectfill(buffer, SCREEN_W - 5, 0, SCREEN_W, SCREEN_H, makecol(255, 255, 0)); // Right*/
220
221 for(int x = 0; x < BoardWidth; ++x)
222 {
223 for(int y = 0; y < BoardHeight; ++y)
224 {
225 if(Board[x][y] == 1) // Barrier
226 rectfill(buffer, x * 5, y * 5, ((x + 1) * 5) - 1, ((y + 1) * 5) - 1, makecol(255, 255, 0));
227 if(Board[x][y] == 2) // Food
228 rectfill(buffer, x * 5, y * 5, ((x + 1) * 5) - 1, ((y + 1) * 5) - 1, makecol(255, 128, 64));
229 }
230 }
231
232 for(std::list<SnakePixel*>::iterator i = Snake.begin(); i != Snake.end(); ++i)
233 {
234 rectfill(buffer, (*i)->x * 5, (*i)->y * 5, (((*i)->x + 1) * 5) - 1, (((*i)->y + 1) * 5) - 1, makecol(192, 192, 192));
235 }
236
237 textprintf_right_ex(buffer, font, SCREEN_W, 0, makecol(255, 0, 0), makecol(255, 255, 0), " Score: %d ", Score);
238
239
240 blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
241 }
242
243 destroy_bitmap(buffer);
244
245 return 0;
246}
247END_OF_MAIN()
There is mine. Compile it how you would any normal allegro program. For more randomness, specify a different debugger level (e.g. -g3 for maximum randomness). I used `g++ minorhack_release.cpp -o minorhack_release -g3 -lalleg` myself. You are the grey snake. Eat the pinkish colored food while avoiding the yellow stuff. Sometimes it doesn't recognize a turn (I didn't have time to fix that ). There may be random bugs but for the most part it works. It reads itself (its own binary executable file) and randomly picks bits from it to use for random positioning of stuff. I didn't have time to code detection of running into yourself, so you can hit yourself and keep going. |
Todd Cope
Member #998
November 2000
|
Cool, snakes |
Richard Phipps
Member #1,632
November 2001
|
Very clever Baf! Now if you can do that, why not a full game next? |
CGamesPlay
Member #2,559
July 2002
|
Onewing: Nice attempt. Once the battle part is done maybe it will work BAF: Pretty cool. Definitely the best in my opinion Todd: You are a close second, but I couldn't figure out how to kill the yellows or blues... All in all, I think it goes BAF, Todd, then Onewing and me tied for third Hmm, but Onewing's might be slightly more involving than mine... -- Ryan Patterson - <http://cgamesplay.com/> |
Simon Parzer
Member #3,330
March 2003
|
Uhh, can we do something like this again, on a weekend perhaps? Completely missed it. |
Derezo
Member #1,666
April 2001
|
I also completely missed it. We should do another one some time! I liked blitzhack, which was 6 hours. "He who controls the stuffing controls the Universe" |
CGamesPlay
Member #2,559
July 2002
|
I was actually going to suggest one of two things. Either another of the same thing as this, or a phase-based competition. Taking place over 1 day, the competition happens in phases: First is a 3-hour coding competition to create a good game engine. You may use any number of source files, but no media, yet. (Time: T+3 hours) Then is a 1-hour break in which we get together and determine which program is the best. The top two will be used for the next part of the competition. (Time: T+4 hours) In the second phase, you may select either of the two previous winners (you may not select the one that you wrote), and enhance it. This part of the competition is 2 hours long, and a rule-o-matic will be used to determine what to enhance (i.e. you must make this enhancement, and at your option may add others). You may use external media for this part of the competition. (Time: T+6 hours) Then is 2-hour break in which we get together and determine which program is the best (that is, which person produced the best enhancements). The top two will again be carried in to the next phase. During this break, you may create media files for use in the next phase. (Time: T+8 hours) The final phase is another 2-hour phase where you can select either of the previous top two winners. In this phase you may select either of the winners, even if one of them is yours. A rule-o-matic will be used to generate a genre requirement, and the goal of the phase is to make the game fit into that genre. (Time: T+10 hours) What do you guys think? I think this is a unique competition idea that should be fun, interactive, and also give you the opportunity to both work with someone else's code and create graphics on a tight deadline. The time line is rather long for a straight-run competition, but there are actually only 3 + 2 + 2 hours that you must be there. If you guys are interested in the phase idea, I will set it up. I imagine we would run it sometime after SpeedHack, but that's at everyone's option. We can do the MinorHack again this weekend either way. -- Ryan Patterson - <http://cgamesplay.com/> |
Onewing
Member #6,152
August 2005
|
Quote: Nice attempt Thanks! I thought it was considering I had absolutely nothing and I had to use gcc (which I prefer not to). I'd be up for another one, but only if I get to use allegro. About the phase-based competition, sounds interesting...and confusing, but interesting. I'm always up for anything. I'm a Hack-Whore. ------------ |
CGamesPlay
Member #2,559
July 2002
|
Well, I'm gonna go ahead and set the time for the next MinorHack to this saturday at the same time of day. If anyone would rather it be moved, let me know and we can work it out. -- Ryan Patterson - <http://cgamesplay.com/> |
BAF
Member #2,981
December 2002
|
I dunno if I'll be participating this weekend, I may have commitments to fulfill. |
Onewing
Member #6,152
August 2005
|
Quote: next MinorHack to this saturday at the same time of day. So I've got a week to make a game, eh? Guess I better get started. Actually, I wouldn't do that, but what's stopping someone else from doing it? ------------ |
FMC
Member #4,431
March 2004
|
I think it is nice as it is, one hour, one source file [FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites] |
Richard Phipps
Member #1,632
November 2001
|
I can pick a theme. Just let me know when.. |
CGamesPlay
Member #2,559
July 2002
|
Quote: Actually, I wouldn't do that, but what's stopping someone else from doing it? I'm going to add a rule-o-matic that selects one stupid rule For instance, "game must use a VM". Very loose but very off-the-wall rules. I don't want to limit genre or theme, because I like having different genres, and some games might not actually have a theme. -- Ryan Patterson - <http://cgamesplay.com/> |
Onewing
Member #6,152
August 2005
|
Quote: Very loose but very off-the-wall rules. Good enough. Maybe, "all functions have to be recursive" or "you must use rotate_sprite in some manner" could be fitting rules. ------------ |
CGamesPlay
Member #2,559
July 2002
|
Those are both good. I have some very creative ideas. I think I will add theme restriction rules, but if one of them is selected there will be a backup rule for games in which there is no theme. -- Ryan Patterson - <http://cgamesplay.com/> |
FMC
Member #4,431
March 2004
|
Quote: all functions have to be recursive I'd need an hour just to think how to implement it [FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites] |
Derezo
Member #1,666
April 2001
|
That would be extremely difficult to implement. Unless you only have one function... "He who controls the stuffing controls the Universe" |
CGamesPlay
Member #2,559
July 2002
|
I am taking down the MinorHack countdown for a while. It will be back before Saturday, don't worry -- Ryan Patterson - <http://cgamesplay.com/> |
BAF
Member #2,981
December 2002
|
Quote: Very clever Baf! Now if you can do that, why not a full game next? I have no motivation. An hour or two is good, once or twice a year I can handle 72 hours, but a full fledge game? [edit] |
|
|