Help please with throwing a rock (shooting)

Razzie.P

Member
I know the answer lies somewhere in the simple shooter tutorial, but I can't seem to follow the script trails and/or read the asm well enough to figure out how to make a player shoot. Help, please!

Lets say I have a simple square as my player, and when I press "A", I want to shoot a small round object to the right that will destroy itself when it collides with a solid object, and will destroy a monster (like the UFOs in the shooter tutorial) if it hits an enemy. When destroyed, I can then press "A" to shoot another. I'd like pressing "B" to shoot the round object to the left, but I think I can figure out that part if I can get the "A" part working.

Thanks in advance for any help offered!
 

dale_coop

Moderator
Staff member
For your shooting projectile:
Set the projectile object (use "Melee"), as "projectile weapon", set its Speed and Acceleration, the Solid/Edge Reaction to "destroy me" and define the bounding box.
Set your Player Action Step 1 (shooting state), set a shooting animation, and the "end of animation" to "go to first (also give it an animation speed).
Then, use the "a_create_projectile.asm" script (located in the "Basic\ModuleScripts\InputScripts\Shooter" folder).

If you want to limit projectiles...
you could try adding this portion of code at the begining of the a_create_projectile script:
Code:
	;; We count the projectiles already on screen to see if can Shoot another one :
	CountObjects #%00000100, #$00	;; count player weapon on screen
	LDA monsterCounter		;; the variable used to count is monsterCounter
	CLC
	CMP #$02		;; compare to 2
	BCC +			;; if less than 2 on screen we can create a projectile
	RTS			;; else we quit   
	+
	;; else, the script continues:
 

Razzie.P

Member
Thanks! Almost got it working, but there are 2 points that I'm not understanding.

1) The code doesn't use the Melee object (second game object in my list) When I set my offsets, it loads the correct sprite for melee, but when I press the button to shoot, it loads the 12th object in my list. That object was named "effect 3" by default. I was able to use that to make the code shoot, but would like to know why it's not using the same thing loading for melee offsets.

2) The code only seems to recognize the "right" offset, no matter which direction I'm facing. How can I force it to use a specfic offset? For example, if I ONLY want it to create the projectile using the left offsite, what part of the code controls that?

Thanks a bunch for all the help with my learning process!
 

dale_coop

Moderator
Staff member
1/ For the projectile, the a_create_projectile script uses tht object defined by the "OBJECT_PLAYER_PROJECTILE" constant. Open the "Project Settings > User Constants" and check the value of the "OBJECT_PLAYER_PROJECTILE" constant. It means in your project the value is currently 11? (counting objects from "0")
Change the value of the "OBJECT_PLAYER_PROJECTILE" constant to "1" if you want to use the Melee object.

2/ In the "a_create_projectile" script, around line 10, you should see:
Code:
     LDA #%00000010
This is "right".

If you want "Left", modify this line to
Code:
     LDA #%00000100

Here, for reference:
Code:
	;FACE_DOWN      = #%00000000
	;FACE_DOWN_RIGHT = #%00000001
	;FACE_RIGHT		= #%00000010
	;FACE_UP_RIGHT	= #%00000011
	;FACE_UP		= #%00000100
	;FACE_UP_LEFT	= #%00000101
	;FACE_LEFT		= #%00000110
	;FACE_DOWN_LEFT	= #%00000111
 
For your shooting projectile:
Set the projectile object (use "Melee"), as "projectile weapon", set its Speed and Acceleration, the Solid/Edge Reaction to "destroy me" and define the bounding box.
Set your Player Action Step 1 (shooting state), set a shooting animation, and the "end of animation" to "go to first (also give it an animation speed).
Then, use the "a_create_projectile.asm" script (located in the "Basic\ModuleScripts\InputScripts\Shooter" folder).

If you want to limit projectiles...
you could try adding this portion of code at the begining of the a_create_projectile script:
Code:
    ;; We count the projectiles already on screen to see if can Shoot another one :
    CountObjects #%00000100, #$00    ;; count player weapon on screen
    LDA monsterCounter        ;; the variable used to count is monsterCounter
    CLC
    CMP #$02        ;; compare to 2
    BCC +            ;; if less than 2 on screen we can create a projectile
    RTS            ;; else we quit  
    +
    ;; else, the script continues:
I know this is an old thread, but this is also the only thread I can find explaining how to limit projectiles. The code given here did not work for me, but by cutting out a couple lines I got it to work just fine.
Code:
;; We count the projectiles already on screen to see if can Shoot another one :
    CountObjects #%00000100, #$00   ;; count player weapon on screen
    CMP #$01        ;; compare to 1
    BCC +canShoot           ;; if less than 1 on screen we can create a projectile
    RTS         ;; else we quit   
    +canShoot
    ;; else, the script continues:
Here I cut out LDA monsterCounter and CLC. In my case, this will restrict the amount of player projectiles on a screen to 1. It's a shorter script that does seemingly the same thing. Just putting it here in case anyone else finds this thread looking for a way to do this. But I also have a question. How could I change this from counting player weapons to counting monster weapons? Or from counting monster weapons to counting monsters? I assume it has to do with the binary at the start of the code, but I'm not exactly sure what it means.
 

dale_coop

Moderator
Staff member
I know this is an old thread, but this is also the only thread I can find explaining how to limit projectiles. The code given here did not work for me, but by cutting out a couple lines I got it to work just fine.
Code:
;; We count the projectiles already on screen to see if can Shoot another one :
    CountObjects #%00000100, #$00   ;; count player weapon on screen
    CMP #$01        ;; compare to 1
    BCC +canShoot           ;; if less than 1 on screen we can create a projectile
    RTS         ;; else we quit  
    +canShoot
    ;; else, the script continues:
Here I cut out LDA monsterCounter and CLC. In my case, this will restrict the amount of player projectiles on a screen to 1. It's a shorter script that does seemingly the same thing. Just putting it here in case anyone else finds this thread looking for a way to do this. But I also have a question. How could I change this from counting player weapons to counting monster weapons? Or from counting monster weapons to counting monsters? I assume it has to do with the binary at the start of the code, but I'm not exactly sure what it means.
Your code is for version 4.5. The original post was for the previous version 4.1. The code may not be compatible between versions.

Please don't hesitate to write a new post if you encounter issues, especially if it's not the same version.
 
Top Bottom