Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Looking for ASM tutorials

Reply to topic
Author Message
  • Joined: 08 Sep 2018
  • Posts: 270
Reply with quote
Looking for ASM tutorials
Post Posted: Mon Oct 07, 2019 4:01 pm
Are there any good z80 ASM tutorials for writing NPC and Enemy movement behavior for top down games(like zelda)? I've been stuck trying to make mine a bit more robust but have to admit its very lacking and a tutorial with a more optimal way of writing that code would be very helpful.

Also if you have any tips on sprite management when theyre on and off screen id love to hear it!
  View user's profile Send private message
  • Joined: 06 Apr 2011
  • Posts: 250
  • Location: Netherlands
Reply with quote
Post Posted: Mon Oct 07, 2019 8:34 pm
I learned to program NPCs from a friend,

I use finite state machines to script NPC. So the drone NPC (in DARC) is scripted as follows:

drone type definition:
; NPC Type list
; (sequential list)
; NPC Type record (4 bytes):
;   - HP
;   - Damage
;   - type flags
;   - exp drop
;
; type flags:
;   [A |V |1 |T | B| E| S| S]
; 0111001b
;         1  = always set to indicate active npc
;         A  = animated (yes/no)
;         V  = Sprite Visible (yes/no)
;         T  = Calculate tileindex? (for non moving npc)
;         B  = bullet collision test
;         E  = can this enemy be shot at all times? E.g. for arena doors
;         S  = Size (8*16 or 16*16)

   db   6, 2,01101100b, 1      ; type 10 - basic drone



The labels (FSM10_sX) are the states the NPC has.
In each state the events (E_xxxx labels) are tested. These are ASM routines.
If an event is true the following state is set and the action (A_xxxx) is triggered. These actions are also assembly routnies. Soem take an extra parameter,

Also each state has an animation pointer (sprite number sequence and collision window).

;===================
;--- BASIC DRONE
;   -set timer
;   -timer == 0 then calculate movement
;
;===================
FSM10_s0:
FSM10_s1:
   dw   ANI10_s1      
   dw   E_DEFAULT,   FSM10_s5,   A_SETTIMER
   db   16   
FSM10_s2:
   dw   ANI10_s2   
   dw   E_DEFAULT,   FSM10_s6,   A_SETTIMER
   db   16   
FSM10_s3:   
   dw   ANI10_s1
   dw   E_DEFAULT,   FSM10_s1,   A_AIM_DRONE
   db   0
FSM10_s4:   
   dw   ANI10_s2
   dw   E_DEFAULT,   FSM10_s2,   A_AIM_DRONE
   db   0   
FSM10_s5:
   dw   ANI10_s1
   dw   E_HPEMPTY,   FSM01_s0,   A_EXPLODE
   db   0   
   dw   E_TIMEREND,   FSM10_s3,   A_NOP
   db   0
   dw   E_MC_LEFT,   FSM10_s6,   A_NOP
   db   0   
   dw   E_DEFAULT,   NO_CHANGE,   A_TIMERDEC
   db   0
FSM10_s6:
   dw   ANI10_s2
   dw   E_HPEMPTY,   FSM01_s0,   A_EXPLODE
   db   0
   dw   E_TIMEREND,   FSM10_s4,   A_NOP
   db   0
   dw   E_MC_RIGHT,   FSM10_s5,   A_NOP
   db   0   
   dw   E_DEFAULT,   NO_CHANGE,   A_TIMERDEC
   db   0


This approach limits the number of actions an NPC can do (only 1) but this also results in less cpu time.and NPC are easier to read and create.

Not sure if this helps. Or makes sense
  View user's profile Send private message
  • Joined: 08 Sep 2018
  • Posts: 270
Reply with quote
Post Posted: Mon Oct 07, 2019 10:39 pm
Zipper wrote
I learned to program NPCs from a friend,

I use finite state machines to script NPC. So the drone NPC (in DARC) is scripted as follows:

...


It does help quite a bit and it actually! Ill have to play around with this info and see what I can add to it. There isnt a lot going on within my game without moving NPCs so I have quite a bit of room in terms of cycles to add all sorts of things. Of course ill have monsters "deactivate" when off screen and just stand still rather than wasting cycles so things like the active npc bit is a nice helpful touch.

Hopefully others will have some good examples of their own to add. Im going to keep scouring the web for anything helpful i can find.
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!