ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Coin/Coin.cpp

Committer:
lewisgw
Date:
2019-04-20
Revision:
21:20478f086bc2
Parent:
16:331be5c7ed80
Child:
26:4253656c0755

File content as of revision 21:20478f086bc2:

#include "Coin.h"

// Define sprite arrays.
int coin_front[5][5] = {
  { 0,0,1,0,0 },
  { 0,1,0,1,0 },
  { 1,0,1,0,1 },
  { 0,1,0,1,0 },
  { 0,0,1,0,0 },
};

int coin_side[5][5] = {
  { 0,0,1,0,0 },
  { 0,0,1,0,0 },
  { 0,0,1,0,0 },
  { 0,0,1,0,0 },
  { 0,0,1,0,0 },
};

// Constructor and destructor.
Coin::Coin() {} 

Coin::~Coin() {}

void Coin::init() {
  _x = 20;
  _y = 33;
  _coin_counter = 0;
}

void Coin::generate_coin() {
  // Toggle the state of the coin every 3 loop iterations so it looks like it is
  // rotating.
  if (_coin_counter == 2) {
    _coin_counter = 0;
    _rotate_coin = !_rotate_coin;
  }
  _coin_counter++;      
}

void Coin::set_coin(int rand_x, int rand_y) {
  if (rand_y > 40) {  // If random number is >40 set it on the top platforms.
    _y = 15;
  } else {
    _y = 33;
  }
  _x = rand_x;
  if (_x < 3 || _x > 78) {  // Ensures the coin does not generate off-screen
    _x = 50;
  }
}

int * Coin::get_coin_sprite() {
  if (_rotate_coin) {
    return *coin_front;
  } else {
    return *coin_side;
  }
}

int Coin::get_coin_x() {
  return _x;
}

int Coin::get_coin_y() {
  return _y;
}