#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define VRX_PIN A0 // Arduino pin connected to VRX pin
#define VRY_PIN A1 // Arduino pin connected to VRY pin
#define VRX_PIN2 A3 // Arduino pin connected to VRX pin
#define VRY_PIN2 A2 // Arduino pin connected to VRY pin
const int SCREEN_WIDTH = 128;
const int SCREEN_HEIGHT = 64;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
//player
int playerx = 50;
int playery = 30;
int playerl = 8;
//enemy 1
int enemy1x = 20;
int enemy1y = 20;
int enemy1l = 10;
int enemy1speed = 2;
int enemy1speedthreshold = 10;
int enemy1colide = 0;
//enemy 1
int enemy2x = 60;
int enemy2y = 20;
int enemy2l = 10;
int enemy2speed = 2;
int enemy2speedthreshold = 1;
int enemy2colide = 0;
//heart pickup
int healthpickup = 0;
int healthx = 0;
int healthy = 0;
int healthl = 8;
//heart ui
int heartx = 10;
int hearty = 2;
int heartl = 8;
//projectile
int projx = 50;
int projy = 50;
int projectilex[10];
int projectiley[10];
int i = 0;
int projl = 6;
int up = 0;
int down = 0;
int left = 0;
int right = 0;
int shootx = 0;
int shooty = 0;
//shop
int selecty = 18;
int movemenudown = 0;
int movemenuup = 0;
int shopopen = 0;
int shopbutton = 0;
int shopbuttonheld = 0;
int selectbutton = 0;
int selectbuttonheld = 0;
int gamerunning = 1;
int itemselected = 1;
int price1 = 2;
int price2 = 2;
int price3 = 2;
int shots = 3;
//
//
//old
int buttonState1 = digitalRead(10);
int buttonState2 = digitalRead(11);
int buttonState3 = digitalRead(9);
int buttonState4 = digitalRead(8);
//old
//
//
//game logic
int winning = 0;
int points = 0;
int reloaded = 1;
int health = 5;
int loopval = 0;
// 'Projectile', 6x6px
const unsigned char Projectile [] PROGMEM = {
0x78, 0xcc, 0xb4, 0xb4, 0xcc, 0x78
};
// 'Heart', 9x8px
const unsigned char Heart [] PROGMEM =
{
0x22, 0x00, 0x77, 0x00, 0xff, 0x80, 0xff, 0x80, 0xff, 0x80, 0x7f, 0x00, 0x3e, 0x00, 0x1c, 0x00
};
// 'Spider', 10x10px
const unsigned char Spider [] PROGMEM =
{
0x40, 0x80, 0x21, 0x00, 0x2d, 0x00, 0x9e, 0x40, 0x7f, 0x80, 0x1e, 0x00, 0x2d, 0x00, 0x40, 0x80,
0x40, 0x80, 0x21, 0x00
};
// "Bat", 10x4px
const unsigned char Bat [] PROGMEM =
{
0xcc, 0xc0, 0xff, 0xc0, 0x7f, 0x80, 0x0c, 0x00
};
// 'shopui128x64', 128x64px
const unsigned char shopui [] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x1d, 0xc7, 0xf1, 0xf1, 0xfc, 0x7c, 0x7e, 0x1f, 0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x1d, 0xc7, 0xf3, 0xf9, 0xfc, 0xfe, 0x7f, 0x3f, 0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x1d, 0xc7, 0xf3, 0xf9, 0xfc, 0xee, 0x7f, 0x3f, 0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x1f, 0xc7, 0x33, 0xf9, 0xdc, 0xee, 0x7f, 0x3c, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x1f, 0xc7, 0xf3, 0x81, 0xdc, 0xfe, 0x77, 0x3f, 0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x1f, 0xc7, 0xc3, 0xb9, 0xfc, 0xfe, 0x77, 0x3f, 0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x1f, 0xc7, 0xc3, 0xb9, 0xf0, 0xfe, 0x7f, 0x3c, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x1f, 0xc7, 0xc3, 0xf9, 0xdc, 0xee, 0x7f, 0x3f, 0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x1f, 0xc7, 0xc3, 0xf9, 0xdc, 0xee, 0x7f, 0x3f, 0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x0f, 0x87, 0xc1, 0xf1, 0xdc, 0xee, 0x7e, 0x1f, 0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
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,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x87, 0xe3, 0xb8, 0xf8, 0xff, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0xf3, 0xb9, 0xfc, 0xff, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0xf3, 0xb9, 0xfc, 0xff, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0x83, 0xf9, 0xfc, 0xff, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0x83, 0xf9, 0xdc, 0x3c, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x81, 0xf3, 0xf9, 0xdc, 0x3c, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x81, 0xf3, 0xf9, 0xdc, 0x3c, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0xf3, 0xb9, 0xfc, 0x3c, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0xf3, 0xb9, 0xfc, 0x3c, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x87, 0xe3, 0xb8, 0xf8, 0x3c, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
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,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x87, 0xe3, 0xf8, 0xfc, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0xf3, 0xf9, 0xfc, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0xf3, 0xf9, 0xfc, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0x83, 0x99, 0xe0, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0x83, 0xf9, 0xfc, 0xfe, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x81, 0xf3, 0xe1, 0xfc, 0xfe, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x81, 0xf3, 0xe1, 0xe0, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0xf3, 0xe1, 0xfc, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0xf3, 0xe1, 0xfc, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x87, 0xe3, 0xe0, 0xfc, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
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,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x8e, 0xe3, 0xf1, 0xf1, 0xe0, 0xff, 0x3b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8e, 0xe7, 0xf3, 0xf9, 0xe0, 0xff, 0x3b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8e, 0xe7, 0xf3, 0xb9, 0xe0, 0xff, 0x3b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0xe7, 0x83, 0xb9, 0xe0, 0xff, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0xe7, 0xf3, 0xf9, 0xe0, 0x3c, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0xe7, 0xf3, 0xf9, 0xe0, 0x3c, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8f, 0xe7, 0x83, 0xf9, 0xfc, 0x3c, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8e, 0xe7, 0xf3, 0xb9, 0xfc, 0x3c, 0x3b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8e, 0xe7, 0xf3, 0xb9, 0xfc, 0x3c, 0x3b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x8e, 0xe3, 0xf3, 0xb9, 0xfc, 0x3c, 0x3b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
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,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'select128x14', 128x14px
const unsigned char select [] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
void purchase1()
{
if (points >= price1)
{
points -= price1;
price1 = ((price1 *3))/ 2;
shots += 1;
}
}
void purchase2()
{
if (points >= price1)
{
points -= price1;
price1 = ((price1 *3))/ 2;
shots += 1;
}
}
void purchase3()
{
if (points >= price1)
{
points -= price1;
price1 = ((price1 *3))/ 2;
shots += 1;
}
}
void setup() {
Serial.begin(9600) ;
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
// Handle allocation failure here (e.g., blink an LED)
}
pinMode(11, INPUT);
pinMode(10, INPUT);
pinMode(9, INPUT);
pinMode(8, INPUT);
pinMode(7, INPUT);
pinMode(6, INPUT);
}
//
//sprites
//
//end of sprites
void attack()
{
if (enemy1speed >= enemy1speedthreshold)
{
if (enemy1x >= playerx)
{
enemy1x -= 1;
}
if (enemy1x <= playerx)
{
enemy1x += 1;
}
if (enemy1y >= playery)
{
enemy1y -= 1;
}
if (enemy1y <= playery)
{
enemy1y += 1;
}
enemy1speed = 0;
}else
{
enemy1speed += 1;
}
if (enemy2speed >= enemy2speedthreshold)
{
if (enemy2x >= playerx)
{
enemy2x -= 1;
}
if (enemy2x <= playerx)
{
enemy2x += 1;
}
if (enemy2y >= playery)
{
enemy2y -= 1;
}
if (enemy2y <= playery)
{
enemy2y += 1;
}
enemy2speed = 0;
}else
{
enemy2speed += 1;
}
}
void win()
{
if (points == 50)
{
winning = 1;
}
}
void Shoot()
{
if (reloaded == 0)
{
projx += (shootx * 3);
projy += (shooty * 3);
if ((projy <= 0) or (projy >= 64) or (projx <= 0) or (projx >= 128))
{
reloaded = 1;
shootx = 0;
shooty = 0;
}
}
if (reloaded == 1)
{
reloaded = 0;
projx = playerx;
projy = playery;
shootx = right - left;
shooty = down - up;
if (shootx == 0 && shooty == 0)
{
reloaded = 1;
}
}
}
//
//
//new
// void Shoot()
// {
// if (reloaded == 0)
// {
// for (i = 0; i < shots; i++)
// {
// projectilex[i] += (shootx * 3);
// projectiley[i] += (shooty * 3);
// if ((projectiley[i] <= 0) or (projectiley[i] >= 64) or (projectilex[i] <= 0) or (projectilex[i] >= 128))
// {
// reloaded = 1;
// shootx = 0;
// shooty = 0;
// }
// }
// }
// if (reloaded == 1)
// {
// reloaded = 0;
// for (i = 0; i < shots; i++)
// {
// projectilex[i] = playerx;
// projectiley[i] = playery;
// shootx = right - left;
// shooty = down - up;
// if (shootx == 0 && shooty == 0)
// {
// reloaded = 1;
// }
// }
// }
// }
//end of new
//
//
void Collision()
{
//enemey and player
if (((playerx - (playerl / 2) <= enemy1x + (enemy1l / 2)) and (playerx + (playerl / 2) >= enemy1x - (enemy1l / 2))) and ((playery - (playerl / 2) <= enemy1y + (enemy1l / 2)) and (playery + (playerl / 2) >= enemy1y - (enemy1l / 2))))
{
spawn();
health -= 1;
}
//enemey2 and player
if (((playerx - (playerl / 2) <= enemy2x + (enemy2l / 2)) and (playerx + (playerl / 2) >= enemy2x - (enemy2l / 2))) and ((playery - (playerl / 2) <= enemy2y + (4 / 2)) and (playery + (playerl / 2) >= enemy2y - (4 / 2))))
{
spawn2();
health -= 1;
}
//player and health pick up
if ((((playerx - (playerl / 2) <= healthx + (heartl / 2)) and (playerx + (playerl / 2) >= healthx - (heartl / 2))) and ((playery - (playerl / 2) <= healthy + (heartl / 2)) and (playery + (playerl / 2) >= healthy - (heartl / 2)))) and healthpickup == 1)
{
health += 1;
healthpickup = 0;
}
if (reloaded == 0)
{
//enemey and projectile
if ((((projx - projl <= enemy1x + (enemy1l / 2)) and (projx + projl >= enemy1x - (enemy1l / 2))) and ((projy - projl <= enemy1y + (enemy1l / 2)) and (projy + projl >= enemy1y - (enemy1l / 2)))))
{
if (random(0, 10) == 2)
{
healthpickup = 1;
healthx = enemy1x;
healthy = enemy1y;
}
spawn();
points += 1;
reloaded = 1;
}
//enemey2 and projectile
if ((((projx - projl <= enemy2x + (enemy2l / 2)) and (projx + projl >= enemy2x - (enemy2l / 2))) and ((projy - projl <= enemy2y + (4 / 2)) and (projy + projl >= enemy2y - (4 / 2)))))
{
if (random(0, 10) == 2)
{
healthpickup = 1;
healthx = enemy2x;
healthy = enemy2y;
}
spawn2();
points += 1;
reloaded = 1;
}
}
}
void spawn()
{
enemy1y = random(20, 53);
enemy1x = random(5, 117);
if (((playerx - (playerl + 4) <= enemy1x + (enemy1l / 2)) and (playerx + (playerl + 4) >= enemy1x - (enemy1l / 2))) and ((playery - (playerl + 4) <= enemy1y + (enemy1l / 2)) and (playery + (playerl + 4) >= enemy1y - (enemy1l / 2))))
{
spawn();
}
}
void spawn2()
{
enemy2y = random(18, 62);
enemy2x = random(5, 123);
if (((playerx - (playerl + 4) <= enemy2x + (enemy2l / 2)) and (playerx + (playerl + 4) >= enemy2x - (enemy2l / 2))) and ((playery - (playerl + 4) <= enemy2y + (4 / 2)) and (playery + (playerl + 4) >= enemy2y - (4 / 2))))
{
spawn2();
}
}
void updateDisplay() {
display.clearDisplay();
if (shopopen == 1)
{
display.drawBitmap(0, 0, shopui, 128, 64, WHITE);
display.drawBitmap(0, ((itemselected * 15 ) + 3), select, 128, 14, WHITE);
}
if (gamerunning == 1)
{
display.fillRect(playerx - (playerl / 2), playery - (playerl / 2), playerl, playerl, WHITE);
display.drawBitmap(enemy1x - (enemy1l / 2), enemy1y - (enemy1l / 2), Spider, enemy1l, enemy1l, WHITE);
display.drawBitmap(enemy2x - (enemy2l / 2), enemy2y - (4 / 2), Bat, enemy2l, 4, WHITE);
while (loopval < health)
{
// Draw the heart
// heart();
display.drawBitmap(heartx, 0, Heart, 9, 8, WHITE);
// Increment loopval and adjust heartx
heartx += 11;
loopval += 1;
}
// Reset loopval and heart x
if (loopval >= health)
{
loopval = 0;
heartx = 0;
}
//draw projectile when fired
// if (reloaded == 0)
// {
// for (i = 0; i < shots; i++)
// {
// projectilex[i] += shootx;
// projectiley[i] += shooty;
// display.drawBitmap((projectilex[i]) - (i * shootx) - (projl / 2), (projectiley[i]) - (i * shooty) - (projl / 2), Projectile, projl, projl, WHITE);
// }
// }
if (reloaded == 0)
{
display.fillRect(projx - (projl / 2), projy - (projl / 2), projl, projl, WHITE);
}
//draw health pickup when active
if (healthpickup == 1)
{
display.drawBitmap(healthx - (healthl / 2), healthy - (healthl / 2), Heart, 9, 8, WHITE);
}
//draw points
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(110, 0);
display.println(points);
//end of new
//
//
}
if (winning == 1)
{
gamerunning = 0;
shopopen = 0;
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("You Win");
}
if (health == 0)
{
gamerunning = 0;
shopopen = 0;
winning = 2;
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("You");
display.println("Lose");
}
//display.drawLine(x1, y1, x2, y2, colour);
//drawPixel(x, y, color)
//rectangle draw, wehere x and y is top left corner
//drawRect(x, y, width, height, color)
//or
//fillRect(x, y, width, height, color)
//drawTriangle(x1, y1, x2, y2, x3, y3, color)
//drawCircle(x, y, radius, color)
// display.println("0");
//invert display
// display.invertDisplay(true);
display.display();
playerx = constrain(playerx, 2, 126);
playery = constrain(playery, 18, 62);
enemy1x = constrain(enemy1x, 11, 123);
enemy1y = constrain(enemy1y, 20, 53);
enemy2x = constrain(enemy2x, 11, 123);
enemy2y = constrain(enemy2y, 18, 62);
}
void loop() {
if (winning == 0)
{
Serial.println(healthpickup);
shopbutton = digitalRead(7);
selectbutton = digitalRead(6);
Serial.print("game running: ");
Serial.print(gamerunning);
Serial.print("shop open: ");
Serial.println(shopopen);
if (gamerunning == 1)
{
buttonState1 = digitalRead(10);
buttonState2 = digitalRead(11);
buttonState3 = digitalRead(9);
buttonState4 = digitalRead(8);
//OLD REMOVE
//
//
playerx -= buttonState2;
playerx += buttonState1;
playery -= buttonState3;
playery += buttonState4;
//
//
//OLD REMOVE
//x
if (analogRead(VRX_PIN) > 596)
{
playerx -= 1;
}
if (analogRead(VRX_PIN) < 396)
{
playerx += 1;
}
//y
if (analogRead(VRY_PIN) > 611)
{
playery += 1;
}
if (analogRead(VRY_PIN) < 411)
{
playery -= 1;
}
//x2
if (analogRead(VRX_PIN2) > 596)
{
left = 1;
}else
{
left = 0;
}
if (analogRead(VRX_PIN2) < 396)
{
right = 1;
}else
{
right = 0;
}
//y2
if (analogRead(VRY_PIN2) > 611)
{
up = 1;
}else
{
up = 0;
}
if (analogRead(VRY_PIN2) < 411)
{
down = 1;
}else
{
down = 0;
}
Collision();
Shoot();
attack();
win();
}
if (shopbutton == 1 and shopbuttonheld == 0)
{
shopbuttonheld = 1;
if (shopopen == 0)
{
shopopen = 1;
gamerunning = 0;
}
else if (shopopen == 1)
{
shopopen = 0;
gamerunning = 1;
}
}else if (shopbutton == 0)
{
shopbuttonheld = 0;
}
if (shopopen == 1)
{
//y
if ((analogRead(VRY_PIN) > 611) and movemenuup == 0)
{
itemselected -= 1;
itemselected = constrain(itemselected, 1, 3);
movemenuup = 1;
}else if (analogRead(VRY_PIN) < 611)
{
movemenuup = 0;
}
if ((analogRead(VRY_PIN) < 411) and movemenudown == 0)
{
itemselected += 1;
itemselected = constrain(itemselected, 1, 3);
movemenudown = 1;
}else if (analogRead(VRY_PIN) > 411)
{
movemenudown = 0;
}
if (selectbutton == 1 and selectbuttonheld == 0)
{
selectbuttonheld = 1;
if (itemselected == 1)
{
purchase1();
}
if (itemselected == 1)
{
purchase2();
}
if (itemselected == 1)
{
purchase3();
}
}else if (selectbutton == 0)
{
selectbuttonheld = 0;
}
}
//
//
//new
// up = digitalRead(13);
// right = digitalRead(12);
//end of new
//
//
}
updateDisplay();
}