Managed to limit the Player projectiles: 2 bullets at a time, to avoid slowdowns or flickering (when to much game objects) when the player shoots like a maniac!
The technique is to declare a variable "limitProjectile" to be the limit (the number of bullets being at the same time on screen). Each time, a projectile is created, the variable is decreased. If the variable is equal to "0", it means already 2 bullets created, the creating object code of the script is skipped.
When the bullet is destroyed (on edge/solid with "Destroy Me" or on a Monsters collision), the variable is increased.
Scripts:
In the "SystemVariable.asm" script, I declared a "limitProjectile" variable:
In the "InitLoads.asm" script, I initialize the variable (number of bullets at a time):
Then I modified the "CreateSimpleProjectileWithMotion.asm" script to check that variable:
I modified the "HandleObjectCollisions.asm" script (around line 362):
I wanted to modify the "Reaction_02.asm" script (in "Routines\System\AI_Reactions" folder) that correspond to the "Destroy Me" in the Object Details solid/edge reactions, but did have succes checking the objct type (the code is needed only for player weapon).
So I made modified the unused "Reaction_03.asm" script:
And in "Project Labels", I rename it to "Destoy Me (Player Weapon)", reassign this reaction to my Melee/projectile object.
Voilà. It should work (2 bullets at a time)
The technique is to declare a variable "limitProjectile" to be the limit (the number of bullets being at the same time on screen). Each time, a projectile is created, the variable is decreased. If the variable is equal to "0", it means already 2 bullets created, the creating object code of the script is skipped.
When the bullet is destroyed (on edge/solid with "Destroy Me" or on a Monsters collision), the variable is increased.
Scripts:
In the "SystemVariable.asm" script, I declared a "limitProjectile" variable:
Code:
limitProjectile .dsb 1 ;; to limit the projectiles
In the "InitLoads.asm" script, I initialize the variable (number of bullets at a time):
Code:
LDA #$02
STA limitProjectile
Then I modified the "CreateSimpleProjectileWithMotion.asm" script to check that variable:
Code:
CreateSimpleProjectileWithMotion:
LDY player1_object
CPY #$FF ;; if the player object is set to ff, he's dead.
BNE playerCanCreateProjectile
RTS
playerCanCreateProjectile:
LDA limitProjectile
BNE continueCreateProjectile
RTS
continueCreateProjectile:
;; get offset
;; in a later version, we will use user defined offsets.
;; for now, we'll place projectile creation at center of object
LDA Object_movement,y
AND #%00000111
TAX
LDA weaponOffsetTableX,x
;;; now we have the offset
CLC
ADC Object_x_hi,y
STA temp1
LDA weaponOffsetTableY,x
CLC
ADC Object_y_hi,y
STA temp2
CreateObject temp1, temp2, #$01, #$00 ;;testVar
LDA Object_movement,y
AND #%00000111
STA temp
TAY
LDA DirectionMovementTable,y
ORA temp
STA Object_movement,x
;; add object size offset.
LDA Object_x_hi,x
SEC
SBC #$08 ;; half of the width of the intended projectile
STA Object_x_hi,x
LDA Object_y_hi,x
SEC
SBC #$08 ;; half of the height of the intended projectile
STA Object_y_hi,x
;;PlaySound #$00, #$00
DEC limitProjectile
RTS
I modified the "HandleObjectCollisions.asm" script (around line 362):
Code:
skipHurtingMonster:
LDX tempx
;; what should we do with the projectile?
INC limitProjectile ;;projectiles limitation related
DeactivateCurrentObject
I wanted to modify the "Reaction_02.asm" script (in "Routines\System\AI_Reactions" folder) that correspond to the "Destroy Me" in the Object Details solid/edge reactions, but did have succes checking the objct type (the code is needed only for player weapon).
So I made modified the unused "Reaction_03.asm" script:
Code:
;; DESTROY ME AND LIMIT (FOR WEAPON)
INC limitProjectile ;;projectiles limitation related
DeactivateCurrentObject
And in "Project Labels", I rename it to "Destoy Me (Player Weapon)", reassign this reaction to my Melee/projectile object.
Voilà. It should work (2 bullets at a time)