Lower projectiles (platformer test)

dale_coop

Moderator
Staff member
I modified some scripts and animations, to have my player shooting projectiles lower if holding Down when he shoots.




Here my "CreateSimpleProjectileWithMotion.ASM" script:

Code:
CreateSimpleProjectileWithMotion:
    LDY player1_object
    CPY #$FF ;; if the player object is set to ff, he's dead.
    BNE playerCanCreateProjectile
    RTS
    
playerCanCreateProjectile:
    ;; 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 gamepad
    AND #%11110000
    CMP #%00100000 ;;check if down is pressed
    BEQ projectileDown
    JMP projectileCenter
    
projectileDown:
    LDA Object_y_hi,x
    SEC
    ADC #$04  ;; half of the height of the intended projectile
    STA Object_y_hi,x
    JMP continueCreateMoreProjectilePlaced
    
projectileCenter:
    LDA Object_y_hi,x
    SEC
    SBC #$08 ;; half of the height of the intended projectile
    STA Object_y_hi,x
    JMP continueCreateMoreProjectilePlaced 
    	
continueCreateMoreProjectilePlaced:	    
    PlaySound #$00, #$00
    ;; here, anything else when he shoots
    RTS

I made an animation too, so my player is on his knees (not great graphics, but...) when he shoots projectiles lower.
I assigned the animation type "OnKnees" to the Action Step 04 in my Player "Object Details".

And made a script to change to that animations when I hold Down.
Here my "ChangeToOnKneesAnimation.asm" script :
Code:
    LDA onLadder
    BNE endcheckLowAnimation
    LDX player1_object
    ChangeObjectState #$04, #$02
    
endcheckLowAnimation:
    RTS

Finally, in input editor, I assigned this script to "HOLD" "Down", and assigned the "ChangeToIdleAnimation.asm" script to "RELEASE" "Down".


Note: another (better?) technique would be to make a new CreateLowerSimpleProjectileWithMotion, creating anothe game objects (the #$02, for example) and assign the offsets as wanted (in the "Game Objets" dialog), and modify the inputs wisely (maybe using a unique script shootProjectile..; and check the gamepad inputs to execute one script or the other).
 
This is awesome I've wanted to do this on my platformer. Crawling zombie enemies here we come. Thanks Dale you're the best man.
 

WolfMerrik

New member
This gets me thinking, particularly about kneeling and the height of the object. Would it be possible to change the player objects bounding box when in the kneeling state? I wouldn't even know what to change and am curious if you have messed around with it. I am using there is a way to change a ObjectBboxTop, although, you may need to make a separate object for this. I will try to mess around with it after work.

Again, awesome post!
 

dale_coop

Moderator
Staff member
I assume it should be possible... the main problem is you would need to define the bounding box in the script. I would prefer if it was in the NESMaker tool (a boundbox by action step would be great) but surely would use too much space :(
 

Bucket Mouse

Active member
Maybe I'm missing something, but applying the kneeling animation should be as simple as mapping the Down button to that animation in Input Scripts.
 

dale_coop

Moderator
Staff member
Yes, exactly... you assign the script to the HOLD Down button, and that's it should work. Like in my video.

The only think you need to keep in mind it's the bounding box is unique to your player (not to the animation). So you have to set a bounding box not to big, so, even when your player is on his knees, the bounding box will not be too much bigger than him.

Bounding_Box.png


In my case, I always make a small bounding box
 

WolfMerrik

New member
Yeah that makes sense, I had made the box on my character small to accommodate, although it would be nice if a crouch could be used in a game to avoid projectiles that would hit you normally (if that makes sense. Having bounding boxes based on actions would be awesome, but you are probably right about it using a lot of space.
 

dale_coop

Moderator
Staff member
Here the list of comparisons for the gamepad:
CMP #%00010000 ;; check if up is pressed
CMP #%00100000 ;;check if down is pressed
CMP #%01000000 ;;check if left is pressed
CMP #%10000000 ;;check if right is pressed
 
Hmm, I'm having the same problem with this script as I am the shootProjectile script. It's not perceiving my direction at all, and constantly shoots towards the left. The ducking script worked, but that didn't modify the source of the project either.
 
I've modified it a bit, but maybe this might work better for you?

Code:
CreateSimpleProjectileWithMotion:
    LDY player1_object
    CPY #$FF ;; if the player object is set to ff, he's dead.
    BNE playerCanCreateProjectile
    RTS
    
playerCanCreateProjectile:
    ;; 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 projOffsetTableX,x
    ;;; now we have the offset
    CLC
    ADC Object_x_hi,y
    STA temp1
    LDA projOffsetTableY,x
    CLC
    ADC Object_y_hi,y
    STA temp2
    CreateObject temp1, temp2, #$03, #$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 gamepad
    AND #%11110000
    CMP #%00100000 ;;check if down is pressed
    BEQ projectileDown
    JMP projectileCenter
    
projectileDown:
    LDA Object_y_hi,x
    SEC
    ADC #$00  ;; half of the height of the intended projectile
    STA Object_y_hi,x
    JMP continueCreateMoreProjectilePlaced
    
projectileCenter:
    LDA Object_y_hi,x
    SEC
    SBC #$04 ;; half of the height of the intended projectile
    STA Object_y_hi,x
    JMP continueCreateMoreProjectilePlaced 
        
continueCreateMoreProjectilePlaced:     
    PlaySound #$00, #$00
    ;; here, anything else when he shoots
    RTS
 
My friend helped me figure out that my "Ignore Main Physics" being checked was causing my grief. Resolving that fixed my directional issues. I was having trouble with the spawn location of my bullets, that your version seems to fix @Nerdy, so that's great!

EDIT: What's the spawn location controlled by? I'd like to tweak it slightly if possible. I doubt it's as simple as adding 2 to the Y value though.
 
The folder that the Player object and power ups are stored in controls that. Click that and it should take you to a screen to set that. See the adventure game tutorial for more details.
 
Also my script there modifies Dale Coop's original code so that it better lines up with my player. Comparing our two different codes might help you with yours.
 
I modified by ducking code, so I don't have to worry about crawling:

Code:
    LDA onLadder
    BNE endcheckLowAnimation
    LDX player1_object
    ChangeObjectState #$04, #$02
    StopMoving player1_object, STOP_LEFT
    StopMoving player1_object, STOP_RIGHT
    rts
    
endcheckLowAnimation:
    RTS

But this did show me a bug with the projectile code(Which was there before, just more obvious now), where if you hold down, and right or left at the same time, the projectile will shoot at standing height. Any ideas on how to solve for that?
 

DanielT1985

Member
This may be off topic, but how did you get your player to shoot a projectile? When I tried doing anything, it gave me a coding error and having to start up a back up. Also, is there a way to limit the range of the projectile? So instead of it going as far as the end of the screen, It can only go to 1 or 2 blocks, like a whip.
 

dale_coop

Moderator
Staff member
DanielT1985 said:
This may be off topic, but how did you get your player to shoot a projectile? When I tried doing anything, it gave me a coding error and having to start up a back up. Also, is there a way to limit the range of the projectile? So instead of it going as far as the end of the screen, It can only go to 1 or 2 blocks, like a whip.

If you're making a platformer game (4.0.11), there is another topic about that: http://nesmakers.com/viewtopic.php?f=28&t=747
For the range of your weapon... just make a weapon (your whip) like in the adventure game tutorial, instead of a projectile.
 
Top Bottom