Friday, 27 December 2019

Enemy Movement

After coding some (very) simple enemy movement patterns for the Freeze64 Xmas Demo a couple of weeks ago, I finally decided to get down to coding the *actual* enemy paths for the game.

This actually began on Christmas Day (who else was coding then??!) when I finally got round to noting down the locations in hex of the enemy sprites in the sprite bank.  This was done using good old fashioned pen and paper while sat in my comfy reclining chair, sipping a nice red Tempranillo!  Here's what my scrappy notes looked like:




Once these hex locations were noted, I got to thinking what information was needed to set up, display and move an enemy sprite.  Obviously, a sprite 'x' and 'y' screen location was needed, but I also need to know colours, the default (start) sprite definition, animation start/end definitions, sprite direction and speed and finally the maximum and minimum screen locations travelled to by the sprite enemy.  To keep things simple, sprites in this game move in straight line paths for now!  The set-up table for level 1 ended up looking like this...

 l1_sprite_x       !byte $19,$20,$4c,$94,$90,$6f,$5a,$0d  
 l1_sprite_y       !byte $cd,$9e,$4f,$a4,$cd,$a8,$54,$85  
 l1_sprite_col     !byte $0a,$07,$0c,$05,$0c,$0c,$0c,$0c  
 l1_sprite_def     !byte $ab,$bf,$ee,$ec,$cf,$c7,$d3,$e8  
 l1_sprite_anims   !byte $ab,$bf,$ee,$ec,$cf,$c7,$d3,$e8  
 l1_sprite_anime   !byte $ac,$c0,$f0,$ee,$d3,$cb,$d7,$eb  
 l1_sprite_dir     !byte $00,$00,$00,$01,$01,$01,$00,$00  
 l1_sprite_spd     !byte $00,$00,$01,$02,$01,$01,$01,$01  
 l1_sprite_min     !byte $00,$00,$53,$53,$19,$5a,$5a,$0d  
 l1_sprite_max     !byte $00,$00,$b8,$a7,$90,$85,$85,$3a  

At first, I was going to have a separate bit of code to handle each enemy, but once I realised that the enemies only move up/down or left/right, I realised I could handle the sprites in a single loop; well two loops actually, one handling vertical movement and the other horizontal. This could be rationalised further into one loop by having another table setting whether each enemy is vertical or horizontal moving, but since the code would be roughly the same, with skips in the loop to handle vertical/horizontal, I decided to keep it simple and have two loops - hopefully this will be easier to read and remember for the future.

I did need to create some more tables holding the sprite animation definitions for each enemy when moving left or right, but I was now ready for some code.  It ended up looking a little like this (note, this is for the horizontally moving enemies only):


; now deal with the horizontal moving enemies  
; zombie, ghost, bat, witch (sprites 4 - 7)            
                       
 enemy_hori_check  
           lda sprite_dir,x  
           cmp #$01  
           beq enemy_hori1  
             
           lda sprite_x,x  
           clc  
           adc sprite_spd,x  
           sta sprite_x,x  
           cmp sprite_max,x  
           bcc next_hori_enemy  
           lda #$01  
           sta sprite_dir,x  
           lda left_enm_def,x  
           sta sprite_def,x  
           sta sprite_anims,x  
           lda left_enm_anime,x  
           sta sprite_anime,x  
           jmp next_hori_enemy  
   
 enemy_hori1  
           lda sprite_x,x  
           sec  
           sbc sprite_spd,x  
           sta sprite_x,x            
           cmp sprite_min,x  
           bcs next_hori_enemy  
           lda #$00  
           sta sprite_dir,x  
           lda rite_enm_def,x  
           sta sprite_def,x  
           sta sprite_anims,x  
           lda rite_enm_anime,x  
           sta sprite_anime,x            
             
 next_hori_enemy  
           inx  
           cpx #$08  
           bne enemy_hori_check
 

Basically all that's happening is the code first checks which direction the sprite should be moving (in my game '0' means down or right and '1' means up or left) and then adds or subtracts from the sprites 'x' position on the screen.  The addition or subtraction can be altered, thus altering the 'speed' of the sprite, by changing the values in the 'speed_spd' table, which the code references in the loop.

Also referenced is each enemies 'max' and 'min' values which determines the end point of the movement path on screen.  Once the max or min is reached, the code switches the 'sprite_dir' so the sprite moves the other way, along with the animation definitions for that direction.

The code for vertical movement is almost identical, save for the sprites 'y' screen value is altered instead.

Once this code is called in the game and the set-up table for level 1 referenced, the enemies ended up doing this (and believe it or not it worked first time!):


I'd call that a successful couple of days and a Merry Christmas indeed!

Next diary entry...

Thursday, 26 December 2019

Xmas Demo Released

The Xmas demo was emailed to Freeze64 subscribers on Christmas Eve, so I guess it's fine to post this here now, doubly so since it has appeared in 'cracked' from on CSDb!




If you would like to play the demo, you can download it here...

If you want to play a 'cracked' version by TRIAD, with some built-in cheats, you can grab that from CSDb here...

Next diary entry...

Thursday, 19 December 2019

Xmas Demo Complete

Since the last entry, I've been working on a couple of entries for the 'Intro Creation Competition' over at CSDb (see here and here), so work on the Chiller 2 Xmas demo for Freeze64 came to a bit of a standstill.

To make up for this, the last few days have been spent preparing the demo for Vinny.  All that really needed doing was working out some coordinate locations for the cross to move to once collected.  I ended up doing this in work on a printed screen grab of the demo level.  The photo below shows the scrappy piece of paper with the screen coordinates on!


As an afterthought and in the sprit of making things extra Christmassy, I edited the charset to include some holly for the title screen and a snowman for the demo level.  Those look a little like this...



Also, in last post I apologised for the short, repetitive music.  Gone!  I've written a short piece of music especially for this Xmas demo based on 'God Rest You Merry, Gentlemen', also know as 'Tidings of Comfort and Joy'.  I did try to make it sound 'scary' in keeping with the game theme; hey, it was the best I could do in the short time I had!

In not wanting to give away too much of the game early on, I've taken the decision to only include 1 enemy type, the ghost which moves along very simple paths.  All other enemy sprites have been removed from the sprite bank!  I've also only included the boy as a playable character along with removing some 'dangerous' scenery.  I've taken the liberty of adding a simple demo complete message as well, should you collect all 20 crosses.

The demo has been tested on a real C64c, with the game engine holding up quite well in the demo.  It appears I have learned how to code 6502 to some extent this year!

Vinny should be emailing out a special subscribers only 16 page Freeze64 email issue on Christmas Eve, with the Chiller 2 demo attached!  The announcement for this can be found on Twitter here...

Next diary entry...