Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

The 20 Line Challenge / 18 line Pong game

Author
Message
xtom
20
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 29th Nov 2002 00:29
Here's a simple pong game I did. It's dodgy to say the least but I just wanted to see if I could make it myself in less than 20 lines. I might try and improve it a bit more or if anyone else wants to go ahead. I'll post the easy to read version in the next post.

hide mouse : box 0,0,10,30 : get image 1,0,0,8,8 : get image 2,0,0,10,30 : sync rate 60 : sync on : sprite 1,0,0,1 : bat1_y=220 : bat2_y=220 : serve=1 : gosub serve
do : box 0,15,640,25 : box 0,470,640,480 : text 0,0,"Player score: "+str$(score1) : text 200,0,"Cpu score: "+str$(score2)
if keystate(30)=1 then dec bat1_y,6 : if bat1_y440 then bat1_y=440
if sprite angle(1)120
if sprite y(1)>bat2_y then inc bat2_Y,6 : if bat2_y>440 then bat2_y=440
if sprite y(1)462 then rotate sprite 1,wrapvalue(180-sprite angle(1))
if sprite y(1)640 : serve=1 : gosub serve : inc score1 : endif
if sprite x(1)
xtom
20
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 29th Nov 2002 00:31
Forum code thing didn't work. Here's it is again.

hide mouse : box 0,0,10,30 : get image 1,0,0,8,8 : get image 2,0,0,10,30 : sync rate 60 : sync on : sprite 1,0,0,1 : bat1_y=220 : bat2_y=220 : serve=1 : gosub serve
do : box 0,15,640,25 : box 0,470,640,480 : text 0,0,"Player score: "+str$(score1) : text 200,0,"Cpu score: "+str$(score2)
if keystate(30)=1 then dec bat1_y,6 : if bat1_y<25 then bat1_y=25
if keystate(44)=1 then inc bat1_y,6 : if bat1_y>440 then bat1_y=440
if sprite angle(1)<180 and sprite x(1)>120
if sprite y(1)>bat2_y then inc bat2_Y,6 : if bat2_y>440 then bat2_y=440
if sprite y(1)<bat2_y then dec bat2_Y,6 : if bat2_y<25 then bat2_y=25
endif : move sprite 1,8 : sprite 2,10,bat1_y,2 : sprite 3,620,bat2_y,2
if sprite collision(1,2)=1 or sprite collision(1,3)=1 then rotate sprite 1,wrapvalue(sprite angle(1)+rnd(90)+90)
if sprite y(1)>462 then rotate sprite 1,wrapvalue(180-sprite angle(1))
if sprite y(1)<25 then rotate sprite 1,wrapvalue(180-sprite angle(1))
if sprite x(1)>640 : serve=1 : gosub serve : inc score1 : endif
if sprite x(1)<0 : serve=2 : gosub serve : inc score2 : endif
sync : loop
serve:
if serve=1 : x=25 : ang=rnd(90)+45 : endif
if serve=2 : x=615 : ang=rnd(90)+225 : endif
y=rnd(380)+50 : sprite 1,x,y,1 : rotate sprite 1,ang : return
xtom
20
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 29th Nov 2002 00:34
This is the code in easier to read form in case anyone want's to play around with it. I'll try this code tag again.

xtom
20
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 29th Nov 2002 01:36
More polished version below. Better collision, ai etc. And squashed into 12 lines. I think some of these commands may only be dbpro compatible, I'm not sure.


xtom
20
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 29th Nov 2002 01:39
Oh bugger, I broke the 5 command to a line rule. Ah well. It's still quite small anyway.
xtom
20
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 29th Nov 2002 20:51
Forgot to say the controls are A and Z. This is one time I could have done with an edit post feature.
Luke
20
Years of Service
User Offline
Joined: 29th Aug 2002
Location: United States
Posted: 30th Nov 2002 19:28
is this for DBpro? doesn't work in DBv1.13

www.CyberLuke.com
xtom
20
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 30th Nov 2002 20:49
Yeah I think some of the sprite commands I'm using are DBPro only.

BTW if anyone can test this in window mode and close it using the x or close. It closes it but seems to leave it running in the background. Using XP and checking processes in the task manager shows it to be still running even though I closed it. Seems to be a bug with closing programs in window mode. Using the end command or escape in full screen mode closes it fully.
xtom
20
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 1st Dec 2002 21:07
Forget that last bit, window modes close fine. Turns out it's because I changed the application window caption from the default "DarkBASIC Pro Project" in the editor. Changing that leads to some strange problems.
Solidz Snake
20
Years of Service
User Offline
Joined: 23rd Oct 2002
Location: United Kingdom
Posted: 2nd Dec 2002 08:09
Take ur time xtom

Snake? What happened? Snake? Snaaaaaaaaaaaaaaaake!!! - Colonel Roy Campbell

Login to post a reply

Server time is: 2022-11-29 14:36:56
Your offset time is: 2022-11-29 14:36:56