help understanding collisions

Raftronaut

Member
dale_coop said:
Yeah, the shaking effect...
It was more a result (side effect) of the code, unfortunately :(
I was thinking about fixing that, but after testing my demo, I thought it could work for your game ;)

If I find time, I’ll try to fix it, to see how it goes.

The shaking works great for me in this game, It could also be useful for interactive cutscenes too! If you boxed your character in with this tile, When the player pressed the inputs, the character sprite would shake.. For example, if the scene was watching bowser carry the princess away, the character would be able to shake in protest.. I could think of other uses as well. Good stuff :)

Dale, do you know if there is a macro to Stop Playing Sound? I created a "grinding" sound effect in famitracker that I could use when colliding with a special duplicate of this tile used only for the boundaries of the playfield like Dirk suggested. I would think if there is a StopPlayingSound Macro I could simply insert the Playsound_testSfx into the tile script and then insert the theoretical "StopSound_testSfx" Macro just before the End Rails part of code...

Is my thinking here correct? And, is there a stop sound macro? I have yet to come across it as I have not had a need for a sound effect that didn't use a specific decay in the volume envelope followed by a blank instrument note stop. This is the only surefire method I've used for implementing SFX and making the transitions smooth..
 

dale_coop

Moderator
Staff member
There is StopSound macro, but that stops sfxx and music.
But if your "grinding" sound effect is short... you wouldn't have to stop it... it will play as long as your player is colliding, and when not, it would not be played... am I wrong?
(need to test... but currenlty at my office, so can't play with NESmaker >_<)

(...NES dev is a lot of experimentations :p)
 

Raftronaut

Member
dale_coop said:
There is StopSound macro, but that stops sfxx and music.
But if your "grinding" sound effect is short... you wouldn't have to stop it... it will play as long as your player is colliding, and when not, it would not be played... am I wrong?
(need to test... but currenlty at my office, so can't play with NESmaker >_<)

(...NES dev is a lot of experimentations :p)

Yes, you are correct in your assumption of the SFX application, the grinding sound effect is short, only 2 rows on a loop!

The truth is, I am not certain how SFX behave without a clear ending stop (or blank instrument) determined inside the Famitracker file. I've never worked with a looping sound effect. I only managed to fit in 15 minutes with nesmaker last night between family stuff and my two jobs so I didn't have a chance to do any testing.

I will do a comprehensive test tonight and post my results :)

I'm looking forward to getting this script fully implemented, this is going to be such a drastic improvement on my gameplay.

Thanks so much for your help as always Dale :)
 

Raftronaut

