Play snake using mbed! A snake-like game that runs on the memoryLCD display on Happy Gecko.
Embed:
(wiki syntax)
Show/hide line numbers
gecko.h
Go to the documentation of this file.
00001 /***************************************************************************//** 00002 * @file gecko.h 00003 * @brief class for creating a gecko-like object and keeps track of its momvement 00004 ******************************************************************************* 00005 * @section License 00006 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b> 00007 ******************************************************************************* 00008 * 00009 * Permission is granted to anyone to use this software for any purpose, 00010 * including commercial applications, and to alter it and redistribute it 00011 * freely, subject to the following restrictions: 00012 * 00013 * 1. The origin of this software must not be misrepresented; you must not 00014 * claim that you wrote the original software. 00015 * 2. Altered source versions must be plainly marked as such, and must not be 00016 * misrepresented as being the original software. 00017 * 3. This notice may not be removed or altered from any source distribution. 00018 * 00019 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no 00020 * obligation to support this Software. Silicon Labs is providing the 00021 * Software "AS IS", with no express or implied warranties of any kind, 00022 * including, but not limited to, any implied warranties of merchantability 00023 * or fitness for any particular purpose or warranties against infringement 00024 * of any proprietary rights of a third party. 00025 * 00026 * Silicon Labs will not be liable for any consequential, incidental, or 00027 * special damages, or any other relief, or for any claim by any third party, 00028 * arising from your use of this Software. 00029 * 00030 ******************************************************************************/ 00031 00032 #include "LS013B7DH03.h" 00033 #include "settings.h" 00034 #include "asymmetricPart.h" 00035 00036 class Gecko{ 00037 private: 00038 uint8_t _position[MAXLENGTH]; 00039 uint8_t _last; 00040 uint8_t _length; 00041 00042 asymmetricPart _head; 00043 00044 void drawPart(silabs::LS013B7DH03 &display, uint8_t x, uint8_t y) const; 00045 void removePart(silabs::LS013B7DH03 &display, uint8_t x, uint8_t y) const; 00046 public: 00047 Gecko(); 00048 00049 /* Moves the snake and redraws it on the display */ 00050 void move(silabs::LS013B7DH03 &display, Direction dir); 00051 00052 /* Redraw the entire snake */ 00053 void draw(silabs::LS013B7DH03 &display) const; 00054 00055 /* Check if the snake has collides with itself */ 00056 bool selfCollision() const; 00057 00058 /* Increases the length of the snake by one STEPSIZE x STEPSIZE tile */ 00059 void increaseLength(silabs::LS013B7DH03 &display, Direction dir); 00060 00061 /* Checks if the head of the snake occupies a STEP */ 00062 bool headOccupiesTile(uint8_t x, uint8_t y) const; 00063 00064 /* Chech if the snake occupies a STEPSIZE x STEPSIZE tile */ 00065 bool occupiesTile(uint8_t x, uint8_t y) const; 00066 00067 /* Get coordinates */ 00068 uint8_t getX(uint8_t indx) const; 00069 uint8_t getY(uint8_t indx) const; 00070 }; 00071 00072
Generated on Thu Jul 14 2022 05:54:03 by
![doxygen](doxygen.png)