Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1327956 Posts in 60042 Topics- by 51313 Members - Latest Member: kretz32

January 18, 2018, 11:25:59 pm

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Coding Challenge 1: Codeblocks
Pages: [1] 2 3
Print
Author Topic: Coding Challenge 1: Codeblocks  (Read 21113 times)
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« on: June 30, 2008, 05:48:37 pm »

Good evening Gentleman

I saw something cool over at the Game Developers Refuge today -  a coding contest where participants had to write a functional game in no more than the space of a DOS console - 80 characters across and 24 rows down. As an example, here's the code I submitted:

Code:
#include <allegro.h> /* 80x24 Codeblock : Arena Shooter!       30th June '08 */
#include <math.h>    /* By Terry Cavanagh  |  http://www.distractionware.com */
BITMAP *b;class m{public:double x,y,d;int t;};class pc{public:void c(int i, int
j, double d, int z){p[n].x=i;p[n].y=j;p[n].t=z;p[n].d=d;n++;}void cp(int i, int
j){p[i].x=p[j].x;p[i].y=p[j].y;p[i].t=p[j].t;p[i].d=p[j].d;}void d(int t){if(
t==n-1)n--;else{for(int i=t;i<n;i++)cp(i,i+1);n--;}}m p[999];int n;};void r(int
x, int y, int s, int c){rectfill(b, x, y, x+s, y+s, c);}int m(int r,int g,int b
){return makecol(r*63,g*63,b*63);}int main(){allegro_init();srand(time(0));int
a,w=640,h=480;install_keyboard();double x=315,y=235,d=0,t,s,f,g=0,k=0,u=0,o=0;
b=create_bitmap(w,h);pc p; p.n=0;set_gfx_mode(2,w,h,0,0);while(!key[59]&&u==0){
clear_bitmap(b);for(int i=0;i<p.n;i++){t=p.p[i].x;s=p.p[i].y;o=p.p[i].t;if(o==0
)r(t,s,2,m(4,4,4));if(o==1)r(t,s,15,m(4,0,0));}circlefill(b,x,y,5,m(0,2,4));t=x
+(sin(d)*30);s=y+(cos(d)*30);hline(b,t-3,s,t+3,m(3,3,3));vline(b,t,s-3,s+3,m(3,
3,3));blit(b,screen,0,0,0,0,w,h);vsync();if(key[84]){x+=sin(d)*4;y+=cos(d)*4;}
if(key[82])d+=0.125;if(key[85]){x-=sin(d)*4;y-=cos(d)*4;}if(key[83])d-=0.125;if
(key[26])f=1;else f=0;if(d<0)d+=6.24;if(d>7)d-=6.24;if(x<0)x=0;if(y<0)y=0;if(x>
w)x=w;if(y>h)y=h;if(g<0){if(f==1){g=10;p.c(x,y,d-0.1,0);p.c(x,y,d+0.1,0);p.c(x,
y,d,0);}}else g--;for(int i=0;i<p.n;i++){t=p.p[i].x; s=p.p[i].y;o=p.p[i].t;if(o
==0){for(int j=0;j<p.n;j++){if(p.p[j].t==1&&abs(p.p[j].x-t)<12&&abs(p.p[j].y-s)
<12)p.d(j);}p.p[i].x+=sin(p.p[i].d)*10;p.p[i].y+=cos(p.p[i].d)*10;if(t<-10||t>w
||s<-10||s>h)p.d(i);}if(o==1){if(t>x)t--;if(t<x)t++;if(s>y)s--;if(s<y)s++;
p.p[i].x=t; p.p[i].y=s;if(abs(t-x)<10&&abs(s-y)<10)u=1;}}if(k<0){k=10;t=rand()%
4;a=rand();if(t==0)p.c(a%w,0,0,1);if(t==1)p.c(a%w,w,0,1);if(t==2)p.c(0,a%h,0,
1);if(t==3)p.c(w,a%h,0,1);}else k--;}return 0;}END_OF_MAIN()

This produces a playable (but not very good) arena shooter! You'll need Allegro to compile it, here's a screeny and a download if you can't get it working:



I had fun putting this together, and I figured people here might like to give it a try as well Smiley So I'm starting a coding challenge to accompany the music challenge on the art board. Our first challenge: write a playable game where the source code fits into a 80x24 console!

The rules:
 - The game has to be basically functional (i.e. interactive).
 - Use any language or standard library you want.
 - The entire game must be self contained (no external graphics or sound).
 - Provide a binary and a screenshot if you can!

We'll take a rough show of hands after a week or so and pass the challenge onto someone else Smiley
Logged

moi
Level 10
*****


DILF SANTA


View Profile WWW
« Reply #1 on: June 30, 2008, 07:19:45 pm »

