Jump to content
IGNORED

Valentine's Day Programming Project


BoatofCar

Recommended Posts

I've never really written a "game" in Basic before, so this may be beyond the grasp of ten days, but I thought it might be kinda neat if I could write a little program for my wife for Valentine's Day. I'd like to have two characters at the bottom of the screen, a boy and a girl, set on a 2D plane. I'd like the joystick to control the boy's left-right movement. When the button is pressed, I'd like him to throw a flower to the girl and have her "catch" it.

 

I have no idea how to draw sprites (or if that's even the right parlance) but I feel like this is something that might be doable for me. What do you think?

Edited by BoatofCar
  • Like 1
Link to comment
Share on other sites

Well, assembly is how just about everything else is written. But if you're not already familiar with 6502, then even a simple project will be a killer.

 

For a really simple project that doesn't demand a lot of performance any BASIC could be adequate. (some versions of Basic more adequate than others.)

 

Mostly horizontal movement of players is easy enough in BASIC. Animation and vertical movement, a bit more difficult for Atari BASIC. A little easier for BASIC XL or TurboBASIC which have commands for this.

Link to comment
Share on other sites

10 days yes Atari BASIC go for it :thumbsup:

Use some graph paper or lego squares to do your graphics. 8x8 squares - use character graphics for your first project. Borrow a routine from one of my BASIC games if you wish - I used the same one on lots of my games http://gwobby.webs.com/

 

Have fun!

Link to comment
Share on other sites

If you download Kendallsoft Klassics Vol 1 http://www.freewebs.com/gwobby/morekendallsoftklassics.htm

don't get too excited now; and take a look at SkyHawk it might be a starting point. Takes ages to initialise so be patient!

post-19705-0-11167200-1391555315_thumb.png

Press reset after loading and you should be able to list the program - for once it has some comments and is not too complex:

 

The charset routine at 8000 shows the X,Z,Q... characters being changed to the eight bytes of data listed below each (I got this one from the game 'Briky' and used it for all my gr.1/2 games until I used fonts on Gorilla Warfare - I think). You can see in Sky Hawk the chopper is two chars next to each other.

 

The joystick stuff is at 100 and only 3 lines of code

:)

 

Perhaps not the most romantic game to use for an example :-D

Edited by therealbountybob
Link to comment
Share on other sites

...a little program for my wife for Valentine's Day. I'd like to have two characters at the bottom of the screen, a boy and a girl, set on a 2D plane. I'd like the joystick to control the boy's left-right movement. When the button is pressed, I'd like him to throw a flower to the girl and have her "catch" it. . . .

 

Here is something in straight ATARI BASIC.

