#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "update.h"
#define velocityY A1
#define button A0
updet updt;
//{
byte arrow[] =
{
B10000,
B11000,
B11100,
B11110,
B11100,
B11000,
B10000,
B00000
};
byte player1[] =
{
B01110,
B11011,
B10101,
B01010,
B01101,
B11010,
B10101,
B01110
};
byte player2[] =
{
B00000,
B00000,
B11111,
B00000,
B00000,
B11111,
B00000,
B00000
};
byte player3[] =
{
B00000,
B00000,
B11110,
B01001,
B01001,
B11110,
B00000,
B00000
};
byte gun[] =
{
B00000,
B00000,
B00000,
B11111,
B11111,
B00000,
B00000,
B00000
};
byte gunAuto[] =
{
B00000,
B00000,
B00000,
B01110,
B01110,
B00000,
B00000,
B00000
};
byte laser[] =
{
B00000,
B00000,
B00000,
B11111,
B00000,
B00000,
B00000,
B00000
};
byte laser2[] =
{
B00000,
B00000,
B00000,
B00000,
B11111,
B00000,
B00000,
B00000
};
byte thunder[] =
{
B00000,
B00000,
B00010,
B10111,
B11101,
B01000,
B00000,
B00000
};
byte bfg[] =
{
B00000,
B00000,
B11111,
B11111,
B11111,
B11111,
B00000,
B00000
};
byte bfg2[] =
{
B00000,
B00000,
B00000,
B11111,
B11111,
B00000,
B00000,
B00000
};
byte bfg4[] =
{
B00000,
B00000,
B00000,
B00100,
B00100,
B00000,
B00000,
B00000
};
byte enemy[] =
{
B01000,
B00100,
B00110,
B01110,
B01110,
B11111,
B11111,
B01110
};
byte blank[] =
{
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
//}
//LiquidCrystal_I2C LCD(0x27, 20, 4);
int option = 0;
//int timer;
int positionY = 0;
int useTime = 0;
bool useButton = false;
int weapon = 2;
int playerLife = 100;
int joyDelay = 0;
/*const int maxNPCs = 20;
int npcType[maxNPCs];
int npcLife[maxNPCs];
int npcLifeMax[maxNPCs];
int npcPositionX[maxNPCs];
int npcPositionY[maxNPCs];
bool npcActive[maxNPCs];
const int maxProjs = 12;
int projType[maxProjs];
int projDamage[maxProjs];
int projHostile[maxProjs];
int projPositionX[maxProjs];
int projPositionY[maxProjs];
bool projActive[maxProjs];*/
int scaleFactor;
int scaleFactor2;
int mode = 0;
void setup()
{
Serial.begin(9600);
pinMode(velocityY, INPUT);
pinMode(button, INPUT);
Serial.println("Terminado");
LCD.init();
LCD.backlight();
LCD.createChar(0, blank);
LCD.createChar(1, arrow);
LCD.setCursor(0, 0);
LCD.write(1);
}
void loop()
{
if (mode == 0)
{
LCD.setCursor(1, 0);
LCD.print(F("Jugar"));
LCD.setCursor(1, 1);
LCD.print(F("Armas"));
LCD.setCursor(1, 2);
LCD.print(F("Clasificacion"));
LCD.setCursor(1, 3);
LCD.print(F("Reiniciar"));
if (joyDelay <= 0)
{
if (analogRead(velocityY) >= 768 && option > 0) //3584
{
LCD.setCursor(0, option);
LCD.write(0);
option--;
LCD.setCursor(0, option);
LCD.write(1);
joyDelay = 6;
}
else if (analogRead(velocityY) < 256 && option < 3) //512
{
LCD.setCursor(0, option);
LCD.write(0);
option++;
LCD.setCursor(0, option);
LCD.write(1);
joyDelay = 6;
}
}
else
{
joyDelay--;
}
if (analogRead(button) > 256)
{
if (option == 0)
{
LCD.clear();
LCD.createChar(1, player1);
LCD.createChar(2, player2);
LCD.createChar(3, player3);
if (weapon == 1)
{
LCD.createChar(4, gunAuto);
}
else if (weapon == 2)
{
LCD.createChar(4, laser);
}
else if (weapon == 3)
{
LCD.createChar(4, thunder);
}
else if (weapon == 4)
{
LCD.createChar(4, bfg);
}
else
{
LCD.createChar(4, gun);
}
//LCD.createChar(4, gun);
LCD.createChar(5, enemy);
//LCD.createChar(6, enemy);
//LCD.createChar(7, enemy);
positionY = 0;
LCD.setCursor(0, positionY);
LCD.write(1);
LCD.setCursor(1, positionY);
LCD.write(2);
LCD.setCursor(2, positionY);
LCD.write(3);
scaleFactor = 7;
scaleFactor2 = 40;
mode++;
}
else
{
}
}
}
else if (mode == 1)
{
for (int i = 0; i < maxProjs; i++)
{
if (projActive[i])
{
updt.UpdateProj(i);
}
}
for (int i = 0; i < maxNPCs; i++)
{
if (npcActive[i])
{
updt.UpdateNPC(i);
}
}
if (joyDelay <= 0)
{
if (analogRead(velocityY) >= 768 && positionY > 0) //3584
{
LCD.setCursor(0, positionY);
LCD.write(0);
LCD.setCursor(1, positionY);
LCD.write(0);
LCD.setCursor(2, positionY);
LCD.write(0);
positionY--;
LCD.setCursor(0, positionY);
LCD.write(1);
LCD.setCursor(1, positionY);
LCD.write(2);
LCD.setCursor(2, positionY);
LCD.write(3);
joyDelay = 6;
}
else if (analogRead(velocityY) < 256 && positionY < 3) //512
{
LCD.setCursor(0, positionY);
LCD.write(0);
LCD.setCursor(1, positionY);
LCD.write(0);
LCD.setCursor(2, positionY);
LCD.write(0);
positionY++;
LCD.setCursor(0, positionY);
LCD.write(1);
LCD.setCursor(1, positionY);
LCD.write(2);
LCD.setCursor(2, positionY);
LCD.write(3);
joyDelay = 6;
}
}
else
{
joyDelay--;
}
useTime--;
if (analogRead(button) > 256 && useTime <= 0 && !useButton)
{
if (weapon == 0)
{
NewProj(0);
useTime = 10;
useButton = true;
}
else if (weapon == 1)
{
NewProj(1);
useTime = 6;
}
else if (weapon == 2)
{
NewProj(2);
useTime = 1;
}
}
else if (analogRead(button) <= 256)
{
useButton = false;
}
if (timer % scaleFactor2 == 0)
{
NewNPC();
}
if (timer % 100 == 0)
{
if (scaleFactor > 2)
{
scaleFactor--;
}
}
if (timer % 20 == 0)
{
if (scaleFactor2 > 15)
{
scaleFactor2--;
}
}
timer++;
delay(33);
}
else if (mode == 2)
{
LCD.setCursor(0, 0);
LCD.print(F("Has morido"));
if (analogRead(button) > 256)
{
LCD.clear();
positionY = 0;
LCD.setCursor(0, positionY);
LCD.write(1);
LCD.setCursor(1, positionY);
LCD.write(2);
LCD.setCursor(2, positionY);
LCD.write(3);
scaleFactor = 7;
scaleFactor2 = 40;
mode--;
}
}
}
void EndGame()
{
for (int i = 0; i < maxProjs; i++)
{
if (projActive[i])
{
projPositionX[i] = 0;
projActive[i] = false;
}
}
for (int i = 0; i < maxNPCs; i++)
{
if (npcActive[i])
{
npcPositionX[i] = 19;
npcActive[i] = false;
}
}
LCD.clear();
mode++;
}
void NewProj(int wpn)
{
for (int i = 0; i < maxProjs; i++)
{
if (!projActive[i])
{
projType[i] = wpn;
projPositionY[i] = positionY;
if (projType[i] == 2)
{
for (int i = 3; i < 20; i++)
{
LCD.setCursor(i, projPositionY[i]);
LCD.write(4);
}
}
else if (projType[i] > 2)
{
}
else
{
projPositionX[i] = 3;
LCD.setCursor(projPositionX[i], projPositionY[i]);
LCD.write(4);
}
projActive[i] = true;
break;
}
}
}
int GetProjTexture(int type)
{
if (type == 0)
{
return 4;
}
if (type == 1)
{
return 7;
}
}
void NewNPC()
{
for (int i = 0; i < maxNPCs; i++)
{
if (!npcActive[i])
{
npcPositionX[i] = 19;
npcPositionY[i] = random(4);
LCD.setCursor(npcPositionX[i], npcPositionY[i]);
LCD.write(3);
npcActive[i] = true;
break;
}
}
}