My game is a top-down shooter, but how do I make player shoot?

darkhog
Posts: 256
Joined: Sun May 13, 2018 10:02 am

My game is a top-down shooter, but how do I make player shoot?

Post by darkhog » Wed Aug 15, 2018 6:51 pm

Any advice?

//edit: I want my player to only shoot after he/she picks up a weapon.
Goaterby
Posts: 13
Joined: Thu Aug 09, 2018 5:42 pm

Re: My game is a top-down shooter, but how do I make player shoot?

Post by Goaterby » Thu Aug 16, 2018 6:06 pm

There was a good topic on it here:

http://nesmakers.com/viewtopic.php?f=3&t=290

Having tried to do something similar, it became apparent that, unless I am mistaken and someone would care to list the directory, there is no simple projectile script in the 4.0.0 release anymore. So you have to make your own simple projectile script using the code provided in the above link like so:

Notice that I commented out the changes the user made, so that it doesn't rely upon their ammo variable they added. If you want to use an ammo system, you can simply use the scripts from the other topic, but this one will get you going out of the box without any other changes.

Code: Select all

CreateSimpleProjectileWithMotion:
    LDY player1_object
    CPY #$FF ;; if the player object is set to ff, he's dead.
    ;BNE playerCanCreateProjectile
    ;RTS
 ;playerCanCreateProjectile:
	;LDA GLOBAL_Player1_Ammo
	;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
    ;JMP decreasePlayerAmmo
    RTS
It should work normally if you make a projectile object, set it as a player weapon, give it a sprite, and set a button press (or hold, release whatever) to run this script during the main gameplay with a NULL target. Let us know how it goes!
User avatar
dale_coop
Posts: 1627
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: My game is a top-down shooter, but how do I make player shoot?

Post by dale_coop » Thu Aug 16, 2018 6:32 pm

The original code (from the beta):

Code: Select all

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
    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
    RTS
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE
User avatar
dale_coop
Posts: 1627
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: My game is a top-down shooter, but how do I make player shoot?

Post by dale_coop » Thu Aug 16, 2018 6:35 pm

Set your "Melee" game object (make it like a bullet for example, set the bounding box, the speed and acceleration) and that it.
Then, if you assign this script to Press B, you will be able to shoot.
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE
darkhog
Posts: 256
Joined: Sun May 13, 2018 10:02 am

Re: My game is a top-down shooter, but how do I make player shoot?

Post by darkhog » Thu Aug 16, 2018 6:46 pm

Thanks, but as I've mentioned I want it to only start working once player will pick up a gun in one of the rooms.
User avatar
dale_coop
Posts: 1627
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: My game is a top-down shooter, but how do I make player shoot?

Post by dale_coop » Thu Aug 16, 2018 7:11 pm

I know you want.
But fist, you need to go by steps... first, make the script work (when you press A, it shoots)
Then you can modify the script, to add some variable to be tested: if a certain variable is a certain value, then I can create the projectile, else I do nothing.
Finally you can make a script that set the value of that certain variable. And assign that script to the "Power up 1" for exemple (in script settings). Power Up 1 corresponds to the "Charge Pickup" in the game objects.
Et voilà :)

Image

Note: if you saw my WIP "PressStart game", you will see I did it. And I shared the code... from the beta
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE
darkhog
Posts: 256
Joined: Sun May 13, 2018 10:02 am

Re: My game is a top-down shooter, but how do I make player shoot?

Post by darkhog » Thu Aug 16, 2018 8:52 pm

Thanks. Since I won't need a full blown ammo system, do you know how to set/read relic flags? So I can make gun powerup trigger a relic 1 and then make shooting code checking for whether a relic flag is set or not.
Image
User avatar
dale_coop
Posts: 1627
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: My game is a top-down shooter, but how do I make player shoot?

Post by dale_coop » Thu Aug 16, 2018 9:27 pm

A lot of property you can see in the tool (NESMaker tool) is not yet implemented in the engine (ASM code).
I think relic and songs, boss, ... are not implemented yet.

I would suggest to use an HUD user variable. For exemple, rename UserVar_3 to "myWeapon", initialized to 0 (would mean no weapon).
So you could modify the ShootProjectile script like this:

Code: Select all

CreateSimpleProjectileWithMotion:
    LDY player1_object
    CPY #$FF ;; if the player object is set to ff, he's dead.
    BNE playerCanCreateProjectile
    RTS
 playerCanCreateProjectile:
	LDA myWeapon  ;;load the variable weapon
	BNE continueCreateProjectile  ;;if NOT equal to zero, when can continue creating the projectile
	RTS  ;; else we stop
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
 
 	;;; we also need to set up the routine to update the HUD
	;; for this to work right, health must be a "blank-then-draw" type element.
	;;STA hudElementTilesToLoad
	;;	LDA #$00
	;;	STA hudElementTilesMax
	;;	LDA DrawHudBytes
	;;	ORA #HUD_ myWeapon
	;;	STA DrawHudBytes   
    RTS
And make a "PowerUpActivateWeapon" script:

Code: Select all

;;; activateWeapon code for player.
;;; works with variable myWeapon
;;; works with HUD variable HUD_myWeapon
	TXA
	STA tempx
	;;;you may want to test against a MAX value.
	;;; this could be a static number in which case you could just check against that number
	;;; or it could be a variable you set up which may change as you go through the game.
	LDA #$01
	STA myWeapon
	
	;;; we also need to set up the routine to update the HUD
	;; for this to work right, health must be a "blank-then-draw" type element.
	;;STA hudElementTilesToLoad
	;;	LDA #$00
	;;	STA hudElementTilesMax
	;;	LDA DrawHudBytes
	;;	ORA #HUD_ myWeapon
	;;	STA DrawHudBytes
	
	LDX tempx
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE
darkhog
Posts: 256
Joined: Sun May 13, 2018 10:02 am

Re: My game is a top-down shooter, but how do I make player shoot?

Post by darkhog » Sat Aug 18, 2018 8:34 pm

dale_coop wrote:
Thu Aug 16, 2018 9:27 pm
A lot of property you can see in the tool (NESMaker tool) is not yet implemented in the engine (ASM code).
I think relic and songs, boss, ... are not implemented yet.
Quoting your post so you get a notification. Do you know if there is a way to limit amount of shots player have at a single time (kinda like Mario can only shoot two fireballs) since I've come across the issue with the original script that makes it so you can fire too much and slow the game, then corrupt it (enemies/NPCs start using weird tiles and palettes and so on). Then I'll make it so you can only shoot after obtaining the gun in a way you have suggested.
User avatar
dale_coop
Posts: 1627
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: My game is a top-down shooter, but how do I make player shoot?

Post by dale_coop » Sat Aug 18, 2018 8:44 pm

Yes you right.
Already talk with Joe about that. I could use a variable to limit the number of projectiles .... or could use a timer Brtween to projectiles.

Didn’t try yet those solutions.
But it’s in my check list ;)
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE
Post Reply