100 REM HAPPY VALENTINE'S DAY GAME/DEMO
110 GOTO 380:REM GO INIT EVERYTHING
120 REM MOVEMENT AND LOGIC
130 HISX=HISX+ST2X(STICK(0))
140 IF HISX>200 THEN HISX=200
150 IF HISX<48 THEN HISX=48
160 HERX=HERX+ST2X(STICK(1))
170 IF HERX>200 THEN HERX=200
180 IF HERX<48 THEN HERX=48
190 IF FLOMV=0 AND STRIG(0)=0 THEN FLOMV=SGN(HERX-HISX)*3:FLOX=HISX
200 FLOX=FLOX+FLOMV:IF FLOMV=0 THEN FLOX=0
210 IF FLOMV<0 AND FLOX<=HERX THEN CATCHES=CATCHES+1:FLOMV=0:FLOX=0
220 IF FLOMV>0 AND FLOX>=HERX THEN CATCHES=CATCHES+1:FLOMV=0:FLOX=0
230 POKE 53248,HISX:POKE 53249,HERX:POKE 53250,FLOX
240 POKE 77,0:IF CATCHES<10 THEN GOTO 130: REM DISABLE ATTRACT MODE, THEM LOOP
250 REM THE END
260 TARGET=HISX-6:IF TARGET<48 THEN TARGET=HISX+6
270 IF HERX=TARGET THEN GOTO 290:REM MOVING HER TO HIM
280 HERX=HERX+SGN(TARGET-HERX):POKE 53249,HERX:GOTO 270
290 POKE 756,226:REM A LAME FONT TRICK
300 ? "         Happy Valentine's Day"
310 FOR OUT=1 TO 10
320 FOR I=48 TO 63 STEP 0.125:POKE 708,I:NEXT I
330 FOR I=63 TO 48 STEP -0.125:POKE 708,I:NEXT I
340 NEXT OUT
350 POKE 708,54
360 GOTO 360
370 REM INIT ALL THE STUFF
380 GRAPHICS 2
390 HISX=78:HERX=170:FLOX=0:FLOMV=0:CATCHES=0
400 FOR I=0 TO 27:POKE 53248+I,0:NEXT I:REM CLEAR COLORS, HPOS, ETC, IN GTIA.
410 POKE 710,198:REM "LAND"
420 POKE 709,14:REM MIGHT WANT TO READ TEXT
430 POKE 708,0:REM THERE'S A REASON FOR THIS, TRUST ME.
440 POKE 706,248:REM FLOWER
450 POKE 705,88:REM GIRL
460 POKE 704,136:REM BOY
470 REM SET PM GRAPHICS
480 PMPAGE=INT((PEEK(561)/8)-1)*8
490 POKE 54279,PMPAGE
500 PMMEM=PMPAGE*256
510 P0MEM=PMMEM+512
520 P1MEM=PMMEM+640
530 P2MEM=PMMEM+768
540 FOR I=0 TO 127
550 POKE P0MEM+I,0:POKE P1MEM+I,0:POKE P2MEM+I,0
560 NEXT I
570 POKE 53277,2:REM GTIA PLAYERS ON
580 POKE 559,42:REM ANTIC SCREEN, PLAYERS, 2 LINE P/M RESOLUTION
590 POKE 623,1:REM PRIORITY ALL P/M ON TOP
600 FOR I=0 TO 9:READ D:POKE P0MEM+86+I,D:NEXT I:REM HIM
610 DATA 24,24,0,60,90,24,0,24,24,60
620 FOR I=0 TO 9:READ D:POKE P1MEM+86+I,D:NEXT I:REM HER
630 DATA 24,24,0,60,90,24,60,126,24,60
640 FOR I=0 TO 5:READ D:POKE P2MEM+86+I,D:NEXT I:REM FLOWER
650 DATA 42,28,8,8,16,16
660 DIM ST2X(15):REM CONVERT STICK TO MOVEMENT
670 FOR I=0 TO 15:READ D:ST2X(I)=D:NEXT I
680 DATA 0,0,0,0,0,2,2,2
690 DATA 0,-2,-2,-2,0,0,0,0
700 GOTO 130

This is slapped this together, so is far from optimal. I tried to arrange it to make it more readable than efficient.

 

No animation. Player/missiles (aka sprites) are not animated. They only move horizontally. Even the thrown flower is just horizontal movement. Animating P/M graphics means adding something in assembly, or using some string magic to simulate assembly speed memory copy, or using a different BASIC altogether. (Which is why I use BASIC XL and not Atari BASIC most of the time.)

 

Both people are allowed to move on screen... The thrown flower should go to the girl character wherever she is, so escape for her is merely an illusion.

 

After 10 flower catches the "game" ends. There's a cheap effect done that capitalizes on the fact that in the second half of the ROM character set the heart character is in the same place as the blank space when using BASIC Mode 2 text (ANTIC modes 6 or 7).

  • Like 1
Link to comment
Share on other sites

New question! I made a few changes and got things just right, and now I'm struggling with getting the program into a format the MYIDE][ can read. I saved the program (along with DOS) as an ATR, but what I'd really like is to make it an XEX or ROM file. Is that difficult to do?

Link to comment
Share on other sites

