pokeemerald/src/field_camera.c

506 lines
15 KiB
C
Raw Normal View History

2017-09-30 13:08:28 -04:00
#include "global.h"
2018-04-18 17:42:41 +05:30
#include "berry.h"
#include "bike.h"
#include "field_camera.h"
#include "field_player_avatar.h"
#include "fieldmap.h"
#include "event_object_movement.h"
2018-04-18 17:42:41 +05:30
#include "gpu_regs.h"
#include "menu.h"
#include "overworld.h"
#include "rotating_gate.h"
#include "sprite.h"
#include "text.h"
2017-09-30 13:08:28 -04:00
2018-05-09 05:07:56 -05:00
EWRAM_DATA bool8 gUnusedBikeCameraAheadPanback = FALSE;
2018-10-16 14:55:16 +01:00
struct FieldCameraOffset
2017-09-30 13:08:28 -04:00
{
2018-10-16 14:55:16 +01:00
u8 xPixelOffset;
u8 yPixelOffset;
u8 xTileOffset;
u8 yTileOffset;
bool8 copyBGToVRAM;
2017-09-30 13:08:28 -04:00
};
static void RedrawMapSliceNorth(struct FieldCameraOffset *, const struct MapLayout *);
static void RedrawMapSliceSouth(struct FieldCameraOffset *, const struct MapLayout *);
static void RedrawMapSliceEast(struct FieldCameraOffset *, const struct MapLayout *);
static void RedrawMapSliceWest(struct FieldCameraOffset *, const struct MapLayout *);
static s32 MapPosToBgTilemapOffset(struct FieldCameraOffset *, s32, s32);
static void DrawWholeMapViewInternal(int, int, const struct MapLayout *);
static void DrawMetatileAt(const struct MapLayout *, u16, int, int);
2022-09-27 15:15:32 -04:00
static void DrawMetatile(s32, const u16 *, u16);
2018-04-18 17:42:41 +05:30
static void CameraPanningCB_PanAhead(void);
static struct FieldCameraOffset sFieldCameraOffset;
static s16 sHorizontalCameraPan;
static s16 sVerticalCameraPan;
2021-04-06 17:17:41 -04:00
static bool8 sBikeCameraPanFlag;
static void (*sFieldCameraPanningCallback)(void);
2018-04-18 17:42:41 +05:30
2018-10-16 14:55:16 +01:00
struct CameraObject gFieldCamera;
u16 gTotalCameraPixelOffsetY;
u16 gTotalCameraPixelOffsetX;
2018-05-09 05:07:56 -05:00
static void ResetCameraOffset(struct FieldCameraOffset *cameraOffset)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
cameraOffset->xTileOffset = 0;
cameraOffset->yTileOffset = 0;
cameraOffset->xPixelOffset = 0;
cameraOffset->yPixelOffset = 0;
cameraOffset->copyBGToVRAM = TRUE;
2018-04-18 17:42:41 +05:30
}
static void AddCameraTileOffset(struct FieldCameraOffset *cameraOffset, u32 xOffset, u32 yOffset)
2018-04-18 17:42:41 +05:30
{
cameraOffset->xTileOffset += xOffset;
2018-10-16 14:55:16 +01:00
cameraOffset->xTileOffset %= 32;
cameraOffset->yTileOffset += yOffset;
2018-10-16 14:55:16 +01:00
cameraOffset->yTileOffset %= 32;
2018-04-18 17:42:41 +05:30
}
static void AddCameraPixelOffset(struct FieldCameraOffset *cameraOffset, u32 xOffset, u32 yOffset)
2018-04-18 17:42:41 +05:30
{
cameraOffset->xPixelOffset += xOffset;
cameraOffset->yPixelOffset += yOffset;
2018-04-18 17:42:41 +05:30
}
void ResetFieldCamera(void)
2018-04-18 17:42:41 +05:30
{
ResetCameraOffset(&sFieldCameraOffset);
2018-04-18 17:42:41 +05:30
}
void FieldUpdateBgTilemapScroll(void)
{
u32 r4, r5;
2018-10-16 14:55:16 +01:00
r5 = sFieldCameraOffset.xPixelOffset + sHorizontalCameraPan;
r4 = sVerticalCameraPan + sFieldCameraOffset.yPixelOffset + 8;
2018-04-18 17:42:41 +05:30
SetGpuReg(REG_OFFSET_BG1HOFS, r5);
SetGpuReg(REG_OFFSET_BG1VOFS, r4);
SetGpuReg(REG_OFFSET_BG2HOFS, r5);
SetGpuReg(REG_OFFSET_BG2VOFS, r4);
SetGpuReg(REG_OFFSET_BG3HOFS, r5);
SetGpuReg(REG_OFFSET_BG3VOFS, r4);
}
2021-04-06 17:17:41 -04:00
void GetCameraOffsetWithPan(s16 *x, s16 *y)
2018-04-18 17:42:41 +05:30
{
*x = sFieldCameraOffset.xPixelOffset + sHorizontalCameraPan;
*y = sFieldCameraOffset.yPixelOffset + sVerticalCameraPan + 8;
2018-04-18 17:42:41 +05:30
}
void DrawWholeMapView(void)
{
2018-06-20 17:41:51 -05:00
DrawWholeMapViewInternal(gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y, gMapHeader.mapLayout);
2018-10-16 14:55:16 +01:00
sFieldCameraOffset.copyBGToVRAM = TRUE;
2018-04-18 17:42:41 +05:30
}
2018-06-20 17:41:51 -05:00
static void DrawWholeMapViewInternal(int x, int y, const struct MapLayout *mapLayout)
2018-04-18 17:42:41 +05:30
{
u8 i;
u8 j;
u32 r6;
u8 temp;
for (i = 0; i < 32; i += 2)
{
2018-10-16 14:55:16 +01:00
temp = sFieldCameraOffset.yTileOffset + i;
2018-04-18 17:42:41 +05:30
if (temp >= 32)
temp -= 32;
r6 = temp * 32;
for (j = 0; j < 32; j += 2)
{
2018-10-16 14:55:16 +01:00
temp = sFieldCameraOffset.xTileOffset + j;
2018-04-18 17:42:41 +05:30
if (temp >= 32)
temp -= 32;
2018-06-20 17:41:51 -05:00
DrawMetatileAt(mapLayout, r6 + temp, x + j / 2, y + i / 2);
2018-04-18 17:42:41 +05:30
}
}
}
2018-10-16 14:55:16 +01:00
static void RedrawMapSlicesForCameraUpdate(struct FieldCameraOffset *cameraOffset, int x, int y)
2018-04-18 17:42:41 +05:30
{
2018-06-20 17:41:51 -05:00
const struct MapLayout *mapLayout = gMapHeader.mapLayout;
2018-04-18 17:42:41 +05:30
if (x > 0)
2018-10-16 14:55:16 +01:00
RedrawMapSliceWest(cameraOffset, mapLayout);
2018-04-18 17:42:41 +05:30
if (x < 0)
2018-10-16 14:55:16 +01:00
RedrawMapSliceEast(cameraOffset, mapLayout);
2018-04-18 17:42:41 +05:30
if (y > 0)
2018-10-16 14:55:16 +01:00
RedrawMapSliceNorth(cameraOffset, mapLayout);
2018-04-18 17:42:41 +05:30
if (y < 0)
2018-10-16 14:55:16 +01:00
RedrawMapSliceSouth(cameraOffset, mapLayout);
cameraOffset->copyBGToVRAM = TRUE;
2018-04-18 17:42:41 +05:30
}
2018-10-16 14:55:16 +01:00
static void RedrawMapSliceNorth(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout)
2018-04-18 17:42:41 +05:30
{
u8 i;
u8 temp;
u32 r7;
2018-10-16 14:55:16 +01:00
temp = cameraOffset->yTileOffset + 28;
2018-04-18 17:42:41 +05:30
if (temp >= 32)
temp -= 32;
r7 = temp * 32;
for (i = 0; i < 32; i += 2)
{
2018-10-16 14:55:16 +01:00
temp = cameraOffset->xTileOffset + i;
2018-04-18 17:42:41 +05:30
if (temp >= 32)
temp -= 32;
2018-06-20 17:41:51 -05:00
DrawMetatileAt(mapLayout, r7 + temp, gSaveBlock1Ptr->pos.x + i / 2, gSaveBlock1Ptr->pos.y + 14);
2018-04-18 17:42:41 +05:30
}
}
2018-10-16 14:55:16 +01:00
static void RedrawMapSliceSouth(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout)
2018-04-18 17:42:41 +05:30
{
u8 i;
u8 temp;
2018-10-16 14:55:16 +01:00
u32 r7 = cameraOffset->yTileOffset * 32;
2018-04-18 17:42:41 +05:30
for (i = 0; i < 32; i += 2)
{
2018-10-16 14:55:16 +01:00
temp = cameraOffset->xTileOffset + i;
2018-04-18 17:42:41 +05:30
if (temp >= 32)
temp -= 32;
2018-06-20 17:41:51 -05:00
DrawMetatileAt(mapLayout, r7 + temp, gSaveBlock1Ptr->pos.x + i / 2, gSaveBlock1Ptr->pos.y);
2018-04-18 17:42:41 +05:30
}
}
2018-10-16 14:55:16 +01:00
static void RedrawMapSliceEast(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout)
2018-04-18 17:42:41 +05:30
{
u8 i;
u8 temp;
2018-10-16 14:55:16 +01:00
u32 r6 = cameraOffset->xTileOffset;
2018-04-18 17:42:41 +05:30
for (i = 0; i < 32; i += 2)
{
2018-10-16 14:55:16 +01:00
temp = cameraOffset->yTileOffset + i;
2018-04-18 17:42:41 +05:30
if (temp >= 32)
temp -= 32;
2018-06-20 17:41:51 -05:00
DrawMetatileAt(mapLayout, temp * 32 + r6, gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y + i / 2);
2018-04-18 17:42:41 +05:30
}
}
2018-10-16 14:55:16 +01:00
static void RedrawMapSliceWest(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout)
2018-04-18 17:42:41 +05:30
{
u8 i;
u8 temp;
2018-10-16 14:55:16 +01:00
u8 r5 = cameraOffset->xTileOffset + 28;
2018-04-18 17:42:41 +05:30
if (r5 >= 32)
r5 -= 32;
for (i = 0; i < 32; i += 2)
{
2018-10-16 14:55:16 +01:00
temp = cameraOffset->yTileOffset + i;
2018-04-18 17:42:41 +05:30
if (temp >= 32)
temp -= 32;
2018-06-20 17:41:51 -05:00
DrawMetatileAt(mapLayout, temp * 32 + r5, gSaveBlock1Ptr->pos.x + 14, gSaveBlock1Ptr->pos.y + i / 2);
2018-04-18 17:42:41 +05:30
}
}
2018-10-16 14:55:16 +01:00
void CurrentMapDrawMetatileAt(int x, int y)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
int offset = MapPosToBgTilemapOffset(&sFieldCameraOffset, x, y);
2018-04-18 17:42:41 +05:30
if (offset >= 0)
{
2018-10-16 14:55:16 +01:00
DrawMetatileAt(gMapHeader.mapLayout, offset, x, y);
sFieldCameraOffset.copyBGToVRAM = TRUE;
2018-04-18 17:42:41 +05:30
}
}
2022-05-17 17:13:29 -04:00
void DrawDoorMetatileAt(int x, int y, u16 *tiles)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
int offset = MapPosToBgTilemapOffset(&sFieldCameraOffset, x, y);
2018-04-18 17:42:41 +05:30
if (offset >= 0)
{
2022-05-17 17:13:29 -04:00
DrawMetatile(METATILE_LAYER_TYPE_COVERED, tiles, offset);
2018-10-16 14:55:16 +01:00
sFieldCameraOffset.copyBGToVRAM = TRUE;
2018-04-18 17:42:41 +05:30
}
}
2018-10-16 14:55:16 +01:00
static void DrawMetatileAt(const struct MapLayout *mapLayout, u16 offset, int x, int y)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
u16 metatileId = MapGridGetMetatileIdAt(x, y);
2022-09-27 15:15:32 -04:00
const u16 *metatiles;
2018-04-18 17:42:41 +05:30
if (metatileId > NUM_METATILES_TOTAL)
2018-04-18 17:42:41 +05:30
metatileId = 0;
if (metatileId < NUM_METATILES_IN_PRIMARY)
2018-06-20 17:41:51 -05:00
metatiles = mapLayout->primaryTileset->metatiles;
2018-04-18 17:42:41 +05:30
else
{
2018-06-20 17:41:51 -05:00
metatiles = mapLayout->secondaryTileset->metatiles;
metatileId -= NUM_METATILES_IN_PRIMARY;
2018-04-18 17:42:41 +05:30
}
2022-12-03 17:29:02 -05:00
DrawMetatile(MapGridGetMetatileLayerTypeAt(x, y), metatiles + metatileId * NUM_TILES_PER_METATILE, offset);
2018-04-18 17:42:41 +05:30
}
2022-09-27 15:15:32 -04:00
static void DrawMetatile(s32 metatileLayerType, const u16 *tiles, u16 offset)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
switch (metatileLayerType)
2018-04-18 17:42:41 +05:30
{
case METATILE_LAYER_TYPE_SPLIT:
2018-10-16 14:55:16 +01:00
// Draw metatile's bottom layer to the bottom background layer.
gOverworldTilemapBuffer_Bg3[offset] = tiles[0];
gOverworldTilemapBuffer_Bg3[offset + 1] = tiles[1];
gOverworldTilemapBuffer_Bg3[offset + 0x20] = tiles[2];
gOverworldTilemapBuffer_Bg3[offset + 0x21] = tiles[3];
2018-10-16 14:55:16 +01:00
// Draw transparent tiles to the middle background layer.
gOverworldTilemapBuffer_Bg2[offset] = 0;
gOverworldTilemapBuffer_Bg2[offset + 1] = 0;
gOverworldTilemapBuffer_Bg2[offset + 0x20] = 0;
gOverworldTilemapBuffer_Bg2[offset + 0x21] = 0;
2018-10-16 14:55:16 +01:00
// Draw metatile's top layer to the top background layer.
gOverworldTilemapBuffer_Bg1[offset] = tiles[4];
gOverworldTilemapBuffer_Bg1[offset + 1] = tiles[5];
gOverworldTilemapBuffer_Bg1[offset + 0x20] = tiles[6];
gOverworldTilemapBuffer_Bg1[offset + 0x21] = tiles[7];
2018-04-18 17:42:41 +05:30
break;
case METATILE_LAYER_TYPE_COVERED:
2018-10-16 14:55:16 +01:00
// Draw metatile's bottom layer to the bottom background layer.
gOverworldTilemapBuffer_Bg3[offset] = tiles[0];
gOverworldTilemapBuffer_Bg3[offset + 1] = tiles[1];
gOverworldTilemapBuffer_Bg3[offset + 0x20] = tiles[2];
gOverworldTilemapBuffer_Bg3[offset + 0x21] = tiles[3];
2018-10-16 14:55:16 +01:00
// Draw metatile's top layer to the middle background layer.
gOverworldTilemapBuffer_Bg2[offset] = tiles[4];
gOverworldTilemapBuffer_Bg2[offset + 1] = tiles[5];
gOverworldTilemapBuffer_Bg2[offset + 0x20] = tiles[6];
gOverworldTilemapBuffer_Bg2[offset + 0x21] = tiles[7];
2018-10-16 14:55:16 +01:00
// Draw transparent tiles to the top background layer.
gOverworldTilemapBuffer_Bg1[offset] = 0;
gOverworldTilemapBuffer_Bg1[offset + 1] = 0;
gOverworldTilemapBuffer_Bg1[offset + 0x20] = 0;
gOverworldTilemapBuffer_Bg1[offset + 0x21] = 0;
2018-04-18 17:42:41 +05:30
break;
case METATILE_LAYER_TYPE_NORMAL:
2018-10-16 14:55:16 +01:00
// Draw garbage to the bottom background layer.
gOverworldTilemapBuffer_Bg3[offset] = 0x3014;
gOverworldTilemapBuffer_Bg3[offset + 1] = 0x3014;
gOverworldTilemapBuffer_Bg3[offset + 0x20] = 0x3014;
gOverworldTilemapBuffer_Bg3[offset + 0x21] = 0x3014;
2018-10-16 14:55:16 +01:00
// Draw metatile's bottom layer to the middle background layer.
gOverworldTilemapBuffer_Bg2[offset] = tiles[0];
gOverworldTilemapBuffer_Bg2[offset + 1] = tiles[1];
gOverworldTilemapBuffer_Bg2[offset + 0x20] = tiles[2];
gOverworldTilemapBuffer_Bg2[offset + 0x21] = tiles[3];
2018-10-16 14:55:16 +01:00
// Draw metatile's top layer to the top background layer, which covers object event sprites.
gOverworldTilemapBuffer_Bg1[offset] = tiles[4];
gOverworldTilemapBuffer_Bg1[offset + 1] = tiles[5];
gOverworldTilemapBuffer_Bg1[offset + 0x20] = tiles[6];
gOverworldTilemapBuffer_Bg1[offset + 0x21] = tiles[7];
2018-04-18 17:42:41 +05:30
break;
}
2020-05-14 01:37:09 -07:00
ScheduleBgCopyTilemapToVram(1);
ScheduleBgCopyTilemapToVram(2);
ScheduleBgCopyTilemapToVram(3);
2018-04-18 17:42:41 +05:30
}
2018-10-16 14:55:16 +01:00
static s32 MapPosToBgTilemapOffset(struct FieldCameraOffset *cameraOffset, s32 x, s32 y)
2018-04-18 17:42:41 +05:30
{
x -= gSaveBlock1Ptr->pos.x;
x *= 2;
if (x >= 32 || x < 0)
return -1;
2018-10-16 14:55:16 +01:00
x = x + cameraOffset->xTileOffset;
2018-04-18 17:42:41 +05:30
if (x >= 32)
x -= 32;
y = (y - gSaveBlock1Ptr->pos.y) * 2;
if (y >= 32 || y < 0)
return -1;
2018-10-16 14:55:16 +01:00
y = y + cameraOffset->yTileOffset;
2018-04-18 17:42:41 +05:30
if (y >= 32)
y -= 32;
return y * 32 + x;
}
2018-10-16 14:55:16 +01:00
static void CameraUpdateCallback(struct CameraObject *fieldCamera)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
if (fieldCamera->spriteId != 0)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
fieldCamera->movementSpeedX = gSprites[fieldCamera->spriteId].data[2];
fieldCamera->movementSpeedY = gSprites[fieldCamera->spriteId].data[3];
2018-04-18 17:42:41 +05:30
}
}
void ResetCameraUpdateInfo(void)
{
2018-10-16 14:55:16 +01:00
gFieldCamera.movementSpeedX = 0;
gFieldCamera.movementSpeedY = 0;
gFieldCamera.x = 0;
gFieldCamera.y = 0;
gFieldCamera.spriteId = 0;
gFieldCamera.callback = NULL;
2018-04-18 17:42:41 +05:30
}
2018-10-16 14:55:16 +01:00
u32 InitCameraUpdateCallback(u8 trackedSpriteId)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
if (gFieldCamera.spriteId != 0)
DestroySprite(&gSprites[gFieldCamera.spriteId]);
gFieldCamera.spriteId = AddCameraObject(trackedSpriteId);
gFieldCamera.callback = CameraUpdateCallback;
2018-04-18 17:42:41 +05:30
return 0;
}
void CameraUpdate(void)
{
int deltaX;
int deltaY;
2018-10-16 14:55:16 +01:00
int curMovementOffsetY;
int curMovementOffsetX;
int movementSpeedX;
int movementSpeedY;
if (gFieldCamera.callback != NULL)
gFieldCamera.callback(&gFieldCamera);
movementSpeedX = gFieldCamera.movementSpeedX;
movementSpeedY = gFieldCamera.movementSpeedY;
2018-04-18 17:42:41 +05:30
deltaX = 0;
deltaY = 0;
2018-10-16 14:55:16 +01:00
curMovementOffsetX = gFieldCamera.x;
curMovementOffsetY = gFieldCamera.y;
2018-04-18 17:42:41 +05:30
2018-10-16 14:55:16 +01:00
if (curMovementOffsetX == 0 && movementSpeedX != 0)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
if (movementSpeedX > 0)
2018-04-18 17:42:41 +05:30
deltaX = 1;
else
deltaX = -1;
}
2018-10-16 14:55:16 +01:00
if (curMovementOffsetY == 0 && movementSpeedY != 0)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
if (movementSpeedY > 0)
2018-04-18 17:42:41 +05:30
deltaY = 1;
else
deltaY = -1;
}
2018-10-16 14:55:16 +01:00
if (curMovementOffsetX != 0 && curMovementOffsetX == -movementSpeedX)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
if (movementSpeedX > 0)
2018-04-18 17:42:41 +05:30
deltaX = 1;
else
deltaX = -1;
}
2018-10-16 14:55:16 +01:00
if (curMovementOffsetY != 0 && curMovementOffsetY == -movementSpeedY)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
if (movementSpeedY > 0)
2018-04-18 17:42:41 +05:30
deltaX = 1;
else
deltaX = -1;
}
2018-10-16 14:55:16 +01:00
gFieldCamera.x += movementSpeedX;
2022-07-04 21:25:19 +01:00
gFieldCamera.x %= 16;
2018-10-16 14:55:16 +01:00
gFieldCamera.y += movementSpeedY;
2022-07-04 21:25:19 +01:00
gFieldCamera.y %= 16;
2018-04-18 17:42:41 +05:30
if (deltaX != 0 || deltaY != 0)
{
CameraMove(deltaX, deltaY);
UpdateObjectEventsForCameraUpdate(deltaX, deltaY);
2018-04-18 17:42:41 +05:30
RotatingGatePuzzleCameraUpdate(deltaX, deltaY);
2021-01-26 05:16:01 -05:00
SetBerryTreesSeen();
AddCameraTileOffset(&sFieldCameraOffset, deltaX * 2, deltaY * 2);
2018-10-16 14:55:16 +01:00
RedrawMapSlicesForCameraUpdate(&sFieldCameraOffset, deltaX * 2, deltaY * 2);
2018-04-18 17:42:41 +05:30
}
AddCameraPixelOffset(&sFieldCameraOffset, movementSpeedX, movementSpeedY);
2018-10-16 14:55:16 +01:00
gTotalCameraPixelOffsetX -= movementSpeedX;
gTotalCameraPixelOffsetY -= movementSpeedY;
2018-04-18 17:42:41 +05:30
}
2018-10-16 14:55:16 +01:00
void MoveCameraAndRedrawMap(int deltaX, int deltaY) //unused
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
CameraMove(deltaX, deltaY);
UpdateObjectEventsForCameraUpdate(deltaX, deltaY);
2018-04-18 17:42:41 +05:30
DrawWholeMapView();
2018-10-16 14:55:16 +01:00
gTotalCameraPixelOffsetX -= deltaX * 16;
gTotalCameraPixelOffsetY -= deltaY * 16;
2018-04-18 17:42:41 +05:30
}
void SetCameraPanningCallback(void (*callback)(void))
2018-04-18 17:42:41 +05:30
{
sFieldCameraPanningCallback = callback;
2018-04-18 17:42:41 +05:30
}
2022-06-01 12:41:57 -04:00
void SetCameraPanning(s16 horizontal, s16 vertical)
2018-04-18 17:42:41 +05:30
{
2022-06-01 12:41:57 -04:00
sHorizontalCameraPan = horizontal;
sVerticalCameraPan = vertical + 32;
2018-04-18 17:42:41 +05:30
}
void InstallCameraPanAheadCallback(void)
{
2018-10-16 14:55:16 +01:00
sFieldCameraPanningCallback = CameraPanningCB_PanAhead;
2021-04-06 17:17:41 -04:00
sBikeCameraPanFlag = FALSE;
2018-10-16 14:55:16 +01:00
sHorizontalCameraPan = 0;
sVerticalCameraPan = 32;
2018-04-18 17:42:41 +05:30
}
void UpdateCameraPanning(void)
{
2018-10-16 14:55:16 +01:00
if (sFieldCameraPanningCallback != NULL)
sFieldCameraPanningCallback();
2018-04-18 17:42:41 +05:30
//Update sprite offset of overworld objects
2018-10-16 14:55:16 +01:00
gSpriteCoordOffsetX = gTotalCameraPixelOffsetX - sHorizontalCameraPan;
gSpriteCoordOffsetY = gTotalCameraPixelOffsetY - sVerticalCameraPan - 8;
2018-04-18 17:42:41 +05:30
}
static void CameraPanningCB_PanAhead(void)
{
u8 var;
2017-09-30 13:08:28 -04:00
2018-04-18 17:42:41 +05:30
if (gUnusedBikeCameraAheadPanback == FALSE)
{
InstallCameraPanAheadCallback();
}
else
{
2021-04-06 17:17:41 -04:00
// this code is never reached
2018-04-18 17:42:41 +05:30
if (gPlayerAvatar.tileTransitionState == T_TILE_TRANSITION)
{
2021-04-06 17:17:41 -04:00
sBikeCameraPanFlag ^= 1;
if (sBikeCameraPanFlag == FALSE)
2018-04-18 17:42:41 +05:30
return;
}
else
{
2021-04-06 17:17:41 -04:00
sBikeCameraPanFlag = FALSE;
2018-04-18 17:42:41 +05:30
}
2017-09-30 13:08:28 -04:00
var = GetPlayerMovementDirection();
2018-04-18 17:42:41 +05:30
if (var == 2)
{
2018-10-16 14:55:16 +01:00
if (sVerticalCameraPan > -8)
sVerticalCameraPan -= 2;
2018-04-18 17:42:41 +05:30
}
else if (var == 1)
{
2018-10-16 14:55:16 +01:00
if (sVerticalCameraPan < 72)
sVerticalCameraPan += 2;
2018-04-18 17:42:41 +05:30
}
2018-10-16 14:55:16 +01:00
else if (sVerticalCameraPan < 32)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
sVerticalCameraPan += 2;
2018-04-18 17:42:41 +05:30
}
2018-10-16 14:55:16 +01:00
else if (sVerticalCameraPan > 32)
2018-04-18 17:42:41 +05:30
{
2018-10-16 14:55:16 +01:00
sVerticalCameraPan -= 2;
2018-04-18 17:42:41 +05:30
}
}
}