Basic Program CONTEST (project 1)

Basic and Machine Language

Moderator: Moderators

User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Post by Jeff-20 »

Wow! 20 lines is really challenging! But I love it!

I was just motivated to play around with my vic yesterday... I have some great ideas now. I think I will have the first entry ready to post by next week. I am really excited about it.

I am really trying to make a small program... (versus crunching fat lines together). It seems like some amazing things can be done. I'm going to work on it tonight.
High Scores, Links, and Jeff's Basic Games page.
vic user
VicGyver
Posts: 1401
Joined: Thu Mar 25, 2004 9:40 am

Post by vic user »

I think once people see some work from someone, that will really get the ball rolling.

looking forward to anything you post

chris
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Here is my entry - Anti-Aircraft Challenge, a direct port of the ZX Spectrum game with the same name which I submitted for the CSS Crap Game Compo 2003. If you prefer to download it instead of typing it in, you can get it here.

Unfortunately I broke the rules by ending up with 25 lines. If we were allowed to make lines longer than what can be typed in (the editor allows 88 characters, but the Basic interpreter accepts 255 characters per logical line), I can reduce it to 19 lines.

Instructions

Your city is under attack by enemy aircraft, dropping bombs on the houses trying to make a safe landing. Your task is of course to defeat this enemy aircraft, and to your help is a single missile.

You move the missile with keys O and P, and fire it with space bar. As soon as the missile is fired, you can't control it anymore. If it doesn't hit its target, you get a new missile to fire. If your missile it hit by an enemy bomb, or if the enemy crashes into a house or eliminates the whole city, you have lost. Only if you hit the aircraft itself, you can feel satisfied.

Known bugs

If a missile didn't hit its target, a new one doesn't appear until you move it or shoot again. This means you can "hide" and wait for an opportunity to attack the enemy. Since the enemy fires at most five bombs at the same time, it will sometimes be defenseless.

If the enemy aircraft manages to remove all the houses, the game will report it has crashed into a house when it hits the line under the city. We can pretend it is a road or subway, and it is a loss anyway.

The game is quite slow, and to speed it up, the whole screen is painted black to start with and then colourized with the houses. This means that a missile, bullet or even enemy aircraft that goes into an area where there used to be a house, it will inherit its colour.

There are no sound effects in the game, mainly because I was too bored to come up with any.

Code: Select all

1 poke36879,24:printchr$(147):fori=0to505:poke38400+i,0:next:deffns(x)=7680+x*22
2 zz=rnd(-ti):fori=0to21:pokefns(22)+i,99:next:fori=1to5:x(i)=-1:d(i)=0:next:xx=0
3 dimh(22):yy=0:pf=-1:ox=-1:px=int(rnd(1)*21)+1:fori=0to21:h(i)=21-int(rnd(1)*12)
4 c=int(rnd(1)*8):on abs((c=ox)+(c=1)) goto 4:ox=c
5 for k=21 to h(i) step -1:poke fns(k)+i,160:poke38400+k*22+i,c:next k,i:ox=0
6 r=fns(yy):if peek(r+xx+1)<>32 then w=1:goto 23
7 poke r+xx,32:poke r+xx+1,62:xx=xx+1:if xx>21 then yy=yy+1:xx=0
8 if pf>=0 then poke fns(pf)+px,32:pf=pf-1:goto 11
9 geta$:px=px+(a$="o"andpx>0)-(a$="p"andpx<21):pf=-1-((a$=" ")*h(px))
10 ifpx<>oxthenpokefns(h(ox)-1)+ox,32:r=h(px)-1:pokefns(r)+px,30:ox=px
11 if pf>=0 then ty=pf:gosub 14:poke fns(pf)+px,30
12 if rnd(1)>0.7 then k=1:gosub 15
13 for k=1 to 5:on abs(x(k)>-1) gosub 19:next:goto 6
14 v=peek(fns(ty)+px):w=abs((v=62)*2+(v=46)*3):onwgoto23:return
15 if k=6 then return
16 if x(k)>-1 or x(k)=xx then k=k+1:goto 15
17 x(k)=xx:y(k)=yy+1
18 poke fns(y(k))+x(k),46:return
19 t=x(k):poke fns(y(k))+t,32:if y(k)>20 then 22
20 y(k)=y(k)+1:r=peek(fns(y(k))+t):w=abs((r=30)*3+(r=32)):onwgoto18,23,23
21 if d(k)<4 then d(k)=d(k)+1:h(t)=h(t)+1:goto 18
22 d(k)=0:x(k)=-1:return
23 restore:for m=1 to w:read b$:next:printchr$(147);b$
24 print:print"hit key to play again!":poke198,0:wait198,1:poke198,0:run
25 data "plane crashed in city!","you defeated the enemy","you were hit by bullet"
Technical notes

I found that Basic will continue on the same line after a "ON value GOTO" construct, which makes it an interesting, although slower alternative to traditional IFs. The trick is to combine the fact that a condition always will evaluate to 0 (false) or -1 (true) and apply ABS:

ON ABS((R=30)*3+(R=32)) GOTO 18,23,23

means that for R=30, the value is ABS(-1*3) = 3. For R=32, the value is ABS(-1) =1 but for all other values it will be 0.

The ON GOTO will associate the first line number with an integer value of 1, the second with 2 etc. The middle line number is a dummy, as the expression never becomes 2. If the expression evaluates to zero, no jump will be executed, and Basic continues on the same line. Neat!

Otherwise, it is quite straightforward with one DEF FN, a lot of POKEd action onto screen memory and a way to scramble (randomize) the random number generator in the beginning by givining it a negative seed.