It worked, kind of! For some reason the flower throwing thing didn't work--I pressed the button and the girl ran toward me and the hearts came up. Also, the hearts weren't "shiny." None of these upset me, but I was just curious as to why that would happen as a result of its compilation. 1200XL hardware?

Link to comment
Share on other sites

The movement and input code is designed around the much slower execution speed of BASIC and is not timer based. So, my guess is that since this is now compiled, it's running at near native machine language speed. So, when you press the button, the flowers are thrown as fast as they can move which is probably all 10 flowers in a fraction of a second, so it may not even be visible. Then the loop for the glowing hearts executes at ML speed, so it probably happens so fast the effect is over before you see it start.

Link to comment
Share on other sites

Here's a cheezy way to put a speed limit on the code. This resets the jiffy clock and waits a few ticks, so it should make the players and flowers work better....

234 POKE 20,0
236 IF  PEEK(20) < 2 THEN GOTO 236

Copy the same lines to 274 and 276 to slow down the loop for the girl running to the boy

274 POKE 20,0
276 IF  PEEK(20) < 2 THEN GOTO 276

In order to insert the delay in the color cycling loops for the glowing hearts the loops have to be split to put the delay inside the FOR/NEXT loop......

320 FOR I=48 TO 63 STEP 0.125:POKE 708,I
324 POKE 20,0
326 IF  PEEK(20) < 2 THEN GOTO 326
328 NEXT I

AND

330 FOR I=63 TO 48 STEP -0.125:POKE 708,I
334 POKE 20,0
336 IF  PEEK(20) < 2 THEN GOTO 336
338 NEXT I

Actually, you could do something more "efficient" like:

234 GOSUB 990
. . .
990 POKE 20,0
995 IF  PEEK(20) < 2 THEN GOTO 995
999 RETURN

So, then you only need to use the GOSUB wherever you want a delay in the code.

 

But that means you always get the same ( < 2 ) delay. So... you could use a "parameter" instead allowing you to tune the length of the pause where the subroutine is called.

234 JIFFIES=2:GOSUB 990
. . .
990 POKE 20,0
995 IF  PEEK(20) < JIFFIES THEN GOTO 995
999 RETURN
Link to comment
Share on other sites

Can I ask some more general questions about the code?

 

You've got it set as Graphics 2, but I thought that was a text only mode.

 

How did you draw the stick figures? I thought you had to PLOT them.

 

What does this line mean? 320 FOR I=48 TO 63 STEP 0.125:POKE 708,I:NEXT I

Link to comment
Share on other sites

Some links for reference: Everything you were afraid to ask about ANTIC/GTIA chips:

http://en.wikipedia.org/wiki/ANTIC

http://en.wikipedia.org/wiki/CTIA_and_GTIA

http://www.virtualdub.org/downloads/Altirra%20Hardware%20Reference%20Manual.pdf

 

 

Can I ask some more general questions about the code?

 

You've got it set as Graphics 2, but I thought that was a text only mode.

 

Graphics 2 is a text mode (that what the hearts are at the end of the demo -- graphics characters). The number "2" opens a screen with mode 2 text at the top, and 4 lines of mode 0 text at the bottom. The program uses the text window as "land" for the characters to walk on.

 

 

 

 

How did you draw the stick figures? I thought you had to PLOT them.

 

The people and the flower are Player/Missile graphics. A sprite-like color overlay.

 

 

 

This is the breakdown of all the P/M graphics parts....

 

This simply zeros out most of the hardware registers in GTIA. A bit toward overkill. The most important thing it does is make sure all Player/Missile object positions are set to 0, so there are no unwanted Players/Missile parts displayed onscreen with the 3 player objects that the program will control.

400 FOR I=0 TO 27:POKE 53248+I,0:NEXT I:REM CLEAR COLORS, HPOS, ETC, IN GTIA.

.

.

 

This sets values in the Operating System shadow registers for the colors of the Player objects...

440 POKE 706,248:REM FLOWER
450 POKE 705,88:REM GIRL
460 POKE 704,136:REM BOY

