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

User avatar
Melatonin
Posts: 3
Joined: Fri Aug 17, 2018 6:26 am

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

Post by Melatonin » Sat Aug 18, 2018 9:25 pm

Followed the steps above and am having a heck of a bug.

Once I import the CreateSimpleProjectile script into the project, it fires a projectile anytime any user input is detected on the controller, including D Pad inputs. This is puzzling as I haven't hooked the code up to anything in the input editor. If I hook up the CreateSimple script to a button, that button will fire the projectile as intended, but again so will the D-Pads.

Any ideas why this script linked above would be acting this way?
User avatar
dale_coop
Posts: 1612
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 9:35 pm

Because you need the fixed movement scripts (the ones that come with NESMaker have issues)
From here: http://nesmakers.com/viewtopic.php?f=19&t=390
-----
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 10:09 pm

Timer-based solution would be highly volatile and based on how fast bullets are moving and how far. I can see game becoming corrupted with slow enough bullets since you'd be able to make a somewhat high amount of bullets.
User avatar
Melatonin
Posts: 3
Joined: Fri Aug 17, 2018 6:26 am

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

Post by Melatonin » Sat Aug 18, 2018 10:13 pm

dale_coop wrote:
Sat Aug 18, 2018 9:35 pm
Because you need the fixed movement scripts (the ones that come with NESMaker have issues)
From here: http://nesmakers.com/viewtopic.php?f=19&t=390
You're a legend, thank you!

For my own education, what in the old script was causing that to happen? There's not much in those scripts so my little asm knowledge isn't cutting it :)
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 10:28 pm

Lack of RTS opcode (return from subroutine). It just kept executing whatever was after the actual code in the rom until it encountered actual rts or game data that may have had illegal opcodes and made game crash.
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 » Sun Aug 19, 2018 12:29 am

Okay, mostly done with the bullet limiting code, with one little problem: When bullets go into the enemy (they're set up as player weapon), the counter doesn't refill properly, the solid reaction of the bullet code seems to not be executed. Any idea how to fix that part? Otherwise it works fine.
User avatar
dale_coop
Posts: 1612
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 » Sun Aug 19, 2018 2:19 pm

In the HandleObjectCollision.asm, find the subroutine "skipHurtingMonster" and you write your code just after the ";; what should we do with the projectile?".
-----
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 » Sun Aug 19, 2018 2:45 pm

Thanks, got it now. Had other minor issue with the weapon pool not resetting on screen change, but I've been able to fix it myself.

There's still a slowdown issues when there are too many objects, but it's okay for now.
User avatar
dale_coop
Posts: 1612
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 » Sun Aug 19, 2018 2:50 pm

Great! Glad you found!
Could you share your code / scripts for other nesmakers who would to same? It would be very nice <3
-----
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 » Sun Aug 19, 2018 3:26 pm

Frankly, most of it is a hack. In some parts it looks nice, but most of it is really ugly. Here's the shooting script though, I'm sure that people will figure out the rest (all it really takes is to increment the counter in places where the bullet gets destroyed, in this script called weaponpool and reset it on screen change):

Code: Select all

shootdathing:

    LDY player1_object
    CPY #$FF ;; if the player object is set to ff, he's dead.
    BNE playerCanCreateProjectile
    RTS
 playerCanCreateProjectile:
    lda guyweapon
    cmp #0
    bne continueshooting
    rts
    continueshooting:
    lda weaponpool
    cmp #0
    bne continueshootingmore
    rts
    continueshootingmore:
    ; removing bullet from the weaponpool
    ldx weaponpool
    dex
    stx weaponpool
    ;; 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
In my case weaponpool is set to 4 as while it still causes some slow down, it doesn't cause corruption at least, even with enemies shooting. Obviously feel free to experiment with it, but I wouldn't suggest setting it to or past 6 as it may cause corruption.

This code requires two custom variables - guyweapon and weaponpool. I suggest creating new file in GameEngineData/Routines/Variables and then including it in the same way UserVariables.asm is included in ZP_and_vars.asm, then making an initialization ASM in GameEngineData/Routines/InitializationScripts and including it in InitLoads.asm, right under the line where hudVarInits.asm is included (you can use UserVariables.asm and hudVarInits.asm as templates how to declare/init a variable if you don't know how)
Post Reply