Projectile Library
Projectile.cpp@5:023fe92d6384, 2017-05-02 (annotated)
- Committer:
- ll14c4p
- Date:
- Tue May 02 15:46:40 2017 +0000
- Revision:
- 5:023fe92d6384
- Parent:
- 4:977109f7b9f6
- Child:
- 6:70b35ebfa8c8
Changed velocity
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ll14c4p | 0:6914458c54cd | 1 | #include "Projectile.h" |
ll14c4p | 1:2aee0cb1ebf9 | 2 | #include "Player.h" |
ll14c4p | 0:6914458c54cd | 3 | |
ll14c4p | 0:6914458c54cd | 4 | Projectile::Projectile() |
ll14c4p | 0:6914458c54cd | 5 | { |
ll14c4p | 0:6914458c54cd | 6 | |
ll14c4p | 0:6914458c54cd | 7 | } |
ll14c4p | 0:6914458c54cd | 8 | |
ll14c4p | 0:6914458c54cd | 9 | Projectile::~Projectile() |
ll14c4p | 0:6914458c54cd | 10 | { |
ll14c4p | 0:6914458c54cd | 11 | |
ll14c4p | 1:2aee0cb1ebf9 | 12 | } |
ll14c4p | 1:2aee0cb1ebf9 | 13 | |
ll14c4p | 3:70c599d9f191 | 14 | |
ll14c4p | 4:977109f7b9f6 | 15 | void Projectile::init(int playerx, int playery) |
ll14c4p | 1:2aee0cb1ebf9 | 16 | { |
ll14c4p | 4:977109f7b9f6 | 17 | printf("playerxy proj = %d %d \n", playerx, playery); |
ll14c4p | 4:977109f7b9f6 | 18 | _playerx = playerx; |
ll14c4p | 4:977109f7b9f6 | 19 | _playery = playery; |
ll14c4p | 1:2aee0cb1ebf9 | 20 | //Make intial position of projectile = centre of player |
ll14c4p | 3:70c599d9f191 | 21 | |
ll14c4p | 1:2aee0cb1ebf9 | 22 | } |
ll14c4p | 1:2aee0cb1ebf9 | 23 | |
ll14c4p | 3:70c599d9f191 | 24 | |
ll14c4p | 3:70c599d9f191 | 25 | |
ll14c4p | 1:2aee0cb1ebf9 | 26 | void Projectile::draw(N5110 &lcd) |
ll14c4p | 3:70c599d9f191 | 27 | { |
ll14c4p | 3:70c599d9f191 | 28 | _velocity.x = 0; |
ll14c4p | 5:023fe92d6384 | 29 | _velocity.y = -3; |
ll14c4p | 3:70c599d9f191 | 30 | |
ll14c4p | 4:977109f7b9f6 | 31 | |
ll14c4p | 4:977109f7b9f6 | 32 | printf("playerxy projdraw = %d %d \n", _playerx, _playery); |
ll14c4p | 3:70c599d9f191 | 33 | |
ll14c4p | 3:70c599d9f191 | 34 | |
ll14c4p | 3:70c599d9f191 | 35 | if(_x <= -1){ |
ll14c4p | 3:70c599d9f191 | 36 | m = 0; |
ll14c4p | 3:70c599d9f191 | 37 | } |
ll14c4p | 3:70c599d9f191 | 38 | if(_x >= 85){ |
ll14c4p | 3:70c599d9f191 | 39 | m = 0; |
ll14c4p | 3:70c599d9f191 | 40 | } |
ll14c4p | 3:70c599d9f191 | 41 | if(_y <= -1){ |
ll14c4p | 3:70c599d9f191 | 42 | m = 0; |
ll14c4p | 3:70c599d9f191 | 43 | } |
ll14c4p | 3:70c599d9f191 | 44 | if(_y >= 49){ |
ll14c4p | 3:70c599d9f191 | 45 | m = 0; |
ll14c4p | 3:70c599d9f191 | 46 | } |
ll14c4p | 3:70c599d9f191 | 47 | |
ll14c4p | 3:70c599d9f191 | 48 | |
ll14c4p | 3:70c599d9f191 | 49 | |
ll14c4p | 3:70c599d9f191 | 50 | if(m == 0){ |
ll14c4p | 4:977109f7b9f6 | 51 | _x = _playerx +1; // Middle of screen // Change these values to change starting position |
ll14c4p | 4:977109f7b9f6 | 52 | _y = _playery +1; // Near bottom of screen |
ll14c4p | 3:70c599d9f191 | 53 | m = m+1; |
ll14c4p | 3:70c599d9f191 | 54 | } |
ll14c4p | 3:70c599d9f191 | 55 | lcd.drawRect(_x,_y,1,1,FILL_BLACK); |
ll14c4p | 3:70c599d9f191 | 56 | printf("projdrawn %d %d \n", _x, _y); |
ll14c4p | 4:977109f7b9f6 | 57 | //printf("playerpos in proj = %d %d \n", playerx, playery); |
ll14c4p | 3:70c599d9f191 | 58 | |
ll14c4p | 1:2aee0cb1ebf9 | 59 | } |
ll14c4p | 1:2aee0cb1ebf9 | 60 | |
ll14c4p | 1:2aee0cb1ebf9 | 61 | void Projectile::update() |
ll14c4p | 1:2aee0cb1ebf9 | 62 | { |
ll14c4p | 1:2aee0cb1ebf9 | 63 | _x += _velocity.x; |
ll14c4p | 1:2aee0cb1ebf9 | 64 | _y += _velocity.y; |
ll14c4p | 1:2aee0cb1ebf9 | 65 | } |
ll14c4p | 1:2aee0cb1ebf9 | 66 | |
ll14c4p | 1:2aee0cb1ebf9 | 67 | void Projectile::set_velocity(Vector2D v) |
ll14c4p | 1:2aee0cb1ebf9 | 68 | { |
ll14c4p | 3:70c599d9f191 | 69 | _velocity.x = v.x; |
ll14c4p | 3:70c599d9f191 | 70 | _velocity.y = v.y; |
ll14c4p | 1:2aee0cb1ebf9 | 71 | } |
ll14c4p | 1:2aee0cb1ebf9 | 72 | |
ll14c4p | 1:2aee0cb1ebf9 | 73 | Vector2D Projectile::get_velocity() |
ll14c4p | 1:2aee0cb1ebf9 | 74 | { |
ll14c4p | 1:2aee0cb1ebf9 | 75 | Vector2D v = {_velocity.x,_velocity.y}; |
ll14c4p | 1:2aee0cb1ebf9 | 76 | return v; |
ll14c4p | 1:2aee0cb1ebf9 | 77 | } |
ll14c4p | 1:2aee0cb1ebf9 | 78 | |
ll14c4p | 1:2aee0cb1ebf9 | 79 | Vector2D Projectile::get_pos() |
ll14c4p | 1:2aee0cb1ebf9 | 80 | { |
ll14c4p | 3:70c599d9f191 | 81 | Vector2D projpos = {_x,_y}; |
ll14c4p | 4:977109f7b9f6 | 82 | //printf("projpos = %f %f \n", projpos.x, projpos.y); |
ll14c4p | 3:70c599d9f191 | 83 | return projpos; |
ll14c4p | 0:6914458c54cd | 84 | } |