Laila Al Badwawi 200906179 SpaceInvaders I declare this my own independent work and understand the university rules on plagiarism.

Dependencies:   mbed

Committer:
fy14lkaa
Date:
Sun May 05 13:41:51 2019 +0000
Revision:
111:e9a048d06690
Parent:
110:755a3a75d9b0
Child:
130:4ce67451d0c1
added a mutator function to set the position of the spaceship at x-coordinate and y-coordinate

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fy14lkaa 105:b206078335a3 1 #include "Spaceship.h"
fy14lkaa 83:a55e77dfee5a 2
fy14lkaa 106:73d5d818ae7d 3 Spaceship::Spaceship()
fy14lkaa 83:a55e77dfee5a 4 {
fy14lkaa 83:a55e77dfee5a 5 }
fy14lkaa 106:73d5d818ae7d 6 Spaceship::~Spaceship()
fy14lkaa 83:a55e77dfee5a 7 {
fy14lkaa 83:a55e77dfee5a 8 }
fy14lkaa 84:d875c6e87398 9
fy14lkaa 87:4635d00ffe9d 10
fy14lkaa 87:4635d00ffe9d 11
fy14lkaa 106:73d5d818ae7d 12 void Spaceship::init(int x_spaceship,int y_spaceship, int speed_spaceship)
fy14lkaa 85:0094d33fb1da 13 {
fy14lkaa 106:73d5d818ae7d 14
fy14lkaa 106:73d5d818ae7d 15 _x_spaceship= x_spaceship;
fy14lkaa 106:73d5d818ae7d 16 _y_spaceship= y_spaceship;
fy14lkaa 106:73d5d818ae7d 17 _speed_spaceship= speed_spaceship;
fy14lkaa 106:73d5d818ae7d 18 }
fy14lkaa 85:0094d33fb1da 19
fy14lkaa 107:83b0bc100600 20 void Spaceship::draw(N5110 &lcd)
fy14lkaa 107:83b0bc100600 21 {
fy14lkaa 107:83b0bc100600 22 lcd.drawRect(_x_spaceship,_y_spaceship,_x_spaceship+5,_y_spaceship+10,FILL_BLACK);
fy14lkaa 107:83b0bc100600 23 //lcd.drawSprite(_x_spaceship,_y_spaceship,10,12,(int *) spaceship_2);
fy14lkaa 107:83b0bc100600 24
fy14lkaa 107:83b0bc100600 25 }
fy14lkaa 108:ca888bb3ed54 26
fy14lkaa 108:ca888bb3ed54 27
fy14lkaa 108:ca888bb3ed54 28 void Spaceship::update(Direction d,float mag)
fy14lkaa 108:ca888bb3ed54 29 {
fy14lkaa 108:ca888bb3ed54 30 _speed_spaceship = int(mag*10.0f);
fy14lkaa 108:ca888bb3ed54 31
fy14lkaa 109:2137a6a63840 32 if(d==N)
fy14lkaa 109:2137a6a63840 33 //pong.update(pad);
fy14lkaa 109:2137a6a63840 34 //render();
fy14lkaa 109:2137a6a63840 35 _y_spaceship-=2;
fy14lkaa 109:2137a6a63840 36 else
fy14lkaa 109:2137a6a63840 37 if(d==S)
fy14lkaa 109:2137a6a63840 38 _y_spaceship+=2;
fy14lkaa 108:ca888bb3ed54 39
fy14lkaa 109:2137a6a63840 40 if(_y_spaceship>=30)
fy14lkaa 109:2137a6a63840 41 _y_spaceship=30;
fy14lkaa 109:2137a6a63840 42 else
fy14lkaa 109:2137a6a63840 43 if(_y_spaceship<=0)
fy14lkaa 109:2137a6a63840 44 _y_spaceship=0;
fy14lkaa 108:ca888bb3ed54 45
fy14lkaa 108:ca888bb3ed54 46 }
fy14lkaa 110:755a3a75d9b0 47
fy14lkaa 110:755a3a75d9b0 48 int Spaceship::get_pos_x()
fy14lkaa 110:755a3a75d9b0 49 {
fy14lkaa 110:755a3a75d9b0 50 return _x_spaceship;
fy14lkaa 110:755a3a75d9b0 51 }
fy14lkaa 110:755a3a75d9b0 52 int Spaceship::get_pos_y()
fy14lkaa 110:755a3a75d9b0 53 {
fy14lkaa 110:755a3a75d9b0 54 return _y_spaceship;
fy14lkaa 110:755a3a75d9b0 55 }
fy14lkaa 111:e9a048d06690 56
fy14lkaa 111:e9a048d06690 57 void Spaceship::set_pos(int x, int y)
fy14lkaa 111:e9a048d06690 58 {
fy14lkaa 111:e9a048d06690 59 _x_spaceship = x;
fy14lkaa 111:e9a048d06690 60 _y_spaceship = y;
fy14lkaa 111:e9a048d06690 61 }