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
asymmetricPart.cpp@80:77210aa1ad9c, 2019-12-26 (annotated)
- Committer:
- batman52
- Date:
- Thu Dec 26 16:47:58 2019 +0000
- Revision:
- 80:77210aa1ad9c
NXP Rapid IoT prototyping kit port of Silabs "Hhungry Gecko" ( https://os.mbed.com/teams/SiliconLabs/code/Hungry_gecko/ ) snake-like game.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
batman52 | 80:77210aa1ad9c | 1 | /***************************************************************************//** |
batman52 | 80:77210aa1ad9c | 2 | * @file asymmetricPart.cpp |
batman52 | 80:77210aa1ad9c | 3 | * @brief class for an asymmetric head object for gecko.h |
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 | #include "asymmetricPart.h" |
batman52 | 80:77210aa1ad9c | 32 | |
batman52 | 80:77210aa1ad9c | 33 | asymmetricPart::asymmetricPart(): _px_map(NULL), _nPix(0){ |
batman52 | 80:77210aa1ad9c | 34 | _posAndDir.x = 0; |
batman52 | 80:77210aa1ad9c | 35 | _posAndDir.y = 0; |
batman52 | 80:77210aa1ad9c | 36 | _posAndDir.direction = UP; |
batman52 | 80:77210aa1ad9c | 37 | } |
batman52 | 80:77210aa1ad9c | 38 | |
batman52 | 80:77210aa1ad9c | 39 | asymmetricPart::asymmetricPart(uint8_t x, uint8_t y, Direction dir, const uint8_t *px_map, uint8_t nPix): _px_map(px_map), _nPix(nPix){ |
batman52 | 80:77210aa1ad9c | 40 | _posAndDir.x = x; |
batman52 | 80:77210aa1ad9c | 41 | _posAndDir.y = y; |
batman52 | 80:77210aa1ad9c | 42 | _posAndDir.direction = dir; |
batman52 | 80:77210aa1ad9c | 43 | } |
batman52 | 80:77210aa1ad9c | 44 | |
batman52 | 80:77210aa1ad9c | 45 | void asymmetricPart::init(uint8_t x, uint8_t y, Direction dir, const uint8_t *px_map, uint8_t nPix){ |
batman52 | 80:77210aa1ad9c | 46 | _posAndDir.x = x; |
batman52 | 80:77210aa1ad9c | 47 | _posAndDir.y = y; |
batman52 | 80:77210aa1ad9c | 48 | _posAndDir.direction = dir; |
batman52 | 80:77210aa1ad9c | 49 | _px_map = px_map; |
batman52 | 80:77210aa1ad9c | 50 | _nPix = nPix; |
batman52 | 80:77210aa1ad9c | 51 | } |
batman52 | 80:77210aa1ad9c | 52 | |
batman52 | 80:77210aa1ad9c | 53 | void asymmetricPart::draw(ColorMemLCD &display, uint8_t color) const{ |
batman52 | 80:77210aa1ad9c | 54 | |
batman52 | 80:77210aa1ad9c | 55 | #if(MULTI_UPDATE) |
batman52 | 80:77210aa1ad9c | 56 | display.window( (_posAndDir.x)*STEPSIZE + BOARDERWIDTH/2 - 1, |
batman52 | 80:77210aa1ad9c | 57 | (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2, |
batman52 | 80:77210aa1ad9c | 58 | STEPSIZE+1, // LCD_DISP_WIDTH - BOARDERWIDTH/2, |
batman52 | 80:77210aa1ad9c | 59 | STEPSIZE ); |
batman52 | 80:77210aa1ad9c | 60 | #endif |
batman52 | 80:77210aa1ad9c | 61 | |
batman52 | 80:77210aa1ad9c | 62 | switch (_posAndDir.direction){ |
batman52 | 80:77210aa1ad9c | 63 | case UP: |
batman52 | 80:77210aa1ad9c | 64 | for (uint8_t i=0;i<_nPix;i++){ |
batman52 | 80:77210aa1ad9c | 65 | display.pixel(_posAndDir.x*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>(_px_map[i] & 0xF), \ |
batman52 | 80:77210aa1ad9c | 66 | (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>( (_px_map[i] >> 4) & 0xF), color); |
batman52 | 80:77210aa1ad9c | 67 | } |
batman52 | 80:77210aa1ad9c | 68 | break; |
batman52 | 80:77210aa1ad9c | 69 | |
batman52 | 80:77210aa1ad9c | 70 | case DOWN: |
batman52 | 80:77210aa1ad9c | 71 | for (uint8_t i=0;i<_nPix;i++){ |
batman52 | 80:77210aa1ad9c | 72 | display.pixel(_posAndDir.x*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>(_px_map[i] & 0xF), \ |
batman52 | 80:77210aa1ad9c | 73 | (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2 + STEPSIZE-1-static_cast<uint8_t>( (_px_map[i] >> 4) & 0xF), color); |
batman52 | 80:77210aa1ad9c | 74 | } |
batman52 | 80:77210aa1ad9c | 75 | break; |
batman52 | 80:77210aa1ad9c | 76 | case RIGHT: |
batman52 | 80:77210aa1ad9c | 77 | for (uint8_t i=0;i<_nPix;i++){ |
batman52 | 80:77210aa1ad9c | 78 | display.pixel(_posAndDir.x*STEPSIZE + BOARDERWIDTH/2 + STEPSIZE-1-static_cast<uint8_t>((_px_map[i] >> 4) & 0xF), \ |
batman52 | 80:77210aa1ad9c | 79 | (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>(_px_map[i] & 0xF), color); |
batman52 | 80:77210aa1ad9c | 80 | } |
batman52 | 80:77210aa1ad9c | 81 | break; |
batman52 | 80:77210aa1ad9c | 82 | case LEFT: |
batman52 | 80:77210aa1ad9c | 83 | for (uint8_t i=0; i<_nPix; i++){ |
batman52 | 80:77210aa1ad9c | 84 | display.pixel(_posAndDir.x*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>((_px_map[i] >> 4) & 0xF), \ |
batman52 | 80:77210aa1ad9c | 85 | (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>(_px_map[i] & 0xF), color); |
batman52 | 80:77210aa1ad9c | 86 | } |
batman52 | 80:77210aa1ad9c | 87 | break; |
batman52 | 80:77210aa1ad9c | 88 | } |
batman52 | 80:77210aa1ad9c | 89 | |
batman52 | 80:77210aa1ad9c | 90 | #if(MULTI_UPDATE) |
batman52 | 80:77210aa1ad9c | 91 | display.update(); |
batman52 | 80:77210aa1ad9c | 92 | #endif |
batman52 | 80:77210aa1ad9c | 93 | |
batman52 | 80:77210aa1ad9c | 94 | } |