.

.

 

This code finds a place to put the memory for the P/M graphics. This starts at the high byte of the display list ( located at peek(561)), and works backwards to find the nearest aligned block of memory needed. This also incorrectly backs up 8 pages (or 2K of memory) when only 1K (4 pages) are needed for the double-line resolution Player/Missile mode.

470 REM SET PM GRAPHICS
480 PMPAGE=INT((PEEK(561)/8)-1)*8

.

.

 

This tells the ANTIC chip where the Player/Missile memory starts (the first page)...

490 POKE 54279,PMPAGE

.

.

 

This calculates the real memory location... pages * 256

500 PMMEM=PMPAGE*256

.

.

 

Now that we know where the Player/Missile memory is located, identify the starting memory location for each individual object. Player 0 is the boy. Player 1 is the girl. Player 2 is the flower.

510 P0MEM=PMMEM+512
520 P1MEM=PMMEM+640
530 P2MEM=PMMEM+768

.

.

 

This clears out (zeros) the memory for each object. 128 bytes each...

540 FOR I=0 TO 127
550 POKE P0MEM+I,0:POKE P1MEM+I,0:POKE P2MEM+I,0
560 NEXT I

.

.

 

This is the control information for enabling Player/Missile display...

53277 is GRACTL on GTIA. The Bit value 2 enables GTIA to accept Player data from ANTIC.

570 POKE 53277,2:REM GTIA PLAYERS ON

.

.

 

559 is the Operating system shadow register for ANTIC's DMA control register. The value 42 tells ANTIC that Playfield DMA is enabled (32) + Player DMA is enabled ( 8 ) + normal screen width (2).

580 POKE 559,42:REM ANTIC SCREEN, PLAYERS, 2 LINE P/M RESOLUTION

.

.

 

This is the Operating System shadow register for GTIA's priority control. Bit value 1 puts all Player/Missile graphics on top of all Playfield graphics,

590 POKE 623,1:REM PRIORITY ALL P/M ON TOP

.

.

 

The next piece of code inserts shapes into the Players' memory which is read from DATA statements...

600 FOR I=0 TO 9:READ D:POKE P0MEM+86+I,D:NEXT I:REM HIM
610 DATA 24,24,0,60,90,24,0,24,24,60

.

The shape data is:

...##... == 24
...##... == 24
........ == 0
..####.. == 60
.#.##.#. == 90
...##... == 24
........ == 0
...##... == 24
...##... == 24
..####.. == 60

The same thing is done for the girl and the flower.

.

.

 

All the Player object movement during the game occurs here. This updates the horizontal position of the Player objects based on joystick input, or calculated position of the flower...

230 POKE 53248,HISX:POKE 53249,HERX:POKE 53250,FLOX

and next:

 

What does this line mean? 320 FOR I=48 TO 63 STEP 0.125:POKE 708,I:NEXT I

 

This loops through a series of values (from 48 to 63 in steps of 0.125) and stores those values in the operating system shadow register of the playfield color corresponding to the Mode 2 text character of the hearts on screen.

48 is the darkest red possible.

63 is the brightest red (nearly white)

So, this ramps up the "shininess" of the hearts from dull to bright. The other loop ramps the brightness down in the other direction from 63 to 48.

This could have been done with SETCOLOR instead of POKE... But, having learned assembly and how the bells and whistles in the Atari really work, I just prefer using POKE.

  • Like 2
Link to comment
Share on other sites

Thank you! Most of that makes sense, although some of it is still over my head.

 

As someone who is not a programmer but is interested in putting together little programs like this just for fun, do you think it is wise for me to learn BASIC first and then move on to Assembler, or just skip BASIC altogether?

Link to comment
Share on other sites

Would it be possible to write the above program in BASIC alone? I realize it would probably be longer and more complicated....

 

What program? Ultra Donkey Kong 2014? Anything is possible, but so many compromises would have to be made and corners would be cut that it would probably have a very high suckage factor.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...