Harry Rance 200925395 Embedded Systems Project

Dependencies:   mbed

Committer:
harryrance
Date:
Tue Apr 11 17:54:59 2017 +0000
Revision:
0:c9bf674fe0c7
Child:
2:50feb42b982c
REVISED - All changed to object oriented format with separate header files. Back to having an array of aliens moving across and down the screen, speeding up with each increment and Game Over screen appearing when array touches shields. Runs smoother.

Who changed what in which revision?

UserRevisionLine numberNew 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
harryrance 0:c9bf674fe0c7 17 _x = x_origin;
harryrance 0:c9bf674fe0c7 18 _y = y_origin;
harryrance 0:c9bf674fe0c7 19
harryrance 0:c9bf674fe0c7 20
harryrance 0:c9bf674fe0c7 21 int direction = 0;
harryrance 0:c9bf674fe0c7 22
harryrance 0:c9bf674fe0c7 23 if (direction == 0) {
harryrance 0:c9bf674fe0c7 24 _velocity.x = speed;
harryrance 0:c9bf674fe0c7 25 } else if (direction == 1) {
harryrance 0:c9bf674fe0c7 26 _velocity.x = -speed;
harryrance 0:c9bf674fe0c7 27 }
harryrance 0:c9bf674fe0c7 28
harryrance 0:c9bf674fe0c7 29 }
harryrance 0:c9bf674fe0c7 30
harryrance 0:c9bf674fe0c7 31 void AliensArray::update()
harryrance 0:c9bf674fe0c7 32 {
harryrance 0:c9bf674fe0c7 33 _x += _velocity.x;
harryrance 0:c9bf674fe0c7 34 _y += _velocity.y;
harryrance 0:c9bf674fe0c7 35 }
harryrance 0:c9bf674fe0c7 36
harryrance 0:c9bf674fe0c7 37 void AliensArray::draw(N5110 &lcd)
harryrance 0:c9bf674fe0c7 38 {
harryrance 0:c9bf674fe0c7 39 type_1_draw(lcd);
harryrance 0:c9bf674fe0c7 40 type_2_draw(lcd);
harryrance 0:c9bf674fe0c7 41 type_3_draw(lcd);
harryrance 0:c9bf674fe0c7 42 lcd.drawRect (0,0,84,48,0);
harryrance 0:c9bf674fe0c7 43 }
harryrance 0:c9bf674fe0c7 44
harryrance 0:c9bf674fe0c7 45 void AliensArray::type_1_draw(N5110 &lcd)
harryrance 0:c9bf674fe0c7 46 {
harryrance 0:c9bf674fe0c7 47 _x_origin = _x/8;
harryrance 0:c9bf674fe0c7 48 _y_origin = _y;
harryrance 0:c9bf674fe0c7 49
harryrance 0:c9bf674fe0c7 50 for (int i = 0; i < 46; i+= 5){
harryrance 0:c9bf674fe0c7 51 lcd.setPixel((_x_origin+10+i)-1,(_y_origin+10)-1);
harryrance 0:c9bf674fe0c7 52 lcd.setPixel((_x_origin+10+i),(_y_origin+10)-1);
harryrance 0:c9bf674fe0c7 53 lcd.setPixel((_x_origin+10+i),(_y_origin+10)+1);
harryrance 0:c9bf674fe0c7 54 lcd.setPixel((_x_origin+10+i)-1,(_y_origin+10)+1);
harryrance 0:c9bf674fe0c7 55 lcd.setPixel((_x_origin+10+i)+1,(_y_origin+10));
harryrance 0:c9bf674fe0c7 56 }
harryrance 0:c9bf674fe0c7 57 }
harryrance 0:c9bf674fe0c7 58
harryrance 0:c9bf674fe0c7 59 void AliensArray::type_2_draw(N5110 &lcd)
harryrance 0:c9bf674fe0c7 60 {
harryrance 0:c9bf674fe0c7 61 _x_origin = _x/8;
harryrance 0:c9bf674fe0c7 62 _y_origin = _y;
harryrance 0:c9bf674fe0c7 63
harryrance 0:c9bf674fe0c7 64 for (int i = 0; i < 46; i+= 5){
harryrance 0:c9bf674fe0c7 65 lcd.setPixel((_x_origin+10+i),(_y_origin+16));
harryrance 0:c9bf674fe0c7 66 lcd.setPixel((_x_origin+10+i)-1,(_y_origin+16));
harryrance 0:c9bf674fe0c7 67 lcd.setPixel((_x_origin+10+i)+1,(_y_origin+16));
harryrance 0:c9bf674fe0c7 68 lcd.setPixel((_x_origin+10+i)+1,(_y_origin+16)-1);
harryrance 0:c9bf674fe0c7 69 lcd.setPixel((_x_origin+10+i)+1,(_y_origin+16)+1);
harryrance 0:c9bf674fe0c7 70 }
harryrance 0:c9bf674fe0c7 71 }
harryrance 0:c9bf674fe0c7 72
harryrance 0:c9bf674fe0c7 73 void AliensArray::type_3_draw(N5110 &lcd)
harryrance 0:c9bf674fe0c7 74 {
harryrance 0:c9bf674fe0c7 75 _x_origin = _x/8;
harryrance 0:c9bf674fe0c7 76 _y_origin = _y;
harryrance 0:c9bf674fe0c7 77
harryrance 0:c9bf674fe0c7 78 for (int i = 0; i < 46; i+= 5){
harryrance 0:c9bf674fe0c7 79 lcd.setPixel((_x_origin+10+i),(_y_origin+22));
harryrance 0:c9bf674fe0c7 80 lcd.setPixel((_x_origin+10+i)-1,(_y_origin+22)-1);
harryrance 0:c9bf674fe0c7 81 lcd.setPixel((_x_origin+10+i),(_y_origin+22)-1);
harryrance 0:c9bf674fe0c7 82 lcd.setPixel((_x_origin+10+i)-1,(_y_origin+22));
harryrance 0:c9bf674fe0c7 83 lcd.setPixel((_x_origin+10+i)+1,(_y_origin+22));
harryrance 0:c9bf674fe0c7 84 lcd.setPixel((_x_origin+10+i)-1,(_y_origin+22)+1);
harryrance 0:c9bf674fe0c7 85 lcd.setPixel((_x_origin+10+i),(_y_origin+22)+1);
harryrance 0:c9bf674fe0c7 86 }
harryrance 0:c9bf674fe0c7 87 }
harryrance 0:c9bf674fe0c7 88
harryrance 0:c9bf674fe0c7 89 Vector2D AliensArray::get_velocity()
harryrance 0:c9bf674fe0c7 90 {
harryrance 0:c9bf674fe0c7 91 Vector2D v = {_velocity.x,_velocity.y};
harryrance 0:c9bf674fe0c7 92 return v;
harryrance 0:c9bf674fe0c7 93 }
harryrance 0:c9bf674fe0c7 94
harryrance 0:c9bf674fe0c7 95 Vector2D AliensArray::get_pos()
harryrance 0:c9bf674fe0c7 96 {
harryrance 0:c9bf674fe0c7 97 Vector2D p = {_x,_y};
harryrance 0:c9bf674fe0c7 98 return p;
harryrance 0:c9bf674fe0c7 99 }
harryrance 0:c9bf674fe0c7 100
harryrance 0:c9bf674fe0c7 101 void AliensArray::set_velocity(Vector2D v)
harryrance 0:c9bf674fe0c7 102 {
harryrance 0:c9bf674fe0c7 103 _velocity.x = v.x;
harryrance 0:c9bf674fe0c7 104 _velocity.y = v.y;
harryrance 0:c9bf674fe0c7 105 }
harryrance 0:c9bf674fe0c7 106
harryrance 0:c9bf674fe0c7 107 void AliensArray::set_pos(Vector2D p)
harryrance 0:c9bf674fe0c7 108 {
harryrance 0:c9bf674fe0c7 109 _x = p.x;
harryrance 0:c9bf674fe0c7 110 _y = p.y;
harryrance 0:c9bf674fe0c7 111 }
harryrance 0:c9bf674fe0c7 112