Daniel Nguyen

Dependencies:   4DGL-uLCD-SE mbed

AlienAlice.cpp

Committer:
dnguyen314
Date:
2017-11-02
Revision:
0:7d7f6032c719

File content as of revision 0:7d7f6032c719:

#include "AlienAlice.h"
#include "uLCD_4DGL.h"
#define ALIEN_HEIGHT 8
#define ALIEN_WIDTH 11
#define _ 0x000000 //BLACK
#define X 0xFFFFFF //WHITE
#include <iostream>

using namespace std;

    int alienAlice_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,
        X,X,X,X,X,X,X,X,X,X,X,
        _,_,_,X,X,_,X,X,_,_,_,
        _,_,X,X,_,_,_,X,X,_,_,
        X,X,_,_,_,X,_,_,_,X,X,
    }; 


    
AlienAlice::AlienAlice(int x, int y)
{
    pos_x = x;
    pos_y = y;
    speed = 6;
}

AlienAlice::~AlienAlice()
{
    
}

void AlienAlice::draw()
{
    uLCD.BLIT(pos_x, pos_y, ALIEN_WIDTH, ALIEN_HEIGHT, alienAlice_sprite);
}

void AlienAlice::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);   
    }    
}