Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace macros and move images to separate header #1

Merged
merged 3 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 14 additions & 100 deletions batandcollisions/batandcollisions.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//bat move and shoot demo
#include <Arduboy2.h>

#include "images.h"

Arduboy2 arduboy;

//define constants
constexpr uint8_t maxSonics = 5; //max number of active player bullets

Expand All @@ -16,9 +20,11 @@ constexpr int backgroundSpeed = 1;
// Limit of the x position of backgrounds
constexpr int backgroundXLimit = -31;

#define MAX_NUM_ENEMIES 3
#define DELAY_MODIFIER 4
#define RESTART_DELAY 300
constexpr int enemiesCount = 3;

constexpr int delayModifier = 4;

constexpr int restartDelay = 300;


//declare global variables here
Expand Down Expand Up @@ -76,7 +82,7 @@ struct EnemyList {
int modB;
};

EnemyList enemyList[MAX_NUM_ENEMIES] = {
EnemyList enemyList[enemiesCount] = {
{ 0, 127, 32, 300, false , 0, 32 },
{ 0, 127, 15, 150, false, 0, 15 },
{ 0, 127, 48, 122, false, 0, 48 },
Expand All @@ -98,98 +104,6 @@ Background background[maxBackgrounds]
{ 96, 0, 0},
{ 128, 0, 0},
};
//sprites
const unsigned char PROGMEM batflap[] =
{
// width, height,
16, 8,
0x40, 0x60, 0x60, 0x60, 0x70, 0x30, 0x1f, 0x3e, 0x36, 0x3f, 0x16, 0x30, 0x70, 0x70, 0x60, 0x40,
};

const unsigned char PROGMEM batglide[] =
{
// width, height,
16, 8,
0x02, 0x06, 0x06, 0x0e, 0x0e, 0x0c, 0x3e, 0x7c, 0x6c, 0x7e, 0x2c, 0x0e, 0x0e, 0x0e, 0x06, 0x02,
};

const unsigned char PROGMEM batdive[] =
{
// width, height,
8, 16,
0x00, 0x80, 0xe0, 0x00, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x1f, 0x7f, 0xf8, 0xdf, 0xff, 0x58, 0x00,
};

const unsigned char PROGMEM sonicbullet[] =
{
// width, height,
4, 4,
0x06, 0x09, 0x09, 0x06,
};

//sprites for background
const unsigned char flat[] PROGMEM
{
// width, height,
32, 9,
0x80, 0x40, 0xa0, 0x40, 0x80, 0x40, 0x80, 0x40, 0xa0, 0x40, 0xa0, 0x40, 0xa0, 0x50, 0x80, 0x40, 0xa0, 0x40, 0xa0, 0x40, 0xa0, 0x50, 0xa0, 0x40, 0xa0, 0x40, 0x80, 0x40, 0xa0, 0x40, 0xa0, 0x40,
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
};

const unsigned char PROGMEM spikeleft[] =
{
// width, height,
32, 9,
0x40, 0xa0, 0x50, 0xaa, 0x55, 0xaa, 0x50, 0x80, 0x40, 0xa0, 0x40, 0xa0, 0x40, 0x80, 0x40, 0x80, 0x40, 0xa0, 0x40, 0xa0, 0x40, 0x80, 0x00, 0xa0, 0x40, 0xa0, 0x50, 0xa0, 0x50, 0xa0, 0x50, 0xa0,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
};

const unsigned char PROGMEM spikeright[] =
{
// width, height,
32, 9,
0x40, 0xa0, 0x40, 0x80, 0x00, 0x80, 0x00, 0x80, 0x40, 0xa0, 0x40, 0xa0, 0x40, 0xa0, 0x50, 0xa0, 0x50, 0xa0, 0x40, 0xa0, 0x40, 0xa0, 0x50, 0xa0, 0x50, 0xa0, 0x50, 0xaa, 0x55, 0xaa, 0x54, 0xa0,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
};
//ceiling
const unsigned char PROGMEM flatup[] =
{
// width, height,
32, 9,
0x02, 0x05, 0x0a, 0x05, 0x02, 0x05, 0x02, 0x05, 0x0a, 0x05, 0x0a, 0x05, 0x0a, 0x15, 0x02, 0x05, 0x0a, 0x05, 0x0a, 0x05, 0x0a, 0x15, 0x0a, 0x05, 0x0a, 0x05, 0x02, 0x05, 0x0a, 0x05, 0x0a, 0x05,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

const unsigned char PROGMEM spikeleftup[] =
{
// width, height,
32, 9,
0x05, 0x0a, 0x15, 0xaa, 0x55, 0xaa, 0x15, 0x02, 0x05, 0x0a, 0x05, 0x0a, 0x05, 0x02, 0x05, 0x02, 0x05, 0x0a, 0x05, 0x0a, 0x05, 0x02, 0x01, 0x0a, 0x05, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x15, 0x0a,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

const unsigned char PROGMEM spikerightup[] =
{
// width, height,
32, 9,
0x05, 0x0a, 0x05, 0x02, 0x01, 0x02, 0x01, 0x02, 0x05, 0x0a, 0x05, 0x0a, 0x05, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x05, 0x0a, 0x05, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x15, 0xaa, 0x55, 0xaa, 0x55, 0x0a,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
};

const unsigned char PROGMEM crowflap[] =
{
// width, height,
15, 8,
0x00, 0x00, 0x00, 0x04, 0x04, 0xae, 0xfa, 0x0e, 0x3e, 0xec, 0xac, 0x88, 0x08, 0x00, 0x00,
};

const unsigned char PROGMEM crowglide[] =
{
// width, height,
15, 7,
0x01, 0x01, 0x0b, 0x09, 0x1f, 0x16, 0x5c, 0x5c, 0x3e, 0x1b, 0x13, 0x11, 0x03, 0x01, 0x01,
};

//runs once on startup
void setup() {
Expand Down Expand Up @@ -381,7 +295,7 @@ void enemyspawn(){
}

void updateenemies(){
for (uint8_t i =0; i <MAX_NUM_ENEMIES; i++){
for (uint8_t i =0; i <enemiesCount; i++){
if (enemyList[i].enabled == true){
if (enemyList[i].enemytype == 0){
crow(i);
Expand Down Expand Up @@ -423,7 +337,7 @@ void enemyReset(int i){
enemyList[i].x = 130;
enemyList[i].y = 8*random(1,7);
enemyList[i].modB = enemyList[i].y;
enemyList[i].delaynext = enemyList[i].delaynext / DELAY_MODIFIER;
enemyList[i].delaynext = enemyList[i].delaynext / delayModifier;
enemyList[i].enabled = false;
}

Expand Down Expand Up @@ -490,8 +404,8 @@ void crow(int i){
}

void increaseDifficulty(){
if (currentenemyindex == MAX_NUM_ENEMIES){
currentdelay = RESTART_DELAY;
if (currentenemyindex == enemiesCount){
currentdelay = restartDelay;
currentenemyindex = 0;
}
}
101 changes: 101 additions & 0 deletions batandcollisions/images.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#pragma once

// For uint8_t
#include <stdint.h>

// For PROGMEM
#include <avr/pgmspace.h>

//sprites
const uint8_t batflap[] PROGMEM
{
// width, height,
16, 8,
0x40, 0x60, 0x60, 0x60, 0x70, 0x30, 0x1f, 0x3e, 0x36, 0x3f, 0x16, 0x30, 0x70, 0x70, 0x60, 0x40,
};

const uint8_t batglide[] PROGMEM
{
// width, height,
16, 8,
0x02, 0x06, 0x06, 0x0e, 0x0e, 0x0c, 0x3e, 0x7c, 0x6c, 0x7e, 0x2c, 0x0e, 0x0e, 0x0e, 0x06, 0x02,
};

const uint8_t batdive[] PROGMEM
{
// width, height,
8, 16,
0x00, 0x80, 0xe0, 0x00, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x1f, 0x7f, 0xf8, 0xdf, 0xff, 0x58, 0x00,
};

const uint8_t sonicbullet[] PROGMEM
{
// width, height,
4, 4,
0x06, 0x09, 0x09, 0x06,
};

//sprites for background
const uint8_t flat[] PROGMEM
{
// width, height,
32, 9,
0x80, 0x40, 0xa0, 0x40, 0x80, 0x40, 0x80, 0x40, 0xa0, 0x40, 0xa0, 0x40, 0xa0, 0x50, 0x80, 0x40, 0xa0, 0x40, 0xa0, 0x40, 0xa0, 0x50, 0xa0, 0x40, 0xa0, 0x40, 0x80, 0x40, 0xa0, 0x40, 0xa0, 0x40,
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
};

const uint8_t spikeleft[] PROGMEM
{
// width, height,
32, 9,
0x40, 0xa0, 0x50, 0xaa, 0x55, 0xaa, 0x50, 0x80, 0x40, 0xa0, 0x40, 0xa0, 0x40, 0x80, 0x40, 0x80, 0x40, 0xa0, 0x40, 0xa0, 0x40, 0x80, 0x00, 0xa0, 0x40, 0xa0, 0x50, 0xa0, 0x50, 0xa0, 0x50, 0xa0,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
};

const uint8_t spikeright[] PROGMEM
{
// width, height,
32, 9,
0x40, 0xa0, 0x40, 0x80, 0x00, 0x80, 0x00, 0x80, 0x40, 0xa0, 0x40, 0xa0, 0x40, 0xa0, 0x50, 0xa0, 0x50, 0xa0, 0x40, 0xa0, 0x40, 0xa0, 0x50, 0xa0, 0x50, 0xa0, 0x50, 0xaa, 0x55, 0xaa, 0x54, 0xa0,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
};

// Ceiling
const uint8_t flatup[] PROGMEM
{
// width, height,
32, 9,
0x02, 0x05, 0x0a, 0x05, 0x02, 0x05, 0x02, 0x05, 0x0a, 0x05, 0x0a, 0x05, 0x0a, 0x15, 0x02, 0x05, 0x0a, 0x05, 0x0a, 0x05, 0x0a, 0x15, 0x0a, 0x05, 0x0a, 0x05, 0x02, 0x05, 0x0a, 0x05, 0x0a, 0x05,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

const uint8_t spikeleftup[] PROGMEM
{
// width, height,
32, 9,
0x05, 0x0a, 0x15, 0xaa, 0x55, 0xaa, 0x15, 0x02, 0x05, 0x0a, 0x05, 0x0a, 0x05, 0x02, 0x05, 0x02, 0x05, 0x0a, 0x05, 0x0a, 0x05, 0x02, 0x01, 0x0a, 0x05, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x15, 0x0a,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

const uint8_t spikerightup[] PROGMEM
{
// width, height,
32, 9,
0x05, 0x0a, 0x05, 0x02, 0x01, 0x02, 0x01, 0x02, 0x05, 0x0a, 0x05, 0x0a, 0x05, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x05, 0x0a, 0x05, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x15, 0xaa, 0x55, 0xaa, 0x55, 0x0a,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
};

const uint8_t crowflap[] PROGMEM
{
// width, height,
15, 8,
0x00, 0x00, 0x00, 0x04, 0x04, 0xae, 0xfa, 0x0e, 0x3e, 0xec, 0xac, 0x88, 0x08, 0x00, 0x00,
};

const uint8_t crowglide[] PROGMEM
{
// width, height,
15, 7,
0x01, 0x01, 0x0b, 0x09, 0x1f, 0x16, 0x5c, 0x5c, 0x3e, 0x1b, 0x13, 0x11, 0x03, 0x01, 0x01,
};