Skip to content

Commit

Permalink
stop scores during debug, reset during tilt
Browse files Browse the repository at this point in the history
  • Loading branch information
rdefeo committed Dec 5, 2024
1 parent 696294b commit 2a14ce2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
14 changes: 14 additions & 0 deletions objects.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ void FixedObject::signal_send() {
hidden = true;
}

void FixedObject::save_state() {
saved.physical = physical;
saved.hidden = hidden;
}

void FixedObject::reset_state() {
physical = saved.physical;
hidden = saved.hidden;
}

void Polygon::draw(Canvas* canvas) {
if(!hidden) {
for(size_t i = 0; i < points.size() - 1; i++) {
Expand Down Expand Up @@ -553,6 +563,10 @@ void Rollover::signal_send() {
// maybe we should start a blink animation of the letters?
}

void Rollover::reset_state() {
activated = false;
}

void Turbo::draw(Canvas* canvas) {
gfx_draw_line(canvas, chevron_1[0], chevron_1[1]);
gfx_draw_line(canvas, chevron_1[1], chevron_1[2]);
Expand Down
10 changes: 10 additions & 0 deletions objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,21 @@ class FixedObject {

void (*notification)(void* app);

struct {
bool physical;
bool hidden;
} saved;

virtual void draw(Canvas* canvas) = 0;
virtual bool collide(Ball& ball) = 0;
virtual void reset_animation() {};
virtual void step_animation() {};

virtual void signal_receive();
virtual void signal_send();

virtual void save_state();
virtual void reset_state();
};

class Polygon : public FixedObject {
Expand Down Expand Up @@ -227,6 +235,8 @@ class Rollover : public FixedObject {

void signal_receive();
void signal_send();

void reset_state();
};

class Turbo : public FixedObject {
Expand Down
24 changes: 16 additions & 8 deletions pinball0.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ void solve(PinballApp* pb, float dt) {
for(auto& b : table->balls) {
for(auto& o : table->objects) {
if(o->physical && o->collide(b)) {
if(pb->game_mode == GM_Tilted) {
if(pb->game_mode == GM_Tilted || table->balls_released == false) {
o->reset_state(); // ensure we do nothing!
continue;
}
if(o->notification) {
Expand Down Expand Up @@ -175,8 +176,8 @@ static void pinball_draw_callback(Canvas* const canvas, void* ctx) {
AlignTop,
furi_string_get_cstr(menu_item.name));
if(i == half_way) {
canvas_draw_disc(canvas, 8, y + 3, 2);
canvas_draw_disc(canvas, 56, y + 3, 2);
canvas_draw_disc(canvas, 6, y + 3, 2);
canvas_draw_disc(canvas, 58, y + 3, 2);
}
y += 12;
}
Expand Down Expand Up @@ -453,6 +454,7 @@ extern "C" int32_t pinball0_app(void* p) {
if(app.settings.debug_mode && app.table->balls_released == false) {
app.table->balls[0].p.x += MANUAL_ADJUSTMENT;
app.table->balls[0].prev_p.x += MANUAL_ADJUSTMENT;
break;
}
bool flipper_pressed = false;
for(auto& f : app.table->flippers) {
Expand All @@ -477,6 +479,7 @@ extern "C" int32_t pinball0_app(void* p) {
if(app.settings.debug_mode && app.table->balls_released == false) {
app.table->balls[0].p.x -= MANUAL_ADJUSTMENT;
app.table->balls[0].prev_p.x -= MANUAL_ADJUSTMENT;
break;
}
bool flipper_pressed = false;
for(auto& f : app.table->flippers) {
Expand All @@ -494,6 +497,11 @@ extern "C" int32_t pinball0_app(void* p) {
case InputKeyUp:
switch(app.game_mode) {
case GM_Playing:
if(app.settings.debug_mode && app.table->balls_released == false) {
app.table->balls[0].p.y -= MANUAL_ADJUSTMENT;
app.table->balls[0].prev_p.y -= MANUAL_ADJUSTMENT;
break;
}
if(event.type == InputTypePress) {
// Table bump and Tilt tracking
uint32_t current_tick = furi_get_tick();
Expand All @@ -508,14 +516,13 @@ extern "C" int32_t pinball0_app(void* p) {
FURI_LOG_W(TAG, "TABLE TILTED!");
app.game_mode = GM_Tilted;
app.table->bump_count = 0;
for(auto& o : app.table->objects) {
o->reset_state();
}
notify_table_tilted(&app);
}
}
}
if(app.settings.debug_mode && app.table->balls_released == false) {
app.table->balls[0].p.y -= MANUAL_ADJUSTMENT;
app.table->balls[0].prev_p.y -= MANUAL_ADJUSTMENT;
}
break;
case GM_TableSelect:
app.table_list.selected =
Expand All @@ -535,11 +542,12 @@ extern "C" int32_t pinball0_app(void* p) {
case InputKeyDown:
switch(app.game_mode) {
case GM_Playing:
app.keys[InputKeyDown] = true;
if(app.settings.debug_mode && app.table->balls_released == false) {
app.table->balls[0].p.y += MANUAL_ADJUSTMENT;
app.table->balls[0].prev_p.y += MANUAL_ADJUSTMENT;
break;
}
app.keys[InputKeyDown] = true;
break;
case GM_TableSelect:
app.table_list.selected =
Expand Down
6 changes: 5 additions & 1 deletion table_parser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,11 @@ Table* table_load_table_from_file(PinballApp* pb, size_t index) {
table->objects.push_back(new_turbo);
}
}
break;

for(auto& o : table->objects) {
o->save_state();
}

} while(false);

if(!table->sm.validate(pb->text, 256)) {
Expand Down

0 comments on commit 2a14ce2

Please sign in to comment.