Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: rec/rect.cpp
- Revision:
- 2:421fb0670c5c
- Child:
- 3:1a134243e2f0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rec/rect.cpp Thu Apr 12 22:46:30 2018 +0000
@@ -0,0 +1,75 @@
+#include "rect.h"
+
+rect::rect()
+{
+
+}
+
+rect::~rect()
+{
+
+}
+
+void rect::init(int x)
+{
+ rect_x = x; // x value on screen is fixed
+ rect_speed = 1; // default speed
+
+
+}
+
+void rect::draw(N5110 &lcd)
+{
+ lcd.drawRect(rect_x,rect_y,4,4,FILL_BLACK);
+ lcd.drawRect(bullet_x,bullet_y,3,3,FILL_BLACK);
+
+}
+
+void rect::update(Direction d,float mag)
+{
+
+ rect_speed = int(mag*10.0f); // scale is arbitrary, could be changed in future
+
+ bullet_x+=2;
+ wait(0.02);
+ bullet_y = rect_y;
+
+ if (bullet_x >84){
+ bullet_x = rect_x;
+ }
+
+
+ // update y value depending on direction of movement
+ // North is decrement as origin is at the top-left so decreasing moves up
+ if (d == N) {
+ rect_y-=rect_speed;
+ } else if (d == S) {
+ rect_y+=rect_speed;
+ }
+ if (d == W) {
+ rect_x-=rect_speed;
+ } else if (d == E) {
+ rect_x+=rect_speed;
+ }
+
+ // check the y origin to ensure that the paddle doesn't go off screen
+ if (rect_y < 1) {
+ rect_y = 1;
+ }
+ if (rect_y > 44) {
+ rect_y = 44;
+ }
+
+ if (rect_x < 1) {
+ rect_x = 1;
+ }
+ if (rect_x > 80) {
+ rect_x = 80;
+ }
+}
+
+
+Vector2D rect::get_pos() {
+ Vector2D p = {rect_x,rect_y};
+ return p;
+}
\ No newline at end of file