Platform game written for the GHI/OutrageousCircuits RETRO game device. Navigate the caves collecting all the pickups and avoiding the creatures and haunted mine carts that patrol the caves. Oh and remember to watch out for the poisonous plants... This game demonstrates the ability to have multiple animated sprites where the sprites can overlap the background environment. See how the player moves past the fence and climbs the wall in the 3rd screen.

Dependencies:   mbed

Revision:
3:a93fe5f207f5
Parent:
0:2ee0812e2615
Child:
4:45ff7fc8a431
--- a/LCD_ST7735/LCD_ST7735.cpp	Thu Dec 04 03:13:14 2014 +0000
+++ b/LCD_ST7735/LCD_ST7735.cpp	Sat Dec 27 23:24:30 2014 +0000
@@ -358,18 +358,26 @@
     int w = *pbmp++;
     int h = *pbmp++;
     
-    clip(x, y, w, h);
-    int c = w * h;
-    beginBatchCommand(CMD_RAMWR);
-    while(c--)
-    {
-        writeBatchData(*pbmp++);
-    }
-    endBatchCommand();
+    drawBitmap(x, y, pbmp, 0, 0, w, h);
 }
 
 void LCD_ST7735::drawBitmap(int x, int y, const uint16_t *pbmp, int srcX, int srcY, int srcWidth, int srcHeight)
 {
+    // Clip if out of screen    
+    if ((x >= _width) || (x + srcWidth < 0) || 
+        (y >= _height) || (y + srcHeight < 0))
+    {
+        return;
+    }
+    
+    // Clip X
+    if (x < 0) { srcX += -x; srcWidth += x; x = 0; }
+    if (x + srcWidth >= _width) { srcWidth += _width - (x + srcWidth); }
+    
+    // Clip Y
+    if (y  < 0) {srcY += -y; srcHeight += y; y = 0; }  
+    if (y + srcHeight >= _height) { srcHeight += _height - (y + srcHeight); }
+    
     int w = *pbmp++;
     int h = *pbmp++;
     
@@ -389,6 +397,21 @@
 
 void LCD_ST7735::drawBitmap(int x, int y, Bitmap4bpp &bmp, int srcX, int srcY, int srcWidth, int srcHeight)
 {
+    // Clip if out of screen    
+    if ((x >= _width) || (x + srcWidth < 0) || 
+        (y >= _height) || (y + srcHeight < 0))
+    {
+        return;
+    }
+    
+    // Clip X
+    if (x < 0) { srcX += -x; srcWidth += x; x = 0; }
+    if (x + srcWidth >= _width) { srcWidth += _width - (x + srcWidth); }
+    
+    // Clip Y
+    if (y  < 0) {srcY += -y; srcHeight += y; y = 0; }  
+    if (y + srcHeight >= _height) { srcHeight += _height - (y + srcHeight); }
+    
     int stride = bmp.getStride();
     
     bool oddStart = srcX & 0x01;
@@ -416,78 +439,6 @@
     endBatchCommand();
 }
 
-void LCD_ST7735::drawGlyph(int x, int y,  uint16_t foregroundColor, uint16_t backgroundColor, const uint8_t *pbmp, int srcX, int srcY, int srcWidth, int srcHeight, bool flipHorizontal)
-{
-    uint8_t fgh = foregroundColor >> 8;
-    uint8_t fgl = (uint8_t)foregroundColor;
-    uint8_t bgh = backgroundColor >> 8;
-    uint8_t bgl = (uint8_t)backgroundColor;
-    
-    int w = (*((uint16_t*)pbmp)) >> 3; pbmp += 4;
-    int byteWidth = srcWidth >> 3;
-        
-    const uint8_t *p = pbmp + (srcX >> 3) + (srcY * w);
-    
-    clip(x, y, srcWidth, srcHeight);
-    beginBatchCommand(CMD_RAMWR);
-    if (!flipHorizontal)
-    {
-        const uint8_t *r = p;
-        for (int iy = 0; iy < srcHeight; ++iy)
-        {
-            for (int ix = 0; ix < byteWidth; ++ix)
-            {
-                uint8_t b = *p++;
-                for(int c = 0; c < 8; ++c)
-                {
-                    if (b & 0x80)
-                    {
-                        writeBatchData(fgh);
-                        writeBatchData(fgl);
-                    }
-                    else
-                    {
-                        writeBatchData(bgh);
-                        writeBatchData(bgl);
-                    }
-                        
-                    b <<= 1;
-                }   
-            }
-            p = (r += w);
-        }
-    }
-    else
-    {
-        p += (byteWidth - 1);
-        const uint8_t *r = p;
-        for (int iy = 0; iy < srcHeight; ++iy)
-        {
-            for (int ix = 0; ix < byteWidth; ++ix)
-            {
-                uint8_t b = *p--;
-                for(int c = 0; c < 8; ++c)
-                {
-                    if (b & 0x01)
-                    {
-                        writeBatchData(fgh);
-                        writeBatchData(fgl);
-                    }
-                    else
-                    {
-                        writeBatchData(bgh);
-                        writeBatchData(bgl);
-                    }
-                        
-                    b >>= 1;
-                }   
-            }
-            p = (r += w);
-        }
-    }
-    endBatchCommand();
-}
-
 void LCD_ST7735::setForegroundColor(uint16_t color)
 {
     _foregroundColorHigh = color >> 8;
@@ -744,3 +695,4 @@
     _cs = 1; 
 }
 
+