Little off topic: I knew an early computer programming magazine that had a similar contest, you had to make the most interesting little program with only two lines of code. With all the limitations inherent to conditional statements, etc...
</off topic>
Logged

subsystems   subsystems   subsystems
Ryan
Level 1
*



View Profile
« Reply #2 on: June 30, 2008, 09:03:40 pm »

Quote from: Terry
We'll take a rough show of hands after a week or so and pass the challenge onto someone else

Confused about what this sentence means. Do we just write one, or is there something more involved? At any rate, this is a super neat idea! I lurk over at GDR as well, I wasn't aware you were Echo.

I'll start on a little entry, dunno if I'll accomplish anything or not, and if I do it will most likely be unoriginal. But it should be a fun experience! Beer!.
Logged
Hideous
That's cool.
Level 10
*****


3D models are the best


View Profile WWW
« Reply #3 on: June 30, 2008, 11:33:56 pm »

Well, there goes python Tongue
Logged

Don Andy
Level 10
*****


Andreas Kämper, Dandy, Tophat Andy


View Profile
« Reply #4 on: July 01, 2008, 12:34:13 am »

- The entire game must be self contained (no external graphics or sound).

But DLLs that the game will probably need to run are allowed, right?

Oh, and I'll probably try to participate, if I can manage to do that before my vacation :D
Logged
increpare
Guest
« Reply #5 on: July 01, 2008, 04:27:22 am »

I like the idea of this; does anyone have any ideas of good combinations of languages/libraries that might work well with these restrictions?
Logged
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #6 on: July 01, 2008, 04:29:38 am »

Quote from: Terry
We'll take a rough show of hands after a week or so and pass the challenge onto someone else

Confused about what this sentence means. Do we just write one, or is there something more involved? At any rate, this is a super neat idea! I lurk over at GDR as well, I wasn't aware you were Echo.

Heh, sorry. This is what I get for writing posts at 3am. I just meant that we'll decide on a winner in the same way that we do for the music contest - everybody just says which codeblock was their favorite and the winner hosts the next coding challenge.

But DLLs that the game will probably need to run are allowed, right?

Ah, yeah, I guess so.  Embarrassed
Logged

increpare
Guest
« Reply #7 on: July 01, 2008, 05:08:58 am »

Our first challenge: write a playable game where the source code fits into a 80x24 console!
What are the output capabilities of the console?  (idly thinking about doing something in Piet) Wink
Logged
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #8 on: July 01, 2008, 05:10:51 am »

Hah - that would be pretty cool. Might be better as a future challenge though Tongue

I briefly thought about using Inform, just to see how much content I could squeeze in Smiley

Logged

increpare
Guest
« Reply #9 on: July 01, 2008, 01:00:20 pm »



Hmm.  Not exactly inspired.  I aimed a little low I'm afraid.  Even with some graphical effects I couldn't fill out the space  Sad I thought that processing might be a pretty good language to do things in, as its code doesn't have much baggage at all.  Oh yeah, the game is what we used to call Buzz-Fizz.  Erm, two numbers on the top of the screen, and an increasing one on the bottom.  If the number on the left divides into it, press b (for 'buzz'), if the one on the right does, press f (for 'fizz'), if they both do, press both.  Yeah.

Code:
int l,a=R(2,7),b=R(1,7)+a,i=1, B=0,F=0,c=0,r=0;void draw(){pushMatrix();int s=
second();if(s==0&&l>s)l=0;if(l<s){r=0;if((i%a==0&&B==0)||(i%b==0&&F==0)||(i%a>0
&&B>0)||(i%b>0&&F>0))r=1;else i++;l=s;B=0;F=0;}if(r>0){translate(R(-5,5),R(-5,5)
);background(255,0,0,0);}else background(R(0,20),R(0,20),R(0,20));PFont f=
loadFont("f");textFont(f,36);fill(255);text(a,6,30);text(b,50,30);textFont(f,50)
;text(i,10,80);if(B!=0){text("buzz",3+R(-5,5),40+R(-5,5));}if(F!=0){text("fizz",
3+R(-5,5),80+R(-5,5));}popMatrix();}void keyPressed(){if(key=='b')B=1;if(key=='f'
)F=1;}int R(int x,int y){return int(random(x,y));};//increpare

Can be played here in applet form you'll all, I'm sure, be more than excited to know. 
Logged
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #10 on: July 01, 2008, 01:06:58 pm »

haha, I keep messing it up Tongue Liked the little visual touches of the shaking text. You had loads of room left though! Feel free to enter again if you're not happy with it (I'm probably going to hack up something else myself by the end of the week if I get a chance).
Logged

Hideous
That's cool.
Level 10
*****


3D models are the best


View Profile WWW
« Reply #11 on: July 01, 2008, 01:37:23 pm »

