summaryrefslogtreecommitdiff
path: root/Turn-to-face-enemy-trainers-when-seen-by-them.md
blob: 212dbcff93311565ddf478062327816449ba2f75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
In all the Pokémon games after Gen 1 (with the exception of FireRed/LeafGreen, who wanted to mimic Gen 1 in this way) the player turns to face an enemy trainer after they see you and walk up to you. Have you ever wanted that to happen in your hack of Red and Blue? It's fairly simple to.

First off, let's go to [engine/overworld/trainer_sight.asm](../blob/master/engine/overworld/trainer_sight.asm) and add a small routine at the end of the file.

```

FaceEnemyTrainer::
	ld a, [wTrainerFacingDirection]
	and a ; SPRITE_FACING_DOWN
	jr z, .facingDown
	cp SPRITE_FACING_UP
	jr z, .facingUp
	cp SPRITE_FACING_LEFT
	jr z, .facingLeft
	jr .facingRight
.facingDown
	ld a, PLAYER_DIR_UP
	jr .done
.facingUp
	ld a, PLAYER_DIR_DOWN
	jr .done
.facingLeft
	ld a, PLAYER_DIR_RIGHT
	jr .done
.facingRight
	ld a, PLAYER_DIR_LEFT
.done
	ld [wPlayerMovingDirection], a ; update player facing
	ret
```

Basically, this routine just checks which direction the enemy trainer is facing, then updates the player's facing direction accordingly, so that the player turns toward the enemy trainer.

Next, we have to actually call this routine for it to take effect. So take a look in [home/trainers.asm](../blob/master/home/trainers.asm) and find the routine called `CheckFightingMapTrainers::` and change this line accordingly:
```diff
	xor a ; EXCLAMATION_BUBBLE
	ld [wWhichEmotionBubble], a
	predef EmotionBubble
-	ld a, D_RIGHT | D_LEFT | D_UP | D_DOWN
+	ld a, $ff
	ld [wJoyIgnore], a
```

We want to ignore all input, not just the arrow keys, because in some situations (such as the final trainer in Viridian Forest) pressing "A" can cause interference as well, since there is a hidden item nearby. And let's face it, players are likely to be spamming "A" while this code is running. So we nip that problem in the bud with this change.

Then scroll down a little to find `DisplayEnemyTrainerTextAndStartBattle::` and edit it like so:

```diff
	ret nz ; return if the enemy trainer hasn't finished walking to the player's sprite
+	farcall FaceEnemyTrainer
+	xor a
	ld [wJoyIgnore], a
	ld a, [wSpriteIndex]
```
This calls the new routine we wrote before, and continues on with the original code as if nothing ever happened. And it's as simple as that! Now when a trainer spots you and walks up to challenge you, you will turn to look at them before they start talking to you and start the battle, just like they do in every other Pokémon game that isn't Gen 1 or its remakes.