Allegro.cc - Online Community

Allegro.cc Forums » The Depot » 2007 Allegro ScreenHack, 80x25 compo

This thread is locked; no one can reply to it. rss feed Print
2007 Allegro ScreenHack, 80x25 compo
HardTranceFan
Member #7,317
June 2006
avatar

Quote:

Mika Turunen said:

Everybody polishing their entries or lost their interest already?

The second.

I'm thinking about another attempt.

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Skywhy
Member #9,243
November 2007
avatar

Too bad, I ended up messing my entry blargh... Would require some serious redoing of things if I wanted to get it in shape for real.

things that are missing:

  1. Death

  2. Proper collision detection for the bullets. Now it's just THROWN together...

  3. Logic locks (but I guess nobody really has these? just rest(x)? :-/)

  4. Redoing of the code so it would qualify for the 80x25

I'm not entirely sure does this qualify for an compo entry but here goes.
screenshot of it:

http://users.evtek.fi/~mikaka/temp/bShot.png

and here is the code:

1#include <allegro.h>//bShot something blargh ////////////////////////////////
2volatile int eT=0;void eL(){eT++;}END_OF_FUNCTION(eL)R(x){return rand()%x;}D(x)
3{double y;if(x==0)y=makecol(250,0,0);if(x==1)y=makecol(0,250,0);if(x==2)///////
4y=makecol(0,0,250);return y;}main(){srand(time(0));BITMAP *B;double e[30][2]=//
5{{0,0}},b[2]={-5,200},h1=96,h2=100,pC,bC,eC[30];int A[30]={0},t,n,C=0,S=0,u=0,L
6=1,w1=25,w2=29;allegro_init();install_keyboard();install_timer();install_int(eL
7,100);set_color_depth(32);set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,200,0,0);B=
8create_bitmap(640,200);LOCK_FUNCTION(eL);while(!key[KEY_ESC]){clear_bitmap(B);
9rect(B,20,-1,34,201,makecol(255,255,0));if(key[KEY_A])C=0;if(key[KEY_S])C=1;if(
10key[KEY_D])C=2;pC=D(C);if(b[0]>0||b[1]<200){b[0]-=2.5;b[1]+=2.5;circle(B,26,b[0
11],1,bC);circle(B,26,b[1],1,bC);}else{if(key[KEY_F]){bC=pC;b[0]=h2-2;b[1]=h1+2;}
12}if(key[KEY_M]&&h2<195)h1+=0.5;if(key[KEY_K]&&h1>0)h1-=0.5;if(S>300){w1=20;w2=
1334;h2=h1+14;L=6;if(eT>0){t=0;eT=0;u=1;}}if(S>200&&S<=300){w1=21;w2=33;h2=h1+12;
14L=5;if(eT>=2){t=0;eT=0;u=1;}}if(S>150&&S<=200){w1=22;w2=32;h2=h1+10;L=4;if(eT>=
154){t=0;eT=0;u=1;}}else if(S>100&&S<=150){w1=23;w2=31;h2=h1+8;L=3;if(eT>=6){t=0;
16eT=0;u=1;}}else if(S>50&&S<=100){w1=24;w2=30;h2=h1+6;L=2;if(eT>=8){t=0;eT=0;u=1
17;}}else if(S<=50){h2=h1+4;L=1;if(eT>=10){t=0;eT=0;u=1;}}if(u){for(n=0;n<30;n++)
18{if(!A[n]&&!t){e[n][0]=645;e[n][1]=R(195);A[n]=1;t=1;eC[n]=D( R(3) );}}}for(n=0
19;n<30;n++){if(((e[n][1]+2.5>b[0]&&e[n][1]+2.5<b[0]+5)||(e[n][1]+2.5>b[1]&&e[n][
201]+2.5<b[1]+5))&&(e[n][0]+2.5>25&&e[n][0]+2.5<30)){if(bC==eC[n]){A[n]=0;S+=5;}}
21if(A[n]&&e[n][0]>-5){ e[n][0]--;rectfill(B,e[n][0],e[n][1],e[n][0]+5,e[n][1]+5,
22eC[n]);}else A[n]=0;}textprintf_ex(B,font,560,5,makecol(250,250,0),-1,"Scr: %d"
23,S);textprintf_ex(B,font,560,185,makecol(250,250,0),-1,"Lvl: %d",L);rectfill(B,
24w1,h1,w2,h2,pC);blit(B,screen,0,0,0,0,640,200);rest(10);}}END_OF_MAIN()////////
25////WASTED SPACE... NOT ENOUGH ROOM FOR PLAYER DEATH :( ///////////////////////