I would love to enter this, but I doubt I am skilled enough.
Logged

joshg
Level 4
****



View Profile WWW
« Reply #12 on: July 01, 2008, 03:50:07 pm »

I don't have time to enter this right now - my current coding challenge is to actually code the game I'm working on my spare time - but I just wanted to say this is awesome and I hope it keeps momentum so I can take a stab at it in a few months or so.
Logged

these are from an actual radio shack in the ghetto
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #13 on: July 01, 2008, 06:16:26 pm »

I didn't really have time to do any proper coding tonight, so I made another one :D It's a simple raycaster maze. The object is to find five red squares, after which the game ends. Arrows to move.



Here's the windows binary: Download

And here's the codeblock to generate it!

Code:
#include <allegro.h> /* 80x24 Codeblock:  Simple Raycaster Maze  1st Jul '08 */
#include <math.h>    /* Terry Cavanagh   |   http://www.distractionware.com  */
BITMAP *b;int xp,yp,n,m;int map[15][15]={{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{1,0,0
,0,0,1,0,1,0,1,0,0,0,0,1},{1,0,2,1,0,0,0,0,0,0,0,0,2,0,1},{1,0,1,1,1,1,1,1,1,1,
1,0,0,0,1},{1,0,0,1,0,0,0,0,0,0,0,0,0,0,1},{1,1,0,1,0,2,2,0,2,2,0,1,1,0,1},{1,0
,0,1,0,2,0,0,0,2,0,1,0,0,1},{1,0,1,1,0,0,0,1,0,0,0,1,0,1,1},{1,0,0,1,0,2,0,0,0,
2,0,1,0,0,1},{1,1,0,1,0,2,2,0,2,2,0,1,1,0,1},{1,0,0,0,0,0,0,0,0,0,0,1,0,0,1},{1
,0,0,0,0,1,1,1,1,1,1,1,1,0,1},{1,0,2,0,0,0,0,0,0,0,0,1,2,0,1},{1,0,0,0,0,1,0,1,
0,1,0,0,0,0,1},{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};int z(int q,int d){if(q==3)
return makecol(255,0,0);d=128-d;if(d<0)d=0;if(q<2)return makecol(d,d,d);if(q==2
)return makecol(d,d,0);}void r(int x,int y,int s,int c){rectfill(b,x,y,x+10,y+s
,c);}void pl(){m=1;while(m>0){xp=rand()%15; yp=rand()%15;m=map[xp][yp];}map[xp]
[yp]=3;n++;}void re(){map[xp][yp]=m;pl();}int main(){allegro_init();srand(time(
0));install_keyboard();double u=0,x=100,y=100,d=0,c,t,s,q,f,g;int a,w=640,h=480
;set_color_depth(32);set_gfx_mode(2,w,h,0,0);b=create_bitmap(w,h);n=-1;pl();
while(!key[KEY_ESC]&&u==0){acquire_bitmap(b);clear_bitmap(b);rectfill(b,0,240,
640,480,makecol(32,32,32));for(int i=0;i<64;i++){c=0;t=x;s=y;while(map[int(t/
100)][int(s/100)]==0 && c<800){c++;q=d+(i*0.0174)-0.5585;t+=sin(q);s+=cos(q);}c
=(10000/c)/cos(i*0.014);r(i*10,240-c,2*c,z(map[int(t/100)][int(s/100)],2000/c))
;}for(int i=0;i<n;i++){r(5+(i*15),465,10,makecol(255,0,0));}blit(b,screen,0,0,0
,0,w,h);release_bitmap(b);vsync();f=x;g=y;if(key[84]){x+=sin(d)*10;y+=cos(d)*10
;}if(key[82])d-=0.125;if(key[85]){x-=sin(d)*10;y-=cos(d)*10;}if(key[83])d+=
0.125;c=map[int(x/100)][int(y/100)];if(c!=0){if(c==3)re();x=f;y=g;}if(n>=5)u=1;
}return 0;}END_OF_MAIN()
Logged

Melly
Level 10
*****


This is how being from "da hood" is like, right?


View Profile
« Reply #14 on: July 01, 2008, 06:36:01 pm »

That's awesome Terry. Very impressive for just 24 lines. YOu're gonna have to teach me to do something like that someday. Tongue
Logged

Feel free to disregard the above.
Games: Minus / Action Escape Kitty
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #15 on: July 01, 2008, 06:51:47 pm »

Raycasters are actually simple enough - check out this tutorial for an explanation:

http://student.kuleuven.be/~m0216922/CG/raycasting.html

This one's pretty good too:

http://www.permadi.com/tutorial/raycast/
Logged

Hideous
That's cool.
Level 10
*****


3D models are the best


View Profile WWW
« Reply #16 on: July 02, 2008, 12:24:51 am »

Thinking of doing ASCII invaders or something.

/extent of my skills
Logged

William Laub
Level 10
*****


Gold Cray


View Profile WWW
« Reply #17 on: July 02, 2008, 04:54:57 pm »

This is a simple bullet hell platformer. Arrows to move, space to jump, requires SDL to compile. Final score is located in stdout.txt.



Fullscreen: http://home.comcast.net/~gravyman3321/GravityHellFullscreen.exe
Not Fullscreen: http://home.comcast.net/~gravyman3321/GravityHellNormal.exe

Code:
#include <cstdlib>  /*    M     *    **    *   *    * *   *   *     *   *    */
#include <iostream> /*   /|\  *  *  *    **  * * * *   * *   ** * *   *  **  */
#include <cmath>    /*  / | \   * *   *  *  **  *   *  *  *  **   *  o. *  * */
#include <SDL.h>    /* /__|__\     *   *  *    *    ***    **   * *   :* **  */
using namespace std;SDL_Surface* s;typedef struct{float h,xp,yp,xv,yv;}b;void d
(int xp,int yp,Uint32 color){*((Uint32 *)s->pixels+yp*s->pitch/4+xp)=color;}int
main(int argc,char *argv[]){b c,a[192];long st,sc,bn,e,x,y;e=0;bn=0;c.h=10;c.xp
=160;c.yp=238;SDL_Init(32);s=SDL_SetVideoMode(320,240,32,0x40000001);SDL_Event
event;Uint8* keys;st=clock();while(e==0){keys=SDL_GetKeyState(NULL);
SDL_PollEvent(&event);if(keys[SDLK_ESCAPE])e=1;c.xv=0;if(keys[SDLK_LEFT])c.xv=-
1.5;if(keys[SDLK_RIGHT])c.xv=1.5;if(keys[SDLK_SPACE]&&c.yv<10){c.yv=-2;keys[
SDLK_SPACE]=0;};if(bn<191){++bn;a[bn].yp=3;a[bn].xp=rand()%320;a[bn].xv=.6*rand
()/(float)RAND_MAX-.3;a[bn].yv=.3*rand()/(float)RAND_MAX;}for(x=0;x<320;++x)for
(y=0;y<240;++y)d(x,y,0);c.xp+=c.xv;if(c.xp<0||c.xp>319){c.xp-=c.xv;c.xv=0;}c.yv
+=.08;c.yp+=c.yv;if(c.yp>239){c.yp=239;c.yv=0;}if(c.yp<3){c.yp = 3;c.yv=10;st-=
1000;}for(x=0;x<bn;++x){a[x].xp+=a[x].xv;a[x].yp+=a[x].yv;if(a[x].xp<0||a[x].xp
>319){a[x].xv*=-1;a[x].xp+=2*a[x].xv;}if(a[x].yp<3||a[x].yp>239){a[x].yv*=-1;a[
x].yp+=2*a[x].yv;}if(abs(c.xp-a[x].xp)<=1&&abs(c.yp-a[x].yp)<=1)--c.h;a[x].xv*=
1.001;a[x].yv*=1.001;d(a[x].xp,a[x].yp,16711680);}d(c.xp,c.yp,2147483647);for(x
=0;x<c.h*32;++x)d(1+x,1,65280);st-=(239-c.yp)/16;sc=clock()-st;if(c.h<1)e=1;
SDL_Flip(s);SDL_Delay(16);}cout<<"sc = "<<sc<<endl;}

For fullscreen, add change 0x40000001 to 0xB0000001

I've got plenty of space left, so this might grow some improvements in the future.

UPDATES:
  • Added infinite space jump
  • Extra points per second for being higher
  • 1000 Extra points for hitting the top
  • Slowed things down a bit and reduced the number of projectiles to 192
« Last Edit: July 04, 2008, 03:26:26 pm by Gold Cray » Logged
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #18 on: July 03, 2008, 04:23:18 am »

Nice! I didn't last long :D

You should provide an EXE for people too Smiley
Logged

mewse
Level 6
*



View Profile WWW
« Reply #19 on: July 03, 2008, 04:49:51 am »

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(char *argv, int argc)
{
    srand(time(NULL));
    char str[1024];
    bool guessedCorrectly = false;

    printf("I'm thinking of a number between six and eleventy billion.\n");
    printf("Try to guess it!\n");
    while( !guessedCorrectly )
    {
        printf("\nEnter your guess.\n");
        fgets(str,1024,stdin);

        if ( rand() & 0x1 )
            printf("Too low!  Try again!\n");
        else
            printf("Too high!  Try again!\n");
    }
    printf("You win!  Wait.. what?\n");
    return 0;
}

 Gentleman
Logged
Pages: [1] 2 3
Print
Jump to:  

Theme orange-lt created by panic