Barış Bilgin Şenol
/
Game_Logic
Saltuk 212
Revision 0:c7dd8e13fa95, committed 2019-05-31
- Comitter:
- Bilgin
- Date:
- Fri May 31 15:13:48 2019 +0000
- Commit message:
- 212 Saltuk
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bullet/Bullet.cpp Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,57 @@ +#include "Bullet.h" + +/** + constructor + bool true means corresponding coordinates will be incremented every tick (false = decrement) +*/ +Bullet::Bullet(short pixel, short x, short y, short dir){ + next = 0; + pxl = 3; + this->x = x; + this->y = y; + this->dir = dir; + collided = false; +} + +void Bullet::move(){ + short a = 4; + if(dir == 1) + y = y - a; + else if(dir == 2) + x = x + a; + else if(dir == 3) + y = y + a; + else if(dir == 4) + x = x - a; + + if(x < 0 || (x + pxl) > 126) + collided = true; + else if(y < 0 || (y + pxl) > 62) + collided = true; +} + +Bullet* Bullet::getNext(){ + return next; +} + +void Bullet::setNext(Bullet* newNext) +{ + next = newNext; +} + +bool Bullet::willBeRemoved(){ + return collided; +} + +void Bullet::getxy(short& xcor, short& ycor){ + xcor = x; + ycor = y; +} + +void Bullet::setCollision(){ + collided = true; +} + +short Bullet::getDir(){ + return dir; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bullet/Bullet.h Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,25 @@ +#ifndef BULLET_H +#define BULLET_H + +#include "mbed.h" + +class Bullet{ + public: + Bullet(short pixel, short x, short y, short dir); + void move(); + Bullet* getNext(); + void setNext(Bullet* newNext); + bool willBeRemoved(); + void getxy(short& xcor, short& ycor); + void setCollision(); + short getDir(); + short x; + short y; + short dir; + bool collided; + + private: + short pxl; + Bullet* next; +}; +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bullet/BulletList.cpp Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,102 @@ +#include "BulletList.h" + +BulletList::BulletList(){ + bulletCount = 0; + head = 0; +} + +BulletList::~BulletList(){ + if (head != 0) + { + Bullet* prev = head; + Bullet* cur = head; + while (cur->getNext() != 0) + { + cur = cur->getNext(); + delete prev; + prev = cur; + } + delete cur; + } +} + +void BulletList::addBullet(short pixel, short x, short y, short dir){ + //add to beginning of the list + if (head != 0) + { + Bullet* newBullet = new Bullet(pixel, x, y, dir); + newBullet->setNext(head); + head = newBullet; + bulletCount++; + } + // add as the head if the head is empty + else + { + head = new Bullet(pixel, x, y, dir); + bulletCount++; + } +} + +void BulletList::removeCollisions(){ + Bullet* cur = head->getNext(); + Bullet* prev = head; + Bullet* temp; + + if(head != 0){ + //check excluding head + while(cur != 0){ + if(cur->willBeRemoved()){ + temp = cur->getNext(); + delete cur; + cur = 0; + cur = temp; + prev->setNext(cur); + } + else{ + prev = cur; + cur = cur->getNext(); + } + } + //check head + if(head->willBeRemoved()){ + temp = head->getNext(); + delete head; + head = 0; + head = temp; + } + } +} + +void BulletList::moveAll(){ + Bullet* cur = head; + + while(cur != 0){ + cur->move(); + cur = cur->getNext(); + } +} + +void BulletList::checkBBCollisions(){ + Bullet* cur = head; + Bullet* comp; + short xcur, ycur, xcomp, ycomp; + + while(cur != 0){ + cur->getxy(xcur, ycur); + comp = cur->getNext(); + while(comp != 0){ + comp->getxy(xcomp, ycomp); + + if((xcur - 2 <= xcomp && xcomp <= xcur + 2) && (ycur - 2 <= ycomp && ycomp <= ycur + 2)){ + cur->setCollision(); + comp->setCollision(); + } + comp = comp->getNext(); + } + cur = cur->getNext(); + } +} + +Bullet* BulletList::getHead(){ + return head; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bullet/BulletList.h Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,23 @@ +#ifndef BULLETLIST_H +#define BULLETLIST_H + +#include "mbed.h" +#include "Bullet.h" +#include <stdint.h> + + +class BulletList{ + public: + BulletList(); + ~BulletList(); + void addBullet(short pixel, short x, short y, short dir); + void removeCollisions(); + void moveAll(); + void checkBBCollisions(); + Bullet* getHead(); + + private: + Bullet* head; + int bulletCount; +}; +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Game/Game.cpp Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,85 @@ +#include "Game.h" + +Game::Game(){ + player = new Player(7, 0, 56, 2); + bullets = new BulletList(); + tanks = new TankList(); + death = false; +} + +void Game::spawnEnemies(){ + short i = 3 - (rand() % 4); + short x, y; + player->getxy(x, y); + switch(i){ + case 0: + if(!(x < 60 && y < 28) && i == 0){ + if(checkForSpawnCollision(0, 0)) + tanks->addTank(7, 0, 0, 1 + (rand() % 4)); + } + break; + case 1: + if(!(x >= 60 && y < 28) && i == 1){ + if(checkForSpawnCollision(120, 0)) + tanks->addTank(8, 120, 0, 1 + (rand() % 4)); + } + break; + case 2: + if(!(x < 60 && y >= 28) && i == 2){ + if(checkForSpawnCollision(0, 56)) + tanks->addTank(8, 0, 56, 1 + (rand() % 4)); + } + break; + case 3: + if(!(x >= 60 && y >= 28) && i == 3){ + if(checkForSpawnCollision(120, 56)) + tanks->addTank(8, 120, 56, 1 + (rand() % 4)); + } + break; + } + +} +//@param x,y are top left coordinates of the spawn location +//@return true if spawnable +bool Game::checkForSpawnCollision(short x, short y){ + Tank* cur = tanks->getHead(); + bool spawn = true; + short xcur, ycur; + + while(cur != 0){ + cur->getxy(xcur, ycur); + + if((x - 7 <= xcur && xcur <= x + 7) && (y - 7 <= ycur && ycur <= y + 7)){ + spawn = false; + } + cur = cur->getNext(); + } + return spawn; +} + +Player* Game::getPlayer(){ + return player; +} + +BulletList* Game::getBullets(){ + return bullets; +} + +TankList* Game::getTanks(){ + return tanks; +} + +void Game::play(){ + tanks->moveAll(bullets); + bullets->moveAll(); + bullets->checkBBCollisions(); + tanks->checkallBTcollisions(bullets->getHead()); + if(player->checkCollisions(bullets->getHead(), tanks->getHead())){ + death = true; + } + else{ + bullets->removeCollisions(); + tanks->removeCollisions(); + spawnEnemies(); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Game/Game.h Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,24 @@ +#ifndef GAME_H +#define GAME_H + +#include "Player.h" +#include "TankList.h" +#include "BulletList.h" +#include "mbed.h" + +class Game{ + public: + Game(); + void spawnEnemies(); + bool checkForSpawnCollision(short x, short y); // returns true if spawnable + Player* getPlayer(); + BulletList* getBullets(); + TankList* getTanks(); + void play(); + bool death; + + Player* player; + BulletList* bullets; + TankList* tanks; +}; +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/KS0108.lib Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/DimiterK/code/KS0108/#e4b50f4c13a8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Player/Player.cpp Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,106 @@ +#include "Player.h" + +/** + constructor + bool true means corresponding coordinates will be incremented every tick (false = decrement) +*/ +Player::Player(short pixel, short x, short y, short dir){ + pxl = pixel; + this->x = x; + this->y = y; + this->dir = dir; + collided = false; + life = 3; +} + +void Player::move(short i){ + short a = 3; + if(i == dir){ + if(dir == 1) + y = y - a; + else if(dir == 2) + x = x + a; + else if(dir == 3) + y = y + a; + else if(dir == 4) + x = x - a; + } + else + dir = i; + + if(x < 0) + x = 0; + else if((x + pxl) > 127) + x = 120; + else if(y < 0) + y = 0; + else if((y + pxl) > 63) + y = 56; +} + +bool Player::willBeRemoved(){ + return collided; +} + +Bullet* Player::fire(){ + Bullet* bullet; + if(dir == 1){ + bullet = new Bullet(2, x+3, y-2, dir); + } + else if(dir == 2){ + bullet = new Bullet(2, x+8, y+3, dir); + } + else if(dir == 3){ + bullet = new Bullet(2, x+3, y+8, dir); + } + else if(dir == 4){ + bullet = new Bullet(2, x-2, y+3, dir); + } + return bullet; +} + +void Player::getxy(short& xcor, short& ycor){ + xcor = x; + ycor = y; +} + +bool Player::checkCollisions(Bullet* bulletHead, Tank* tankHead){ + Bullet* bcomp = bulletHead; + short xcomp, ycomp; + + while(bcomp != 0){ + bcomp->getxy(xcomp, ycomp); + + if((x - 1 <= xcomp && xcomp <= x + 7) && (y - 1 <= ycomp && ycomp <= y + 7)){ + collided = true; + bcomp->setCollision(); + } + bcomp = bcomp->getNext(); + } + Tank* tcomp = tankHead; + + while(tcomp != 0){ + tcomp->getxy(xcomp, ycomp); + + if((x - 7 <= xcomp && xcomp <= x + 7) && (y - 7 <= ycomp && ycomp <= y + 7)){ + collided = true; + tcomp->setCollision(); + } + tcomp = tcomp->getNext(); + } + + if(collided){ + life--; + collided = false; + return true; + } + return false; +} + +short Player::getLife(){ + return life; +} + +short Player::getDir(){ + return dir; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Player/Player.h Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,27 @@ +#ifndef PLAYER_H +#define PLAYER_H + +#include "mbed.h" +#include "Bullet.h" +#include "Tank.h" + +class Player{ + public: + Player(short pixel, short x, short y, short dir); + void move(short i); + bool willBeRemoved(); + Bullet* fire(); + void getxy(short& xcor, short& ycor); + bool checkCollisions(Bullet* bulletHead, Tank* tankHead); + short getLife(); + short getDir(); + short x; + short y; + short dir; + bool collided; + short life; + + private: + short pxl; +}; +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tank/Tank.cpp Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,110 @@ +#include "Tank.h" + +/** + constructor + bool true means corresponding coordinates will be incremented every tick (false = decrement) +*/ +Tank::Tank(short pixel, short x, short y, short dir){ + next = 0; + pxl = pixel; + this->x = x; + this->y = y; + this->dir = dir; + collided = false; +} + +Bullet* Tank::move(){ + Bullet* temp = 0; + short a = 3; + short i = rand() % 10; + if(1 <= i && i <= 4){ + dir = i; + } + else if(i == 0 || ((5 <= i) && (i <= 8))){ + if(dir == 1) + y = y - a; + else if(dir == 2) + x = x + a; + if(dir == 3) + y = y + a; + else if(dir == 4) + x = x - a; + } + else{ + temp = fire(); + } + + if(x < 0) + x = 0; + else if(x > 120) + x = 120; + else if(y < 0) + y = 0; + else if(y > 56) + y = 56; + + + return temp; +} + +void Tank::changeDirection(short i){ + dir = i; +} + +Tank* Tank::getNext(){ + return next; +} + +void Tank::setNext(Tank* newNext) +{ + next = newNext; +} + +bool Tank::willBeRemoved(){ + return collided; +} + +Bullet* Tank::fire(){ + Bullet* bullet; + if(dir == 1){ + bullet = new Bullet(2, x+3, y-2, dir); + } + else if(dir == 2){ + bullet = new Bullet(2, x+8, y+3, dir); + } + else if(dir == 3){ + bullet = new Bullet(2, x+3, y+8, dir); + } + else if(dir == 4){ + bullet = new Bullet(2, x-2, y+3, dir); + } + return bullet; +} + +void Tank::getxy(short& xcor, short& ycor){ + xcor = x; + ycor = y; +} + +void Tank::checkBTcollisions(Bullet* listhead){ + Bullet* comp = listhead; + short xcomp, ycomp; + + while(comp != 0){ + comp->getxy(xcomp, ycomp); + + if((x - 1 <= xcomp && xcomp <= x + 7) && (y - 1 <= ycomp && ycomp <= y + 7)){ + collided = true; + comp->setCollision(); + } + comp = comp->getNext(); + } +} + +void Tank::setCollision(){ + collided = true; +} + +short Tank::getDir(){ + return dir; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tank/Tank.h Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,30 @@ +#ifndef TANK_H +#define TANK_H + +#include "mbed.h" +#include "Bullet.h" +#include "BulletList.h" + +class Tank{ + public: + Tank(short pixel, short x, short y, short dir); + Bullet* move(); + void changeDirection(short i); + Tank* getNext(); + void setNext(Tank* newNext); + bool willBeRemoved(); + Bullet* fire(); + void getxy(short& xcor, short& ycor); + void checkBTcollisions(Bullet* listhead); + void setCollision(); + short getDir(); + short x; + short y; + short dir; + bool collided; + + private: + short pxl; + Tank* next; +}; +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tank/TankList.cpp Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,94 @@ +#include "TankList.h" + +TankList::TankList(){ + tankCount = 0; + head = 0; +} + +TankList::~TankList(){ + if (head != 0) + { + Tank* prev = head; + Tank* cur = head; + while (cur->getNext() != 0) + { + cur = cur->getNext(); + delete prev; + prev = cur; + } + delete cur; + } +} + +void TankList::addTank(short pixel, short x, short y, short dir){ + //add to beginning of the list + if (head != 0) + { + Tank* newTank = new Tank(pixel, x, y, dir); + newTank->setNext(head); + head = newTank; + tankCount++; + } + // add as the head if the head is empty + else + { + head = new Tank(pixel, x, y, dir); + tankCount++; + } +} + +void TankList::removeCollisions(){ + Tank* cur = head->getNext(); + Tank* prev = head; + Tank* temp; + + if(head != 0){ + //check excluding head + while(cur != 0){ + if(cur->willBeRemoved()){ + temp = cur->getNext(); + delete cur; + cur = 0; + cur = temp; + prev->setNext(cur); + } + else{ + prev = cur; + cur = cur->getNext(); + } + } + //check head + if(head->willBeRemoved()){ + temp = head->getNext(); + delete head; + head = 0; + head = temp; + } + } +} + +void TankList::moveAll(BulletList* blist){ + Tank* cur = head; + Bullet* fired; + + while(cur != 0){ + fired = cur->move(); + if(fired != 0) + blist->addBullet(2, fired->x, fired->y, fired->dir); + + cur = cur->getNext(); + } +} + +void TankList::checkallBTcollisions(Bullet* listhead){ + Tank* cur = head; + + while(cur != 0){ + cur->checkBTcollisions(listhead); + cur = cur->getNext(); + } +} + +Tank* TankList::getHead(){ + return head; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tank/TankList.h Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,23 @@ +#ifndef TANKLIST_H +#define TANKLIST_H + +#include "mbed.h" +#include "Tank.h" +#include <stdint.h> + + +class TankList{ + public: + TankList(); + ~TankList(); + void addTank(short pixel, short x, short y, short dir); + void removeCollisions(); + void moveAll(BulletList* blist); + void checkallBTcollisions(Bullet* listhead); + Tank* getHead(); + + private: + Tank* head; + int tankCount; +}; +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/image.h Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,142 @@ +#ifndef IMAGE_H +#define IMAGE_H + +unsigned char face[] = { +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x7f, +0x7f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, +0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x3f, 0x3f, 0x1f, +0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f, 0x0f, +0x0f, 0x07, 0x07, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, +0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, +0x03, 0x03, 0x07, 0x0f, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0xb3, 0x3f, 0xbf, +0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xfe, 0xfe, +0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x7f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0xbf, 0xbf, +0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0x3f, 0x1e, 0x18, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xe8, +0xf0, 0x60, 0xa0, 0x8e, 0x10, 0x00, 0x00, 0x30, 0x78, 0x78, 0xf8, 0xf0, 0xf1, 0xf0, 0xf2, 0xf0, +0xf0, 0xf0, 0xf8, 0xfc, 0xfe, 0xfe, 0xfc, 0xbc, 0xb6, 0xf0, 0xf0, 0xe0, 0xf1, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xf9, 0xfc, 0xfc, 0xbe, 0xbe, 0xbc, 0xfc, 0xfe, 0xfa, 0xf8, 0xfc, 0xfc, 0xfc, +0xf8, 0xfa, 0xfe, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0x7b, 0x7f, 0x7f, 0x3e, 0x1e, 0x00, 0x00, 0x00, +0x00, 0xb0, 0xf0, 0xf0, 0xfc, 0xbc, 0xfc, 0xfc, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xfb, 0xf8, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0f, +0x1f, 0x3f, 0x7f, 0xff, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xed, 0xef, 0xee, 0xed, 0xed, 0xef, +0xad, 0xed, 0xed, 0xef, 0xff, 0xff, 0xff, 0xef, 0xef, 0xe7, 0xe7, 0xe7, 0xe7, 0xf7, 0xff, 0xff, +0xff, 0xff, 0x7f, 0x7f, 0x3f, 0x2f, 0x1d, 0x18, 0x1c, 0x0e, 0x0c, 0x00, 0x00, 0xe0, 0xf0, 0xfc, +0xfd, 0xfd, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, +0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x0f, 0xcf, 0xcf, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x80, +0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x83, 0x81, 0x03, 0x03, 0x03, 0x03, 0x07, 0x07, 0x27, 0x27, 0x67, +0x67, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe3, 0x83, 0x81, 0x81, +0xc1, 0xe0, 0xe0, 0xf0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0x03, 0x27, 0xe3, +0xe3, 0xe3, 0xe3, 0xe7, 0xe7, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, +0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, +0x07, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, +0x21, 0x77, 0x77, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0xfc, 0xf8, 0xfb, 0xff, 0xff, +0xff, 0xfe, 0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x7c, 0x38, 0x38, 0x38, 0x1c, 0x1f, 0x0f, +0x0f, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + + +unsigned char cat[] = { +0xcc, 0x4c, 0x44, 0x44, 0xc4, 0xe4, 0xe0, 0xe0, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x33, +0x3f, 0xff, 0xf8, 0xf8, 0xf0, 0xc0, 0xc0, 0xe0, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xbf, 0x3f, 0x3f, 0x3f, 0x1f, 0x60, 0xe0, 0xf0, 0xf8, 0xe7, 0x03, 0x03, 0x0b, 0x3f, 0xff, +0xfc, 0xfc, 0x7e, 0x02, 0x06, 0x07, 0x00, 0x00, 0x03, 0x1f, 0x03, 0x33, 0xff, 0xff, 0xff, 0x03, +0x01, 0x00, 0xd8, 0xf8, 0xf8, 0xe0, 0x23, 0x17, 0x0f, 0x0f, 0x1f, 0x1f, 0x7f, 0xff, 0xff, 0xff, +0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xfe, 0xfe, 0xfa, 0xfe, 0xfc, 0xfc, 0xf8, 0xf8, 0xff, 0xff, 0xfe, 0xfc, 0x78, 0x10, 0x0c, +0x00, 0x80, 0xc0, 0xc0, 0xc0, 0x81, 0x81, 0x80, 0x80, 0x00, 0x00, 0x00, 0x18, 0x18, 0x10, 0x84, +0xce, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xe0, 0x80, 0x00, 0x00, 0x00, 0x9f, 0xff, 0xff, 0xff, 0xfe, 0xf0, 0xe0, 0x60, 0x00, +0xc7, 0x9f, 0x3f, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0f, 0x1d, 0x00, +0x00, 0x60, 0x7f, 0x7f, 0x7f, 0x7f, 0x0f, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xfe, 0xff, 0xff, 0xff, +0x7f, 0x7f, 0x7f, 0x7f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, +0x7f, 0x7f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0xf7, 0x83, 0x0f, 0x0f, 0x1f, 0x1f, 0x0e, 0x00, +0x04, 0x00, 0x00, 0x01, 0x01, 0xf7, 0xff, 0xff, 0x9f, 0x1f, 0x1f, 0x0f, 0xce, 0xec, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xbf, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xe1, 0x81, 0x81, 0x07, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, +0x01, 0x03, 0x03, 0x03, 0x07, 0x07, 0x0e, 0x0e, 0xff, 0xf3, 0xfb, 0xfb, 0xe9, 0xe1, 0xf4, 0xc3, +0xfa, 0xff, 0xec, 0xf2, 0xf8, 0xc8, 0xd0, 0x80, 0x80, 0xdc, 0xf8, 0xf8, 0xd6, 0xf8, 0x5c, 0x00, +0x00, 0x00, 0xe0, 0xe0, 0xf8, 0xf8, 0xfc, 0x1e, 0x05, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf8, 0xfe, 0xff, +0xff, 0x7f, 0x7f, 0x1f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x07, +0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x03, 0x0e, 0x1c, 0x31, 0xe3, 0xc3, 0xc3, 0x07, +0x1f, 0x3f, 0x3f, 0x3f, 0x7f, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0x67, +0x67, 0x4f, 0x07, 0x07, 0x07, 0x07, 0x0e, 0x0e, 0x1c, 0x1c, 0x5c, 0x38, 0x38, 0x38, 0x78, 0x78, +0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xfe, 0xfd, 0xbf, 0x1f, 0x07, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x7c, 0x7c, +0x3c, 0x3c, 0x1c, 0x0c, 0x0c, 0x0c, 0x0e, 0x06, 0x07, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x8c, 0xff, 0xfe, 0xfe, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, +0x00, 0x00, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, +0x00, 0x10, 0x10, 0x11, 0x01, 0x00, 0x00, 0x03, 0x07, 0x0f, 0x0f, 0x1f, 0x1f, 0x7f, 0x7c, 0x7c, +0xf8, 0xf4, 0xe4, 0xe8, 0xca, 0xc8, 0xc0, 0xf0, 0xf0, 0xe0, 0xe0, 0xe0, 0xe0, 0xf0, 0xf0, 0xf8, +0xfc, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfc, 0xfc, 0xec, 0xf6, 0xff, 0x0f, 0x47, 0xfb, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0x91, 0x00, 0x00, 0x00, 0x30, 0xf8, 0xf4, 0xfc, 0xfc, 0xfc, 0xfe, 0xfe, 0x9e, +0x18, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, +0x8c, 0x8e, 0xdf, 0xff, 0xff, 0xbf, 0xa7, 0x81, 0x81, 0x80, 0x00, 0x01, 0x01, 0x01, 0x00, 0x17, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc2, 0xc3, 0xdc, +0x5c, 0x04, 0x00, 0x00, 0x00, 0x20, 0x20, 0xa0, 0x80, 0x00, 0x00, 0x10, 0x10, 0xf3, 0xfe, 0xfe, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0x6f, 0x7f, 0x7f, 0x6f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xef, +0xcf, 0x97, 0x97, 0x9f, 0x17, 0x1f, 0x0f, 0x1f, 0x1f, 0x1f, 0x0f, 0x0f, 0x07, 0x0f, 0x07, 0x07, +0x07, 0x83, 0xc3, 0xe3, 0xf3, 0xf9, 0xff, 0xff, 0x3f, 0x3f, 0x3f, 0x1b, 0x1b, 0x4b, 0x49, 0xec, +0xee, 0xfc, 0x3e, 0x1e, 0x07, 0x23, 0x29, 0x29, 0x29, 0x09, 0x49, 0x49, 0x49, 0x49, 0xc9, 0xf9, +0xb9, 0x9f, 0x8f, 0x83, 0x03, 0x8b, 0xff, 0x1e, 0x12, 0x10, 0x10, 0x10, 0x01, 0x01, 0x00, 0x25, +0xd8, 0xc8, 0xc0, 0xe4, 0xe4, 0xf0, 0x72, 0x78, 0x78, 0x58, 0x1d, 0x2c, 0x0f, 0x0f, 0x07, 0x04, +0x02, 0x82, 0x8a, 0x80, 0x84, 0xc4, 0xc0, 0xc0, 0xc2, 0x62, 0xe0, 0xf8, 0xfd, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xaf, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xf7, 0xea, 0xeb, 0xe3, 0xea, 0xee, 0xe3, 0xc7, 0xc7, +0xc7, 0xc7, 0x87, 0x8f, 0x87, 0x0e, 0x06, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, +0x03, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, +0x01, 0x02, 0x02, 0x00, 0x04, 0x06, 0x0a, 0x0d, 0x15, 0x15, 0x3b, 0x3a, 0x72, 0x56, 0xa4, 0xa4, +0x40, 0xc8, 0xc8, 0xf0, 0xfd, 0xff, 0x2f, 0x23, 0x02, 0x02, 0x00, 0x04, 0x04, 0x00, 0x08, 0x08, +0x0b, 0x81, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x02, 0x02, 0x00, 0x80, 0x08, 0x10, +0x04, 0x82, 0x07, 0x03, 0x03, 0x27, 0x25, 0x70, 0x60, 0xe8, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xfe, 0xff, 0xf3, 0xf1, 0xf8, 0xf2, +0xe3, 0xe0, 0xe1, 0xf8, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0xc3, 0xe7, 0xf7, +0xe1, 0x81, 0xc7, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x60, 0xe0, 0xe0, 0xe0, 0x60, 0x38, 0x1e, +0x1f, 0x0f, 0x9b, 0xff, 0xff, 0x0f, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80 +}; + + +unsigned int heart[] = {8, 8, 0x0C, 0x1F, 0x3F, 0x7E, 0x3F, 0x1F, 0x0C, 0x00}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,268 @@ +#include "mbed.h" +#include "KS0108.h" +#include "image.h" +#include "Game.h" + +DigitalIn butUp(PTE21); +DigitalIn butRight(PTE20); +DigitalIn butDown(PTE29); +DigitalIn butLeft(PTE22); +DigitalIn butMiddle(PTE23); + +KS0108 display (PTC5,PTC7, PTC0, PTC3, PTC11, PTC10, PTA1, PTA2, PTD4, PTA12, PTA4, PTA5, PTC8, PTC9); +void draw(int type, int posX, int posY, int direction); //1.player 2.bot 3.bullet +void erase(int type, int posX, int posY, int direction); +void drawAll(); +void eraseAll(); +Game* game; + +int main() +{ + srand(time(0)); + display.FullScreenBMP(face); + wait(1); + display.ClearScreen(); + + //my stuff + game = new Game(); + + while(1) + { + drawAll(); + wait_ms(40); + display.ClearScreen(); + //eraseAll(); + if(!butUp) + game->getPlayer()->move(1); + else if(!butRight) + game->getPlayer()->move(2); + else if(!butDown) + game->getPlayer()->move(3); + else if(!butLeft) + game->getPlayer()->move(4); + else if(!butMiddle){ + Bullet* temp = game->getPlayer()->fire(); + game->getBullets()->addBullet(2, temp->x, temp->y, temp->dir); + } + game->play(); + } +} + +void drawAll(){ + //draw player + draw(1, game->getPlayer()->x, game->getPlayer()->y, game->getPlayer()->dir); + + //draw tanks + Tank* tcur = game->getTanks()->getHead(); + + while(tcur != 0){ + draw(2, tcur->x, tcur->y, tcur->dir); + tcur = tcur->getNext(); + } + + //draw bullets + Bullet* bcur = game->getBullets()->getHead(); + + while(bcur != 0){ + draw(3, bcur->x, bcur->y, bcur->dir); + bcur = bcur->getNext(); + } + + //draw hearts + unsigned short i = 57; + for(unsigned short j = game->getPlayer()->getLife(); j > 0; i = i + 5, j--){ + draw(5, i, 0, 0); + } + + if(game->death){ + delete game->bullets; + delete game->tanks; + game->bullets = new BulletList(); + game->tanks = new TankList(); + erase(1, game->getPlayer()->x, game->getPlayer()->y, game->getPlayer()->dir); + draw(4, game->getPlayer()->x, game->getPlayer()->y, 1); + wait(3); + game->getPlayer()->x = 0; + game->getPlayer()->y = 56; + game->getPlayer()->dir = 2; + game->death = false; + } + + if(game->player->getLife() == 0){ + display.ClearScreen(); + display.FullScreenBMP(cat); + while(1); + } +} + +void eraseAll(){ + //display.ClearScreen(); + //draw hearts + unsigned short i = 57; + for(unsigned short j = game->getPlayer()->getLife(); j > 0; i = i + 5, j--){ + erase(5, i, 0, 0); + } + + //draw player + erase(1, game->getPlayer()->x, game->getPlayer()->y, game->getPlayer()->dir); + + //draw tanks + Tank* tcur = game->getTanks()->getHead(); + + while(tcur != 0){ + erase(2, tcur->x, tcur->y, tcur->dir); + tcur = tcur->getNext(); + } + + //draw bullets + Bullet* bcur = game->getBullets()->getHead(); + + while(bcur != 0){ + erase(3, bcur->x, bcur->y, bcur->dir); + bcur = bcur->getNext(); + } +} + +void draw(int type, int posX, int posY, int direction) //1.player 2.bot 3.bullet 4.x 5.heart +{ + switch(type) + { + case 1: + switch(direction) + { + case 1: + display.FullRectangle(posX, posY + 2, posX + 7, posY + 7, BLACK); + display.FullRectangle(posX + 3, posY, posX + 4, posY + 1, BLACK); + break; + case 2: + display.FullRectangle(posX, posY, posX + 5, posY + 7, BLACK); + display.FullRectangle(posX + 6, posY + 3, posX + 7, posY + 4, BLACK); + break; + case 3: + display.FullRectangle(posX, posY, posX + 7, posY + 5, BLACK); + display.FullRectangle(posX + 3, posY + 6, posX + 4, posY + 7, BLACK); + break; + case 4: + display.FullRectangle(posX + 2, posY, posX + 7, posY + 7, BLACK); + display.FullRectangle(posX, posY + 3, posX + 1, posY + 4, BLACK); + break; + default: break; + } + break; + + case 2: + switch(direction) + { + case 1: + display.FullRectangle(posX, posY + 2, posX + 7, posY + 7, BLACK); + display.FullRectangle(posX + 3, posY, posX + 4, posY + 1, BLACK); + display.FullRectangle(posX + 2, posY + 5, posX + 5, posY + 7, WHITE); + break; + case 2: + display.FullRectangle(posX, posY, posX + 5, posY + 7, BLACK); + display.FullRectangle(posX + 6, posY + 3, posX + 7, posY + 4, BLACK); + display.FullRectangle(posX, posY + 2, posX + 2, posY + 5, WHITE); + break; + case 3: + display.FullRectangle(posX, posY, posX + 7, posY + 5, BLACK); + display.FullRectangle(posX + 3, posY + 6, posX + 4, posY + 7, BLACK); + display.FullRectangle(posX + 2, posY, posX + 5, posY + 2, WHITE); + break; + case 4: + display.FullRectangle(posX + 2, posY, posX + 7, posY + 7, BLACK); + display.FullRectangle(posX, posY + 3, posX + 1, posY + 4, BLACK); + display.FullRectangle(posX + 5, posY + 2, posX + 7, posY + 5, WHITE); + break; + default: break; + } + break; + + case 3: + display.FullRectangle(posX, posY, posX + 1, posY + 1, BLACK); + break; + + case 4: + display.Line(posX, posY, posX + 7, posY + 7, BLACK); + display.Line(posX + 7, posY, posX, posY + 7, BLACK); + break; + + case 5: + //display.DrawBitmap(heart, posX, posY, BLACK); + display.FullRectangle(posX, posY, posX + 3, posY + 3, BLACK); + display.FullRectangle(posX + 1, posY + 1, posX + 2, posY + 2, WHITE); + break; + default: break; + } +} + +void erase(int type, int posX, int posY, int direction) //1.player 2.bot 3.bullet 4.x 5.heart +{ + switch(type) + { + case 1: + switch(direction) + { + case 1: + display.FullRectangle(posX, posY + 2, posX + 7, posY + 7, WHITE); + display.FullRectangle(posX + 3, posY, posX + 4, posY + 1, WHITE); + break; + case 2: + display.FullRectangle(posX, posY, posX + 5, posY + 7, WHITE); + display.FullRectangle(posX + 6, posY + 3, posX + 7, posY + 4, WHITE); + break; + case 3: + display.FullRectangle(posX, posY, posX + 7, posY + 5, WHITE); + display.FullRectangle(posX + 3, posY + 6, posX + 4, posY + 7, WHITE); + break; + case 4: + display.FullRectangle(posX + 2, posY, posX + 7, posY + 7, WHITE); + display.FullRectangle(posX, posY + 3, posX + 1, posY + 4, WHITE); + break; + default: break; + } + break; + + case 2: + switch(direction) + { + case 1: + display.FullRectangle(posX, posY + 2, posX + 7, posY + 7, WHITE); + display.FullRectangle(posX + 3, posY, posX + 4, posY + 1, WHITE); + //display.FullRectangle(posX + 2, posY + 5, posX + 5, posY + 7, WHITE); + break; + case 2: + display.FullRectangle(posX, posY, posX + 5, posY + 7, WHITE); + display.FullRectangle(posX + 6, posY + 3, posX + 7, posY + 4, WHITE); + //display.FullRectangle(posX, posY + 2, posX + 2, posY + 5, WHITE); + break; + case 3: + display.FullRectangle(posX, posY, posX + 7, posY + 5, WHITE); + display.FullRectangle(posX + 3, posY + 6, posX + 4, posY + 7, WHITE); + //display.FullRectangle(posX + 2, posY, posX + 5, posY + 2, WHITE); + break; + case 4: + display.FullRectangle(posX + 2, posY, posX + 7, posY + 7, WHITE); + display.FullRectangle(posX, posY + 3, posX + 1, posY + 4, WHITE); + //display.FullRectangle(posX + 5, posY + 2, posX + 7, posY + 5, WHITE); + break; + default: break; + } + break; + + case 3: + display.FullRectangle(posX, posY, posX + 1, posY + 1, WHITE); + break; + + case 4: + display.Line(posX, posY, posX + 7, posY + 7, WHITE); + display.Line(posX + 7, posY, posX, posY + 7, WHITE); + break; + + case 5: + //display.DrawBitmap(heart, posX, posY, BLACK); + display.FullRectangle(posX, posY, posX + 3, posY + 3, WHITE); + //display.FullRectangle(posX + 1, posY + 1, posX + 2, posY + 2, WHITE); + break; + default: break; + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri May 31 15:13:48 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file