![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Daniel Nguyen
Dependencies: 4DGL-uLCD-SE mbed
Diff: AlienMoo.cpp
- Revision:
- 0:7d7f6032c719
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AlienMoo.cpp Thu Nov 02 19:15:07 2017 +0000 @@ -0,0 +1,89 @@ +#include "AlienMoo.h" +#define ALIEN_HEIGHT 8 +#define ALIEN_WIDTH 11 +#define _ 0x000000 //BLACK +#define X 0xFFFFFF //WHITE +#include "uLCD_4DGL.h" +#include <iostream> +using namespace std; + + int alienMooDown_sprite[ALIEN_HEIGHT * ALIEN_WIDTH] = { + _,_,_,_,_,_,_,_,_,_,_, + _,_,_,_,X,X,X,_,_,_,_, + _,_,_,X,_,_,_,X,_,_,_, + _,_,X,_,_,X,_,_,X,_,_, + _,_,X,_,_,_,_,_,X,_,_, + _,_,_,X,_,_,_,X,_,_,_, + _,_,_,_,X,X,X,_,_,_,_, + _,_,_,_,_,_,_,_,_,_,_, + }; + + int alienMooUp_sprite[ALIEN_HEIGHT * ALIEN_WIDTH] = { + _,_,_,X,X,X,X,X,_,_,_, + _,_,X,_,_,_,_,_,X,_,_, + _,X,_,_,X,X,X,_,_,X,_, + X,_,_,_,X,_,X,_,_,_,X, + X,_,_,_,X,X,X,_,_,_,X, + _,X,_,_,_,_,_,_,_,X,_, + _,_,X,_,_,_,_,_,X,_,_, + _,_,_,X,X,X,X,X,_,_,_, + }; + + +AlienMoo::AlienMoo(int x, int y) +{ + change = 0; + pos_x = x; + pos_y = y; + speed = 3; +} + +AlienMoo::~AlienMoo() +{ + +} + +void AlienMoo::draw() +{ + if(change) + { + uLCD.BLIT(pos_x, pos_y, ALIEN_WIDTH, ALIEN_HEIGHT, alienMooDown_sprite); + change = 0; + } + else + { + uLCD.BLIT(pos_x, pos_y, ALIEN_WIDTH, ALIEN_HEIGHT, alienMooUp_sprite); + change = 1; + } +} + +void AlienMoo::update() +{ + if (move) + { + uLCD.filled_rectangle(pos_x, pos_y, pos_x + ALIEN_WIDTH, pos_y + ALIEN_HEIGHT, BLACK); + if (moveLeft == 0) + { + pos_x += speed; + if (pos_x > 110) + { + moveLeft = 1; + } + } + else if (moveLeft == 1) + { + pos_x -= speed; + if (pos_x < 10) + { + moveLeft = 0; + } + } + draw(); + } + else + { + uLCD.filled_rectangle(pos_x, pos_y, pos_x + ALIEN_WIDTH, pos_y + ALIEN_HEIGHT, BLACK); + } +} + + \ No newline at end of file