Skip to content

Commit

Permalink
FIX: Now fake taps show the correct tile
Browse files Browse the repository at this point in the history
  • Loading branch information
afska committed Oct 15, 2023
1 parent 390cb34 commit 41ba7e3
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 80 deletions.
59 changes: 16 additions & 43 deletions src/objects/Arrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,17 @@
#include "utils/SpriteUtils.h"
#include "utils/pool/ObjectPool.h"

#define ARROW_ANIMATION_START_OFFSET(direction) \
((direction == ArrowDirection::UPLEFT || \
direction == ArrowDirection::UPRIGHT || \
direction == ArrowDirection::UPLEFT_DOUBLE || \
direction == ArrowDirection::UPRIGHT_DOUBLE) \
? -5 \
: 5)

#define BOUNCE_ANIMATION_START 15

inline void ARROW_initialize(ArrowDirection direction,
u32& start,
u32& startTile,
u32& endTile,
ArrowFlip& flip) {
ArrowDirection singleDirection =
static_cast<ArrowDirection>(direction % ARROWS_TOTAL);
if (singleDirection == ArrowDirection::CENTER) {
start = ARROW_FRAMES * 2;
flip = ArrowFlip::NO_FLIP;
} else {
start = ARROW_FRAMES *
(singleDirection % 2); // 0 for DOWNLEFT and DOWNRIGHT cases,
// 1 for UPLEFT and UPRIGHT cases

switch (singleDirection) {
case ArrowDirection::DOWNLEFT:
flip = ArrowFlip::NO_FLIP;
break;
case ArrowDirection::UPLEFT:
flip = ArrowFlip::FLIP_Y;
break;
case ArrowDirection::UPRIGHT:
flip = ArrowFlip::FLIP_BOTH;
break;
case ArrowDirection::DOWNRIGHT:
flip = ArrowFlip::FLIP_X;
default:
break;
}
}
startTile = ARROW_BASE_TILE[singleDirection];
endTile = ARROW_END_TILE[singleDirection];
flip = ARROW_FLIP_TILE[singleDirection];
}

class Arrow : public IPoolable {
Expand All @@ -72,34 +44,34 @@ class Arrow : public IPoolable {
bool isHoldTail = type == ArrowType::HOLD_TAIL;
bool isHoldFakeHead = type == ArrowType::HOLD_FAKE_HEAD;

u32 start = 0;
ARROW_initialize(direction, start, this->flip);
u32 startTile = 0;
u32 endTile = 0;
ARROW_initialize(direction, startTile, endTile, this->flip);
this->type = type;
this->direction = direction;
this->playerId = playerId;
this->timestamp = timestamp;
this->isFake = isFake;
this->start = start;
this->startTile = startTile;
this->endTile = endTile;
this->endAnimationStartFrame =
isHoldFakeHead ? start + ARROW_ANIMATION_START_OFFSET(direction)
: BOUNCE_ANIMATION_START;
isHoldFakeHead ? endTile : BOUNCE_ANIMATION_START;

sprite->enabled = true;
sprite->moveTo(ARROW_CORNER_MARGIN_X(playerId) + ARROW_MARGIN * direction,
ARROW_INITIAL_Y);

if (isHoldFill || isHoldTail) {
u32 tileOffset = isHoldFill ? ARROW_HOLD_FILL_TILE : ARROW_HOLD_TAIL_TILE;
SPRITE_goToFrame(sprite.get(), start + tileOffset);
SPRITE_goToFrame(sprite.get(), startTile + tileOffset);
} else if (isHoldFakeHead)
animatePress();
else if (isFake)
SPRITE_goToFrame(sprite.get(), start + ARROW_FAKE_TILE);
SPRITE_goToFrame(sprite.get(), endTile + ARROW_FAKE_TILE);
else
sprite->makeAnimated(this->start, ARROW_ANIMATION_FRAMES,
sprite->makeAnimated(startTile, ARROW_ANIMATION_FRAMES,
ARROW_ANIMATION_DELAY);

isFake = false;
siblingId = -1;
holdArrow = NULL;
isLastFill = false;
Expand Down Expand Up @@ -162,7 +134,8 @@ class Arrow : public IPoolable {

private:
std::unique_ptr<Sprite> sprite;
u32 start = 0;
u32 startTile = 0;
u32 endTile = 0;
ArrowFlip flip = ArrowFlip::NO_FLIP;
int siblingId = -1;
HoldArrow* holdArrow = NULL;
Expand Down
14 changes: 8 additions & 6 deletions src/objects/ArrowHolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
ArrowHolder::ArrowHolder(ArrowDirection direction,
u8 playerId,
bool reuseTiles) {
u32 start = 0;
ARROW_initialize(direction, start, this->flip);
u32 startTile = 0;
u32 endTile = 0;
ARROW_initialize(direction, startTile, endTile, this->flip);
this->direction = direction;
this->playerId = playerId;
this->start = start;
this->startTile = startTile;
this->endTile = endTile;

SpriteBuilder<Sprite> builder;
sprite = builder.withData(spr_arrowsTiles, sizeof(spr_arrowsTiles))
Expand All @@ -25,7 +27,7 @@ ArrowHolder::ArrowHolder(ArrowDirection direction,
if (reuseTiles)
SPRITE_reuseTiles(sprite.get());

SPRITE_goToFrame(sprite.get(), start + ARROW_HOLDER_IDLE(direction));
SPRITE_goToFrame(sprite.get(), endTile);
}

void ArrowHolder::blink() {
Expand All @@ -39,8 +41,8 @@ void ArrowHolder::tick() {
flip == ArrowFlip::FLIP_BOTH);

u32 currentFrame = sprite->getCurrentFrame();
u32 idleFrame = start + ARROW_HOLDER_IDLE(direction);
u32 pressedFrame = start + ARROW_HOLDER_PRESSED(direction);
u32 idleFrame = endTile;
u32 pressedFrame = endTile + ARROW_HOLDER_PRESSED_OFFSET;

if ((isPressed || isBlinking) && currentFrame < pressedFrame) {
SPRITE_goToFrame(sprite.get(), currentFrame + 1);
Expand Down
13 changes: 3 additions & 10 deletions src/objects/ArrowHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@
#include "Arrow.h"
#include "base/InputHandler.h"

#define ARROW_HOLDER_IDLE(direction) \
((direction == ArrowDirection::UPLEFT || \
direction == ArrowDirection::UPRIGHT || \
direction == ArrowDirection::UPLEFT_DOUBLE || \
direction == ArrowDirection::UPRIGHT_DOUBLE) \
? -5 \
: 5)

#define ARROW_HOLDER_PRESSED(direction) (ARROW_HOLDER_IDLE(direction) + 2)
#define ARROW_HOLDER_PRESSED_OFFSET 2

class ArrowHolder : public InputHandler {
public:
Expand All @@ -30,7 +22,8 @@ class ArrowHolder : public InputHandler {

private:
std::unique_ptr<Sprite> sprite;
u32 start = 0;
u32 startTile = 0;
u32 endTile = 0;
ArrowFlip flip = ArrowFlip::NO_FLIP;
bool isBlinking = false;
};
Expand Down
17 changes: 11 additions & 6 deletions src/objects/ArrowInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@
#define ARROWS_GAME_TOTAL (isDouble() ? 10 : 5)

const u32 ARROWS_TOTAL = 5;
const u32 ARROW_FRAMES = 10;
const int ARROW_OFFSCREEN_LIMIT = -13;
const u32 ARROW_TILEMAP_LOADING_ID = 1000;
const u32 ARROW_LAYER_FRONT = 0;
const u32 ARROW_LAYER_MIDDLE = 1;
const u32 ARROW_LAYER_BACK = 2;
const u32 ARROW_ANIMATION_FRAMES = 5;
const u32 ARROW_ANIMATION_DELAY = 2;
const u32 ARROW_HOLD_FILL_TILE = 9;
const u32 ARROW_HOLD_TAIL_TILE = 0;
const u32 ARROW_FAKE_TILE = 7;

const u32 ARROW_MIN_MULTIPLIER = 1;
const u32 ARROW_MAX_MULTIPLIER = 6;
Expand Down Expand Up @@ -63,4 +57,15 @@ enum ArrowDirection {
enum ArrowState { ACTIVE, OUT };
enum ArrowFlip { NO_FLIP, FLIP_X, FLIP_Y, FLIP_BOTH };

const u32 ARROW_ANIMATION_FRAMES = 5;
const u32 ARROW_ANIMATION_DELAY = 2;
const u8 ARROW_BASE_TILE[] = {0, 10, 20, 10, 0};
const u8 ARROW_END_TILE[] = {5, 5, 25, 5, 5};
const ArrowFlip ARROW_FLIP_TILE[] = {ArrowFlip::NO_FLIP, ArrowFlip::FLIP_Y,
ArrowFlip::NO_FLIP, ArrowFlip::FLIP_BOTH,
ArrowFlip::FLIP_X};
const u32 ARROW_HOLD_FILL_TILE = 9;
const u32 ARROW_HOLD_TAIL_TILE = 0;
const u32 ARROW_FAKE_TILE = 2;

#endif // ARROW_ENUMS_H
16 changes: 9 additions & 7 deletions src/objects/ui/ArrowSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ const u32 AUTOFIRE_SPEEDS = 4;
ArrowSelector::ArrowSelector(ArrowDirection direction,
bool reuseTiles,
bool reactive) {
u32 start = 0;
ARROW_initialize(direction, start, this->flip);
u32 startTile = 0;
u32 endTile = 0;
ARROW_initialize(direction, startTile, endTile, this->flip);
this->direction = direction;
this->start = start;
this->startTile = startTile;
this->endTile = endTile;
this->reactive = reactive;

SpriteBuilder<Sprite> builder;
sprite = builder.withData(spr_arrowsTiles, sizeof(spr_arrowsTiles))
.withSize(SIZE_16_16)
.withAnimated(start, ANIMATION_FRAMES, ANIMATION_DELAY)
.withAnimated(startTile, ANIMATION_FRAMES, ANIMATION_DELAY)
.withLocation(0, 0)
.buildPtr();

Expand Down Expand Up @@ -70,8 +72,8 @@ void ArrowSelector::tick() {
return;

u32 currentFrame = sprite->getCurrentFrame();
u32 idleFrame = start + ARROW_HOLDER_IDLE(direction) + 1;
u32 pressedFrame = start + ARROW_HOLDER_PRESSED(direction);
u32 idleFrame = endTile + 1;
u32 pressedFrame = endTile + ARROW_HOLDER_PRESSED_OFFSET;

if (isPressed && currentFrame != pressedFrame) {
if (currentFrame < idleFrame || currentFrame > pressedFrame)
Expand All @@ -80,5 +82,5 @@ void ArrowSelector::tick() {
SPRITE_goToFrame(sprite.get(), max(currentFrame + 1, pressedFrame));
} else if (!isPressed && currentFrame >= idleFrame &&
currentFrame <= pressedFrame)
sprite->makeAnimated(start, ANIMATION_FRAMES, ANIMATION_DELAY);
sprite->makeAnimated(startTile, ANIMATION_FRAMES, ANIMATION_DELAY);
}
3 changes: 2 additions & 1 deletion src/objects/ui/ArrowSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class ArrowSelector : public InputHandler {

private:
std::unique_ptr<Sprite> sprite;
u32 start = 0;
u32 startTile = 0;
u32 endTile = 0;
ArrowFlip flip = ArrowFlip::NO_FLIP;
bool reactive = true;
u32 globalLastPressFrame = 0;
Expand Down
11 changes: 6 additions & 5 deletions src/objects/ui/ArrowTutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
#include "utils/SpriteUtils.h"

ArrowTutorial::ArrowTutorial(ArrowDirection direction) {
u32 start = 0;
ARROW_initialize(direction, start, this->flip);
u32 startTile = 0;
u32 endTile = 0;
ARROW_initialize(direction, startTile, endTile, this->flip);
this->direction = direction;
this->start = start;
this->startTile = startTile;
this->endTile = endTile;

SpriteBuilder<Sprite> builder;
sprite = builder.withData(spr_arrowsTiles, sizeof(spr_arrowsTiles))
Expand All @@ -26,6 +28,5 @@ void ArrowTutorial::tick() {
sprite->flipVertically(flip == ArrowFlip::FLIP_Y ||
flip == ArrowFlip::FLIP_BOTH);

SPRITE_goToFrame(sprite.get(),
isOn ? start : start + ARROW_HOLDER_IDLE(direction));
SPRITE_goToFrame(sprite.get(), isOn ? startTile : endTile);
}
3 changes: 2 additions & 1 deletion src/objects/ui/ArrowTutorial.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class ArrowTutorial {

private:
std::unique_ptr<Sprite> sprite;
u32 start = 0;
u32 startTile = 0;
u32 endTile = 0;
ArrowFlip flip = ArrowFlip::NO_FLIP;
bool isOn = false;
};
Expand Down
2 changes: 1 addition & 1 deletion src/scenes/AdminScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "scenes/StartScene.h"
#include "utils/SceneUtils.h"

#define TITLE "ADMIN MENU (v1.6.0)"
#define TITLE "ADMIN MENU (v1.6.1)"
#define OPTIONS_COUNT 6
#define OPTION_ARCADE_CHARTS 0
#define OPTION_RUMBLE 1
Expand Down

0 comments on commit 41ba7e3

Please sign in to comment.