The array H(0..21) holds the remaining height of the houses in number of screen rows (or rather which row they are starting on). X(1..5) and D(1..5) are the enemy bombs horizontal and vertical positions.

Good luck to the rest of you writing your games, and we'll see if this one is accepted although it is 25 lines. At least it should serve as a source to get some tips and inspiration how to make the most out of Basic.
Anders Carlsson

Image Image Image Image Image
vic user
VicGyver
Posts: 1401
Joined: Thu Mar 25, 2004 9:40 am

Post by vic user »

wicked!

can't wait to try it!

chris
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

I think there might be one or two bugs more - the only way to win is to appear right before (not hitting) the aircraft, and if you do, you still get a message about losing. Also, sometimes you will be able to escape a bomb as the two pass by eachother simultaneously.

I'll see if I can come up with one more game in a few lines less.
Anders Carlsson

Image Image Image Image Image
aneurysm
not your PAL
Posts: 178
Joined: Sat Mar 06, 2004 11:06 pm

Post by aneurysm »

damn
and I was gonna just do a number guessing game...
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Post by Jeff-20 »

I'm having fun with this!

I am taking my time to make something impressive. Making a game in 20 lines is like artfully pruning a bonsai tree.
High Scores, Links, and Jeff's Basic Games page.
vic user
VicGyver
Posts: 1401
Joined: Thu Mar 25, 2004 9:40 am

Post by vic user »

Hi Anders;

I downloaded the .prg file for your game, and tried to use VICE to load it, as an attached image.

It started to load and then froze up.

Do you know what I am doing wrong, perhaps not using the right way to load?

Chris
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Heh. It is a raw program file, neither a tape, disk or cartridge image. Thus, it will not easily autostart. I have now put a slow-loading TAP image on the web page:

http://www.mds.mdh.se/~dal95acn/vicfiles/antiair.tap

It could even be used with mtap or some tap2wav converter for those who like to store their programs on audio tape. :P

Here is how you otherwise can load and run a PRG in the emulator:

1. Store the PRG somewhere you remember where
2. Turn off true drive emulation (Options -> True Drive Emulation)
3. Set directory (Settings -> Device settings -> Drive 8 -> Directory)
4. Load the program with LOAD"ANTIAIR.PRG",8
Anders Carlsson

Image Image Image Image Image
vic user
VicGyver
Posts: 1401
Joined: Thu Mar 25, 2004 9:40 am

Post by vic user »

Sweet!

I have not read any doucmentation for VICE, so only know things from trial and error, ...
or when I ask for help I guess :)

Chris
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

I think the documentation (as always when it is open source software) is very weak. The included documents are sometimes outdated or applies to a different platform than the one you have, and the website is slightly unstructured with a haystack bug- and knowledge base.

Maybe it is the price one has to pay for not paying, you get limited support and even documentation. Unfortunately, I'm a little like that myself, although I'm trying to point out the least self-explaining things. It was not long ago I installed Debian Linux at home and despite being experienced and have done it before swore a lot about how downright user hostile it still is in many respects.

Oh well, enough about that off-topic rant. Good luck with programming. Currently I'm too busy with other stuff so I doubt I will make another 20 line attempt soon.
Anders Carlsson

Image Image Image Image Image
vic user
VicGyver
Posts: 1401
Joined: Thu Mar 25, 2004 9:40 am

Post by vic user »

Good luck with programming. Currently I'm too busy with other stuff so I doubt I will make another 20 line attempt soon.
After all the talk about using the cassette buffer and the range of 673 to 767, I went nuts over the long weekend, and started restructuring a program I have been working on. I am now using the 8k range in block 5 to store data, and having a blast.

I don't know about you, but I find that I often program in binges. I will not do much for a while, and then I find I am typing away like a mad man, and jotting down notes, etc..

I would like to become more disciplined, and try and at least do 15 minutes of working on programs, every day.

That way, I won't start forgetting some things I am working on, and I am at least getting a little bit done, rather than none at all, and I am sure the 15 minutes will strecth out.

I also have to stop looking ahead too much, when working on a program. Sometimes I find myself thinking "This is going to take forever, and look at all the problems I have to solve to get this program to work", and then I get discouraged.

I find I am far more productive if I work on small parts of the program, perfect it, and then move on from there. Breaking down eveyrthing into little modules sort of thing.

Chris
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

vic user wrote:I would like to become more disciplined, and try and at least do 15 minutes of working on programs, every day.
Nah, then it almost turns into something you do for a living, although you don't make money out of it. Not even if I'm unemployed or retired, I think I would find the joy if I was working it every day.

I often think "tonight I have some time" or "today I feel motivated to do something", but unless there is a deadline or ongoing activity I have to participate in, I often "degrade" into playing around instead.

I also look ahead and discourage myself, both at work and privately. If I have other tasks to do, I can reschedule them and wait for a day when I have extra much inspiration. Although I'm not very religious or believe in astrology, I really have faith in biorhythms and the concept that the physical, intellectual and emotional capacities will flow in independent sinusoidal patterns over time. Some days I can feel that one ability is greater than another one, and almost wants to check with some biorhythm calculator to see if it agrees with me. :)
Anders Carlsson

Image Image Image Image Image
aneurysm
not your PAL
Posts: 178
Joined: Sat Mar 06, 2004 11:06 pm

Post by aneurysm »

good thing the VIC has biorhythms covered
vic user
VicGyver
Posts: 1401
Joined: Thu Mar 25, 2004 9:40 am

Post by vic user »

I don't know too much about biorhythms, but I can recall that I was far more productive in my studies at uni, when it was late at night. Not so good in the late morning early afternoon.

chris
Post Reply