Skip to content

Commit

Permalink
improved pong controls based on orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
d03n3rfr1tz3 committed Mar 20, 2024
1 parent 86df8af commit f9751f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/app/games/pong/pong_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ PongApp::PongApp(PongIcon *icon)
{
gameInstance = this;
mParentIcon = icon;

control_orientation = display_get_rotation();

log_d("Creating game tiles...");
if (!AllocateAppTiles(2, 1))
{
Expand Down Expand Up @@ -440,7 +441,23 @@ void PongApp::UpdatePlayer1()
ttgo->bma->getAccel(acc);

// set new position by accelerator
int16_t new_position = acc.y * 0.2;
int16_t new_position = 0;
switch (control_orientation) {
case 270:
new_position = 0 - acc.x * 0.2;
break;
case 180:
new_position = acc.y * 0.2;
break;
case 90:
new_position = acc.x * 0.2;
break;
case 0:
default:
new_position = 0 - acc.y * 0.2;
break;
}

if (new_position > 0 + PLAYER_BOUNDARY) new_position = 0 + PLAYER_BOUNDARY;
if (new_position < 0 - PLAYER_BOUNDARY) new_position = 0 - PLAYER_BOUNDARY;

Expand Down Expand Up @@ -480,7 +497,7 @@ void PongApp::UpdatePlayer2()

void PongApp::UpdateBoard()
{
log_i("Updating Board to %d : %d", score_p1, score_p2);
log_d("Updating Board to %d : %d", score_p1, score_p2);

char temp[10];
snprintf(temp, sizeof(temp), "%d : %d", score_p1, score_p2);
Expand Down
1 change: 1 addition & 0 deletions src/app/games/pong/pong_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class PongApp : public GameBase
PongIcon *mParentIcon = 0;
bool pong_inited = false;
bool pong_active = false;
uint32_t control_orientation;

// Gameplay data
uint8_t ball_speed = BALL_SPEED_MIN;
Expand Down

0 comments on commit f9751f2

Please sign in to comment.