From 1d69c79942622eddb531406cabaed77d73bb4c40 Mon Sep 17 00:00:00 2001 From: ZephyrLabs <65145081+ZephyrLabs@users.noreply.github.com> Date: Thu, 3 Dec 2020 19:46:36 +0530 Subject: Addition of new files in MakeList added Paddle.cpp and Paddle.h --- src/displayapp/screens/Paddle.cpp | 100 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/displayapp/screens/Paddle.cpp (limited to 'src/displayapp/screens/Paddle.cpp') diff --git a/src/displayapp/screens/Paddle.cpp b/src/displayapp/screens/Paddle.cpp new file mode 100644 index 00000000..94833adc --- /dev/null +++ b/src/displayapp/screens/Paddle.cpp @@ -0,0 +1,100 @@ +#include "Paddle.h" +#include "../DisplayApp.h" +#include "../LittleVgl.h" + +using namespace Pinetime::Applications::Screens; +extern lv_font_t jetbrains_mono_extrabold_compressed; +extern lv_font_t jetbrains_mono_bold_20; + +Paddle::Paddle(Pinetime::Applications::DisplayApp *app, Pinetime::Components::LittleVgl& lvgl) : Screen(app){ + app->SetTouchMode(DisplayApp::TouchModes::Polling); + + points = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(points, "0"); + lv_obj_align(points, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0); + + paddle.header.always_zero = 0; + paddle.header.w = 4; + paddle.header.h = 60; + paddle.data_size = 60 * 4 * LV_COLOR_SIZE / 8; + paddle.header.cf = LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED; + paddle.data = paddle_map; + paddle_image = lv_img_create(lv_scr_act(), NULL); + lv_img_set_src(paddle_image, &paddle); + + ball.header.always_zero = 0; + ball.header.w = 24; + ball.header.h = 24; + ball.data_size = 24 * 24 * LV_COLOR_SIZE / 8; + ball.header.cf = LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED; + ball.data = ball_map; + ball_image = lv_img_create(lv_scr_act(), NULL); + lv_img_set_src(ball_image, &ball); +} + +Paddle::~Paddle() { + // Reset the touchmode + app->SetTouchMode(DisplayApp::TouchModes::Gestures); + lv_obj_clean(lv_scr_act()); +} + +bool Paddle::Refresh() { + + if((counter++ % 5) == 0){ + + counter = 0; + + ball_x += dx; + ball_y += dy; + + lv_obj_set_pos(ball_image, ball_x, ball_y); + + //checks if it has touched the sides (floor and ceiling) + if(ball_y <= 0 || ball_y >= 215){ + dy *= -1; + } + + //checks if it has touched the side (left side) + if(ball_x >= 215){ + dx *= -1; + } + + //checks if it is in the position of the paddle + if(ball_y >= (y_paddle_bottom + 16) && ball_y <= (y_paddle_top - 8)){ + if(ball_x >= 0 && ball_x < 4){ + lv_obj_set_pos(ball_image, 5, ball_y); + dx *= -1; + score++; + } + } + + //checks if it has gone behind the paddle + else if(ball_x <= -40){ + ball_x = 107; + ball_y = 107; + score = 0; + } + sprintf(Val, "%d", score); + lv_label_set_text(points, Val); + } + return running; +} + +bool Paddle::OnButtonPushed() { + running = false; + return true; +} + + +bool Paddle::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + return true; +} + +bool Paddle::OnTouchEvent(uint16_t x, uint16_t y) { + + lv_obj_set_pos(paddle_image, 0, y - 30); // sets the center paddle pos. (30px offset) with the the y_coordinate of the finger and defaults the x_coordinate to 0 + y_paddle_top = y - 30; // refreshes the upper extreme of the paddle + y_paddle_bottom = y + 30; // refreshes the lower extreme of the paddle + + return true; +} -- cgit v1.2.3 From 4f41d4d85465f7cfedd92c45a0bc6d7f2d60dad3 Mon Sep 17 00:00:00 2001 From: ZephyrLabs <65145081+ZephyrLabs@users.noreply.github.com> Date: Thu, 3 Dec 2020 20:03:11 +0530 Subject: Update Paddle.cpp create Paddle.cpp --- src/displayapp/screens/Paddle.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/displayapp/screens/Paddle.cpp') diff --git a/src/displayapp/screens/Paddle.cpp b/src/displayapp/screens/Paddle.cpp index 94833adc..6695257e 100644 --- a/src/displayapp/screens/Paddle.cpp +++ b/src/displayapp/screens/Paddle.cpp @@ -98,3 +98,4 @@ bool Paddle::OnTouchEvent(uint16_t x, uint16_t y) { return true; } + -- cgit v1.2.3 From 418d857308a60cf19a5002a6291f73b48445310e Mon Sep 17 00:00:00 2001 From: ZephyrLabs <65145081+ZephyrLabs@users.noreply.github.com> Date: Thu, 3 Dec 2020 20:59:22 +0530 Subject: Update Paddle.cpp bugfix: add missing class --- src/displayapp/screens/Paddle.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/displayapp/screens/Paddle.cpp') diff --git a/src/displayapp/screens/Paddle.cpp b/src/displayapp/screens/Paddle.cpp index 6695257e..aaba8d90 100644 --- a/src/displayapp/screens/Paddle.cpp +++ b/src/displayapp/screens/Paddle.cpp @@ -6,7 +6,7 @@ using namespace Pinetime::Applications::Screens; extern lv_font_t jetbrains_mono_extrabold_compressed; extern lv_font_t jetbrains_mono_bold_20; -Paddle::Paddle(Pinetime::Applications::DisplayApp *app, Pinetime::Components::LittleVgl& lvgl) : Screen(app){ +Paddle::Paddle(Pinetime::Applications::DisplayApp* app, Pinetime::Components::LittleVgl& lvgl) : Screen(app), lvgl{lvgl} { app->SetTouchMode(DisplayApp::TouchModes::Polling); points = lv_label_create(lv_scr_act(), NULL); @@ -98,4 +98,3 @@ bool Paddle::OnTouchEvent(uint16_t x, uint16_t y) { return true; } - -- cgit v1.2.3 From ea4d2560cf6e0a726ae0d2fa037fe52cfa9a948a Mon Sep 17 00:00:00 2001 From: ZephyrLabs <65145081+ZephyrLabs@users.noreply.github.com> Date: Tue, 8 Dec 2020 10:06:30 +0530 Subject: Update Paddle.cpp added changes from PR --- src/displayapp/screens/Paddle.cpp | 136 ++++++++++++++++++++++++++++++++------ 1 file changed, 115 insertions(+), 21 deletions(-) (limited to 'src/displayapp/screens/Paddle.cpp') diff --git a/src/displayapp/screens/Paddle.cpp b/src/displayapp/screens/Paddle.cpp index aaba8d90..36b81733 100644 --- a/src/displayapp/screens/Paddle.cpp +++ b/src/displayapp/screens/Paddle.cpp @@ -6,20 +6,115 @@ using namespace Pinetime::Applications::Screens; extern lv_font_t jetbrains_mono_extrabold_compressed; extern lv_font_t jetbrains_mono_bold_20; +namespace{ +const uint8_t paddle_map[] = { + 0xfc, 0xfe, 0xfc, 0xff, /*Color of index 0*/ + 0xff, 0xff, 0xff, 0xff, /*Color of index 1*/ + + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, +}; + +const uint8_t ball_map[] = { + 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, + 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, + 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, + 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, + 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, + 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, + 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, + 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, + 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, + 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, + 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, + 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, + 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, + 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, + 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, + 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, 0x6f, 0xed, +}; +} + Paddle::Paddle(Pinetime::Applications::DisplayApp* app, Pinetime::Components::LittleVgl& lvgl) : Screen(app), lvgl{lvgl} { app->SetTouchMode(DisplayApp::TouchModes::Polling); - points = lv_label_create(lv_scr_act(), NULL); + points = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text(points, "0"); lv_obj_align(points, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0); paddle.header.always_zero = 0; paddle.header.w = 4; paddle.header.h = 60; - paddle.data_size = 60 * 4 * LV_COLOR_SIZE / 8; - paddle.header.cf = LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED; + paddle.data_size = 68; + paddle.header.cf = LV_IMG_CF_INDEXED_1BIT; paddle.data = paddle_map; - paddle_image = lv_img_create(lv_scr_act(), NULL); + paddle_image = lv_img_create(lv_scr_act(), nullptr); lv_img_set_src(paddle_image, &paddle); ball.header.always_zero = 0; @@ -28,7 +123,7 @@ Paddle::Paddle(Pinetime::Applications::DisplayApp* app, Pinetime::Components::Li ball.data_size = 24 * 24 * LV_COLOR_SIZE / 8; ball.header.cf = LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED; ball.data = ball_map; - ball_image = lv_img_create(lv_scr_act(), NULL); + ball_image = lv_img_create(lv_scr_act(), nullptr); lv_img_set_src(ball_image, &ball); } @@ -44,38 +139,38 @@ bool Paddle::Refresh() { counter = 0; - ball_x += dx; - ball_y += dy; + BallX += dx; + BallY += dy; - lv_obj_set_pos(ball_image, ball_x, ball_y); + lv_obj_set_pos(ball_image, BallX, BallY); //checks if it has touched the sides (floor and ceiling) - if(ball_y <= 0 || ball_y >= 215){ + if(BallY <= 0 || BallY >= 215){ dy *= -1; } //checks if it has touched the side (left side) - if(ball_x >= 215){ + if(BallX >= 215){ dx *= -1; } //checks if it is in the position of the paddle - if(ball_y >= (y_paddle_bottom + 16) && ball_y <= (y_paddle_top - 8)){ - if(ball_x >= 0 && ball_x < 4){ - lv_obj_set_pos(ball_image, 5, ball_y); + if(BallY >= (PaddleBottomY + 16) && BallY <= (PaddleTopY - 8)){ + if(BallX >= 0 && BallX < 4){ + lv_obj_set_pos(ball_image, 5, BallY); dx *= -1; score++; } } //checks if it has gone behind the paddle - else if(ball_x <= -40){ - ball_x = 107; - ball_y = 107; + else if(BallX <= -40){ + BallX = 107; + BallY = 107; score = 0; } - sprintf(Val, "%d", score); - lv_label_set_text(points, Val); + sprintf(scoreStr, "%d", score); + lv_label_set_text(points, scoreStr); } return running; } @@ -85,7 +180,6 @@ bool Paddle::OnButtonPushed() { return true; } - bool Paddle::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return true; } @@ -93,8 +187,8 @@ bool Paddle::OnTouchEvent(Pinetime::Applications::TouchEvents event) { bool Paddle::OnTouchEvent(uint16_t x, uint16_t y) { lv_obj_set_pos(paddle_image, 0, y - 30); // sets the center paddle pos. (30px offset) with the the y_coordinate of the finger and defaults the x_coordinate to 0 - y_paddle_top = y - 30; // refreshes the upper extreme of the paddle - y_paddle_bottom = y + 30; // refreshes the lower extreme of the paddle + PaddleTopY = y - 30; // refreshes the upper extreme of the paddle + PaddleBottomY = y + 30; // refreshes the lower extreme of the paddle return true; } -- cgit v1.2.3 From b098d27d086733fad3d6c4e04385b73e0c123ef8 Mon Sep 17 00:00:00 2001 From: ZephyrLabs <65145081+ZephyrLabs@users.noreply.github.com> Date: Sun, 20 Dec 2020 09:23:31 +0530 Subject: Update Paddle.cpp tranparent paddle bug fix. --- src/displayapp/screens/Paddle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/displayapp/screens/Paddle.cpp') diff --git a/src/displayapp/screens/Paddle.cpp b/src/displayapp/screens/Paddle.cpp index 36b81733..14ae2202 100644 --- a/src/displayapp/screens/Paddle.cpp +++ b/src/displayapp/screens/Paddle.cpp @@ -155,7 +155,7 @@ bool Paddle::Refresh() { } //checks if it is in the position of the paddle - if(BallY >= (PaddleBottomY + 16) && BallY <= (PaddleTopY - 8)){ + if(BallY <= (PaddleBottomY + 16) && BallY >= (PaddleTopY - 8)){ if(BallX >= 0 && BallX < 4){ lv_obj_set_pos(ball_image, 5, BallY); dx *= -1; -- cgit v1.2.3 From 61e78d338b9dbf620e0292dcd15252da131a2bd3 Mon Sep 17 00:00:00 2001 From: ZephyrLabs <65145081+ZephyrLabs@users.noreply.github.com> Date: Sun, 20 Dec 2020 09:32:00 +0530 Subject: Update Paddle.cpp fix uppercase --- src/displayapp/screens/Paddle.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'src/displayapp/screens/Paddle.cpp') diff --git a/src/displayapp/screens/Paddle.cpp b/src/displayapp/screens/Paddle.cpp index 14ae2202..347abb62 100644 --- a/src/displayapp/screens/Paddle.cpp +++ b/src/displayapp/screens/Paddle.cpp @@ -134,39 +134,37 @@ Paddle::~Paddle() { } bool Paddle::Refresh() { - if((counter++ % 5) == 0){ - counter = 0; - BallX += dx; - BallY += dy; + ballX += dx; + ballY += dy; - lv_obj_set_pos(ball_image, BallX, BallY); + lv_obj_set_pos(ball_image, ballX, ballY); //checks if it has touched the sides (floor and ceiling) - if(BallY <= 0 || BallY >= 215){ + if(ballY <= 0 || ballY >= 215){ dy *= -1; } //checks if it has touched the side (left side) - if(BallX >= 215){ + if(ballX >= 215){ dx *= -1; } //checks if it is in the position of the paddle - if(BallY <= (PaddleBottomY + 16) && BallY >= (PaddleTopY - 8)){ - if(BallX >= 0 && BallX < 4){ - lv_obj_set_pos(ball_image, 5, BallY); + if(ballY <= (paddleBottomY + 16) && ballY >= (paddleTopY - 8)){ + if(ballX >= 0 && ballX < 4){ + lv_obj_set_pos(ball_image, 5, ballY); dx *= -1; score++; } } //checks if it has gone behind the paddle - else if(BallX <= -40){ - BallX = 107; - BallY = 107; + else if(ballX <= -40){ + ballX = 107; + ballY = 107; score = 0; } sprintf(scoreStr, "%d", score); @@ -185,10 +183,9 @@ bool Paddle::OnTouchEvent(Pinetime::Applications::TouchEvents event) { } bool Paddle::OnTouchEvent(uint16_t x, uint16_t y) { - lv_obj_set_pos(paddle_image, 0, y - 30); // sets the center paddle pos. (30px offset) with the the y_coordinate of the finger and defaults the x_coordinate to 0 - PaddleTopY = y - 30; // refreshes the upper extreme of the paddle - PaddleBottomY = y + 30; // refreshes the lower extreme of the paddle + paddleTopY = y - 30; // refreshes the upper extreme of the paddle + paddleBottomY = y + 30; // refreshes the lower extreme of the paddle return true; } -- cgit v1.2.3 From cc04c2c1f8a8a05cf284ad69a43b5cd682e37172 Mon Sep 17 00:00:00 2001 From: ZephyrLabs <65145081+ZephyrLabs@users.noreply.github.com> Date: Sun, 20 Dec 2020 11:53:39 +0530 Subject: Update Paddle.cpp blankline removal --- src/displayapp/screens/Paddle.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/displayapp/screens/Paddle.cpp') diff --git a/src/displayapp/screens/Paddle.cpp b/src/displayapp/screens/Paddle.cpp index 347abb62..9a04b3b7 100644 --- a/src/displayapp/screens/Paddle.cpp +++ b/src/displayapp/screens/Paddle.cpp @@ -186,6 +186,5 @@ bool Paddle::OnTouchEvent(uint16_t x, uint16_t y) { lv_obj_set_pos(paddle_image, 0, y - 30); // sets the center paddle pos. (30px offset) with the the y_coordinate of the finger and defaults the x_coordinate to 0 paddleTopY = y - 30; // refreshes the upper extreme of the paddle paddleBottomY = y + 30; // refreshes the lower extreme of the paddle - return true; } -- cgit v1.2.3