Bucket Mouse
Active member
This isn't something I need right now, just something I've been thinking about. For an adventure game to have a stealth section, it needs enemies that recognize when the player is standing in front of them. I feel like I've absorbed enough of the NES programming language that I should be able to figure this out. I did not write the ASM itself yet; just the logic that it should follow.
First you need two variables: one to load tile positions onto, and a counting variable. We also need to determine how close you need to be for the enemy to see you...let's say it's five tiles.
First we would load the address of the tile the enemy is currently standing on into variable #1. Next we would need to read which direction that enemy is currently facing.
If facing right, the program would add 1 to the first variable, If facing left, the program would subtract 1. If facing up it would subtract 16; if facing down it would add 16.
Then it would CMP that tile with player1_object to see if there's a match. If not, the program would add 1 to the counting variable, then loop. If the counting variable equals 5 the program would end...until the next frame.
If player1_object is detected, the program would JMP or JSR to another routine, where you can put whatever you want to happen.....a text box, a fired projectile, a warp to a "jail" screen.
POSSIBLE BUG: If the enemy is looking right and the distance to the edge of the screen is less than 5, the enemy's sight would stretch all the way to the next row of tiles on the left side of the screen. This could lazily be avoided by strategically placing objects so the player can't stand in that zone. An actual solution would be more complicated.
The biggest hurdle in actually writing the ASM for this would be finding the names for the directions the enemy faces, since the program needs to determine which kind of math to use. There is a FaceDirection macro, but it uses two values, not one.
First you need two variables: one to load tile positions onto, and a counting variable. We also need to determine how close you need to be for the enemy to see you...let's say it's five tiles.
First we would load the address of the tile the enemy is currently standing on into variable #1. Next we would need to read which direction that enemy is currently facing.
If facing right, the program would add 1 to the first variable, If facing left, the program would subtract 1. If facing up it would subtract 16; if facing down it would add 16.
Then it would CMP that tile with player1_object to see if there's a match. If not, the program would add 1 to the counting variable, then loop. If the counting variable equals 5 the program would end...until the next frame.
If player1_object is detected, the program would JMP or JSR to another routine, where you can put whatever you want to happen.....a text box, a fired projectile, a warp to a "jail" screen.
POSSIBLE BUG: If the enemy is looking right and the distance to the edge of the screen is less than 5, the enemy's sight would stretch all the way to the next row of tiles on the left side of the screen. This could lazily be avoided by strategically placing objects so the player can't stand in that zone. An actual solution would be more complicated.
The biggest hurdle in actually writing the ASM for this would be finding the names for the directions the enemy faces, since the program needs to determine which kind of math to use. There is a FaceDirection macro, but it uses two values, not one.