A downloadable game

[WAVE INVADERS] ---------------------------------------------------------------

BY LUIS PIERI

[COMPO] -----------------------------------------------------------------------

CATEGORY  : PUR-120

LINK      : https://lupoman.itch.io/Wave_Invaders

         

DATE      : 04-FEB-2025 TO 25-MAR-2025

COMPO     : BASIC 10 LINER CONTEST

            https://gkanold.wixsite.com/homeputerium/rules2025

DEADLINE  : April 5th, 2025


[IDEA] ------------------------------------------------------------------------

You control a space turret and fire shots to destroy the waves of space invaders that are advancing to the capitol city!

If one invader can go pass your left side its game over!

Use O and P keys to control the turret, autofire is enabled.

The scroll effect is created changing only the attributes with

LPRINT Hack! (redirecting LPRINT TO attrib RAM from

https://blog.jafma.net/2020/08/29/efficient-basic-coding-for-the-zx-spectrum-v/#en_5)


[FILES] -----------------------------------------------------------------------

In the ZIP file you will find:

- Wave_invaders.tap : the basic program to be loaded in the ZX Spectrum or in a

                      emulator (see help section)

- Wave_invaders.jpg : Screenshot of the game

- Wave_invaders.gif : An animated gif to show the gameplay

- Wave_invaders.bas : The version to be converted into .TAP developed in a modern 

                      computer, much easier to work with and the converted with

                      ZMakeBas (http://freestuff.grok.co.uk/zxtext2p/index.html)

- pur120proof.txt   : A text file with the zx basic dump to calculate properly

                      the length of each line (taking into account token and automatic spaces)      

- wave_invaders.txt : This file.  

                  


[CODE EXPLANATION] ------------------------------------------------------------

  - The code below is formated to be converted with the utility ZMakeBas.

  - Once converted the lines are much shorter in the ZX Basic.

  - You can see the final listing opening the .TAP file on the emulator.

  - Use Boolean expressions directly to the vars in order to save Ifs

  - Use calculated ATTRIB RAM positions to save calculation time

  - The speed is achived avoiding printing graphics, in the main loop we only

    update the attributes (ink and paper), the UDG are printed at the start only.

    To erase a invader we only need to put attrib to 0 (black ink with black paper).

  - ZX Spectrum attrib memory starts at 22528 to 22528+768  (23296)

  - The first UDG char is 144 = UDG "A"

  - The Invaders have 4 bands with different colours, all bright on, paper black.

  - So in total we need 9 UDGS (1 ship, 1 shot, 2xinvader and 5 for invaders formation)

  - Formation: 4 invaders, 3 invaders, 2 invaders, 1 invader, 0 invaders:

    the invaders could be 5 different stacks formations (UDGs):

     ..E.F.G.H.I..

     ..*..........

     ..*.*........

     ..*.*.*......

     ..*.*.*.*....

  - When the player shot collides with invaders, it moves up one char in the pos in S$

  - Also the attrib pos of the shot is poked with red paper and ink, and shot is reset


# LINE 1 ----------------------------------------------------------------------========================================

# Load the UDG data, set the colors and border, print the name of the game

# Init Var E as 23008 to speed up

#

1 RANDOMIZE:                                           (Seed for RND)

  RESTORE 9:                                           (Reset data to read)

  FOR F=0TO71:READ A:POKE USR"a"+F,A+(F>31)*64:NEXT F: (Read and set all the User Defined Graphics)

  BRIGHT 1:PAPER 0:INK 4:BORDER 0:CLS:                 (Set the color and clear screen)

  PRINT"WAVE INVADERS":PRINT:PRINT"by L.PIERI":        (Print the title)

  LET E=23008:LET H=0                                  (Init address var and hiscore var)


# LINE 2 ----------------------------------------------------------------------========================================

# Init vars

# Var Y: Ship attrib location in RAM

# Var X: Old Y

# Var M: Shot attrib location in RAM

# Var E: Value 23008

# Var S: Score

# Var H: Hiscore

# Var C: for animation

# Var I: Holds Attrib to string pos conversion

#                                                                                                          

2 PRINT AT 5,0;"HI:";H:    (Print the current hiscore)

  LET Y=23184:             (Init the Position of the player in Attr RAM)

  LET M=Y-32:              (Init the missile position in Attr RAM relative to player)

  LET S=0:LET C=0:         (Init score var and animation var)

  LET S$="\i\i\i\i\i\i\i\i\i\i\i\i\i\i\i\i\i\i\h\i\i\i\i\g\h\i\i\i\i\f\i\i\i\h\g\i\i\i\e\i\i\g\i\i\i" 

  (Initial level design, each UDG char is converted to a strip of attrib data using the LPrint hack)


# LINE 3 ----------------------------------------------------------------------========================================

# PRINT BACKGROUND

# 4 rows of alternating invaders

# 4 rows of missiles

# 1 row of ship

#                                                                                                      

3 PRINT AT 7,0;"1P:0    ":                       (Print initial score)

  FOR G=12 TO 15:FOR F=0 TO 15:                  (Print all the UDG chars beforehand)

  PRINT AT G,F*2;"\c\d";                         (Print alternating Invaders to simulate animation)

        AT G+4,F*2;"\{16}\{00}\b\b";             (Print the missile strips)

        AT 20,F*2;"\{16}\{00}\a\a";              (Print player ship strip)

        AT 21,F*2;"\{17}\{04}\{19}\{00}\..\..":  (Print the base strip)

  NEXT F:NEXT G


# LINE 4 MAIN LOOP START ----------------------------------------------------------------------========================

# Pointer the LPRINT to the Attrib RAM (LPrint Hack)

# Move scroll left aliens stacks every other time

# Check for need to add another random section

#

4 POKE 23680,0:POKE 23681,89:                        (Poke to redirect Lprint to print in Attributes RAM)

  LET S$=S$(INT(C)+1TO):                             (Scroll the invaders stacks when animation var C=1)

  IF LEN S$<34 THEN LET S$=S$+"\i"+"\i"+"\i"+CHR$ R  (If there's less than 34 chars in level add random invaders wave)


# LINE 5 ----------------------------------------------------------------------========================================

# Alien Waves print section (we don't really print anything, just change attributes)

# Using the LPRINT attr hack (89*256 = 22784), to print a string to ATTR RAM in the ZX Spectrum

# The stacks of invaders are already printed in all the columns, and the scroll effect is created

# moving only the attrib (scrolling left)

# Using this line also for update anim var 

# Check if an alien move past left border of screen

5 LPRINT S$(TO32):                                   (Print the attrib to show the stacks of invaders)

  LET C=(C+0.25)*(C<1):                              (Update anim vars, 1/4 of ship or missile speed)

  IF S$(1)<"\i" THEN                                 (Check for Game Over, if an invader is into the left most)

    BORDER 2:PRINT AT 10,11;"\{16}\{06}GAME OVER":   (Print Game Over)

    BEEP 1.5,-50:BORDER 0:                           (Do end sound and change border back to normal)

    LET H=H+(S-H)*(S>H):                             (Calculate Hiscore, Hiscore + (Score-Hiscore) only if Score is higher)

    GO TO 2                                          (Restart game)


# LINE 6 ----------------------------------------------------------------------========================================

# Read last key pressed, reset lastkey, calculate random stack of aliens, move ship

# before o$=INKEYS$  o chr(PEEK 23560)

#

6 LET O=PEEK 23560:POKE 23560,0:                   (Read last key pressed and reset it)

  LET R=148+RND*4:                                 (Calculate a random alien stack/Wave)

  LET X=Y:                                         (save old player pos)

  LET Y=Y-(O=111 AND Y>23168)+(O=112 AND Y<23199)  (Check for O or P keys to move ship)


# LINE 7 ----------------------------------------------------------------------========================================

# "print" ship and missile(we dont really print anything, just change attrib col to show the UDG beneath)

# also calculate missile pos in string, only delete ship if moved, only delete missile if its above ship

7 POKE Y,68:                 (Show the player in pos Y, changing the attrib value)

  POKE M+(M<23136)*32,0:     (Delete Missile in pos M, changing attrib value only if in second row or above, to minimize flicker)

  POKE M,68+(M<23040)*14:    (Show Missile in pos M, changing attrib value)

  LET I=M-E+1:               (Convert the missile attrib pos in string position to check collision later)

  LET M=M-32:                (Move missile one row up)

  IF X<>Y THEN POKE X,0      (Only delete player previous position if moved, to avoid flicker)


# LINE 8 ----------------------------------------------------------------------========================================

# Check if missile hit an alien, cascade the upper aliens, update score, make sound

#

8 IF M<E THEN LET M=Y-32:            (Check if missile reached first row of invaders)

    IF S$(I)<>"\i" THEN              (Check if there's one or more invaders)

      LET S=S+CODE S$(I)-147:        (Calculate score depending of invader color) 

      PRINT AT 7,0;"1P:";S:          (Update the score in the screen)

      LET S$(I)=CHR$(CODE S$(I)+1):  (Substract one invaders of the stack, just move to the next UDG)

      BEEP .05,-40+I/2               (Boom sound)


# LINE 9 ----------------------------------------------------------------------========================================

# End of loop

# UDG DATA USR "A" Ship, "B" Missile, "C" & "D" for invader

#  for saving chars, make all data = data-64 and in the poke add 64

#

9 GO TO 4:  (Return to the start of main loop)

  DATA 24,24,60,126,126,126,126,126,0,24,16,8,16,8,24,0,124,254,186,214,254,40,198,0,124,254,254,146,254,108,40,0

  (UDG data for ship, missile and invaders)


# LINE 10 ---------------------------------------------------------------------========================================

# UDG DATA USR "E", "F", "G", "H", "I" for 5 invaders segments:

# udg data sectors

#

10 DATA 0,0,0,0,1,2,3,5,0,0,0,0,0,1,2,3,0,0,0,0,0,0,1,2,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0

   (UDG data for Invaders stacks, colors, the 64 are added in the read loop to save chars)

# invaders   : 64 + 0 + 1 (bright+ink blue+paper black)

#              64 + 0 + 6 (bright+ink cyan+paper black)

#              64 + 0 + 3 (bright+ink red+paper black)

#              64 + 0 + 4 (bright+ink magenta+paper black)

# ship is    : 64 + 0 + 5 (bright+ink green+paper black)

# shot is    : 64 + 0 + 5 (bright+ink green+paper black)

[END] -------------------------------------------------------------------------

Download

Download
pur120proof.txt 8.9 kB
Download
wave_invaders.bas 9.7 kB
Download
wave_invaders.tap 1.7 kB
Download
wave_invaders.txt 11 kB

Install instructions

[HELP] ------------------------------------------------------------------------

  - Open your favarite zx spectrum emulator

  - Menu File -> Open Tape -> Select wave_invaders.tap

  - The LOAD command will appear automcatically if not type L (LOAD Command) 

    and shift-p twice. 

  - Wait until "0/0" appears.

  - If you press Enter key the listing will appear.

  - Press R for RUN command and then enter.

  - The game starts automatically, you can control your ship with 'O' and 'P',

    autofire is enabled, so you dont have to worry to fire missiles.

  - Destroy the waves of aliens before their reach the left of the screen.

  - Above the playfield, you will see the score and hiscore.

Comments

Log in with itch.io to leave a comment.

very good