Tile that allows function only while on Tile

Craigery

Active member
For my Leon game I want a function where when you are on a Shadow Tile, then you can press down to switch animations and make player invincible to enemies. I think I need a script for the Tile and for a movement script, but I am not sure how this could work. I using the Scrolling Platformer Base.

I assume the Tile says something like:
Check if player is on tile
If player is on tile then set ShadowBit to 1

Then the movement script would say:
Check ShadowBit
If bit is 1 then changestate to #
If bit is 0 then do nothing

Am I going in the right direction? Maybe someone else has done something similar that could be purposed?
 

Mugi

Member
tile codes only run when you collide with them.
to make a tile that allows only the player do something, you start off the tile code by comparing X to the player (whatever collides with the tile, is loaded into X when the tile code runs.)
so you do
Code:
CPX player1_object
BEQ +
JMP endtilefunction
+
<put whatever you want the tile to do here>
endtilefunction:

after this, since you want to be able to hide at a button press, you propably want to do something along the lines of reading the gamepad to see if a certain button is pressed;
(this stuff would go into the "code space" on the above code.)

Code:
LDA gamepad
AND #%xxxxxxxx ; read whatever input you want here
BNE dotilestuff ; mind you when doing an AND read, the function of BEQ / BNE (branch if equal / branch not equal) is inverted.
JMP endtilefunction

dotilestuff:

something along the lines. it's not very complicated, just take it one step at the time. what you want to do ? what you need to do to get there? (read a gamepad for example.)

for an example of a similar function, here's how my wall grabbing tile looks like.

Code:
; 03_WallGrabTile

    CPX player1_object
    BNE dontMessWithGravity
    
    LDA gamepad
    AND #%00010000              ; is up pressed ?
    BEQ dontMessWithGravity
    
    LDA Object_v_speed_hi,x
    BEQ dontMessWithGravity     ; v_speed 0 won't allow wallgrab
    BMI dontMessWithGravity     ; are we falling downwards ?
    
    LDX player1_object          ; fetch facing direction of player 
    LDA Object_movement,x
    AND #%00001111
    CMP #%00000110
    BEQ doLeftCollisionCheck

    LDA collisionPoint1         ; compare top right collision point
    CMP #$03                    ; compare against "wallgrab tile"
    BNE dontMessWithGravity
    JMP doGrab
    
doLeftCollisionCheck:
    LDA collisionPoint0         ; compare top left collision point
    CMP #$03                    ; compare against "wallgrab tile"
    BNE dontMessWithGravity

doGrab:                         ; enable grabbing the wall
    ChangeObjectState #$07, #$03

dontMessWithGravity:

it starts off by checking if the player collides with the tile, if not, end the code
then it reads gamepad to check if up is pressed, if not, end the code.
then it reads the vertical speed of the object loaded in X, if 0 or negative, end the code.
then it reads which direction the object is facing, and depending on the result, it either does a left or a right collision check.
finally, all the conditions are met, and the tile enables the function (changes player action state to 7)
 

Craigery

Active member
Mugi, thank you so much for your help! After a few hours of me rubber ducking it this is just about doing what I want (at 1am it all finally started to click zzzzz...) Right now the animation doesn't fully play and stays on the first frame.

Here is what I came up with:

Code:
	CPX player1_object	;;Loads Player
	BEQ +				;;if Branch is Equal to the player? then go to plus
	JMP endLeonShadow	;;if not then end script
+						;;continue from line 2
	LDA gamepad			;;Loads gamepad
	AND #%00010000 		;;checks if UP is pressed
	BNE startLeonShadow	;;if so then go to startLeonShadow
	JMP endLeonShadow	;;jump to endLeonShadow

startLeonShadow:
	ChangeObjectState #$04, #$01	;; Change action step to 04
	
endLeonShadow:


I am also trying to figure out how to ignore other inputs while UP is pressed. I saw another post you replied to about doing this only in select rooms, but haven't figure out how to translate that to this. I saw some code of SuperNatetendo on snapping the player to the ladder tile, but again it's a little above me so far.
 

Mugi

Member
not exactly ignoring other inputs, but im assuming you want to ignore other movement while up is pressed in order for the character to stay in action state 4 ?
if so, this is fairly easy to do, you simply need to add a check to the beginning of any input you want to ignore in state 4, as such:

Code:
GetCurrentActionType player1_object ; load object's action state
CMP #$04 ; compare to 04
BNE + ; we are not in action state 04, go to +
RTS ; we are in action state 4, don't run the script
+

and there you go.
if you put this to the beginning of say, your move left input script, then that script will not run if the player is in action state 04, thus "the input is ignored"
 

dale_coop

Moderator
Staff member
Be careful, the Handle Extra Controls script overrides some of those animation states... when you don't touch any button, it will set you back to action step 0... when you're on a ladder or when you are in the air (jumping), it changes the action step too... etc
 

Mugi

Member
oh yes, the cursed extra controll script that always lurks there to destroy everything :p
well, same can be done to that file too thouhg, check for state 4, if state 4, dont run it.
 

Mugi

Member
dale_coop said:
Yep, I hate that script >_<

i feel you. Dimesnionshift still has it too, but it's been on my list of "shit to get sent to oblivion" for a long time now. especialy since i dont use the ladders or whatnots anymore, so all it really does is extra problems :p
 

dale_coop

Moderator
Staff member
Yeah, this script was added to change action state in some cases (ladder, in the air, ...), I can understand that... but it's causing so much troubles when you want a different behavior.
Hope in the next version this script will no more be used.
 

Craigery

Active member
Turning on the No Gravity bit prevents movement like I wanted and it now the animation plays... weird. I am still working on trying to get the player to snap to the tile.
 

dale_coop

Moderator
Staff member
"snap to the tile"? you mean... your ladder tile ?
if you could illustrate with some video or screenshots, it would help.
 

Craigery

Active member
What I mean is when I press up while on the tile the player_object will snap the the center of the tile. I believe Mega Man does this, if you are touching any part of the ladder and press up you would be centered with the ladder tile. I won't actually be using the ladder tile in this game.
 

dale_coop

Moderator
Staff member
That makes sense on a ladder... and the code is not very difficult.
A tile size is 16px... So, my next question is how is your player ? the object's size ?
 

Craigery

Active member
player is 16x16.

Left is if player_object is only partially touching tile.
Center is slightly off center.
Right is if he is centered with the tile. It allows you to see the black of the cat and the slightly different colored shadow. This is how I would like it.

https://drive.google.com/file/d/1Yd1T_dgKkjBADzVCMy_vBhrl3Rz4rItd/
 

dale_coop

Moderator
Staff member
But in fact... as I am understanding it... it's not that you would like to snap for certain tiles... you would like a 16x16grid based movements ? (that would be a totally different approach... instead of modifying the tiles scripts... I would suggest to made custom movement scripts like RIGHT:X = X + 16 ... LEFT:X = X - 16... UP:Y = Y - 16... DOWN:Y = Y + 16)?
 

dale_coop

Moderator
Staff member
Else to place the player at the horizontal center of a tile... on tile collision.
Code:
LDA tileX
AND #%11110000
STA Object_x_hi,x
 

Craigery

Active member
I tried this, but it doesn't snap. Am i interpenetrating this correctly?

Code:
	CPX player1_object	;;Loads Player
	BEQ +				;;if Branch is Equal to the player? then go to plus
	JMP endLeonShadow	;;if not then end script
+						;;continue from line 2
	LDA gamepad	;;Loads gamepad
	AND #%00010000 		;;checks if UP is pressed
	BNE startLeonShadow	;;if so then go to startLeonShadow
	JMP endLeonShadow	;;jump to endLeonShadow

startLeonShadow:
	LDA tileX				;;Load current tile x position
	AND #%11110000		;;tiles center?
	STA Object_x_hi,x		;;store
	ChangeObjectState #$06, #$01	;; Change action step to 06
	
endLeonShadow:
 

dale_coop

Moderator
Staff member
Oops, sorry, my bad... I forgot something...
try with:
Code:
LDA tileX
AND #%11110000
STA Object_x_hi,x
STA xHold_hi

else, your script is correct :)
 

Craigery

Active member
That worked! Dale you rock. Just for clarification, how does the #%11110000 translate? Like how does that mean the center of the tile? Does that mean quarters of a tile; every 2 pixels?
 

dale_coop

Moderator
Staff member
Glad it worked...
"LDA tileX" is the horizontal coord of the current collision (with the tile) but it can be anywhere from X (the coord of the left of the tile) to X+16px (16px is the width of a tile).
So doing "AND #%11110000" just removes the extra pixels (we truncate) to get just the X coord (the left of the tile).
And we assign that coord to the player X (the left coord of the player object)... and because the tile and your player has the same width (16px) we don't need to shift it (Add or Sub some px).
 
Top Bottom