Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » The 2004 Allegro ScreenHack

This thread is locked; no one can reply to it. rss feed Print
The 2004 Allegro ScreenHack
GullRaDriel
Member #3,861
September 2003
avatar

Krzysztof Kluczek, either your source code is buggy and cannot be compiled or i am a donkey using gcc, but i can't be able to compile it, even when i turn off all access checking and warning.

After testing all source code except allegro gl and Krzysztof one, i give my voice to Ryan game.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

23yrold3yrold
Member #1,134
March 2001
avatar

Quote:

It's a clone of Kablam!

I think you mean "Kaboom!" ...

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Ryan Broomfield
Member #3,126
January 2003

yeah, kaboom. My bad :D

shippay

Krzysztof Kluczek
Member #4,191
January 2004
avatar

Strange, I compiled it under Linux Slackware 9 without problems and got it running smoothly.

Here is my "makefile" (providing test.cpp is a source file):

#! /bin/sh
g++ `allegro-config --cflags` -c test.cpp
g++ -o test test.o -lalleg -lpthread -s -lm -ldl -export-dynamic

I tried other ways to compile it and yes, I didn`t manage to compile it using Linux gcc and I tried both .c and .cpp extensions.

I guess, the reason it may crash is using GFX_VGA 320x200 8-bit mode. I guess it isn`t using SVGA-Lib under Linux, so it might have failed on some systems (I was running as a root on my system since I was too lazy to configure Allegro properly and X-Windows aren`t properly set on my system). Since game has no failure checks, it can crash this way.

Also I don`t know, if all compilers will understand definition of m[90][90]={} and clear entire array at startup, since I don`t know if such behavior is ANSI standard.

Well, if the reason is GFX_VGA, I`ll try to switch to GFX_AUTODETECT and 320x240x8, so it should run.

And thanks everybody for opinions and testing. :)

Thomas Fjellstrom
Member #476
June 2000
avatar

Krzysztof: the X11 driver is default on my system, modes that the XWFS driver (does full screen X11 modes) can't handle get done by the XWIN driver (does windowed X11 modes).
and heres how I compiled: g++ file.cpp -o file `allegro-config --libs`. That resulted in an instant crash when run. (SIGSEGV)

edit: ouch, yeah, not checking set_gfx_mode for failure will result in a nice crash... maybe set to GFX_AUTODETECT...

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Krzysztof Kluczek
Member #4,191
January 2004
avatar

Quote:

ouch, yeah, not checking set_gfx_mode for failure will result in a nice crash...

Especially when using GFX_VGA, which is described in help as a DOS/Linux console mode and probably isn`t supposed to run under X. :P

Ok, I squeezed pit-falling routine a bit and managed to insert GFX_AUTODETECT. It should run now.

Of course the level has also changed a bit, but there are still 150 coins and all of them are available.

1#include <allegro.h>/* Bartenstein 3D! by Krzysztof Kluczek (c) 2004 */
2#include <math.h>/*-- A complete 3D engine on one 80x25 screen */
3typedef int i;i x,y,n,l,Q=0,j[90][90],s;char m[90][90]={},*g=(char*)m,*h=g,*k=g
4,*p=g+1,c;float b,u,v,a,d,z[320],A=0,X=1.5,Y=1.5,q[999][9]={},*t;BITMAP*w;RGB r;
5void cl(){d=atan((x-160)/200.);u=cos(A+d);v=sin(A+d);b=50/cos(d)+10;for(l=y=100;
6y>0;){c=y>9?m[i(b/y*u+X)][i(b/y*v+Y)]+2*(y&~3):0;c++&7?c&7?vline(w,x,99+y,99+l,c
7),0:0,putpixel(w,x,100-y,c),0:(z[x]=b/y,vline(w,x,99+l,100-y,c),y=0);y--;l=c&7?y
8:l;}}void sq(){u=cos( A);v=sin(A);for(l=0;l<Q;l++)t=q[l],a=t[2]-X,b=t[3]-Y,t[0]=
9a*u+b*v,t[1]=b*u-a*v;u=1E9;while(1){v=0;for(x=0;x<Q;x++)a=q[x][0],v<a&&a<u?l=x,v
10=a:0;if(v<.1)break;u=v;t=q[l];d=160+200*t[1]/t[0];a=16/t[0];for(n=-a;x=d+n,n<=a;
11n++)if(x>=0&&x<320&&z[x]>t[0]+.3)y=sqrt(a*a-n*n),vline(w,x,99-y,100+y,251-8*i(t[
120]*4));}}i cc(){d=0.4;return m[i(X-d)][i(Y-d)]&&m[i(X-d)][i(Y+d)]&&m[i(X+d)][i(Y
13-d)]&&m[i(X+d)][i(Y+d)];}void mv(){X+=(u=a*cos(A));if(!cc())X-=u;Y+=(v=a*sin(A))
14;if(!cc())Y-=v;}i main(){allegro_init();install_keyboard();set_gfx_mode(GFX_AUT\
15ODETECT,320,200,0,0);w=create_bitmap(320,200);PACKFILE *f=pack_fopen(__FILE__,"\
16r");while(pack_fgets(p+=90,88,f));pack_fclose(f);for(;g<h+8100;g++)(*g&=7)==2?j[
17i(q[Q][2]=(g-k)/90+.5)][i(q[Q][3]=(g-k)%90+.5)]=Q++:0;for(y=0;y<256;y++){x=y/4;r
18.r=y&1?x:0;r.g=y&2?x:0;r.b=y&4?x:0;set_color(y,&r);} s=Q;while(s&&!key[KEY_ESC])
19{g=m[i(X)]+i(Y);if(*g==7){for(y=0;y<1740;y++){if(!(y%30))vsync(); blit(w,screen,
200,199,0,199-y,320,1);}break;}if(*g==2){*g=3;s--;q[j[i(X)][i(Y)]][2]=-9;}for(x=0;
21x<320;x++)cl();sq();a=0.07;if(key[KEY_LEFT])A-=a;if(key[KEY_RIGHT])A+=a;if(key[\
22KEY_UP])mv();if(key[KEY_DOWN]){a=-a;mv();}u=300;v=20;line(w,u,v,u+9*cos(A),v+9*\
23sin(A),254);putpixel(w,u,v,255);textprintf(w,font,0,0,255,"%d",s);vsync();blit(w
24,screen,0,0,0,0,320,200);}clear(screen);textout(screen,font,s?"Game Over":"You \
25win!",124,96,255);while(!key[KEY_ESC]);}END_OF_MAIN();/* * * -----------------*/

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

which is described in help as a DOS/Linux console mode and probably isn`t supposed to run under X.

A linux console program "can" be launched from inside X... AFAIK. I just don't have any of the console drivers setup ;)

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Krzysztof Kluczek
Member #4,191
January 2004
avatar

I don`t think, console drivers would expect the program changing graphics mode to VGA. :P

Anyway, is it running now? :)

Billybob
Member #3,136
January 2003

Ok, I've squeezed my code even more and I was able to make some major improvements! I took some tips from marcello's code(replacing decimal numbers with variables). I replaced a non-portable number with it's proper GFX_OPENGL_WINDOWED. That means this code can now probably run under Linux, although I haven't tested. I'll test as soon as I can for all you Linux people, so expect more news. I also added END_OF_MAIN() for more comptablitiy and the types to a variable and main. The code now compiles under MinGW and MSVC. Attached is the entire package. The source for the 80x25 version, the source for the original source code(before squeezing), the batch file for building under MinGW(probably DJGPP as well), and an already built exe.

I hope this update will allow more people to play my game, especially Linux users, since Linux rules.

CGamesPlay
Member #2,559
July 2002
avatar

Ryan: Take out my comments and mine is smaller :)

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

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

Billybob
Member #3,136
January 2003

Krzysztof Kluczek: Awesome game. I was able to compile it just fine(MinGW32). Very interesting how you used your own sourcecode as the map, heh. I wouldn't have imagined a raycaster would fit in 80x25, but I guess it does!

Goodbytes
Member #448
June 2000
avatar

Well, the competition is progressing nicely :)
A clarification to the rules: You can't use external data. Apparently K.K has used his source code as the map? I'll allow that.

My own entry is currently being worked on... i.e. not started yet :)


--
~Goodbytes

Krzysztof Kluczek
Member #4,191
January 2004
avatar

Well, my program is a bit hacky raycaster since it only draws floors using base/y*cos() and base/y*sin() to determine tile position. If a tile contains a wall the rendering is ended and if it contains a pit rendering floor is delayed. As a result, rendering walls isn`t very much accurate especially at edges (it is possible to look through walls that have one common point, which true raycaster won`t allow).

Pit-falling routine is even more hacky since I`m just copying bottom screen line up the screen using such a speed, that it`s possible to see that something is moving but impossible to see how it is done. :)

And I used source as a map since it`s the easiest way to be sure that all coins can be reached.

I think I`ll start working over my next 80x25 game. Multiple entries are allowed AFAIK. :)

btw. Goodbytes, have you posted a news about this contest on Allegro.cc?

Radagar
Member #2,768
September 2002
avatar

Krzysztof Kluczek,

I get all types of Syntax errors when I try to compile your program in MSVC. It complains about a ton of stuff...

Complains about missing semicolons and newlines in constant strings, etc.

------------
Radagar - So your vote is for A.D.H.D.?
Chris Katko - Well, that was uninten--ooh kitty!

Krzysztof Kluczek
Member #4,191
January 2004
avatar

Probably MSVC doesn`t understand escapes at the end of some lines (the only explain for unterminated string). Missing semicolons etc. could be results of error recovery after hitting that backslashes. I`ll try to fix that. This program compiles under gcc with only double->int conversion warnings.

(still you could change the file manually and join these escaped lines, just let it read from the old source)

edit: here`s the code without those backslashes:

1#include <allegro.h>/* Bartenstein 3D! by Krzysztof Kluczek (c) 2004 */
2#include <math.h>/*-- A complete 3D engine on one 80x25 screen */
3typedef int i; i x,y,n,l,Q=0,j[90][90],s;char m[90][90]={},*g=(char*)m,*h=g,*k=g
4,*p=g+1,c; float b,u,v,a,d,z[320],A=0,X=1.5,Y=1.5,q[999][9]={},*t;BITMAP*w;RGB r
5;void cl(){d=atan((x -160)/200.);u=cos(A+d);v=sin(A+d);b=50/cos(d)+10;for(l=y=
6100;y>0;){c=y>9?m[i(b/y*u+X)][i(b/y*v+Y)]+2*(y&~3):0;c++&7?c&7?vline(w,x,99+y,99
7+l,c),0:0,putpixel(w,x,100-y,c),0:(z[x]=b/y,vline(w,x,99+l,100-y,c),y=0);y--;l=c
8&7?y:l;}}void sq(){u=cos(A);v= sin(A);for(l=0;l<Q;l++)t=q[l],a=t[2]-X,b=t[3]-Y,t
9[0]=a*u+b*v,t[1]=b*u-a*v;u=1E9;while(1){v=0;for(x=0;x<Q;x++)a=q[x][0],v<a&&a<u?l
10=x,v=a:0;if(v<.1)break;u=v;t=q[l];d=160+200*t[1]/t[0];a=16/t[0];for(n=-a;x=d+n,n
11<=a;n++)if(x>=0&&x<320&&z[x]>t[0]+.3)y=sqrt(a*a-n*n),vline(w,x,99-y,100+y,251-8*
12i(t[0]*4));}}i cc(){d=0.4;return m[i(X-d)][i(Y-d)]&&m[i(X-d)][i(Y+d)]&&m[i(X+d)]
13[i(Y-d)]&&m[i(X+d)][i(Y+d)];}void mv(){X+=(u=a*cos(A));if(!cc())X-=u;Y+=(v=a*sin
14(A));if(!cc())Y-=v;}i main(){allegro_init();install_keyboard();set_gfx_mode(/**/
15GFX_AUTODETECT,320,200,0,0);w=create_bitmap(320,200);PACKFILE *f=pack_fopen(/**/
16__FILE__,"r");while(pack_fgets(p+=90,88,f));pack_fclose(f);for(;g<h+8100;g++)(*g
17&=7)==2?j[i(q[Q][2]=(g-k)/90+.5)][i(q[Q][3]=(g-k)%90+.5)]=Q++:0;for(y=0;y<256 ;y
18++){x=y/4;r.r=y&1?x:0;r.g=y&2?x:0;r.b=y&4?x:0;set_color(y,&r);}s=Q;while(s&&!key
19[KEY_ESC]){g=m[i(X)]+i(Y);if(*g==7){for(y=0;y<1740;y++){if(!(y%30))vsync();blit(
20w,screen,0,199,0,199-y,320,1);}break;}if(*g==2){*g=3;s--;q[j[i(X)][i(Y)]][2]=-9;
21}for(x=0;x<320;x++)cl();sq();a=0.07;if(key[KEY_LEFT])A-=a;if(key[KEY_RIGHT])A+=a
22;if(key[KEY_UP])mv();if(key[KEY_DOWN]){a=-a;mv();}u=300;v=20;line(w,u,v,u+9*cos(
23A),v+9*sin(A),254);putpixel(w,u,v,255);textprintf(w,font,0,0,255,"%d",s);vsync()
24;blit(w,screen,0,0,0,0,320,200);}clear(screen);textout(screen,font,s?"Game Over"
25:"You win!",124,96,255);while(!key[KEY_ESC]);}END_OF_MAIN();//------------------

Billybob
Member #3,136
January 2003

I use backslashes in my most recent code, and that compiled under MSVC & MinGW32...so not sure why your code wouldn't compile.

LSd016
Member #3,561
May 2003

Nothing special.

1#include <allegro.h> /* this be made by lsd */
2#include <mem.h>
3bool IsAround(int x1, int y1, int x2, int y2, int tol)
4{if((x1+tol>x2 && x1-tol<x2) && (y1+tol>y2 && y1-tol<y2)) return true;
5return false;}void main(void)
6{allegro_init();set_color_depth(16);install_keyboard();install_timer();
7install_mouse();
8set_gfx_mode(GFX_AUTODETECT, 640, 480,0,0);alert("Kill the circles",
9"don't let them go off-screen", "'kay?","OK",0,'o',0);
10int posx[16]; int posy[16];
11for(int i=0;i<16;i++){posx<i>=320;posy<i>=240;}int score=0;
12BITMAP *buf=create_bitmap(640,480);while(!key[KEY_ESC]){clear(buf);
13for(int i=0;i<16;i++)
14circle(buf, posx<i>, posy<i>, 8+(rand()%4), makecol(100,rand()%230,rand()%78));
15triangle(buf, mouse_x, mouse_y, mouse_x+10,
16mouse_y, mouse_x, mouse_y+20, makecol(255,0,0));
17textprintf(buf, font, 0,0, makecol(0,255,255),"Score: %d", score);vsync();
18blit(buf, screen, 0,0,0,0,640, 480);for(int i=0;i<16;i++){
19if(posx<i>>640 || posx<i><0 || posy<i>>480 || posy<i><0)
20{alert(0,"Game over, man, game over!",
21"http://inercia.dcc.online.pt/scene.org/parties/1999/antiq99/mmul/gover99.zip",
22"OK",0,'o',0);return;}posx<i>+=(rand()%10)-5;posy<i>+=(rand()%10)-5;}
23if(mouse_b&1)for(int i=0;i<16;i++){
24if(IsAround(posx<i>, posy<i>, mouse_x, mouse_y, 10)){posx<i>=320; posy<i>=240;
25score++;}}}}END_OF_MAIN();

you only need to hold the mouse button, it's better that way.

____________________________________________
[update soon]

Freke
Member #3,393
April 2003

LSd016: It complained about the mem.h not being found, but when that include was removed it compiled fine.

Krzysztof Kluczek
Member #4,191
January 2004
avatar

Quote:

you only need to hold the mouse button, it's better that way.

Especially if your mouse pointer is in the middle of the screen. I`ve got 5107 that way. :P

I compiled it under DJGPP and it complained about return without a value. I fixed it and everything else is ok. :)

LSd016
Member #3,561
May 2003

Freke: You got a strange compiler, I thought mem* functions had always been in mem.h.

[edit]

Quote:

Especially if your mouse pointer is in the middle of the screen. I`ve got 5107 that way.

But you can't go with this forever. Anyway, maybe I'll make something better tomorrow.

____________________________________________
[update soon]

Krzysztof Kluczek
Member #4,191
January 2004
avatar

DJGPP libc help says, mem* are in <string.h>
(mem.h still works fine on my compiler)

Ryan Broomfield
Member #3,126
January 2003

http://www.shippysite.com/screen2.gif
YES! I got bliggity blam down to 1337 bytes (would be a little bit less on linux).
OH AND BY THE WYA CGAMESPLAY, my code is now way smaller than yours (without comments) :D

UPDATE I just realized that this game is only 20 lines, so it would qualify for that 20 line compo too.

1#include <allegro.h>
2#define C circlefill(screen
3#define R rectfill(screen
4#define F textprintf(screen,font,0
5struct B{int x,u;double y;}z[150];main(int d,char**b){memset(z,0,sizeof(struct
6B)*150);double q=160,Z=1;int s=0,r=200,Q=40,D=20,P=160,p=3,f=0;allegro_init();
7install_keyboard();install_mouse();set_gfx_mode(GFX_AUTODETECT,320,200,0,0);
8while(!key[KEY_ESC]){R,0,0,319,40,8);R,0,40,319,199,2);F,0,15,"%i",s);if((int)q<
9r-Z)q+=Z;else if((int)q>r+Z)q-=Z;else r=rand()%320;Z+=.0005;Q=(int)((double)(60/
10Z));R,q-6,12,q+6,36,0);C,q,16,8,15);C,q-3,16,2,0);C,q+3,16,2,0);R,q-10,8,q+10,12
11,0);R,q-5,4,q+5,8,0);for(d=0;d<p;++d)R,P-10,175-(d*10),P+9,180-(d*10),15);P=
12mouse_x;if(P<10)P=10;if(P>310)P=310;for(d=0;d<150;++d){if(z[d].u>0){z[d].y+=Z/2;
13C,z[d].x,z[d].y,4,0);line(screen,z[d].x+3,z[d].y-3,z[d].x+5,z[d].y-5,15);line(
14screen,z[d].x+5,z[d].y-5,z[d].x+5+((rand()%4)-2),z[d].y-5+((rand()%4)-2),14);if(
15z[d].y>199){z[d].u=0;--p;q=160;Z=1;r=200;Q=40;D=20;f=0;P=160;memset(z,0,sizeof(
16struct B)*150);}else if(z[d].y>=178-p*10&&z[d].y<=182&&z[d].x>=P-12&&z[d].x<=P+
1712){z[d].u=-5;s+=50;}}else{if(z[d].u<0){C,z[d].x,z[d].y,-z[d].u,12);++z[d].u;}
18else if(f>=Q+D){z[d].u=1;z[d].x=q;z[d].y=16;f=0;D=rand()%Q;}}}if(p<1)break;++f;
19vsync();}F,99,15,"FINAL: %i! PRESS SPACE!",s);while(readkey()>>8!=KEY_SPACE){}}
20END_OF_MAIN()

shippay

Carrus85
Member #2,633
August 2002
avatar

The only thing I can say, is if you are still running into size problems, couldn't you make your code smaller (on the screen, anyway) by preresolving all of the constants? Also, why not add the comma in your circlefill, rectfill, and text printf functions up above? That way you are only using one comma, instead of one occurance of a comma every function call... (besides, you have tons of room up above by your compiler command things (sorry, can't remember exact term right now, oy...))... heck, you could even through in a semicolon to the beginning of you compiler define, so it looks like...

#define C ;circlefill(screen,

Think of all that wonderful space you are saving! (True, this wouldn't necessaryily work, but it should in theory.)

EDIT--- heck, if compiler defines worked that way, you could do something like

#define db double
#define el else
#define f if (
#define ei else if

but then again, you would be lengthening the program by doing that... too bad you can't stack preprocessor commands...

I'm dumb!... this could get real interesting

gnolam
Member #2,030
March 2002
avatar

Carrus: It would work better with macros, but since #defines waste a whole line each I'd use function pointers instead :)

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Elias
Member #358
May 2000

You don't have to waste a full line with #defines. Just see how I used them, both #defines are about 80 characters.

It worked like this:

#define A(x,y,z) z?long_func_1(x,y):long_func_2(x,y)

Of course, the extra z param wastes some space, but for me I saved quite some lines with it :)

--
"Either help out or stop whining" - Evert



Go to: