Created
February 7, 2016 18:23
-
-
Save flaki/8d2b3a798c5949d846af to your computer and use it in GitHub Desktop.
MARS ATTACK! A tiny hack on the Clouduboy Sprite Demo for the Arduboy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Arduboy.h" | |
// Pre-drawn pixelart animation - Spinny Saucer (17x7, 2 frames) | |
PROGMEM const unsigned char sprite1[] = { /*17x7*/ 0x8, 0x18, 0x38, 0x38, 0x74, 0x7e, 0x6e, 0x3f, 0x2f, 0x3f, 0x6e, 0x7e, 0x74, 0x38, 0x38, 0x18, 0x8 }; | |
PROGMEM const unsigned char sprite2[] = { /*17x7*/ 0x8, 0x18, 0x38, 0x38, 0x7c, 0x76, 0x7e, 0x2f, 0x3f, 0x2f, 0x7e, 0x76, 0x7c, 0x38, 0x38, 0x18, 0x8 }; | |
Arduboy arduboy; | |
int animationSpeed = 3; | |
int animFrame = 0; | |
int cSprite = 0; | |
void setup() { | |
arduboy.start(); | |
arduboy.setTextSize(3); | |
arduboy.setCursor(0,0); | |
arduboy.print("Sprite\nDemo"); | |
arduboy.display(); | |
} | |
int x = 0, y = 24; | |
int sx = 1, sy = 1; | |
void loop () { | |
// pause render until it's time for the next frame | |
if (!(arduboy.nextFrame())) | |
return; | |
// Update flapping animation | |
if (--animFrame <= 0) { | |
animFrame = animationSpeed; | |
cSprite = !cSprite; | |
} | |
// Update position | |
x += sx; | |
y += sy; | |
if (x>108 || x<1) sx = -sx; | |
if (y>56 || y<1) sy = -sy; | |
// Clear display, redraw background text | |
arduboy.clearDisplay(); | |
arduboy.setCursor(0,0); | |
arduboy.print("Sprite\nDemo"); | |
// Draw shadow | |
arduboy.drawBitmap(0 +x,2 +y, cSprite ? sprite1 : sprite2, 17,7, BLACK); | |
arduboy.drawBitmap(2 +x,2 +y, cSprite ? sprite1 : sprite2, 17,7, BLACK); | |
// Draw Bat | |
arduboy.drawBitmap(1 +x,1 +y, cSprite ? sprite1 : sprite2, 17,7, WHITE); | |
// Update Screen | |
arduboy.display(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment