Play snake using mbed! A snake-like game that runs on the memoryLCD display on Happy Gecko.
Embed:
(wiki syntax)
Show/hide line numbers
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(silabs::LS013B7DH03 &display, uint8_t color) const{ 00054 switch (_posAndDir.direction){ 00055 case UP: 00056 for (uint8_t i=0;i<_nPix;i++){ 00057 display.pixel(_posAndDir.x*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>(_px_map[i] & 0xF), \ 00058 (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>( (_px_map[i] >> 4) & 0xF), color); 00059 } 00060 break; 00061 00062 case DOWN: 00063 for (uint8_t i=0;i<_nPix;i++){ 00064 display.pixel(_posAndDir.x*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>(_px_map[i] & 0xF), \ 00065 (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2 + STEPSIZE-1-static_cast<uint8_t>( (_px_map[i] >> 4) & 0xF), color); 00066 } 00067 break; 00068 case RIGHT: 00069 for (uint8_t i=0;i<_nPix;i++){ 00070 display.pixel(_posAndDir.x*STEPSIZE + BOARDERWIDTH/2 + STEPSIZE-1-static_cast<uint8_t>((_px_map[i] >> 4) & 0xF), \ 00071 (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>(_px_map[i] & 0xF), color); 00072 } 00073 break; 00074 case LEFT: 00075 for (uint8_t i=0; i<_nPix; i++){ 00076 display.pixel(_posAndDir.x*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>((_px_map[i] >> 4) & 0xF), \ 00077 (_posAndDir.y+TOPEDGE)*STEPSIZE + BOARDERWIDTH/2 + static_cast<uint8_t>(_px_map[i] & 0xF), color); 00078 } 00079 break; 00080 } 00081 } 00082
Generated on Thu Jul 14 2022 05:54:03 by 1.7.2