Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411486 Posts in 69371 Topics- by 58427 Members - Latest Member: shelton786

April 24, 2024, 10:29:12 AM

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 24099 times)
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #20 on: July 03, 2008, 04:55:00 AM »

Awesome :D
Logged

increpare
Guest
« Reply #21 on: July 03, 2008, 05:47:16 AM »

mewse: ho ho ho

Terry, gosh your projects are substantial (just compiled them now, can't get anything sdl-related to compile on osx so can't try out goldcray's Sad  ).
Logged
Hideous
That's cool.
Level 10
*****


3D models are the best


View Profile WWW
« Reply #22 on: July 03, 2008, 08:18:34 AM »

hmmmm

if I remember correctly, i can do #define p = printf right?

i suck :D
Logged

increpare
Guest
« Reply #23 on: July 03, 2008, 08:41:26 AM »

hmmmm

if I remember correctly, i can do #define p = printf right?

i suck :D
All's fair in love and codeblocks.
Logged
Hideous
That's cool.
Level 10
*****


3D models are the best


View Profile WWW
« Reply #24 on: July 03, 2008, 08:43:11 AM »

Aagh I can't do C. I'm not good at this.
Logged

Don Andy
Level 10
*****


Andreas Kämper, Dandy, Tophat Andy


View Profile
« Reply #25 on: July 03, 2008, 08:52:48 AM »

I fear I'll have to pass on that one. I kinda lack ideas on what to do, and still have lots of stuff to do, to prepare for the vacation I'm going on shortly :T
Logged
increpare
Guest
« Reply #26 on: July 03, 2008, 10:15:49 AM »

I'm surprised an 80x24 APL implementation of quake hasn't appeared yet ...
« Last Edit: July 03, 2008, 01:41:56 PM by increpare » Logged
Don Andy
Level 10
*****


Andreas Kämper, Dandy, Tophat Andy


View Profile
« Reply #27 on: July 03, 2008, 12:47:04 PM »

I'm surprised a 80x24 APL implementation of quake hasn't appeared yet ...

After seeing Terry's last example, he's probably working on Wolfenstein 3D in 80x24 already :D
Logged
Ryan
Level 1
*



View Profile
« Reply #28 on: July 03, 2008, 02:09:13 PM »

So I've gotten too busy with class, I thought it'd be better to post what I had.

Code:
#include <allegro.h> /* 80x24 Codeblock Challenge: Asteroids!  1 July 2008    */
#include <math.h>    /* RyanA | arrows, can't shoot yet, nothing to do :(     */
BITMAP *b;int w=400;float P=M_PI,P2=2*P,x=w/2,y=x,a=P/2,f=.01,xv=0,yv=0,tv=0;int
main(){allegro_init();install_keyboard();set_gfx_mode(2,w,w,0,0);b=create_bitmap
(w,w);while(!key[59]){if(key[82])tv-=.005;if(key[83])tv+=.005;if(key[84]){xv+=c\
os(a)*.047;yv+=sin(a)*.047;}if(key[85]){xv*=.99;yv*=.99;}x+=xv;y+=yv;a+=tv;while
(a>P2)a-=P2;while(a<0)a+=P2;tv*=.94;xv*=.99;yv*=.99;if(x>w)x=0;if(x<0)x=w;if(y>w
)y=0;if(y<0)y=w;int p[6]={x+10*cos(a),y+10*sin(a),x+10*cos(a+.75*P),y+10*sin(a+
.75*P),x+10*cos(a+1.25*P),y+10*sin(a+1.25*P)};clear_bitmap(b);polygon(b,3,p,15);
blit(b,screen,0,0,0,0,w,w);vsync();}}END_OF_MAIN()

There's 14 lines left, originally I planned on doing ship vs. ship deathmatch, I may rewrite it using structs to keep the lines down. It was a fun experience, Terry. Normally I'm trying to format my code as clean as possible :D. I'll definitely finish this [bullets + player2] or code some other tiny thing in the future.

As for the screenshots, the only code I've written is ship controls and physics, so these are sorta pointless. Hooray triangle on a black screen!

Logged
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #29 on: July 04, 2008, 09:01:18 AM »

Nice Smiley Hope you get a chance to finish it!
Logged

Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #30 on: July 04, 2008, 04:17:07 PM »

Awesome work so far Smiley We should probably wrap this up, say, middle of next week and move on to another challenge to keep the momentum going. Unfortunately I won't be around, so does someone else want to look after that?
Logged

Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #31 on: July 04, 2008, 11:07:30 PM »

I can try to come up with something. Also wanna try to make something for this one this weekend.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #32 on: July 05, 2008, 11:40:14 PM »

Here's something quick i threw together:
Code:
#include<SDL.h>/* 80x24 Codeblock : Tiny LCD Glitch Fighter. Ivan Safrin.*/
Uint32 d(Uint32 c,char v){char o[3]={(c>>16)& 255,(c>>8)& 255,c & 255};return((o
[0]/v)<<16)+((o[1]/v)<<8)+(o[2]/v);}int main(int a,char *v[]){int done=0;Uint32
i,j,k,t,l,e,x=5,y=10,b=500,gt=0;Uint32 q[768],z[256],w[768],r[768];memset(z,0,
256*4);memset(w,0,768*4);for(i=0;i<768;i++){q[i]=(rand()%2);}SDL_Surface *u;
SDL_Surface *s;Uint32*ptr,col,inc=0;SDL_Init(SDL_INIT_VIDEO);u=SDL_SetVideoMode(
640,480,32,SDL_SWSURFACE);s=SDL_CreateRGBSurface(SDL_SWSURFACE,640,480,32,0,0,0,
0);ptr=(Uint32*)s->pixels;while(!done){SDL_Event event;while(SDL_PollEvent(
&event)){switch(event.type){case SDL_KEYDOWN:switch(event.key.keysym.sym){case
SDLK_LEFT:x--;break;case SDLK_RIGHT:x++;break;case SDLK_UP:y--;break;case
SDLK_SPACE:w[((y+1)*32)+x+3]=435;break;case SDLK_DOWN:y++;break;}break;case
SDL_QUIT:done=1;break;}}if(y>21)y=21;if(y<0)y=0;if(x>29)x=29;if(x<0)x=0;l=t;t=
SDL_GetTicks();e=t-l;col=0xff0000;Uint32 tcol;gt +=e;if(gt>50){gt=0;j=1+rand()%7
;for(i=0;i<8;i++){z[31+(32*i)]=0;}for(i=7;i>j;i--){z[31+(32*i)]=2;}for(i=0;i<255
;i++){if(i%32!=0)z[i]=z[i+1];}for(i=767;i>0;i--){if(i%32!=0)w[i]=w[i-1];}for(i=0
;i<767;i++){if(i%32!=0)r[i]=r[i+1];}if(rand()%4==1)r[31+((rand()%24)*32)]=435;if
(rand()% 40==1)b=100+(rand()%3000);}memset(q,0,3072);memcpy(q,w,768*4);memcpy(q+
(16*32),z,256*4);memset(q+((y)*32)+x-1,1,12);memset(q+((y+1)*32)+x,1,12);memset(
q+((y+2)*32)+x-1,1,12);for(i=0;i<768;i++){if(w[i]==435){
r[i]=0;r[i+1]=0;}if(r[i]==435){if(q[i]==16843009)b=1;q[i]=r[i];}}for(i=0;i<768;
i++){tcol=(col/(b));tcol=d(tcol,1+(q[i]*20));for(j=0;j<19;j++){for(k=0;k<19;k++)
{*(ptr +((i/32)*12800)+((i%32)*20)+(j*640)+k)=((tcol+1+rand()%20));}}if(i%32==0
&&i!=0){col-=inc;}}inc+=e*5;SDL_BlitSurface(s,NULL,u,NULL);SDL_Flip(u);}
SDL_Quit();return(0);}/*Arrows to move.Space to shoot. Kill & avoid bullets */
Should compile with SDL

Windows binary: CLICKY!
« Last Edit: July 06, 2008, 07:45:23 AM by toastie » Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #33 on: July 06, 2008, 01:11:45 AM »

Haha, oops, i left a debug printf in there.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
Hideous
That's cool.
Level 10
*****


3D models are the best


View Profile WWW
« Reply #34 on: July 06, 2008, 02:37:52 AM »

The colours are confusing, but dude, that rocks.
Logged

Annabelle Kennedy
Awesomesauce
Level 8
*


♥Android Love♥


View Profile
« Reply #35 on: July 06, 2008, 05:03:08 AM »

haha toastie thats so amazing for a codeblock, im genuinely impressed, with everyones!

great work!!
Logged
Melly
Level 10
*****


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


View Profile
« Reply #36 on: July 06, 2008, 03:56:27 PM »

Toastie that's crazy. Looks like you also ran out of space for a quit game button. Tongue
Logged

Feel free to disregard the above.
Games: Minus / Action Escape Kitty
Gold Cray
Level 10
*****


Gold Cray


View Profile WWW
« Reply #37 on: July 07, 2008, 07:11:08 PM »

I humbly present part two of my two part series, Better Know a Codeblock.
This time: a simple platformer based on the GLAS Large Amorphous Solid (GLAS) Engine (originally seen in Gravity Hell). The goal is to reach the top four times in the shortest possible time... span.
Left and right to move, space to jump, escape to exit.

http://home.comcast.net/~gravyman3321/PlatclimberNormal.exe
http://home.comcast.net/~gravyman3321/PlatclimberFullscreen.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[9];long st,sc,bn,e,x,i,y,g;e=0;bn=0;c.h=4;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=-3
;if(keys[SDLK_RIGHT])c.xv=3;if(keys[SDLK_SPACE]&&g){c.yv=-5;keys[SDLK_SPACE]=0;
srand(clock());}g=0;if(bn<8&&clock()>1250*bn){++bn;a[bn].yp=3;a[bn].xp=10+rand()
%300;}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;}if(!g)c.yv+=.2;c.yp+=c.yv;if(c.yp>239){c.yp=239;c.yv=0;g
=1;}if(c.yp<3){c.yp = 3;c.yv=10;--c.h;}for(x=0;x<bn;++x){a[x].yp+=.5;if(a[x].yp>
239)if(a[x].yp>239){a[x].yp=3;a[x].xp=10+rand()%300;}if(c.yp>a[x].yp&&(c.yp-c.yv
)<a[x].yp&&abs(c.xp-a[x].xp)<=9){c.yv=.5;c.yp=a[x].yp-1;g=1;}for(i=0;i<18;++i)if
(a[x].xp-9+i>=0&&a[x].xp-9+i<320)d(a[x].xp-9+i,a[x].yp,16711680);}d(c.xp,c.yp,
2147483647);for(x=0;x<(4-c.h)*80;++x)d(x,1,65280);sc=clock()-st;if(c.h<1)e=1;
SDL_Flip(s);SDL_Delay(16);}cout<<"sc = "<<sc<<endl;}
Logged
Decipher
Guest
« Reply #38 on: July 08, 2008, 04:55:21 PM »

