
Joshua O'hara 201291390
Dependencies: mbed
Ship/Ship.cpp@6:5bea67cc96f9, 2020-03-23 (annotated)
- Committer:
- josh_ohara
- Date:
- Mon Mar 23 15:20:59 2020 +0000
- Revision:
- 6:5bea67cc96f9
- Parent:
- 5:e5bb95fb308b
- Child:
- 7:06a2558155f0
Beginning engine contruction
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
josh_ohara | 3:8a140aa1ddcd | 1 | #include "Ship.h" |
josh_ohara | 2:c2316b659b97 | 2 | |
josh_ohara | 6:5bea67cc96f9 | 3 | void Ship::init(int height, int width) |
josh_ohara | 2:c2316b659b97 | 4 | { |
josh_ohara | 2:c2316b659b97 | 5 | X = WIDTH/2 + width/2; |
josh_ohara | 3:8a140aa1ddcd | 6 | Y = HEIGHT - height; |
josh_ohara | 6:5bea67cc96f9 | 7 | Height = height; |
josh_ohara | 6:5bea67cc96f9 | 8 | Width = width; |
josh_ohara | 2:c2316b659b97 | 9 | Speed = 0.5; |
josh_ohara | 2:c2316b659b97 | 10 | } |
josh_ohara | 2:c2316b659b97 | 11 | |
josh_ohara | 2:c2316b659b97 | 12 | void Ship::draw(N5110 &lcd) |
josh_ohara | 2:c2316b659b97 | 13 | { |
josh_ohara | 2:c2316b659b97 | 14 | lcd.drawRect(X,Y,Width,Height,FILL_BLACK); |
josh_ohara | 2:c2316b659b97 | 15 | } |
josh_ohara | 2:c2316b659b97 | 16 | |
josh_ohara | 2:c2316b659b97 | 17 | void Ship::update(Direction d,float mag) |
josh_ohara | 2:c2316b659b97 | 18 | { |
josh_ohara | 2:c2316b659b97 | 19 | Speed = int(mag*10.0f); |
josh_ohara | 2:c2316b659b97 | 20 | |
josh_ohara | 2:c2316b659b97 | 21 | if (d == E) { |
josh_ohara | 2:c2316b659b97 | 22 | X+=Speed; |
josh_ohara | 2:c2316b659b97 | 23 | } else if (d == NE) { |
josh_ohara | 2:c2316b659b97 | 24 | X+=0.5*Speed; |
josh_ohara | 2:c2316b659b97 | 25 | } else if (d == SE) { |
josh_ohara | 2:c2316b659b97 | 26 | X+=0.5*Speed; |
josh_ohara | 2:c2316b659b97 | 27 | } else if (d == W) { |
josh_ohara | 2:c2316b659b97 | 28 | X-=Speed; |
josh_ohara | 2:c2316b659b97 | 29 | } else if (d == NW) { |
josh_ohara | 2:c2316b659b97 | 30 | X-=0.5*Speed; |
josh_ohara | 2:c2316b659b97 | 31 | } else if (d == SW) { |
josh_ohara | 2:c2316b659b97 | 32 | X-=0.5*Speed; |
josh_ohara | 2:c2316b659b97 | 33 | } |
josh_ohara | 2:c2316b659b97 | 34 | |
josh_ohara | 2:c2316b659b97 | 35 | if (X < 1) { |
josh_ohara | 2:c2316b659b97 | 36 | X = 1; |
josh_ohara | 2:c2316b659b97 | 37 | } |
josh_ohara | 2:c2316b659b97 | 38 | if (X > HEIGHT - Height - 1) { |
josh_ohara | 2:c2316b659b97 | 39 | X = HEIGHT - Height - 1; |
josh_ohara | 2:c2316b659b97 | 40 | } |
josh_ohara | 2:c2316b659b97 | 41 | } |
josh_ohara | 2:c2316b659b97 | 42 | |
josh_ohara | 2:c2316b659b97 | 43 | Vector2D Ship::get_position() { |
josh_ohara | 2:c2316b659b97 | 44 | Vector2D p = {X,Y}; |
josh_ohara | 2:c2316b659b97 | 45 | return p; |
josh_ohara | 2:c2316b659b97 | 46 | } |
josh_ohara | 3:8a140aa1ddcd | 47 | |
josh_ohara | 3:8a140aa1ddcd | 48 | int Ship::get_height() { |
josh_ohara | 3:8a140aa1ddcd | 49 | int height = Height; |
josh_ohara | 3:8a140aa1ddcd | 50 | return height; |
josh_ohara | 3:8a140aa1ddcd | 51 | } |
josh_ohara | 3:8a140aa1ddcd | 52 | |
josh_ohara | 3:8a140aa1ddcd | 53 | int Ship::get_width() { |
josh_ohara | 3:8a140aa1ddcd | 54 | int width = Width; |
josh_ohara | 3:8a140aa1ddcd | 55 | return width; |
josh_ohara | 3:8a140aa1ddcd | 56 | } |
josh_ohara | 4:18a1fc4c38e0 | 57 | |
josh_ohara | 5:e5bb95fb308b | 58 | //void Ship::set_life(bool l) { |
josh_ohara | 5:e5bb95fb308b | 59 | // Life = l; |
josh_ohara | 5:e5bb95fb308b | 60 | //} |
josh_ohara | 3:8a140aa1ddcd | 61 | |
josh_ohara | 2:c2316b659b97 | 62 | |
josh_ohara | 2:c2316b659b97 | 63 |