NXP Rapid IoT prototyping kit port of Silabs "hungry gecko" smake-like game. https://os.mbed.com/teams/SiliconLabs/code/Hungry_gecko/

Dependencies:   lib_sx9500 GraphicsDisplay ColorMemLCD Large_fonts

See a detailed description of this project on Hackster.io . https://www.hackster.io/marcomerli/riotwear-snake-ca6dfc

Committer:
batman52
Date:
Fri Dec 27 16:04:44 2019 +0000
Revision:
81:737dff75e013
Parent:
80:77210aa1ad9c
add use of touch sensor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
batman52 80:77210aa1ad9c 1 /***************************************************************************//**
batman52 80:77210aa1ad9c 2 * @file gecko.h
batman52 80:77210aa1ad9c 3 * @brief class for creating a gecko-like object and keeps track of its momvement
batman52 80:77210aa1ad9c 4 *******************************************************************************
batman52 80:77210aa1ad9c 5 * @section License
batman52 80:77210aa1ad9c 6 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
batman52 80:77210aa1ad9c 7 *******************************************************************************
batman52 80:77210aa1ad9c 8 *
batman52 80:77210aa1ad9c 9 * Permission is granted to anyone to use this software for any purpose,
batman52 80:77210aa1ad9c 10 * including commercial applications, and to alter it and redistribute it
batman52 80:77210aa1ad9c 11 * freely, subject to the following restrictions:
batman52 80:77210aa1ad9c 12 *
batman52 80:77210aa1ad9c 13 * 1. The origin of this software must not be misrepresented; you must not
batman52 80:77210aa1ad9c 14 * claim that you wrote the original software.
batman52 80:77210aa1ad9c 15 * 2. Altered source versions must be plainly marked as such, and must not be
batman52 80:77210aa1ad9c 16 * misrepresented as being the original software.
batman52 80:77210aa1ad9c 17 * 3. This notice may not be removed or altered from any source distribution.
batman52 80:77210aa1ad9c 18 *
batman52 80:77210aa1ad9c 19 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
batman52 80:77210aa1ad9c 20 * obligation to support this Software. Silicon Labs is providing the
batman52 80:77210aa1ad9c 21 * Software "AS IS", with no express or implied warranties of any kind,
batman52 80:77210aa1ad9c 22 * including, but not limited to, any implied warranties of merchantability
batman52 80:77210aa1ad9c 23 * or fitness for any particular purpose or warranties against infringement
batman52 80:77210aa1ad9c 24 * of any proprietary rights of a third party.
batman52 80:77210aa1ad9c 25 *
batman52 80:77210aa1ad9c 26 * Silicon Labs will not be liable for any consequential, incidental, or
batman52 80:77210aa1ad9c 27 * special damages, or any other relief, or for any claim by any third party,
batman52 80:77210aa1ad9c 28 * arising from your use of this Software.
batman52 80:77210aa1ad9c 29 *
batman52 80:77210aa1ad9c 30 ******************************************************************************/
batman52 80:77210aa1ad9c 31
batman52 80:77210aa1ad9c 32 // #include "LS013B7DH03.h"
batman52 80:77210aa1ad9c 33 #include "settings.h"
batman52 80:77210aa1ad9c 34 #include "asymmetricPart.h"
batman52 80:77210aa1ad9c 35
batman52 80:77210aa1ad9c 36 class Gecko{
batman52 80:77210aa1ad9c 37 private:
batman52 80:77210aa1ad9c 38 uint8_t _position[MAXLENGTH];
batman52 80:77210aa1ad9c 39 uint8_t _last;
batman52 80:77210aa1ad9c 40 uint8_t _length;
batman52 80:77210aa1ad9c 41
batman52 80:77210aa1ad9c 42 asymmetricPart _head;
batman52 80:77210aa1ad9c 43
batman52 80:77210aa1ad9c 44 void drawPart(ColorMemLCD &display, uint8_t x, uint8_t y) const;
batman52 80:77210aa1ad9c 45 void removePart(ColorMemLCD &display, uint8_t x, uint8_t y) const;
batman52 80:77210aa1ad9c 46
batman52 80:77210aa1ad9c 47 public:
batman52 80:77210aa1ad9c 48 Gecko();
batman52 80:77210aa1ad9c 49
batman52 80:77210aa1ad9c 50 /* Moves the snake and redraws it on the display */
batman52 80:77210aa1ad9c 51 void move(ColorMemLCD &display, Direction dir);
batman52 80:77210aa1ad9c 52
batman52 80:77210aa1ad9c 53 /* Redraw the entire snake */
batman52 80:77210aa1ad9c 54 void draw(ColorMemLCD &display) const;
batman52 80:77210aa1ad9c 55
batman52 80:77210aa1ad9c 56 /* Check if the snake has collides with itself */
batman52 80:77210aa1ad9c 57 bool selfCollision() const;
batman52 80:77210aa1ad9c 58
batman52 80:77210aa1ad9c 59 /* Increases the length of the snake by one STEPSIZE x STEPSIZE tile */
batman52 80:77210aa1ad9c 60 void increaseLength(ColorMemLCD &display, Direction dir);
batman52 80:77210aa1ad9c 61
batman52 80:77210aa1ad9c 62 /* Checks if the head of the snake occupies a STEP */
batman52 80:77210aa1ad9c 63 bool headOccupiesTile(uint8_t x, uint8_t y) const;
batman52 80:77210aa1ad9c 64
batman52 80:77210aa1ad9c 65 /* Chech if the snake occupies a STEPSIZE x STEPSIZE tile */
batman52 80:77210aa1ad9c 66 bool occupiesTile(uint8_t x, uint8_t y) const;
batman52 80:77210aa1ad9c 67
batman52 80:77210aa1ad9c 68 /* Get coordinates */
batman52 80:77210aa1ad9c 69 uint8_t getX(uint8_t indx) const;
batman52 80:77210aa1ad9c 70 uint8_t getY(uint8_t indx) const;
batman52 80:77210aa1ad9c 71 };
batman52 80:77210aa1ad9c 72
batman52 80:77210aa1ad9c 73