diff options
author | Simponic <loganthebean222@gmail.com> | 2020-08-11 22:13:56 -0600 |
---|---|---|
committer | Simponic <loganthebean222@gmail.com> | 2020-08-11 22:13:56 -0600 |
commit | 723f879f85f25c2d466146e08261e0ae993c72b6 (patch) | |
tree | 185f367c712554f92c14b0074503ff0667e098c3 /source/playerObject.c | |
parent | e84e232f8d003f3cf3340517d8bf6b65ba430143 (diff) | |
download | geometry-dash-gba-723f879f85f25c2d466146e08261e0ae993c72b6.tar.gz geometry-dash-gba-723f879f85f25c2d466146e08261e0ae993c72b6.zip |
Added basic camera controls
Diffstat (limited to 'source/playerObject.c')
-rw-r--r-- | source/playerObject.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/source/playerObject.c b/source/playerObject.c index 3d7ec05..98135a2 100644 --- a/source/playerObject.c +++ b/source/playerObject.c @@ -3,7 +3,7 @@ void initializePlayerObject (playerObject *object) { // Initialize the point and velocity of a player object object->vel = createVelocity(0, 0); - object->pt = createPoint(20 << FIX_SHIFT, 100 << FIX_SHIFT); + object->pt = createPoint(15 << FIX_SHIFT, 0 << FIX_SHIFT); } playerObject createPlayerObject (OBJ_ATTR *obj_buffer, OBJ_AFFINE *affine_buffer, int pallete_bank, int tile_id) { @@ -13,15 +13,15 @@ playerObject createPlayerObject (OBJ_ATTR *obj_buffer, OBJ_AFFINE *affine_buffer initializePlayerObject(&temp); temp.rotation = 0; temp.obj = obj_buffer; - temp.affine = affine_buffer; + temp.affine = affine_buffer; temp.pallete_bank = pallete_bank; temp.tile_id = tile_id; temp.isJumping = 0; obj_set_attr(temp.obj, - ATTR0_SQUARE | ATTR0_AFF | ATTR0_AFF_DBL_BIT, // Set attribute 1 to be a square using affine - ATTR1_SIZE_16 | ATTR1_AFF_ID(0), // Set size to 16 x 16 - ATTR2_PALBANK(pallete_bank) | tile_id // Which pallete to use, as we are in - // 16-color mode + ATTR0_SQUARE | ATTR0_AFF | ATTR0_AFF_DBL_BIT, // Set attribute 1 to be a square using affine and double size + ATTR1_SIZE_16 | ATTR1_AFF_ID(0), // Set size to 16 x 16 + ATTR2_PALBANK(pallete_bank) | tile_id // Which pallete to use, as we are in + // 16-color mode ); obj_set_pos(temp.obj, temp.pt.x >> FIX_SHIFT, temp.pt.y >> FIX_SHIFT); return temp; @@ -50,28 +50,27 @@ void rotatePlayer (playerObject *object) { object->affine->pc = sinAlpha; object->affine->pd = cosAlpha; } -u32 roundToNearest90Degrees(u32 rotation) { +void rotateToNearest90Degrees(playerObject *object) { // Round a rotation to the nearest 90 degree equivalent of "binary radians" // (Where 2pi = 0xFFFF and 0pi = 0) + u32 rotation = object->rotation; u32 twoPi = 0xFFFF << 4; u32 pi = 0x8000 << 4; u32 halfPi = 0x4000 << 4; u32 quarterPi = 0x2000 << 4; - if (rotation > quarterPi && rotation < 3 * quarterPi) { - return halfPi; + object->rotation = halfPi; } else if (rotation > 3 * quarterPi && rotation < (pi + quarterPi)) { - return pi; + object->rotation = pi; } else if (rotation > (pi + quarterPi) && rotation < (pi + 3*quarterPi)) { - return pi + halfPi; + object->rotation = pi + halfPi; } else if (rotation < quarterPi || rotation > (twoPi - quarterPi)) { - return 1; + object->rotation = 0; } - return 1; } void updatePlayer (playerObject *object, u32 GROUND_LEVEL) { @@ -82,7 +81,7 @@ void updatePlayer (playerObject *object, u32 GROUND_LEVEL) { object->isJumping = 0; object->pt.y = GROUND_LEVEL << FIX_SHIFT; // Don't go through ground object->vel.dy = 0; - object->rotation = roundToNearest90Degrees(object->rotation); + rotateToNearest90Degrees(object); } else { object->isJumping = 1; @@ -90,9 +89,9 @@ void updatePlayer (playerObject *object, u32 GROUND_LEVEL) { object->rotation += 100 << 8; } rotatePlayer(object); - // Update the player object's attributes' position - obj_set_pos(object->obj, object->pt.x >> FIX_SHIFT, object->pt.y >> FIX_SHIFT); + // Update the player object's attributes' position and subtract 8 pixels in + // both axes because the sprite is using the DBL_BIT for attr0 + obj_set_pos(object->obj, (object->pt.x >> FIX_SHIFT) - 8, (object->pt.y >> FIX_SHIFT) - 9); // Update the player's second attribute (tile and pallete bank) object->obj->attr2 = ATTR2_BUILD(object->tile_id, object->pallete_bank, 0); } - |