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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers asymmetricPart.cpp Source File

asymmetricPart.cpp

Go to the documentation of this file.
00001 /***************************************************************************//**
00002  * @file asymmetricPart.cpp
00003  * @brief class for an asymmetric head object for gecko.h
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 #include "asymmetricPart.h"
00032 
00033 asymmetricPart::asymmetricPart(): _px_map(NULL), _nPix(0){
00034     _posAndDir.x = 0;
00035     _posAndDir.y = 0;
00036     _posAndDir.direction = UP;
00037 }
00038 
00039 asymmetricPart::asymmetricPart(uint8_t x, uint8_t y, Direction dir, const uint8_t *px_map, uint8_t nPix): _px_map(px_map), _nPix(nPix){
00040     _posAndDir.x = x;
00041     _posAndDir.y = y;
00042     _posAndDir.direction = dir;
00043 }
00044 
00045 void asymmetricPart::init(uint8_t x, uint8_t y, Direction dir,  const uint8_t *px_map, uint8_t nPix){
00046     _posAndDir.x = x;
00047     _posAndDir.y = y;
00048     _posAndDir.direction = dir;
00049     _px_map = px_map;
00050     _nPix = nPix;
00051 }
00052 
00053 void asymmetricPart::draw(ColorMemLCD &display, uint8_t color) const{
00054 
00055 #if(MULTI_UPDATE)
00056         display.window( (_posAndDir.x)*STEPSIZE + BOARDERWIDTH/2 - 1, 
00057                        (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2, 
00058                        STEPSIZE+1, // LCD_DISP_WIDTH - BOARDERWIDTH/2,
00059                        STEPSIZE );
00060 #endif
00061     
00062     switch (_posAndDir.direction){
00063     case UP:
00064         for (uint8_t i=0;i<_nPix;i++){
00065                 display.pixel(_posAndDir.x*STEPSIZE + BOARDERWIDTH/2 +  static_cast<uint8_t>(_px_map[i] & 0xF), \
00066                         (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>( (_px_map[i] >> 4) & 0xF), color);
00067             }
00068         break;
00069 
00070     case DOWN:
00071         for (uint8_t i=0;i<_nPix;i++){
00072             display.pixel(_posAndDir.x*STEPSIZE +  BOARDERWIDTH/2 + static_cast<uint8_t>(_px_map[i] & 0xF), \
00073                     (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2 + STEPSIZE-1-static_cast<uint8_t>( (_px_map[i] >> 4) & 0xF), color);
00074         }
00075         break;
00076     case RIGHT:
00077         for (uint8_t i=0;i<_nPix;i++){
00078             display.pixel(_posAndDir.x*STEPSIZE + BOARDERWIDTH/2 + STEPSIZE-1-static_cast<uint8_t>((_px_map[i] >> 4) & 0xF), \
00079                     (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>(_px_map[i] & 0xF), color);
00080         }
00081         break;
00082     case LEFT:
00083         for (uint8_t i=0; i<_nPix; i++){
00084             display.pixel(_posAndDir.x*STEPSIZE +  BOARDERWIDTH/2 + static_cast<uint8_t>((_px_map[i] >> 4) & 0xF), \
00085                     (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>(_px_map[i] & 0xF), color);
00086         }
00087         break;
00088     }
00089 
00090 #if(MULTI_UPDATE)
00091     display.update();
00092 #endif
00093 
00094 }