Invader

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
at67
Posts: 193
Joined: 14 May 2018, 08:29

Invader

Post by at67 » 09 Jul 2020, 03:54

It runs on ROMv3 or above, latest .gt1 file is attached:
Invader.gt1
(11.56 KiB) Downloaded 71 times
Link to video:
https://www.youtube.com/watch?v=VK8WBsOlMFM

- Runs on ROMv3 or higher.
- Will have authentic AI modeled after the original when it is complete.
- There are 50 invaders instead of 55.
- The invaders are 1 to 2 pixels thinner than the original.
- The invaders are stacked closer together both horizontally and vertically due to limitations in Gigatron pixel real estate, (this makes the game somewhat easier).
- The code follows the original when drawing the invaders, i.e. one invader per 60Hz frame drawn from left to right, bottom to top.
- Collision detection is performed trivially as a screen-space to invader array space transformation, rather than cycling through every invader and testing against the player bullet, (bounding boxes/circles, pixel reading, etc).
- Collision detection is even faster than partition space algorithms or divide and conquer techniques, but suffers from the slight disadvantage that the mapping process doesn't take into account invaders with slightly smaller sizes, (such as the top row). So that hits can be registered when in fact the player bullet was missing by one pixel either side, (this makes the game somewhat easier).
- Uses many tricks to save every single byte and vCPU cycle possible, but there are many more opportunities to squeeze out more bytes and cycles.
- Uses embedded ASM code within the BASIC code to draw the bullets and damage the barriers.
- The main loop always runs at 60Hz in screen mode 2 until there are around 4 invaders left, then the frame rate starts to drop as the main loop wastes more and more time checking empty invaders slots in the invader data structure.
- The solution to the tanking frame rate is to traverse an ever decreasing linked list, instead of traversing a constant sized 2D array.

Here is an example of how the player bullet is drawn using embedded ASM code, it's trivial to use vCPU code within gtBASIC and access variables, subs/procs/labels, etc.

Code: Select all

proc drawPlayerBullet
    'no bullets while invader is asploding
    if &(ixy) then return
    
    'no bullet so exit
    if &(pbullet.hi = 0) then return

    asm 'setup SYS function
        LDWI    SYS_VDrawBits_134
        STW     giga_sysFn
    endasm

    if peek(pbxy + &h0000) &&= &h0C
        pbullet.lo = 0
        
        gosub smashBarrier
    endif

    asm 'setup SYS params
        LDWI    0x3F00
        STW     giga_sysArg0
        LDW     _pbxy
        STW     giga_sysArg4        
    endasm

    if &(pbullet.lo)
        asm 'draw bullet
            LDI     0xF8
            ST      giga_sysArg2
            SYS     134
        endasm
        
        pbxy.hi = pbxy.hi - 2
        if pbxy.hi &&< 8
            pbullet = 0
            
            asm 'erase bullet if top of screen
                LDI     0x00
                ST      giga_sysArg2
                SYS     134
            endasm
        endif
        return
    endif
    
    asm 'erase bullet if pbullet.lo = 0
        LDI     0x00
        ST      giga_sysArg2
        SYS     134
    endasm
    
    pbullet = 0
endproc
Last edited by at67 on 17 Jul 2020, 08:05, edited 3 times in total.

walter
Site Admin
Posts: 87
Joined: 13 May 2018, 08:00

Re: Invader

Post by walter » 09 Jul 2020, 06:23

It's impressive how you are able to create this is so little time.

at67
Posts: 193
Joined: 14 May 2018, 08:29

Re: Invader

Post by at67 » 11 Jul 2020, 11:46

It's a lot fun in the initial stages, pixel fu...dging, and prototyping the basic functionality usually only takes a few hours; but then all the little details start to stack up and 20 hours have come and gone.

Here's the latest video:
https://www.youtube.com/watch?v=RslPzHFAG1Y

Almost finished, just requires the following:

Code: Select all

- The Saucer.
- Sound effects.
- Tuning of the Invader bullets.
- Increasing difficulty based on the player's score, (like the original).
- A menu with options to change/toggle auto-fire, starting difficulty, player bullet speed, etc.
- The main loop always runs at 60Hz in screen modes 1, 2 and 3.
- A doubly linked list was indeed the solution to the tanking frame-rate problem.
- Invader bullets can be increased up to 15 before the frame-rate begins to dip below 60Hz, (15 invader bullets is basically rain and impossible to dodge).
- A glitch with player bullet erasing when an Invader is exploding.
- A glitch causing phantom bullet to bullet explosions.

walter
Site Admin
Posts: 87
Joined: 13 May 2018, 08:00

