Yufan Zhong / Mbed 2 deprecated GOLD_MINER

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Monster.cpp Source File

Monster.cpp

00001 #include "Monster.h"
00002 
00003 // nothing doing in the constructor and destructor
00004 Monster::Monster()
00005 {
00006 
00007 }
00008 Monster::~Monster()
00009 {
00010 
00011 }
00012 
00013 //initialise the monster
00014 void Monster::init(float speed)
00015 {
00016     _speed = speed;
00017     _x = WIDTH-3;  // x value on screen is fixed
00018     _y = 22;  // y depends on height of screen and height of Monster
00019 }
00020 
00021 void Monster::draw(N5110 &lcd)
00022 {
00023     // draw the monster
00024     lcd.drawRect(_x,_y,3,3,FILL_BLACK);
00025 }
00026 
00027 void Monster::update()
00028 {
00029     _x-= _speed; //update the position 
00030     if (_x < -2) {
00031         _x = WIDTH; //if reach the end then back to the start point
00032     }
00033 }
00034 
00035 //set the position of monster
00036 void Monster::set_pos(int x) {
00037     _x = x;
00038 }
00039 
00040 //return the position of monster
00041 int Monster::get_pos() {
00042     int p = _x;
00043     return p;
00044 }
00045 
00046 //set the speed of monster
00047 void Monster::set_speed(float speed) {
00048     _speed = speed;
00049 }
00050 
00051 //return the speed of monster
00052 float Monster::get_speed() {
00053     float s = _speed;
00054     return s;
00055 }