Target Library
Dependents: GameProject_Prototype
Target.cpp@11:5b2be6934e1b, 2017-05-02 (annotated)
- Committer:
- ll14c4p
- Date:
- Tue May 02 16:25:54 2017 +0000
- Revision:
- 11:5b2be6934e1b
- Parent:
- 10:45a0af3e607c
- Child:
- 12:855610bdba49
Added set position
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ll14c4p | 10:45a0af3e607c | 1 | #include "Target.h" |
ll14c4p | 10:45a0af3e607c | 2 | |
ll14c4p | 10:45a0af3e607c | 3 | Target::Target() |
ll14c4p | 10:45a0af3e607c | 4 | { |
ll14c4p | 10:45a0af3e607c | 5 | |
ll14c4p | 10:45a0af3e607c | 6 | } |
ll14c4p | 10:45a0af3e607c | 7 | |
ll14c4p | 10:45a0af3e607c | 8 | Target::~Target() |
ll14c4p | 10:45a0af3e607c | 9 | { |
ll14c4p | 10:45a0af3e607c | 10 | |
ll14c4p | 10:45a0af3e607c | 11 | } |
ll14c4p | 10:45a0af3e607c | 12 | |
ll14c4p | 10:45a0af3e607c | 13 | int sprite2[5][5] = { |
ll14c4p | 10:45a0af3e607c | 14 | {1,0,1,0,1}, |
ll14c4p | 10:45a0af3e607c | 15 | {0,1,0,1,0}, |
ll14c4p | 10:45a0af3e607c | 16 | {1,0,1,0,1}, |
ll14c4p | 10:45a0af3e607c | 17 | {0,1,0,1,0}, |
ll14c4p | 10:45a0af3e607c | 18 | {1,0,1,0,1}, |
ll14c4p | 10:45a0af3e607c | 19 | }; |
ll14c4p | 10:45a0af3e607c | 20 | |
ll14c4p | 10:45a0af3e607c | 21 | int n = 0; |
ll14c4p | 10:45a0af3e607c | 22 | int b = 0; |
ll14c4p | 10:45a0af3e607c | 23 | int v = 0; |
ll14c4p | 10:45a0af3e607c | 24 | void Target::init() //Delete Int |
ll14c4p | 10:45a0af3e607c | 25 | { |
ll14c4p | 10:45a0af3e607c | 26 | |
ll14c4p | 10:45a0af3e607c | 27 | |
ll14c4p | 10:45a0af3e607c | 28 | } |
ll14c4p | 10:45a0af3e607c | 29 | |
ll14c4p | 10:45a0af3e607c | 30 | |
ll14c4p | 10:45a0af3e607c | 31 | void Target::draw(N5110 &lcd) |
ll14c4p | 10:45a0af3e607c | 32 | { |
ll14c4p | 10:45a0af3e607c | 33 | |
ll14c4p | 10:45a0af3e607c | 34 | _velocity.x = 0; |
ll14c4p | 11:5b2be6934e1b | 35 | _velocity.y = 1; |
ll14c4p | 10:45a0af3e607c | 36 | |
ll14c4p | 10:45a0af3e607c | 37 | if(_x <= -1){ |
ll14c4p | 10:45a0af3e607c | 38 | n = 0; |
ll14c4p | 10:45a0af3e607c | 39 | } |
ll14c4p | 10:45a0af3e607c | 40 | if(_x >= 85){ |
ll14c4p | 10:45a0af3e607c | 41 | n = 0; |
ll14c4p | 10:45a0af3e607c | 42 | } |
ll14c4p | 10:45a0af3e607c | 43 | if(_y <= -1){ |
ll14c4p | 10:45a0af3e607c | 44 | n = 0; |
ll14c4p | 10:45a0af3e607c | 45 | } |
ll14c4p | 10:45a0af3e607c | 46 | if(_y >= 49){ |
ll14c4p | 10:45a0af3e607c | 47 | n = 0; |
ll14c4p | 10:45a0af3e607c | 48 | } |
ll14c4p | 10:45a0af3e607c | 49 | |
ll14c4p | 10:45a0af3e607c | 50 | if(n == 0){ |
ll14c4p | 10:45a0af3e607c | 51 | _x = rand() % 79; |
ll14c4p | 10:45a0af3e607c | 52 | _y = 0; //rand() % 20; |
ll14c4p | 10:45a0af3e607c | 53 | n = n+1; |
ll14c4p | 10:45a0af3e607c | 54 | } |
ll14c4p | 10:45a0af3e607c | 55 | |
ll14c4p | 10:45a0af3e607c | 56 | lcd.drawSprite(_x,_y,5,5,(int *)sprite2); |
ll14c4p | 10:45a0af3e607c | 57 | } |
ll14c4p | 10:45a0af3e607c | 58 | |
ll14c4p | 10:45a0af3e607c | 59 | |
ll14c4p | 10:45a0af3e607c | 60 | |
ll14c4p | 10:45a0af3e607c | 61 | Vector2D Target::get_pos() |
ll14c4p | 10:45a0af3e607c | 62 | { |
ll14c4p | 10:45a0af3e607c | 63 | Vector2D Targetpos = {_x,_y}; |
ll14c4p | 10:45a0af3e607c | 64 | //printf("Targetpos from Target = %f %f \n", Targetpos.x, Targetpos.y); |
ll14c4p | 10:45a0af3e607c | 65 | return Targetpos; |
ll14c4p | 10:45a0af3e607c | 66 | } |
ll14c4p | 10:45a0af3e607c | 67 | |
ll14c4p | 10:45a0af3e607c | 68 | |
ll14c4p | 10:45a0af3e607c | 69 | |
ll14c4p | 10:45a0af3e607c | 70 | |
ll14c4p | 10:45a0af3e607c | 71 | void Target::update() |
ll14c4p | 10:45a0af3e607c | 72 | { |
ll14c4p | 10:45a0af3e607c | 73 | _x += _velocity.x; |
ll14c4p | 10:45a0af3e607c | 74 | _y += _velocity.y; |
ll14c4p | 10:45a0af3e607c | 75 | } |
ll14c4p | 10:45a0af3e607c | 76 | |
ll14c4p | 10:45a0af3e607c | 77 | void Target::set_velocity(Vector2D v) |
ll14c4p | 10:45a0af3e607c | 78 | { |
ll14c4p | 10:45a0af3e607c | 79 | _velocity.x = v.x; |
ll14c4p | 10:45a0af3e607c | 80 | _velocity.y = v.y; |
ll14c4p | 10:45a0af3e607c | 81 | } |
ll14c4p | 10:45a0af3e607c | 82 | |
ll14c4p | 10:45a0af3e607c | 83 | Vector2D Target::get_velocity() |
ll14c4p | 10:45a0af3e607c | 84 | { |
ll14c4p | 10:45a0af3e607c | 85 | Vector2D v = {_velocity.x,_velocity.y}; |
ll14c4p | 10:45a0af3e607c | 86 | return v; |
ll14c4p | 10:45a0af3e607c | 87 | } |
ll14c4p | 11:5b2be6934e1b | 88 | |
ll14c4p | 11:5b2be6934e1b | 89 | void Target::set_pos(Vector2D p) |
ll14c4p | 11:5b2be6934e1b | 90 | { |
ll14c4p | 11:5b2be6934e1b | 91 | _x = p.x; |
ll14c4p | 11:5b2be6934e1b | 92 | _y = p.y; |
ll14c4p | 11:5b2be6934e1b | 93 | } |