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:
- 3:1a134243e2f0
- Parent:
- 2:421fb0670c5c
- Child:
- 5:0a116644cce2
diff -r 421fb0670c5c -r 1a134243e2f0 rec/rect.cpp --- a/rec/rect.cpp Thu Apr 12 22:46:30 2018 +0000 +++ b/rec/rect.cpp Sun Apr 15 17:36:29 2018 +0000 @@ -9,44 +9,33 @@ { } - -void rect::init(int x) +void rect::init(int x,int y) { - rect_x = x; // x value on screen is fixed - rect_speed = 1; // default speed - - + //rect_x = x; // x value on screen is fixed + //rect_y = y; + rect_speed = 0.7; // 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); - + lcd.drawRect(rect_x,rect_y,5,5,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; - } + if (d == N) { - - // 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) { + if (d == W) { rect_x-=rect_speed; } else if (d == E) { rect_x+=rect_speed; @@ -72,4 +61,4 @@ Vector2D rect::get_pos() { Vector2D p = {rect_x,rect_y}; return p; -} \ No newline at end of file +}