Limit the projectiles 2 bullets at a time [NESMaker 4.0.0]

dale_coop

Moderator
Staff member
Yeah, you right Convoy_Avenger.
So you could add some code in the "Routines\System\HanldScreenLoads.asm" script (around line 388), for example, replacing:
Code:
DoneWithThisScreenLoad:	
	;; if you do not want triggers to go away
	;;; comment out this sub routine.
	;;; make this a screen bit.
	JSR updateNametable_checkForTriggers
	JSR countAllMonsters

	LDA #$00
	STA update_screen
By:
Code:
DoneWithThisScreenLoad:	
	;; if you do not want triggers to go away
	;;; comment out this sub routine.
	;;; make this a screen bit.
	JSR updateNametable_checkForTriggers
	JSR countAllMonsters

	LDA #$02            ;;limit projectiles
	STA limitProjectile ;;limit projectiles

	LDA #$00
	STA update_screen
 

mouse spirit

Well-known member
Thanks so much dale and convoy.I am using 4.1.5 and was able to adapt my script accodingly.This is great.

I have a problem though.When i speak to an npc,i have no projectiles,in the same screen if i speak to an npc again,i have infinite projectiles.It's fine when i leave screen as i have it reset to 2 projectile limits and reloads to 2.


Edit:
Fixxed it. I added some lines to ActivateTextbox asm.
Around line 63 you should see. ...

turnthetextboxon:
Code:
     LDA .....blah blah
                STA ......blah blah

So after that i added....

Code:
 LDA #$02
           STA limitProjectile
           INC limitProjectile
           INC limitProjectile

That fixes my problem.
 

dale_coop

Moderator
Staff member
Glad you found out.
This is an old post. Now I would not (I don't) fo like that. I prefer add a small code in the create_projectile script that counts how many projectiles already on screen... and if already the limit number I skip the code (don't create another projectile)
You can find that piece of code here: http://nesmakers.com/viewtopic.php?p=11769#p11769
 

TheRetroBro

Active member
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!

2BulletsProjectilesf250fccff2159398.gif


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)
old thread but curious. is there a way to limit how for you can shoot your projectiles? right now I can shoot all the way across screen and it makes the game alittle to easy
 

baardbi

Well-known member
old thread but curious. is there a way to limit how for you can shoot your projectiles? right now I can shoot all the way across screen and it makes the game alittle to easy
On the projectile object, set a timer on the first action step to 2 or 3 (or whatever number works best). Then set end action to DestroyMe.
 
Top Bottom