harry rance
/
Revised_Space_Invaders
Harry Rance 200925395 Embedded Systems Project
AliensArray.cpp@2:50feb42b982c, 2017-04-26 (annotated)
- Committer:
- harryrance
- Date:
- Wed Apr 26 17:40:17 2017 +0000
- Revision:
- 2:50feb42b982c
- Parent:
- 0:c9bf674fe0c7
- Child:
- 5:2eb139b24219
Game engine complete. Boss fight implemented (very hard!) and end game screen characteristics change depending on whether you defeated the boss or the boss defeated you.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
harryrance | 0:c9bf674fe0c7 | 1 | #include "AliensArray.h" |
harryrance | 0:c9bf674fe0c7 | 2 | |
harryrance | 0:c9bf674fe0c7 | 3 | |
harryrance | 0:c9bf674fe0c7 | 4 | AliensArray::AliensArray() |
harryrance | 0:c9bf674fe0c7 | 5 | { |
harryrance | 0:c9bf674fe0c7 | 6 | |
harryrance | 0:c9bf674fe0c7 | 7 | } |
harryrance | 0:c9bf674fe0c7 | 8 | |
harryrance | 0:c9bf674fe0c7 | 9 | AliensArray::~AliensArray() |
harryrance | 0:c9bf674fe0c7 | 10 | { |
harryrance | 0:c9bf674fe0c7 | 11 | |
harryrance | 0:c9bf674fe0c7 | 12 | } |
harryrance | 0:c9bf674fe0c7 | 13 | |
harryrance | 0:c9bf674fe0c7 | 14 | void AliensArray::initialise(int x_origin, int y_origin, int speed) |
harryrance | 0:c9bf674fe0c7 | 15 | { |
harryrance | 0:c9bf674fe0c7 | 16 | _x = x_origin; |
harryrance | 0:c9bf674fe0c7 | 17 | _y = y_origin; |
harryrance | 0:c9bf674fe0c7 | 18 | |
harryrance | 0:c9bf674fe0c7 | 19 | int direction = 0; |
harryrance | 0:c9bf674fe0c7 | 20 | |
harryrance | 0:c9bf674fe0c7 | 21 | if (direction == 0) { |
harryrance | 2:50feb42b982c | 22 | _velocity.x = speed * 1.5; |
harryrance | 0:c9bf674fe0c7 | 23 | } else if (direction == 1) { |
harryrance | 0:c9bf674fe0c7 | 24 | _velocity.x = -speed; |
harryrance | 0:c9bf674fe0c7 | 25 | } |
harryrance | 0:c9bf674fe0c7 | 26 | |
harryrance | 0:c9bf674fe0c7 | 27 | } |
harryrance | 0:c9bf674fe0c7 | 28 | |
harryrance | 0:c9bf674fe0c7 | 29 | void AliensArray::update() |
harryrance | 0:c9bf674fe0c7 | 30 | { |
harryrance | 0:c9bf674fe0c7 | 31 | _x += _velocity.x; |
harryrance | 0:c9bf674fe0c7 | 32 | _y += _velocity.y; |
harryrance | 0:c9bf674fe0c7 | 33 | } |
harryrance | 0:c9bf674fe0c7 | 34 | |
harryrance | 0:c9bf674fe0c7 | 35 | void AliensArray::draw(N5110 &lcd) |
harryrance | 0:c9bf674fe0c7 | 36 | { |
harryrance | 0:c9bf674fe0c7 | 37 | type_1_draw(lcd); |
harryrance | 2:50feb42b982c | 38 | type_1_1_draw(lcd); |
harryrance | 0:c9bf674fe0c7 | 39 | lcd.drawRect (0,0,84,48,0); |
harryrance | 2:50feb42b982c | 40 | |
harryrance | 0:c9bf674fe0c7 | 41 | } |
harryrance | 0:c9bf674fe0c7 | 42 | |
harryrance | 0:c9bf674fe0c7 | 43 | void AliensArray::type_1_draw(N5110 &lcd) |
harryrance | 0:c9bf674fe0c7 | 44 | { |
harryrance | 2:50feb42b982c | 45 | int add_x = 0; |
harryrance | 0:c9bf674fe0c7 | 46 | _x_origin = _x/8; |
harryrance | 0:c9bf674fe0c7 | 47 | _y_origin = _y; |
harryrance | 2:50feb42b982c | 48 | for (int j = 0; j < 11; j++){ |
harryrance | 2:50feb42b982c | 49 | add_x +=5; |
harryrance | 2:50feb42b982c | 50 | _array_x[0][j] = add_x; |
harryrance | 0:c9bf674fe0c7 | 51 | |
harryrance | 0:c9bf674fe0c7 | 52 | } |
harryrance | 2:50feb42b982c | 53 | |
harryrance | 2:50feb42b982c | 54 | for (int scan_j = 0; scan_j < 11; scan_j++){ |
harryrance | 2:50feb42b982c | 55 | int ind = _array_x[0][scan_j]; |
harryrance | 2:50feb42b982c | 56 | |
harryrance | 2:50feb42b982c | 57 | if (array_active[0][scan_j] == 1){ |
harryrance | 2:50feb42b982c | 58 | lcd.setPixel((_x_origin+10+ind)-1,(_y_origin+10)-1); |
harryrance | 2:50feb42b982c | 59 | lcd.setPixel((_x_origin+10+ind),(_y_origin+10)-1); |
harryrance | 2:50feb42b982c | 60 | lcd.setPixel((_x_origin+10+ind),(_y_origin+10)+1); |
harryrance | 2:50feb42b982c | 61 | lcd.setPixel((_x_origin+10+ind)-1,(_y_origin+10)+1); |
harryrance | 2:50feb42b982c | 62 | lcd.setPixel((_x_origin+10+ind)+1,(_y_origin+10)); |
harryrance | 2:50feb42b982c | 63 | } |
harryrance | 2:50feb42b982c | 64 | } |
harryrance | 2:50feb42b982c | 65 | |
harryrance | 0:c9bf674fe0c7 | 66 | } |
harryrance | 0:c9bf674fe0c7 | 67 | |
harryrance | 2:50feb42b982c | 68 | void AliensArray::type_1_1_draw(N5110 &lcd) |
harryrance | 0:c9bf674fe0c7 | 69 | { |
harryrance | 2:50feb42b982c | 70 | int add_x = 0; |
harryrance | 0:c9bf674fe0c7 | 71 | _x_origin = _x/8; |
harryrance | 0:c9bf674fe0c7 | 72 | _y_origin = _y; |
harryrance | 2:50feb42b982c | 73 | for (int j = 0; j < 11; j++){ |
harryrance | 2:50feb42b982c | 74 | add_x +=5; |
harryrance | 2:50feb42b982c | 75 | _array_x[1][j] = add_x; |
harryrance | 0:c9bf674fe0c7 | 76 | |
harryrance | 0:c9bf674fe0c7 | 77 | } |
harryrance | 2:50feb42b982c | 78 | |
harryrance | 2:50feb42b982c | 79 | for (int scan_j = 0; scan_j < 11; scan_j++){ |
harryrance | 2:50feb42b982c | 80 | int ind = _array_x[1][scan_j]; |
harryrance | 2:50feb42b982c | 81 | |
harryrance | 2:50feb42b982c | 82 | if (array_active[1][scan_j] == 1){ |
harryrance | 2:50feb42b982c | 83 | lcd.setPixel((_x_origin+10+ind)-1,(_y_origin+16)-1); |
harryrance | 2:50feb42b982c | 84 | lcd.setPixel((_x_origin+10+ind),(_y_origin+16)-1); |
harryrance | 2:50feb42b982c | 85 | lcd.setPixel((_x_origin+10+ind),(_y_origin+16)+1); |
harryrance | 2:50feb42b982c | 86 | lcd.setPixel((_x_origin+10+ind)-1,(_y_origin+16)+1); |
harryrance | 2:50feb42b982c | 87 | lcd.setPixel((_x_origin+10+ind)+1,(_y_origin+16)); |
harryrance | 2:50feb42b982c | 88 | } |
harryrance | 2:50feb42b982c | 89 | } |
harryrance | 2:50feb42b982c | 90 | |
harryrance | 0:c9bf674fe0c7 | 91 | } |
harryrance | 0:c9bf674fe0c7 | 92 | |
harryrance | 0:c9bf674fe0c7 | 93 | Vector2D AliensArray::get_velocity() |
harryrance | 0:c9bf674fe0c7 | 94 | { |
harryrance | 0:c9bf674fe0c7 | 95 | Vector2D v = {_velocity.x,_velocity.y}; |
harryrance | 0:c9bf674fe0c7 | 96 | return v; |
harryrance | 0:c9bf674fe0c7 | 97 | } |
harryrance | 0:c9bf674fe0c7 | 98 | |
harryrance | 0:c9bf674fe0c7 | 99 | Vector2D AliensArray::get_pos() |
harryrance | 0:c9bf674fe0c7 | 100 | { |
harryrance | 0:c9bf674fe0c7 | 101 | Vector2D p = {_x,_y}; |
harryrance | 0:c9bf674fe0c7 | 102 | return p; |
harryrance | 0:c9bf674fe0c7 | 103 | } |
harryrance | 0:c9bf674fe0c7 | 104 | |
harryrance | 0:c9bf674fe0c7 | 105 | void AliensArray::set_velocity(Vector2D v) |
harryrance | 0:c9bf674fe0c7 | 106 | { |
harryrance | 0:c9bf674fe0c7 | 107 | _velocity.x = v.x; |
harryrance | 0:c9bf674fe0c7 | 108 | _velocity.y = v.y; |
harryrance | 0:c9bf674fe0c7 | 109 | } |
harryrance | 0:c9bf674fe0c7 | 110 | |
harryrance | 0:c9bf674fe0c7 | 111 | void AliensArray::set_pos(Vector2D p) |
harryrance | 0:c9bf674fe0c7 | 112 | { |
harryrance | 0:c9bf674fe0c7 | 113 | _x = p.x; |
harryrance | 0:c9bf674fe0c7 | 114 | _y = p.y; |
harryrance | 0:c9bf674fe0c7 | 115 | } |
harryrance | 0:c9bf674fe0c7 | 116 |