explorer game

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
el17my
Date:
Tue Apr 28 17:30:29 2020 +0000
Parent:
24:d7a794fd1228
Commit message:
4.29

Changed in this revision

Coin/Coin.cpp Show diff for this revision Revisions of this file
Coin/Coin.h Show diff for this revision Revisions of this file
--- a/Coin/Coin.cpp	Tue Apr 28 17:24:20 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-#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() {
-  // Starting position of the coin.
-  _x = 20;
-  _y = 33;
-  _coin_counter = 0;
-}
-
-void Coin::generate_coin() {
-  // Toggle the state of the coin every 3 loop iterations. This will be used to  
-  // print different coin sprites 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) {
-  // Set the coin coords based on input values.
-  if (rand_y > 40) {  
-    _y = 15;  // Set the coin on the top platforms.
-  } else {
-    _y = 33;  // Set coin on the bottom platforms.
-  }
-  _x = rand_x;
-  if (_x < 3 || _x > 78) {  // Ensures the coin does not generate off-screen.
-    _x = 50;  // Default value if the coin generates off-screen.
-  }
-}
-
-int * Coin::get_coin_sprite() {
-  // Return different coin sprites.
-  if (_rotate_coin) {
-    return *coin_front;
-  } else {
-    return *coin_side;
-  }
-}
-
-int Coin::get_coin_x() {
-  return _x;
-}
-
-int Coin::get_coin_y() {
-  return _y;
-} 
-
-
--- a/Coin/Coin.h	Tue Apr 28 17:24:20 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,111 +0,0 @@
-#ifndef COIN_H
-#define COIN_H
-
-#include "mbed.h"
-
-/** Coin Class
-* @brief Generates a coin for the skateboarder to collect *@author Lewis Wooltorton
-* @date April 2019
-
-@code
-
-#include "mbed.h"
-#include "N5110.h"
-#include "Gamepad.h"
-#include "Coin.h"
-#include <cstdlib>
-#include <ctime>
-
-N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
-Gamepad gamepad;
-Coin _coin;
-
-int _skater_x;
-int _skater_y;
-int _player_score;
-bool _coin_collision_flag;
-
-int main() {
-  _coin.init();
-  srand(time(NULL));
-  _player_score = 0;
-  _skater_x = 50;
-  _skater_y = 20;
-  while(1) {
-    
-    // If the skater collides with the coin, set the flag, add 1 to the score 
-    // move the coin to a new random position and make a noise on the buzzer.
-    if (_skater_x == _coin.get_coin_x() 
-      && (_skater_y == _coin.get_coin_y() - 10)) {  
-    _coin_collision_flag = true;
-    _player_score++;
-    _coin.set_coin((rand() % 100),(abs(rand() % 100 - 20)));  // Place coin 
-    // on a constrained random position.
-    gamepad.tone(1500, 0.05);  // Make collection noise on buzzer.
-    wait(0.05);
-    gamepad.tone(3000, 0.05);   
-    }
-    
-    // Print the coin.
-    lcd.drawSprite(_coin.get_coin_x(),_coin.get_coin_y(),5,5,
-                   (int*)_coin.get_coin_sprite());
-  }
-}
-       
-@endcode
-*/
-
-class Coin {
- public:
-  // Constructor and Destructor.
-  /**
-  * @brief Constructor @details Non user specified.
-  */
-  Coin();
-  /**
-  * @brief Destructor @details Non user specified.
-  */
-  ~Coin();
-  
-  // Mutators.
-  /** 
-  * @breif Initialises Coin object. 
-  */
-  void init();
-  /**
-  * @breif Sets the Coin coordinates.
-  * @param rand_x @details a random number that determines the x coordinate
-  * @param rand_y @details a random number that determines if the Coin is generated on the upper or lower platforms
-  */
-  void set_coin(int rand_x, int rand_y);
-  
-  // Accessors.
-  /**
-  * @breif Gets the Coin sprite.
-  * @returns The Coin sprite (an integer array)
-  */
-  int * get_coin_sprite();
-  /**
-  * @breif Gets the x coordinate.
-  * @returns The x coordinate of the Coin
-  */ 
-  int get_coin_x();
-  /**
-  * @breif Gets the y coordinate.
-  * @returns The y coordinate of the Coin
-  */
-  int get_coin_y(); 
-  
-  // Member Methods.
-  /**
-  * @breif Generates the coin. @details Selects the coin sprite
-  */
-  void generate_coin();
-    
- private:
-  int _x;
-  int _y;
-  int _coin_counter;
-  bool _rotate_coin;
-};
-#endif