So how about taking the challenge one step further then? Mouse control, window caption, countdown timer and full (totally fake Tongue) LCD display emulation, and most important of all total random level generator! There you go lads.

Requires SDL to compile.

Code:
#include<SDL/SDL.h>/*! <~~~~~~~~~~~~~~ Krysp :*: by Decipher ~~~~~~~~~~~~~~> !*/
SDL_Surface*e;SDL_Rect f;SDL_Rect k={0,0,7,7};int p(int x,int y){return*((int*)e
->pixels+x+y*480)==874069;}void g(){f.x=f.y=1,f.w=f.h=7;SDL_FillRect(e,0,5824849
);for(;f.x<480;f.x+=8){for(;f.y<480;f.y+=8)SDL_FillRect(e,&f,874069);f.y=1;}f.x=
(rand()%60)*8+1;srand(time(0));f.y=(rand()%60)*8+1;int h=0;int i=rand()%2399;
while(h<2400){switch(rand()%4){case 0:if(f.y>9){f.y-=8;break;}continue;case 1:if
(f.x<465){f.x+=8;break;}continue;case 2:if(f.y<465){f.y+=8;break;}continue;case
3:if(f.x>9)f.x-=8;else continue;}if(h==i)k.x=f.x,k.y=f.y;SDL_FillRect(e,&f,
5824849);++h;}SDL_FillRect(e,&k,255);}int main(int a,char**b){SDL_Event d;char z
[99]="Krysp ";SDL_Init(32);SDL_Surface*c=SDL_SetVideoMode(480,480,32,0);e=
SDL_CreateRGBSurface(0,480,480,32,0,0,0,0);int t=SDL_GetTicks();g();while(1){if(
SDL_PollEvent(&d)){if(d.type==12)break;else{int x=d.button.x;int y=d.button.y;if
(d.button.button==1&&x<f.x+13&&x>f.x-5&&y<f.y+13&&y>f.y-5){x=((x>>3)<<3)+1;y=((y
>>3)<<3)+1;if(!p(x+2,y+2)){f.x=x;f.y=y;if(f.x==k.x&&f.y==k.y){t=SDL_GetTicks();g
();}}}}}SDL_BlitSurface(e,0,c,0);SDL_FillRect(c,&f,0);int u=SDL_GetTicks()-t;
itoa(20-u/1000,z+6,10);SDL_WM_SetCaption(z,z);if(u>20000)break;SDL_Flip(c);
SDL_Delay(20);}SDL_FreeSurface(e);SDL_Quit();return 0;}
/* You are the black dot, who needs to eat that blue dot in 20 seconds. Controls
 * are fairly simple : click on the black dot and drag. The game never ends!
 * There's a continuous generation as you eat the blue dot. I guess this is also
 * the only game submitted 'til now that features a window caption & a counter!
 *                          OH, FORGOT TO TELL!
 *                       IT IS GOOD TO HAVE SPACE!
 ******************************************************************************/

Click here for the {Executable}
[edit]Saved a few more bytes.
[edit2]Bugfix.
« Last Edit: July 09, 2008, 02:08:17 AM by Decipher » Logged
Gold Cray
Level 10
*****


Gold Cray


View Profile WWW
« Reply #39 on: July 08, 2008, 06:25:40 PM »

Awesome. The mouse control feels a bit buggy at times, but the level generation is really nice. This would have been a good entry for the Procedural Generation Competition.
Logged
Pages: 1 [2] 3
Print
Jump to:  

Theme orange-lt created by panic