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
alien/alien.cpp@13:9d6ee753eca6, 2019-04-19 (annotated)
- Committer:
- fy14lkaa
- Date:
- Fri Apr 19 17:33:57 2019 +0000
- Revision:
- 13:9d6ee753eca6
- Parent:
- 11:df8ce6637022
- Child:
- 14:6c4bce33c1a1
added a function to draw the alien (lcd.drawRect) by using N5110 and lcd libraries .
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| fy14lkaa | 10:13e6996223d5 | 1 | #include "alien.h" |
| fy14lkaa | 10:13e6996223d5 | 2 | |
| fy14lkaa | 10:13e6996223d5 | 3 | |
| fy14lkaa | 10:13e6996223d5 | 4 | alien::alien() |
| fy14lkaa | 10:13e6996223d5 | 5 | { |
| fy14lkaa | 10:13e6996223d5 | 6 | |
| fy14lkaa | 10:13e6996223d5 | 7 | } |
| fy14lkaa | 10:13e6996223d5 | 8 | |
| fy14lkaa | 10:13e6996223d5 | 9 | alien::~alien() |
| fy14lkaa | 10:13e6996223d5 | 10 | { |
| fy14lkaa | 10:13e6996223d5 | 11 | |
| fy14lkaa | 10:13e6996223d5 | 12 | } |
| fy14lkaa | 10:13e6996223d5 | 13 | |
| fy14lkaa | 10:13e6996223d5 | 14 | void alien::init(int size,int speed) |
| fy14lkaa | 10:13e6996223d5 | 15 | { |
| fy14lkaa | 10:13e6996223d5 | 16 | |
| fy14lkaa | 11:df8ce6637022 | 17 | _size = size; |
| fy14lkaa | 11:df8ce6637022 | 18 | |
| fy14lkaa | 11:df8ce6637022 | 19 | |
| fy14lkaa | 13:9d6ee753eca6 | 20 | |
| fy14lkaa | 11:df8ce6637022 | 21 | |
| fy14lkaa | 11:df8ce6637022 | 22 | |
| fy14lkaa | 11:df8ce6637022 | 23 | srand(time(NULL)); |
| fy14lkaa | 11:df8ce6637022 | 24 | int direction = rand() % 8; // randomise initial direction. |
| fy14lkaa | 11:df8ce6637022 | 25 | |
| fy14lkaa | 11:df8ce6637022 | 26 | // 4 possibilities. Get random modulo and set velocities accordingly |
| fy14lkaa | 11:df8ce6637022 | 27 | if (direction == 0) { |
| fy14lkaa | 11:df8ce6637022 | 28 | _velocity.x = speed; |
| fy14lkaa | 11:df8ce6637022 | 29 | _velocity.y = speed; |
| fy14lkaa | 11:df8ce6637022 | 30 | } else if (direction == 1) { |
| fy14lkaa | 11:df8ce6637022 | 31 | _velocity.x = speed; |
| fy14lkaa | 11:df8ce6637022 | 32 | _velocity.y = -speed; |
| fy14lkaa | 11:df8ce6637022 | 33 | } else if (direction == 2) { |
| fy14lkaa | 11:df8ce6637022 | 34 | _velocity.x = speed; |
| fy14lkaa | 11:df8ce6637022 | 35 | _velocity.y = speed; |
| fy14lkaa | 11:df8ce6637022 | 36 | } else { |
| fy14lkaa | 11:df8ce6637022 | 37 | _velocity.x = -speed; |
| fy14lkaa | 11:df8ce6637022 | 38 | _velocity.y = -speed; |
| fy14lkaa | 11:df8ce6637022 | 39 | } |
| fy14lkaa | 11:df8ce6637022 | 40 | } |
| fy14lkaa | 11:df8ce6637022 | 41 | |
| fy14lkaa | 11:df8ce6637022 | 42 | |
| fy14lkaa | 13:9d6ee753eca6 | 43 | void Ball::draw(N5110 &lcd) |
| fy14lkaa | 13:9d6ee753eca6 | 44 | { |
| fy14lkaa | 13:9d6ee753eca6 | 45 | lcd.drawRect(_x,_y,_size,_size,FILL_BLACK); |
| fy14lkaa | 13:9d6ee753eca6 | 46 | } |
| fy14lkaa | 13:9d6ee753eca6 | 47 | |
| fy14lkaa | 11:df8ce6637022 | 48 |