Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Coin.cpp
00001 #include "Coin.h" 00002 00003 // Define sprite arrays. 00004 int coin_front[5][5] = { 00005 { 0,0,1,0,0 }, 00006 { 0,1,0,1,0 }, 00007 { 1,0,1,0,1 }, 00008 { 0,1,0,1,0 }, 00009 { 0,0,1,0,0 }, 00010 }; 00011 00012 int coin_side[5][5] = { 00013 { 0,0,1,0,0 }, 00014 { 0,0,1,0,0 }, 00015 { 0,0,1,0,0 }, 00016 { 0,0,1,0,0 }, 00017 { 0,0,1,0,0 }, 00018 }; 00019 00020 // Constructor and destructor. 00021 Coin::Coin() {} 00022 00023 Coin::~Coin() {} 00024 00025 void Coin::init() { 00026 // Starting position of the coin. 00027 _x = 20; 00028 _y = 33; 00029 _coin_counter = 0; 00030 } 00031 00032 void Coin::generate_coin() { 00033 // Toggle the state of the coin every 3 loop iterations. This will be used to 00034 // print different coin sprites so it looks like it is rotating. 00035 if (_coin_counter == 2) { 00036 _coin_counter = 0; 00037 _rotate_coin = !_rotate_coin; 00038 } 00039 _coin_counter++; 00040 } 00041 00042 void Coin::set_coin(int rand_x, int rand_y) { 00043 // Set the coin coords based on input values. 00044 if (rand_y > 40) { 00045 _y = 15; // Set the coin on the top platforms. 00046 } else { 00047 _y = 33; // Set coin on the bottom platforms. 00048 } 00049 _x = rand_x; 00050 if (_x < 3 || _x > 78) { // Ensures the coin does not generate off-screen. 00051 _x = 50; // Default value if the coin generates off-screen. 00052 } 00053 } 00054 00055 int * Coin::get_coin_sprite() { 00056 // Return different coin sprites. 00057 if (_rotate_coin) { 00058 return *coin_front; 00059 } else { 00060 return *coin_side; 00061 } 00062 } 00063 00064 int Coin::get_coin_x() { 00065 return _x; 00066 } 00067 00068 int Coin::get_coin_y() { 00069 return _y; 00070 } 00071 00072
Generated on Mon Jul 18 2022 14:06:02 by
1.7.2