Re: Invader

Post by walter » 11 Jul 2020, 13:18

It's looking great. Is there info about how the algorithm works to be found on the internet, or did you have to recreate it just by looking at it?

at67
Posts: 193
Joined: 14 May 2018, 08:29

Re: Invader

Post by at67 » 12 Jul 2020, 02:27

I used these two references for understanding the mechanics of the scoring system, bullet delays and overall timing of each of the functional modules.

https://www.classicgaming.cc/classics/s ... play-guide
http://www.computerarcheology.com/Arcade/SpaceInvaders/

But I mostly studied the 0.25 playback option in YouTube videos of the original game play and rendered my own Gigatron interpreted version.

The most impressive thing about the original Space Invaders, (apart from being the world's first arcade hit, running on such limited hardware and being a cracking game to play), is the fact that they managed to keep the entire thing running at a constant 60Hz, smooth, stable and flicker free.

walter
Site Admin
Posts: 87
Joined: 13 May 2018, 08:00

Re: Invader

Post by walter » 12 Jul 2020, 08:19

Those games came out in a time where people had to put effort into writing very lean code, possibly using some dirty tricks as well. It's funny to see that the Gigatron requires you to take on that mindset again.

I did not know this was really the first blockbuster arcade game. When I spent time in the Arcade a long time ago, I can't remember playing it. I was hooked to Asteroids, with its vector graphics. It came out 1 year after Invader. I have one that is still going strong:
ASTEROIDS.gif
ASTEROIDS.gif (467.01 KiB) Viewed 1651 times

blaknite
Posts: 22
Joined: 18 Jun 2020, 01:10
Contact:

Re: Invader

Post by blaknite » 13 Jul 2020, 02:27

This looks great! I'm really keen to give it a go when it's finished. I'm also super impressed by how quickly it's coming together. Awesome!

at67
Posts: 193
Joined: 14 May 2018, 08:29

Re: Invader

Post by at67 » 13 Jul 2020, 03:39

It's almost done, saucer and saucer scoring mechanics are in, difficulty balancing is in, invader bullet tuning is in, plus lots of little bug fixes.

TODO:
- Sound effects.
- Level 100 easter egg.

at67
Posts: 193
Joined: 14 May 2018, 08:29

Re: Invader

Post by at67 » 13 Jul 2020, 03:43

walter wrote:
12 Jul 2020, 08:19
Those games came out in a time where people had to put effort into writing very lean code, possibly using some dirty tricks as well. It's funny to see that the Gigatron requires you to take on that mindset again.
This! This is exactly it and I personally think that we have only witnessed the tip of the iceberg with what the Gigatron is truly capable of.
walter wrote:
12 Jul 2020, 08:19
I have one that is still going strong:
I am oh so super jealous.

at67
Posts: 193
Joined: 14 May 2018, 08:29

Re: Invader

Post by at67 » 15 Jul 2020, 13:27

Final update:

*Edit* moved .gt1 file and video link to first post.

Code: Select all

- Sound effects, game-play, balancing, levels/difficulty, saucer and Easter Egg are in.
- Runs on ROMv3 or higher.
- Runs at 60Hz in mode 2 100% of the time.
- Replicates the Saucer scoring system except for the bug in the original code that only accesses 15 out of the 16
score values within the saucer score table.
- So instead of counting 8, then 14, (15th shot hits saucer), you count 8 then 15 and 16th shot hits saucer for your
fat 300 bonus points, (as was originally intended by the developers), and then 15 recurring until the next level.
- Rarely invaders will shoot through their buddies because they think they have a clear shot, I'm not going to fix this
bug as that part of the code is small and efficient and will balloon out with IF statements for an obscure corner case.
- Player's missile always goes through invader missiles, (unlike the original which had 3 missile types with varying
defence capabilities).
- Player missile to invader missile collisions will only cause missile to missile explosions for the first collision,
subsequent collisions, (for that same player missile), don't get their own collision animation, (it's also fairly rare).
- You can shoot the pixels that make up the saucer bonus score animation if you are quick enough.
- The audio was the most difficult part of this project by far, trying to programmatically match the original
synthesised effects with the limited capabilities of the Gigatron's audio was challenging to say the least;
I accomplished this feat with varying degrees of success.
- You can fall victim to stray bullet syndrome after clearing a wave.
- There is approximately 2Kbytes of RAM available, so I added some bonus animations and audio as well as the
Easter Egg if you can get to level 100, (good luck without cheating).
Last edited by at67 on 17 Jul 2020, 08:03, edited 2 times in total.

Post Reply