It really did seem much more awesome in my head than it ended up being. I guess it's a pathetic attempt at some sort of shoot em up/rhythm game without music. How do you like that? :P

You can get the exe file from here with the alleg42.dll. Only for Win.

Controls:

  1. A - change color to red

  2. S - change color to green

  3. D - change color to blue

  4. F - fire up and down

  5. K - move up

  6. M - move down

Game idea:
Dodge enemies and shoot them with the same color bullets. Red bullets kill red enemies and so on... Since the player death is not implemented, you don't even have to dodge the enemies. Yahoo~. Endless ... "fun"... Ugh... As the game does on, you grow bigger and the enemies are supposed to grow bigger, the dodging gets harder, or atleast SHOULD get harder but really doesn't since you can't die ;D

I had my share of fun tinkering with this. Also, since it really doesn't have any sort of "logic locks", only the rest(10), the results are that the game performance will vary on different machines ALOT. On some it's playable and on some it's not. Too bad. Also since the bullet collision ain't that good, it might miss some of the hits you do :)

Another thing I again noticed was that good variable names are awesome. I ended up doing alot of one letter/two letter variables to save up space and other even more stupid things to save up chars. Man this compo was nuts.

Oh yeah, final note: guys, your entries are awesome. I can't believe you came up with stuff like that. It really shows that in a small compo like this, the game idea is everything.

Tomasz Grajewski
Member #4,284
February 2004

I've made another pong version, this time more playable and challenging:
http://www.allegro.cc/files/attachment/595282

1#include <math.h>
2#include <allegro.h> // Ultra simple pong clone in 20 lines of code - v3 //
3BITMAP*s;int e,ls,rs;struct B{int r,c;float x,y,vx,vy;B(){r=8;c=3;x=s->w/2;y=s->
4h/2;vx=(rand()%2)?-4:4;vy=0;}virtual void m(){x+=vx;y+=vy;if(x<r){x=r;vx*=-1;rs
5++;}if(x>s->w-r){x=s->w-r;vx*=-1;ls++;}if(y<r){y=r;vy*=-1;}if(y>s->h-r){y=s->h-r
6;vy*=-1;}}virtual void d(){circlefill(s,(int)x,(int)y,r,c);}};struct P:public B{
7P(int _x){r=96;c=5;x=_x;y=s->h/2;vx=vy=0;}virtual void m(){x+=vx;y+=vy;if(y<0)y=
80;if(y>s->h-1)y=s->h-1;}};void cc(B&b,P&p){int cd=b.r+p.r;float ad=sqrt((p.x-b.x
9)*(p.x-b.x)+(p.y-b.y)*(p.y-b.y));if(ad<cd){float na=atan2(p.y-b.y,p.x-b.x),md=cd
10-ad;b.x+=md*cos(na+M_PI);b.y+=md*sin(na+M_PI);float nx=cos(na),ny=sin(na),a1=b.
11vx*nx+b.vy*ny,a2=p.vx*nx+p.vy*ny,op=a1-a2;b.vx=-op*nx;b.vy=-op*ny;}}int main(){
12srand(time(0));allegro_init();install_keyboard();set_gfx_mode(1,640,480,0,0);s=
13create_bitmap(SCREEN_W,SCREEN_H);B b;P pl(-96+15),pr(s->w+96-16);while(!e){if(k\
14ey[59])e=1;if(key[KEY_S])pl.vy=2;else if(key[KEY_W])pl.vy=-2;else pl.vy=0;if(key
15[KEY_DOWN])pr.vy=2;else if(key[KEY_UP])pr.vy=-2;else pr.vy=0;b.m();pl.m();pr.m()
16;cc(b,pl);cc(b,pr);clear_to_color(s,15);vline(s,s->w/2-2,0,s->h-1,11);vline(s,s
17->w/2-1,0,s->h-1,11);b.d();pl.d();pr.d();textprintf_centre_ex(s,font,s->w/2-1,4,
181,-1,"%3i : %-3i",ls,rs);blit(s,screen,0,0,0,0,s->w,s->h);rest(10);}destroy_bit\
19map(s);return 0;}END_OF_MAIN()//////////////////////////////////////////////////
20////////////////////////////////////////////////////////////////////////////////
21////////////////////////////////////////////////////////////////////////////////
22////////////////////////////////////////////////////////////////////////////////
23////////////////////////////////////////////////////////////////////////////////
24////////////////////////////////////////////////////////////////////////////////

___________________________________________________________________________________________
mBlocks - a Tetris clone written in JavaScript | Merix Studio - website design & development | Zeitgeist

Matthew Leverton
Supreme Loser
January 1999
avatar

Structures, variables with more than one letter, ... you guys are wasteful!

Tomasz Grajewski
Member #4,284
February 2004

Matthew Leverton said:

Structures, variables with more than one letter, ... you guys are wasteful!

Yeah, I know, now I'm trying to minimalise mine code.

BTW, love C++ for things like that:

From

if(y<r)
{
  y=r;
  vy*=-1;
}

if(y>s->h-r)
{
  y=s->h-r;
  vy*=-1;
}

to

y=y<r?vy*=-1,r:y>s->h-r?vy*=-1,s->h-r:y;

Four bytes saved ;D

___________________________________________________________________________________________
mBlocks - a Tetris clone written in JavaScript | Merix Studio - website design & development | Zeitgeist

Matthew Leverton
Supreme Loser
January 1999
avatar

Does C++ explicitly define what happens in the case of:

int a = b ? c, d : e, f;

?

Tomasz Grajewski
Member #4,284
February 2004

Quote:

Does C++ explicitly define what happens in the case of:
int a = b ? c, d : e, f;
?

The comma separated values are evaluated from left to right, so d or f will be returned for a, if this is what you ask for. The ternary conditional is evaluated from right to left.

___________________________________________________________________________________________
mBlocks - a Tetris clone written in JavaScript | Merix Studio - website design & development | Zeitgeist

Matthew Leverton
Supreme Loser
January 1999
avatar

I was just wondering if the commas are well defined sequence points in that example, but I suppose they are. They aren't in function calls (e.g.: f(a(), b(), c())), but obviously that's a different situation.

Karadoc ~~
Member #2,749
September 2002
avatar

Næssén and Ted, your game is awesome. 80x25 or not, that game is really good.

-edit-
I haven't played cursor*10 before, so part of the reason I like this game is that it seemed so original and innovative. Now that I've tried cursor*10 this game doesn't seem as original (obviously) but I still prefer this one.

-----------

Skywhy
Member #9,243
November 2007
avatar

Tasty update of not so tasty "game" ... :)

1#include <allegro.h>//ScreenHack08 entry - bShot///////////////////////////////
2volatile int eT=0,gT=0,gU;eL(){eT++;gT++;gU=1;}END_OF_FUNCTION(eL)R(x){return
3rand()%x;}D(x){double y;if(x==0)y=makecol(250,0,0);if(x==1)y=makecol(0,250,0);
4if(x==2)y=makecol(0,0,250);return y;}main(){srand(time(0));BITMAP *B;double e[
560][2]={{0,0}},b[2]={-5,200},h1=96,h2=100,pC,bC,eC[60];int A[60]={0},t,n,C=0,S=
60,u=0,L=1,w1=20,w2=34,eu=14,pA=1;allegro_init();install_keyboard();install_int(
7eL,100);set_color_depth(32);B=create_bitmap(640,200);B=create_bitmap(640,200);
8LOCK_FUNCTION(eL);LOCK_VARIABLE(eT);LOCK_VARIABLE(gT);LOCK_VARIABLE(gU);
9set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,200,0,0);while(!key[KEY_ESC]){
10clear_bitmap(B);if(pA){rect(B,20,-1,34,201,makecol(255,255,0));if(key[KEY_A])C=
110;if(key[KEY_S])C=1;if(key[KEY_D])C=2;pC=D(C);if(b[0]>0||b[1]<200){b[0]-=2.5;b[
121]+=2.5;circle(B,26,b[0],1,bC);circle(B,26,b[1],1,bC);}else{if(key[KEY_F]){bC=
13pC;b[0]=h2-2;b[1]=h1+2;}}if(key[KEY_M]&&h2<195)h1+=0.5;if(key[KEY_K]&&h1>0)h1-=
140.5;if(gT%100==0&&gU){if(eu-1>=1){eu-=1;gU=0;gT=0;L++;}}if(S>300)h2=h1+18;else
15if(S>250)h2=h1+15;else if(S>200)h2=h1+13;else if(S>150)h2=h1+11;else if(S>100)
16h2=h1+9;else if(S>50)h2=h1+7;else h2=h1+4;if(eT>=eu){t=0;eT=0;u=1;}if(u){for(n=
170;n<60;n++){if(!A[n]&&!t){e[n][0]=645;e[n][1]=R(195);A[n]=1;t=1;eC[n]=D(R(3));}
18}}for(n=0;n<60;n++){if(((e[n][1]+2.5>b[0]&&e[n][1]+2.5<b[0]+5)||(e[n][1]+2.5>b[
191]&&e[n][1]+2.5<b[1]+5))&&(e[n][0]+2.5>25&&e[n][0]+2.5<30)){if(bC==eC[n]){A[n]=
200;S+=5;}}if(A[n]&&e[n][0]>-5){e[n][0]--;rectfill(B,e[n][0],e[n][1],e[n][0]+5,e[
21n][1]+5,eC[n]);}else A[n]=0;if(e[n][0]<w2&&e[n][0]>w1&&e[n][1]>h1&&e[n][1]<h2)
22pA=0;if(e[n][0]<w2&&e[n][0]>w1&&e[n][1]+5>h1&&e[n][1]+5<h2)pA=0;}textprintf_ex(
23B,font,200,190,makecol(250,250,0),-1,"Scr: %d/Lvl: %d",S,L);rectfill(B,w1,h1,w2
24,h2,pC);}else{textprintf_ex(B,font,100,90,makecol(250,250,0),-1,"Scr:%d/Lvl:%d"
25,S,L);}blit(B,screen,0,0,0,0,640,200);rest(10);}}END_OF_MAIN()

Compiling the code gives pile of warnings since I had to cut through loads of things to even get this much done... I know there is room for even more improvements but the current improvements popped into my head last night. :) Suddenly during the night I just got these ideas how to replace stuff and how to do things a bit differently to save even more space.

Added features:

  1. Death! Long waited player death. Now you can die. Start dodging :)

  2. After small period of time the enemy spawn rate starts getting higher and higher.

  3. Scoring points grows your "vessel" bigger.

Things I should redo:

  1. Proper collision for bullets, it's annoyingly hard to hit the enemies.

  2. And change to different kind of bullets for easier hitting too.

I don't know, it's still not good but heyh.. got atleast something done. Might do even more updates on it. Don't know at the moment.

Oh yeah, and you feel like just playing it, you can get the updated exe + alleg42.dll from here.

HardTranceFan
Member #7,317
June 2006
avatar

Here's my second game. It's a side scroller shoot-em-up. You're the green triangle, and you must avoid the grey cavern walls and shoot as many yellow orbs as you can before you crash.

Control is with the mouse, left button to fire.

1#include <allegro.h>////////////Side scrolling shooter by HardTranceFan/////////
2int i,j,h,w=200,d=-1,c=0,e=1,o=0,n=1,p=1,l=0,g=13158600,Y=13158400,mx,my,f=0,z,s
3=0,oh,lh,dh,bx=-1,by=-1;BITMAP *b,*k;int q(int x,int y){return _getpixel32(k,x+o
4,y);}void m(int x,int y){if(q(x,y)==Y){_putpixel32(k,x+o,y,0);m(x,y+1);m(x,y-1);
5m(x-1,y);m(x+1,y);}}void v(int x,int y){if((++c>(rand()%20)+15)||h<15||h>465-w){
6d*=-1;c=0;}h+=(rand()%10)*d;if(h>oh){triangle(k,x,oh,y,h,x,h,0);triangle(k,x,oh+
7w,y,oh+w,y,h+w,0);lh=h;dh=h-oh;}else{triangle(k,x,oh,y,oh,y,h,0);triangle(k,x,oh
8+w,x,h+w,y,h+w,0);lh=oh;dh=oh-h;}rectfill(k,x,lh,y,lh+w-dh,0);oh=h;}int T(){////
9return q(mx-5,my-5)|q(mx+5,my)|q(mx-5,my+5);}int B(){if(bx<0)return 0;return q(
10bx,by);}main(){allegro_init();install_keyboard();install_mouse();set_color_depth
11(32);set_gfx_mode(2,640,480,0,0);scare_mouse();b=create_bitmap(640, 480);oh=h;h=
12140;k=create_bitmap(650, 480);clear_to_color(k,g);for(i=0;i<65;i++)v(i*10,i*10+
1310);l=p;position_mouse(20,240);while(f!=2){if(!f){poll_mouse();mx=mouse_x;l--;my
14=mouse_y;if(!l){l=p;o=(o+e);if(o>10){o=0;blit(k,b,10,0,0,0,640,480);blit(b,k,0,0
15,0,0,640,480);rectfill(k,640,0,650,480,g);v(640,650);if(!(++n%30))w=(w-5<50)?49:
16w-5;else if(!(n%200))e++;}if(!(rand()%100))circlefill(k,644,rand()%w+h,5,Y);}if(
17bx<0){if(mouse_b&1){bx=mx+2;by=my;}}else bx+=2;if(bx>640)bx=-1;}blit(k,b,o,0,0,0
18,640,480);if(T())f=1;if(B()){s+=10;m(bx,by);bx=-1;}if(key[KEY_ESC])f=2;triangle(
19b,mx-5,my-5,mx+5,my,mx-5,my+5,51200);if(bx>0)circlefill(b,bx,by,2,200);/////////
20textprintf_ex(b,font,10,460,0,-1,"Score: %d",s);if(f)textprintf_ex(b,font,280,//
21235,16711680,-1,"You crashed.");blit(b,screen,0,0,0,0,640,480);rest(1);}}///////
22END_OF_MAIN()///////////////////////////////////////////////////////////////////
23////////////////////////////////////////////////////////////////////////////////
24/////////////ZOMG!!!! Spare space!!! What a waste of [binary] trees!!///////////
25////////////////////////////////////////////////////////////////////////////////

