From 8b31d9ed2eb64ed8bb6b8b433d7c6a2711320584 Mon Sep 17 00:00:00 2001 From: SlyVTT Date: Mon, 11 Sep 2023 22:43:25 +0200 Subject: [PATCH] added bucket and relauncher --- CMakeLists.txt | 2 +- src/Pinball/pinball_entities.h | 24 ++++++++++++++++++++++++ src/Pinball/tables.h | 16 ++++++++++++---- src/main.cpp | 22 ++++++++++++++++++++-- src/parameters.h | 2 ++ 5 files changed, 59 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 338b9f1..f42c271 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ set(ASSETS set(ASSETS_cg assets-cg/font.png assets-cg/font_pinball.png - assets-cg/abyss.png + # assets-cg/abyss.png # ... ) diff --git a/src/Pinball/pinball_entities.h b/src/Pinball/pinball_entities.h index 6bdb478..328cec6 100644 --- a/src/Pinball/pinball_entities.h +++ b/src/Pinball/pinball_entities.h @@ -42,6 +42,25 @@ public: this->pos.Add(this->vel, dt); } + void SetSpeed( Vector2D speed ){ + this->vel = speed.Clone(); + } + + void SetPosition( Vector2D position ){ + this->pos = position.Clone(); + } + + bool IsStopped( void ) { + if (this->vel.Length() <= libnum::num32( 0.02 ) ) return true; + else return false; + } + + bool IsInBucket( Vector2D BucketMin, Vector2D BucketMax ) { + if (this->pos.x >= BucketMin.x && this->pos.y >= BucketMin.y && + this->pos.x <= BucketMax.x && this->pos.y <= BucketMax.y) return true; + else return false; + } + libnum::num32 radius, mass, restitution; Vector2D pos, vel; uint16_t color; @@ -201,6 +220,11 @@ struct Scene Vector2D Lock_pos; uint16_t Lock_color; + Vector2D BucketMin, BucketMax; + + uint8_t CurrentBallToLaunch; + Vector2D InitialPosition; + }; diff --git a/src/Pinball/tables.h b/src/Pinball/tables.h index a84fa7c..e19f708 100644 --- a/src/Pinball/tables.h +++ b/src/Pinball/tables.h @@ -16,7 +16,7 @@ libnum::num32 cScale; libnum::num32 simWidth; libnum::num32 simHeight; -extern bopti_image_t img_abyss; +// extern bopti_image_t img_abyss; extern uint8_t CurrentSequence; @@ -333,7 +333,7 @@ void Setup_Table_3(void) { MyPinball.score = 0; MyPinball.gravity.Set(Vector2D(libnum::num32(0.0), libnum::num32(-1.0))); - MyPinball.sideimage = &img_abyss; + MyPinball.sideimage = nullptr; // &img_abyss; MyPinball.borders.clear(); MyPinball.borders.emplace_back(libnum::num32(0.74), libnum::num32(0.25)); @@ -457,7 +457,7 @@ void Setup_Table_4(void) { MyPinball.score = 0; MyPinball.gravity.Set(Vector2D(libnum::num32(0.0), libnum::num32(-1.0))); - MyPinball.sideimage = &img_abyss; + MyPinball.sideimage = nullptr ; //&img_abyss; MyPinball.borders.clear(); MyPinball.borders.emplace_back( libnum::num32(0.74), libnum::num32(0.25) ); @@ -641,16 +641,24 @@ void Setup_Table_5(void) { MyPinball.Lock_color = RGB565_LEMONYELLOW; + MyPinball.BucketMin = Vector2D( libnum::num32(0.42), libnum::num32(0.02) ); + MyPinball.BucketMax = Vector2D( libnum::num32(0.58), libnum::num32(0.10) ); + MyPinball.balls.clear(); libnum::num32 ball_radius = libnum::num32(0.03); libnum::num32 ball_mass = libnum::num32(PI) * ball_radius * ball_radius; Vector2D ball_pos1(libnum::num32(1.075), libnum::num32(0.15)); - Vector2D ball_vel1(libnum::num32(0.0), libnum::num32(3.5)); +// Vector2D ball_vel1(libnum::num32(0.0), libnum::num32(3.5)); + Vector2D ball_vel1(libnum::num32(0.0), libnum::num32(0.0)); + MyPinball.balls.push_back(Ball(ball_radius, ball_mass, ball_pos1, ball_vel1, 0.2, RGB565_LEMONYELLOW)); + MyPinball.CurrentBallToLaunch = 0; + MyPinball.InitialPosition = ball_pos1.Clone(); + /* Vector2D ball_pos2(libnum::num32(1.075), libnum::num32(0.45)); Vector2D ball_vel2(libnum::num32(0.0), libnum::num32(3.5)); diff --git a/src/main.cpp b/src/main.cpp index 21fd66c..e3f746d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -171,6 +171,13 @@ static void render(void) { /* Clear Screen */ azrp_clear(RGB565_BLACK); + + if (MyPinball.balls[MyPinball.CurrentBallToLaunch].IsInBucket( MyPinball.BucketMin , MyPinball.BucketMax )) + azrp_rect( 10, 10, 10, 10, C_GREEN ); + else + azrp_rect( 10, 10, 10, 10, C_RED );; + + /* render the side image if available */ if (MyPinball.sideimage != nullptr) azrp_image_p8(azrp_width - MyPinball.sideimage->width - 25, 5, @@ -248,6 +255,9 @@ static void get_inputs(float dt) { MyPinball.flippers[i].touchIdentifier = libnum::num32(-1); } + +#if(!DEMO) + /* RESET THE GAME AND CHANGE THE CURRENT TABLE ( [OPTN] + [Fx] loads Table #x )*/ if (MyKeyboard.IsKeyPressed(MYKEY_OPTN) && MyKeyboard.IsKeyHoldPressed(MYKEY_F1)) { @@ -274,10 +284,18 @@ static void get_inputs(float dt) { SetupScene(5); } +#endif - if (MyKeyboard.IsKeyHoldPressed(MYKEY_EXE)) { - SetupScene(CurrentSequence); + if (MyKeyboard.IsKeyPressed(MYKEY_EXE)) { + if (MyPinball.balls[MyPinball.CurrentBallToLaunch].IsStopped() || MyPinball.balls[MyPinball.CurrentBallToLaunch].IsInBucket( MyPinball.BucketMin , MyPinball.BucketMax )) + { + cumulatedTime=0.0f; + MyPinball.locker_is_enabled = false; + MyPinball.balls[MyPinball.CurrentBallToLaunch].SetPosition( MyPinball.InitialPosition ); + MyPinball.balls[MyPinball.CurrentBallToLaunch].SetSpeed( Vector2D( libnum::num32(0.0), libnum::num32(3.5)) ); + + } } // TODO : to be changed to remove cumulatedTime diff --git a/src/parameters.h b/src/parameters.h index f30588e..51b131b 100644 --- a/src/parameters.h +++ b/src/parameters.h @@ -10,4 +10,6 @@ #define SCALE_PIXEL 1 + #define DEMO 1 + #endif \ No newline at end of file