Member
dale_coop said:
There is StopSound macro, but that stops sfxx and music.
But if your "grinding" sound effect is short... you wouldn't have to stop it... it will play as long as your player is colliding, and when not, it would not be played... am I wrong?
(need to test... but currenlty at my office, so can't play with NESmaker >_<)

(...NES dev is a lot of experimentations :p)



Hey Dale, only had about 30 minutes last night to do some tests, I inserted the following Macro Just before the End Rails command:
PLaySound #sfx_grind
(Is there a better place in the code to insert this command?)
The sound effect engages fine when the player collides with the rail tile, however, the "grind" sound effect (on the noise channel) will remain on until another event triggers a sound in the noise channel occurs. Since my projectile uses the noise channel, I can cancel the grind sfx loop but pressing the projectile input. The noise channel then rejoins the music.

So basically I do not know how to tell the looping sound effect to stop playing when NOT colliding with the RAIL tile. I could create an additional "BLANK" sound effect that could be played as a command to cancel the grind loop and return to music, but I do not where in code that would occur to insert the command.. any thoughts?

Could I simply add a "PlaySound #sfx_blank" AFTER the final "endRails:" statement of the code? Would that work? (at the office currently so I cannot test, just trying to think this through).
 

dale_coop

Moderator
Staff member
Not sure where you could "PlaySound #sfx_blank"... you would like to be played when no more collision with the rail tile (but it means the rail tile will not be executed, in that case).
You could try putting it around line 20, just before the line:
Code:
RailsTopBottom:
but even here, I am not sure.

Stoping sounds is not a trivial thing in nesmaker >_<

Or maybe if you don't make a loop sound... but just one 1 or 2 loops... maybe the sound will stop itself automatically?
 

Raftronaut

Member
dale_coop said:
Stoping sounds is not a trivial thing in nesmaker >_<

Or maybe if you don't make a loop sound... but just one 1 or 2 loops... maybe the sound will stop itself automatically?

I may have to try this, I presume that everytime contact is made with the rail the sound effect will reset which could work out ok if I made the sfx_grind 4 or 5 seconds long. The player would maybe feel the "essence" of the sound effect by only catching a short burst of the sound. This may be the solution to use here...

There are so many examples of continuous SFX in old nes games, for example the motor sounds in virtually any NES racing game, rad racer, excitebike, mach rider etc.. Though also in other adventure games like Samus' Footsteps in Metroid, or certain flamethrower sounds in Heavy Barrel or Guerilla War. Or the machine gun in Contra/probotechtor. Though I imagine the sound effects in those cases are linked directly to the input commands.

It has to be possible. I wonder if this is something I could bother Derek at Gradual games about to see how the sound engine would address this.. I am sure other nesmakers would find it useful.
 

Raftronaut

Member
dale_coop said:
Not sure where you could "PlaySound #sfx_blank"... you would like to be played when no more collision with the rail tile (but it means the rail tile will not be executed, in that case).
You could try putting it around line 20, just before the line:
Code:
RailsTopBottom:
but even here, I am not sure.

Stoping sounds is not a trivial thing in nesmaker >_<

Or maybe if you don't make a loop sound... but just one 1 or 2 loops... maybe the sound will stop itself automatically?

Hello Dale! I had a chance to do some tests this weekend. It turns out the looping sfx issue is actually pretty simple. I created a short sound effect in famitracker (4 rows) and one more row to add a blank instrument to finish as I always do.
grindage.PNG
Upon testing I discovered that the sound effect will play continuosly as long as I was pressing the input into the "rail". You can see here in the 1st half of this test video that the sfx_grind is working as it should:
https://youtu.be/DCh1eu5_YwQ
However, the second half of the video shows the upper rails and the sound effect does not play. I inserted the Playsound only at the end of the script here, Is there a better way to do this?
Code:
	;; checking center left collision point
	LDA collisionPoint4
	BNE RailsLeftRight		;; there is a left collision
	
	;; checking center right collision point
	LDA collisionPoint5
	BNE RailsLeftRight		;; there is a right collision

	;; checking center right collision point
	LDA collisionPoint0
	CLC
	ADC collisionPoint1
	BNE doRailSlidingDown	;; there is a top collision

	;; checking center right collision point
	LDA collisionPoint2
	CLC
	ADC collisionPoint3
	BNE doRailSlidingUp		;; there is a bottom collision
	

	  
	 
RailsTopBottom:	
	;; block vertical movement:
	LDA yPrev
	STA Object_y_hi,x
	STA yHold_hi
	JMP endRails
	
RailsLeftRight:
	;; solid from sides:
	LDA #TILE_SOLID
	STA tile_solidity
	
	;; now checking the game pad (if pressing Up)
	;; to slide the player vertically
	LDA gamepad
	AND #%00010000
	BNE doRailSlidingDown


doRailSlidingDown:
	;; a small sliding down:
	LDA yPrev
	CLC
	ADC #$01
	STA Object_y_hi,x
	STA yHold_hi
	JMP endRails
	
	
doRailSlidingUp:
	;; a small sliding up:
	LDA yPrev
	SEC
	SBC #$01
	STA Object_y_hi,x
	STA yHold_hi
	

	PlaySound #sfx_grind
	
endRails:

I've tried inserting PlaySound #sfx_grind in between each block of code but cannot get the sfx to trigger on the northern top rail. I am kind of stumped, but the actual sfx loop we discussed is working great on the bottom rail! Almost there, I presume if sfx were linked to actions without endings like jumping or shooting, the sfx would loop with buttons being held etc depending on the application. AT LEAST it is good know that looping SFX can be set up normally in famitracker! That is a good start, once I figure this concept out fully I'll make a post in the music section explaining how looping sfx can be easily set up.

Now, besides the SFX on the top side, the rails are functioning pretty much as needed. I decided to do some experiments and subbed in the rail script with the default solid behavior tiles script. Unfortunately the results were not what I had hoped for, the player behaved like a wet bar of soap around obstacles, pressing on, or in between any solid obstacle would result in the player being squeezed quickly out or around the cracks. It's kind of comical, as well, it causes collision issues with my NPCS, if you watch till the end of the video you'll see the solid tiles holding the npcs cause them to wander off and leave the sandwiches.. that made me laugh really hard when I saw it, I am really starting to appreciate unintended programming glitches as great comedy :)
https://youtu.be/YmuicuWXyps

So, from here I suppose I can implement the rails into my game as they are and leave the solid obstacles on the road as the default sticky solid behavior script. Or at least look for a happy medium in the solid behavior section in the meantime.

I wish I could simply decrease the resistance of the default solid object script slightly so it doesn't feel as punishing at the scroll speed i've chosen. Many shmups would simply use instant death tiles to make up the backgrounds and this solid tile wouldn't be a problem. So this particular issue may be unique to a game type such as mine (obstacle based racing shooter?!?! OBRShmup?!? lol) .

Any advice on that SFX problem would be greatly appreciated, I'm stumped!
 

dale_coop

Moderator
Staff member
You could try adding the PlaySound in both doRailSlidingUp and doRailSlidingDown...
like that:

Code:
	;; checking center left collision point
	LDA collisionPoint4
	BNE RailsLeftRight		;; there is a left collision
	
	;; checking center right collision point
	LDA collisionPoint5
	BNE RailsLeftRight		;; there is a right collision

	;; checking center right collision point
	LDA collisionPoint0
	CLC
	ADC collisionPoint1
	BNE doRailSlidingDown	;; there is a top collision

	;; checking center right collision point
	LDA collisionPoint2
	CLC
	ADC collisionPoint3
	BNE doRailSlidingUp		;; there is a bottom collision
	

	  
	 
RailsTopBottom:	
	;; block vertical movement:
	LDA yPrev
	STA Object_y_hi,x
	STA yHold_hi
	JMP endRails
	
RailsLeftRight:
	;; solid from sides:
	LDA #TILE_SOLID
	STA tile_solidity
	
	;; now checking the game pad (if pressing Up)
	;; to slide the player vertically
	LDA gamepad
	AND #%00010000
	BNE doRailSlidingDown


doRailSlidingDown:
	;; a small sliding down:
	LDA yPrev
	CLC
	ADC #$01
	STA Object_y_hi,x
	STA yHold_hi
	PlaySound #sfx_grind
	JMP endRails
	
	
doRailSlidingUp:
	;; a small sliding up:
	LDA yPrev
	SEC
	SBC #$01
	STA Object_y_hi,x
	STA yHold_hi
	PlaySound #sfx_grind
	
endRails:
 

dale_coop

Moderator
Staff member
And... maybe? in the the "RailsTopBottom"...? (not sure, I say that without testing myself :p) like this:

Code:
	;; checking center left collision point
	LDA collisionPoint4
	BNE RailsLeftRight		;; there is a left collision
	
	;; checking center right collision point
	LDA collisionPoint5
	BNE RailsLeftRight		;; there is a right collision

	;; checking center right collision point
	LDA collisionPoint0
	CLC
	ADC collisionPoint1
	BNE doRailSlidingDown	;; there is a top collision

	;; checking center right collision point
	LDA collisionPoint2
	CLC
	ADC collisionPoint3
	BNE doRailSlidingUp		;; there is a bottom collision
	

	  
	 
RailsTopBottom:	
	;; block vertical movement:
	LDA yPrev
	STA Object_y_hi,x
	STA yHold_hi
	PlaySound #sfx_grind
	JMP endRails
	
RailsLeftRight:
	;; solid from sides:
	LDA #TILE_SOLID
	STA tile_solidity
	
	;; now checking the game pad (if pressing Up)
	;; to slide the player vertically
	LDA gamepad
	AND #%00010000
	BNE doRailSlidingDown


doRailSlidingDown:
	;; a small sliding down:
	LDA yPrev
	CLC
	ADC #$01
	STA Object_y_hi,x
	STA yHold_hi
	PlaySound #sfx_grind
	JMP endRails
	
	
doRailSlidingUp:
	;; a small sliding up:
	LDA yPrev
	SEC
	SBC #$01
	STA Object_y_hi,x
	STA yHold_hi
	PlaySound #sfx_grind
	
endRails:
 

Raftronaut

Member
dale_coop said:
And... maybe? in the the "RailsTopBottom"...? (not sure, I say that without testing myself :p) like this:

Code:
	;; checking center left collision point
	LDA collisionPoint4
	BNE RailsLeftRight		;; there is a left collision
	
	;; checking center right collision point
	LDA collisionPoint5
	BNE RailsLeftRight		;; there is a right collision

	;; checking center right collision point
	LDA collisionPoint0
	CLC
	ADC collisionPoint1
	BNE doRailSlidingDown	;; there is a top collision

	;; checking center right collision point
	LDA collisionPoint2
	CLC
	ADC collisionPoint3
	BNE doRailSlidingUp		;; there is a bottom collision
	

	  
	 
RailsTopBottom:	
	;; block vertical movement:
	LDA yPrev
	STA Object_y_hi,x
	STA yHold_hi
	PlaySound #sfx_grind
	JMP endRails
	
RailsLeftRight:
	;; solid from sides:
	LDA #TILE_SOLID
	STA tile_solidity
	
	;; now checking the game pad (if pressing Up)
	;; to slide the player vertically
	LDA gamepad
	AND #%00010000
	BNE doRailSlidingDown


doRailSlidingDown:
	;; a small sliding down:
	LDA yPrev
	CLC
	ADC #$01
	STA Object_y_hi,x
	STA yHold_hi
	PlaySound #sfx_grind
	JMP endRails
	
	
doRailSlidingUp:
	;; a small sliding up:
	LDA yPrev
	SEC
	SBC #$01
	STA Object_y_hi,x
	STA yHold_hi
	PlaySound #sfx_grind
	
endRails:

Ahhhh ok, I had tried to insert the playsound between the paragraphs and it did not work. I see if you insert it in the middle of the statements the sound effect plays correctly. I set it to the last script you posted and it worked perfectly!

https://youtu.be/ona0tG5aKeI
I've already replaced all the border tiles in my game with these "rails" tiles and it works perfectly during gameplay!
 

Raftronaut

Member
Dirk said:
Cool to see or better hear it working :)

For sure, it was a great suggestion :)

How do you think the SFX turned out?

I wasn't sure if it should be more percussive like a gravel road or static like sandpaper. I tried for the happy medium. Also, I left the volume low so it wouldn't be too annoying. I haven't decided if I want it louder yet.
 

Dirk

Member
I think it turned out great. As you wrote it's not distracting, but it gets the message across.
I think the volume is good, but I'm curious how it would sound a bit louder.
 

Raftronaut

Member
dale_coop said:
And... maybe? in the the "RailsTopBottom"...? (not sure, I say that without testing myself :p) like this:

Code:
	;; checking center left collision point
	LDA collisionPoint4
	BNE RailsLeftRight		;; there is a left collision
	
	;; checking center right collision point
	LDA collisionPoint5
	BNE RailsLeftRight		;; there is a right collision

	;; checking center right collision point
	LDA collisionPoint0
	CLC
	ADC collisionPoint1
	BNE doRailSlidingDown	;; there is a top collision

	;; checking center right collision point
	LDA collisionPoint2
	CLC
	ADC collisionPoint3
	BNE doRailSlidingUp		;; there is a bottom collision
	

	  
	 
RailsTopBottom:	
	;; block vertical movement:
	LDA yPrev
	STA Object_y_hi,x
	STA yHold_hi
	PlaySound #sfx_grind
	JMP endRails
	
RailsLeftRight:
	;; solid from sides:
	LDA #TILE_SOLID
	STA tile_solidity
	
	;; now checking the game pad (if pressing Up)
	;; to slide the player vertically
	LDA gamepad
	AND #%00010000
	BNE doRailSlidingDown


doRailSlidingDown:
	;; a small sliding down:
	LDA yPrev
	CLC
	ADC #$01
	STA Object_y_hi,x
	STA yHold_hi
	PlaySound #sfx_grind
	JMP endRails
	
	
doRailSlidingUp:
	;; a small sliding up:
	LDA yPrev
	SEC
	SBC #$01
	STA Object_y_hi,x
	STA yHold_hi
	PlaySound #sfx_grind
	
endRails:

So after further testing I discovered that not only does the rails tile sound effect work perfectly for the player, it also works for the enemies! This was an unforeseen development......

https://youtu.be/1Vx8DLmfGWs

Would the most efficient way to solve this be to write a branching statement for the playsound in the script?
 

dale_coop

Moderator
Staff member
Try this one:
Code:
	;; checking center left collision point
	LDA collisionPoint4
	BNE RailsLeftRight		;; there is a left collision
	
	;; checking center right collision point
	LDA collisionPoint5
	BNE RailsLeftRight		;; there is a right collision

	;; checking center right collision point
	LDA collisionPoint0
	CLC
	ADC collisionPoint1
	BNE doRailSlidingDown	;; there is a top collision

	;; checking center right collision point
	LDA collisionPoint2
	CLC
	ADC collisionPoint3
	BNE doRailSlidingUp		;; there is a bottom collision
	

	  
	 
RailsTopBottom:	
	;; block vertical movement:
	LDA yPrev
	STA Object_y_hi,x
	STA yHold_hi
	;PlaySound #sfx_grind
	JMP endRails
	
RailsLeftRight:
	;; solid from sides:
	LDA #TILE_SOLID
	STA tile_solidity
	
	;; now checking the game pad (if pressing Up)
	;; to slide the player vertically
	LDA gamepad
	AND #%00010000
	BNE doRailSlidingDown


doRailSlidingDown:
	;; a small sliding down:
	LDA yPrev
	CLC
	ADC #$01
	STA Object_y_hi,x
	STA yHold_hi
	;PlaySound #sfx_grind
	JMP endRails
	
	
doRailSlidingUp:
	;; a small sliding up:
	LDA yPrev
	SEC
	SBC #$01
	STA Object_y_hi,x
	STA yHold_hi
	;PlaySound #sfx_grind
	
endRails:
	CPX player1_object
	BNE endRailsWithNoSound
	PlaySound #sfx_grind
	
endRailsWithNoSound:
 

Raftronaut

Member
AHHHH, this works perfect!

I haven't written a successful branching statement yet, i've studied the nerdy nights and absorbed what I can, which has only helped me read code so far, reading your solutions in code is always such a pleasure :)

Here is a video of your hard work in action:

https://youtu.be/D2WStDN3C5g


As always, extremely grateful for your help :) You have no idea how much I appreciate the assistance!
 

Raftronaut

Member
Dirk said:
I think it turned out great. As you wrote it's not distracting, but it gets the message across.
I think the volume is good, but I'm curious how it would sound a bit louder.

Now that It's working optimally I went back into famitracker and increased the volume of the dedicated instrument I created for the sound effect. I like the overall effect when it's louder, much more abrasive, or startling.

https://youtu.be/tm936j0Uilo

Again, thanks for the feedback, I would have left the issue alone after the first iteration. It was definitely worthwhile pursuing and adds a little more polish to my games. Cheers!
 
Top Bottom