{"name":"595290","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/8\/b85d32d32803630ad64ce5068b61d9a6.jpg","w":645,"h":504,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/8\/b85d32d32803630ad64ce5068b61d9a6"}595290

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

ZOMG!!!! Spare space!!! What a waste of [binary] trees!!

ZOMG! What a waste of corn!

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

Tobias Dammers
Member #2,604
August 2002
avatar

Attached is a little tool that takes some of the tedious work off your shoulders.

What it does:

Reads a C or C++ source file, removes all unnecessary stuff (whitespace unless absolutely needed, comments), renames all identifiers that start with a dollar sign into the shortest possible set of identifiers (first a single underscore, then a through z, then A through Z, then combinations of these plus digits; most-often-used identifiers get the shortest names), replaces character literarals by their numeric counterparts (because for everything below 100 the latter are shorter, above 100 they're equally long), formats the whole thing to max. 80 characters wide, and sends it to stdout.

How to use:

1. Unzip into a folder of your choice.
2. Compile using something like g++ *.cpp -o compress
3. In your code, prepend all of your own identifiers you want replaced (types, variables, functions) with a $. Identifiers without a $ will be left alone.
4. Assuming your original, unoptimized source file is foo.c, use something like this: compress foo.c > foo_compressed.c

For example, my attempt at (yet another) snake:

1#include <allegro.h>
2#define c(cond, code) case cond: code; break;
3 
4typedef int $var;
5 
6$var $val1024 = 1024;
7$var $val256 = 256;
8$var $val32 = 32;
9$var $backbuf;
10$var $head = 1;
11$var $tail = 0;
12$var $tar_length = 2;
13$var $cur_length = 2;
14$var $dir = 1;
15$var $part_xy[32] = { 527, 528, 0 };
16$var $coinpos=0;
17$var $running=1;
18$var $newhead;
19$var $paused = 1;
20$var $speed = 1;
21$var $score = 0;
22 
23$var $multifunc0($var $func) {
24 switch ($func) {
25 c(0, $coinpos = rand() % $val1024)
26 c(1, return readkey() % $val256)
27 }
28}
29 
30$var $drawpixel($var $xy, $var $color) {
31 putpixel($backbuf, $xy % $val32, $xy >> 5, $color); return $color;
32}
33 
34$var $readpixel($var $xy) {
35 return getpixel($backbuf, $xy % $val32, $xy >> 5);
36}
37 
38$var $set_head_or_tail($ht, $color) {
39 return
40 $drawpixel($part_xy[$ht],
41 $color);
42}
43 
44$var $display_number($var $label, $var $number, $var $pos, $var $color) {
45 textprintf_ex(screen, font, 0, $pos*9, $color, -1, "%s: %i", $label, $number);
46}
47 
48$var main() {
49 // $var $i;
50
51 allegro_init();
52 set_gfx_mode(2, $val256, $val256, 0, 0);
53 install_keyboard();
54 $backbuf = create_bitmap($val32, $val32);
55 clear($backbuf);
56
57 /*
58 for ($i = 0; $i < 16; ++$i)
59 rectfill(screen, $i * 8, 0, ($i + 1) * 8, 8, $i);
60 readkey();
61 */
62
63 // $coinpos = rand() % $val1024;
64 $multifunc0(0);
65
66 $set_head_or_tail($head,
67 $set_head_or_tail($tail,
68 2));
69 $drawpixel($coinpos, 6);
70
71 while ($running) {
72 stretch_blit($backbuf, screen, 0, 0, $val32, $val32, 0, 0, $val256, $val256);
73 $display_number("Length", $cur_length, 0, 7);
74 $display_number("Speed", $speed, 1, 7);
75 $display_number("Score", $score, 2, 7);
76 if ($paused)
77 // { readkey(); $paused = 0; }
78 $paused = ($multifunc0(1)&$val1024);
79
80 rest($val1024 / ($speed + 1));
81 for (;keypressed();) {
82 // switch (readkey() % $val256) {
83 switch ($multifunc0(1)) {
84 c(27,$running=0)
85 c('a',$dir=-1)
86 c('d',$dir=1)
87 c('w',$dir=-$val32)
88 c('s',$dir=$val32)
89 }
90 }
91 $newhead = ($head + 1) % $val32;
92 $var $newpos = $part_xy[$newhead] = $part_xy[$head] + $dir;
93 switch ($readpixel($newpos)) {
94 case 6:
95 $score += $speed * $tar_length;
96 if (++$tar_length == $val32) {
97 clear($backbuf);
98 $head =
99 $dir = 1;
100 $tail = 0;
101 $tar_length =
102 $cur_length = 2;
103 $part_xy[0] = 527;
104 $part_xy[1] = 528;
105 $set_head_or_tail($head,
106 $set_head_or_tail($tail,
107 2));
108 ++$speed;
109 $paused = 1;
110 }
111 for ($multifunc0(0); $readpixel($coinpos); $multifunc0(0))
112 ;
113 $drawpixel($coinpos, 6);
114 break;
115 c(0, ) // empty cell: pass through
116 default: $running=0;
117 }
118 $head = $newhead;
119 $set_head_or_tail($head, 2);
120 if ($cur_length < $tar_length) {
121 ++$cur_length == 32;
122 }
123 else {
124 $set_head_or_tail($tail, 0);
125 $tail = ($tail + 1) % $val32;
126 }
127 }
128 $display_number("Game Over. Score", $score, 9, 13);
129
130 // readkey();
131 $multifunc0(1);
132}
133END_OF_MAIN()

...is converted into this cryptic mess:

1#include <allegro.h>
2#define c(cond, code) case cond: code; break;
3typedef int _;_ u=1024;_ k=256;_ a=32;_ d;_ b=1;_ g=0;_ p=2;_ n=2;_ f=1;_ l[32]=
4{527,528,0};_ m=0;_ r=1;_ w;_ t=1;_ q=1;_ s=0;_ i(_ y){switch(y){c(0,m=rand()%u)
5c(1,return readkey()%k)}}_ v(_ j,_ e){putpixel(d,j%a,j>>5,e);return e;}_ x(_ j){
6return getpixel(d,j%a,j>>5);}_ h(z,e){return v(l[z],e);}_ o(_ A,_ C,_ B,_ e){
7textprintf_ex(screen,font,0,B*9,e,-1,"%s: %i",A,C);}_ main(){allegro_init();
8set_gfx_mode(2,k,k,0,0);install_keyboard();d=create_bitmap(a,a);clear(d);i(0);h(
9b,h(g,2));v(m,6);while(r){stretch_blit(d,screen,0,0,a,a,0,0,k,k);o("Length",n,0,
107);o("Speed",q,1,7);o("Score",s,2,7);if(t)t=(i(1)&u);rest(u/(q+1));for(;
11keypressed();){switch(i(1)){c(27,r=0)c(97,f=-1)c(100,f=1)c(119,f=-a)c(115,f=a)}}
12w=(b+1)%a;_ D=l[w]=l<b>+f;switch(x(D)){case 6:s+=q*p;if(++p==a){clear(d);b=f=1;g
13=0;p=n=2;l[0]=527;l[1]=528;h(b,h(g,2));++q;t=1;}for(i(0);x(m);i(0));v(m,6);break
14;c(0,)default:r=0;}b=w;h(b,2);if(n<p){++n==32;}else{h(g,0);g=(g+1)%a;}}o(
15"Game Over. Score",s,9,13);i(1);}END_OF_MAIN()

BTW, that game lacks some very basic features like edge collision (or proper wrapping), but hey, I still have 10 lines left.

-- edit --

Oh, and one more thing: C has this "nice" feature called "weak typing", which enables you to do things like this:

int b = create_bitmap(256, 256);
int c = "Hello world!";

In other words, pretty much anything can be an int.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Matthew Leverton
Supreme Loser
January 1999
avatar

I just edit my code exactly as you see in the 80x25 box. :o

I never use whitespace anyway since I end up just sitting there all day wondering if I should use tabs or spaces. :-/

Tobias Dammers
Member #2,604
August 2002
avatar

You mean like this?

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

nonnus29
Member #2,606
August 2002
avatar

No more entries? Some one needs to take us into the 3rd dimension with ray casting Castle Wolfenstein in 80x25....

HardTranceFan
Member #7,317
June 2006
avatar

Given this thread is still open, I may have a crack at another idea...

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

BAF
Member #2,981
December 2002
avatar

A raycaster in 80x25? :o

kenmasters1976
Member #8,794
July 2007

This weekend I tried to turn my Tetris into 3D, but the Allegro 3D functions have long names and you have to call plenty of them, plus the vertex definitions and it easily went beyond the 25 lines. Even blitting from the buffer to the screen was annoying and the result wasn't even that great, not to mention how much slower it became, so I did quit.

Screenshot:
{"name":"595366","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/1\/51bbe58adc86990fb5c2869534fd3d93.gif","w":263,"h":431,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/1\/51bbe58adc86990fb5c2869534fd3d93"}595366

Jakub Wasilewski
Member #3,653
June 2003
avatar

Quote:

No more entries? Some one needs to take us into the 3rd dimension with ray casting Castle Wolfenstein in 80x25....

Didn't Krzysztof Kluczek do exactly that for the previous ScreenHack?

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

nonnus29
Member #2,606
August 2002
avatar

I think he did 'ray tracing' in one line actually. For raycasting, you only need to draw a line... repeatedly. :P

James Stanley
Member #7,275
May 2006
avatar

Bit late, but here's what I've worked on today and yesterday:

1#include<allegro.h>/* Breakout for Allegro ScreenHack 2008 - By James Stanley */
2float x,y,m,X,Y;int b,w=100,B[24],i,l=1,L=3,c,C[5],d;r(){x=160;y=180;X=-.5,Y=-.5
3;b=160;}R(int a, int e, int f,int g, unsigned int h){rectfill(c,a,e,f,g,h);}a(){
4return b-w/2;}e(){return b+w/2;}o(){return((i%4)*80)+5;}p(){return ((i/4)*20)+5;
5}main(){allegro_init();install_keyboard();set_color_depth(16);set_gfx_mode(2,320
6,200,320,200);c=create_bitmap(320,200);for(i=0;i<5;i++){C<i>=makecol((125-i*25)+
7100,l*40,0);}for(i=0;i<24;i++){B<i>=i/5;}r();while(!key[59]){clear_to_color(c,0)
8;if(key[82])b-=2;if(key[83])b+=2;if(a()<0)b=w/2;if(e()>320) b=320-w/2;x+=X;y+=Y;
9if(x<4){x=4;X=-X;}if(y<4){y=4;Y=-Y;}if(x>316){x=316;X=-X;}if(y>180){if(x>a()&&(x
10<e())){Y=-Y;y=180;if(key[82])X-=.1;if(key[83])X+=.1;}else if(((x+4)>a())&&((x-4)
11<e())){X=-X;Y=-Y;y=180;if(key[82])X-=.2;if(key[83])X+=.2;}}if(y>204){L--;r();}d=
120;for(i=0;i<24;i++){if(B<i><5){d=1;if((x>(o()+70))&&((x-8)<(o()+70))){if((y<(p()
13+10))&&(y>p())){X=-X;x=o()+78;B<i>++;}else if(((y+8)>p())&&(y<p())){m=X;X=Y;Y=m;
14B<i>++;}else if(((y-8)<(p()+10))&&(y>(p()+10))){m=X;X=-Y;Y=-m;B<i>++;}}else if((
15x<o())&&((x+8)>o())){if((y<(p()+10))&&(y>p())){X=-X;x=o()-8;B<i>++;}else if(((y+
168)>p())&&(y<p())){m=X;X=-Y;Y=-m;B<i>++;}else if(((y-8)<(p()+10))&&(y>(p()+10))){
17m=X;X=Y;Y=m;B<i>++;}}else if(((y+8)>p())&&(y<p())){if((x>o())&&(x<(o()+70))){Y=-
18Y;y=p()-8;B<i>++;}}else if(((y-8)<(p()+10))&&(y>(p()+10))) {if((x>o())&&(x<(o()+
1970))){Y=-Y;y=p()+18;B<i>++;}}R(o(),p(),o()+70,p()+10,C[B<i>]);}}if(!d){l++;for(i
20=0;i<5;i++){C<i>=makecol((i*25)+100,l*40,0);}for(i=0;i<24;i++){B<i>=i/5;}L++;r()
21;w*=.8;}textprintf_ex(c,font,4,120,-1,-1,"Lives: %d Level: %d",L,l);R(x-4,y-4
22,x+4,y+4,-1); R(a(), 184, e(),196,-1); blit(c, screen, 0,0,0,0,320,200);if(L<0){
23textout_centre_ex(c,font,"G A M E O V E R",160,100,-1,-1);while(!key[59])blit(
24c,screen,0,0,0,0,320,200);return 0;}}}END_OF_MAIN()/*Only 24 lines, never mind*/

Controls are Left and Right arrow. ESC to quit.

http://stanley.homelinux.org/images/80x25.png

EDIT:
Should've said: there is no timing.
Run a busy wait in the background if it's too fast ;).

madpenguin
Member #2,201
April 2002
avatar

Hmm...I'll play!

I can't really work on it until I get home and don't have an idea anyway, but I have been thinking about some shortening tricks I haven't seen anyone do yet.

In particular, I haven't seen anyone do something like this:

#define  I  int
I(*DS)(I,I,I,I)=draw_sprite;I(*CB)(I,I)=create_bitmap;

/* and later on in your code */

BITMAP *b;
b=CB(64,64);DS(screen,b,1,1);

If you have a lot of calls to draw_sprite() or create_bitmap(), this might be a pretty significant space savings. This should save people from burning the first few lines on #defines (a cautionary note: this WILL generate warnings, at least with gcc)

May entries assume that they'll be run from the same directory the source file is in? I have some asset generation stupidity in mind...

---------------------------------------------
Cynicism field generator is enabled and operating at 97% of capacity

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

#define I int

A waste of space. You lose 80 characters to save 2 bytes. Are you going to use int over 40 times? All variables should be global and then you only need one int. And all functions default to returning int with int parameters.

Almost every #define is a waste.

Quote:

I(*DS)(I,I,I,I)=draw_sprite;I(*CB)(I,I)=create_bitmap;

Again, how often do you really call those functions? I created a Tetris game with a single rectfill and a single blit.

madpenguin
Member #2,201
April 2002
avatar

I actually have something somewhat sprite-heavy in mind; there might be a lot of calls to draw_sprite() (although the same trick would work for any routine with a long name and argument list that gets called a lot). I'm not sure if this will save me space or not, although it seems like it might (and yes, I agree that #defines are a huge space waster). I didn't know that all functions defaulted to int arguments, though, that might come in handy.

I haven't quite cooked up a strategy for encoding stick figure animations yet; the game I'm envisioning might not even be possible...

---------------------------------------------
Cynicism field generator is enabled and operating at 97% of capacity



Go to: