// PS6 V12.0
#define OLED_SOFT_64
#define BTN_OK 2
#define BTN_UP 3
#define BTN_DOWN 4
#define BTN_LEFT 8
#define BTN_RIGHT 9
#define OLED_PWR1 5
#define OLED_PWR2 6
#define OLED_PWR3 7
#include <directADC.h>
#include <EEPROM.h>
#include <GyverPower.h>
#include <GyverTimer.h>
#include <GyverButton.h>
#include <GyverOLED.h>
GyverOLED<SSD1306_128x64, OLED_BUFFER> oled;
GButton ok(BTN_OK, HIGH_PULL);
GButton up(BTN_UP, HIGH_PULL);
GButton down(BTN_DOWN, HIGH_PULL);
GButton left(BTN_LEFT, HIGH_PULL);
GButton right(BTN_RIGHT, HIGH_PULL);
const uint8_t FOH_Plus[] PROGMEM = {
0x00, 0x00, 0x00, 0x10, 0x38, 0x10, 0x00, 0x00, };
const uint8_t FOH_Face_1[] PROGMEM = {
0x1C, 0x56, 0x5E, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F, };
const uint8_t FOH_Face_2[] PROGMEM = {
0x7E, 0x7F, 0xFF, 0xF7, 0xEF, 0x6B, 0x6E, 0x2C, };
const uint8_t FOH_Tail_Left_1[] PROGMEM = {
0xB6, 0xFE, 0xFE, 0xFC, 0x7C, 0x38, 0x38, 0x7C, };
const uint8_t FOH_Tail_Left_2[] PROGMEM = {
0x5B, 0x7F, 0x7F, 0x3F, 0x3E, 0x1C, 0x1C, 0x3E, };
const uint8_t FOH_Tail_Right_1[] PROGMEM = {
0x7E, 0x7C, 0x7C, 0xFC, 0xFE, 0xFE, 0xFE, 0xB6, };
const uint8_t FOH_Tail_Right_2[] PROGMEM = {
0x7E, 0x3E, 0x3E, 0x3F, 0x7F, 0x7F, 0x7F, 0x5B, };
const uint8_t FOH_hookRight[] PROGMEM = {
0x00, 0x78, 0xCC, 0x87, 0x83, 0xC0, 0x60, 0x00, };
const uint8_t FOH_hookLeft[] PROGMEM = {
0x00, 0x60, 0xC0, 0x83, 0x87, 0xCC, 0x78, 0x00, };
const uint8_t FOH_hookRight2[] PROGMEM = {
0x78, 0xCC, 0x86, 0x83, 0xC3, 0x00, 0x00, 0x00, };
const uint8_t FOH_hookLeft2[] PROGMEM = {
0x00, 0x00, 0x00, 0xC3, 0x83, 0x86, 0xCC, 0x78, };
const uint8_t boll[] PROGMEM = {
0x06, 0x0F, 0x0F, 0x06, };
const uint8_t Icon8x8[] PROGMEM = {
0x3C, 0x42, 0xBD, 0x95, 0x95, 0xAD, 0x42, 0x3C, };
const uint8_t Rizha_Mavpa_1_8x8[] PROGMEM = {
0x00, 0x00, 0x00, 0xF0, 0xF8, 0xFC, 0xFC, 0xBE, };
const uint8_t Rizha_Mavpa_2_8x8[] PROGMEM = {
0x1E, 0xBE, 0xEE, 0xC4, 0xE8, 0xF0, 0x80, 0x00, };
const uint8_t Rizha_Mavpa_3_8x8[] PROGMEM = {
0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0F, 0x8F, };
const uint8_t Rizha_Mavpa_4_8x8[] PROGMEM = {
0xDF, 0xDF, 0x9F, 0x0F, 0x0C, 0x0E, 0x07, 0x00, };
const uint8_t Rizha_Mavpa_5_8x8[] PROGMEM = {
0x00, 0x18, 0x3C, 0x7C, 0xFE, 0xFE, 0xFF, 0xFF, };
const uint8_t Rizha_Mavpa_6_8x8[] PROGMEM = {
0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x00, 0x00, 0x00, };
byte rizhaMavpa_x = 58;
byte rizhaMavpa_y = 12;
void setup() {
oledEnable();
buttonsSetting();
Wire.setClock(800000L);
oled.drawBitmap(rizhaMavpa_x, rizhaMavpa_y, Rizha_Mavpa_1_8x8, 8, 8);
oled.drawBitmap(rizhaMavpa_x + 8, rizhaMavpa_y, Rizha_Mavpa_2_8x8, 8, 8);
oled.drawBitmap(rizhaMavpa_x, rizhaMavpa_y + 8, Rizha_Mavpa_3_8x8, 8, 8);
oled.drawBitmap(rizhaMavpa_x + 8, rizhaMavpa_y + 8, Rizha_Mavpa_4_8x8, 8, 8);
oled.drawBitmap(rizhaMavpa_x, rizhaMavpa_y + 16, Rizha_Mavpa_5_8x8, 8, 8);
oled.drawBitmap(rizhaMavpa_x + 8, rizhaMavpa_y + 16, Rizha_Mavpa_6_8x8, 8, 8);
oled.drawBitmap(30, 40, Icon8x8, 8, 8);
oled.setCursor(40, 5);
oled.print(F("izha Mavpa"));
oled.update();
delay(3000);
}
void loop() {
static uint8_t pointer = 1;
buttonsTick();
if(up.isClick() or up.isStep()) {
pointer = constrain(pointer - 2, 1, 5);
}
if(down.isClick() or down.isStep()) {
pointer = constrain(pointer + 2, 1, 5);
}
if(ok.isClick() or ok.isStep()) {
switch (pointer) {
case 1: PlayGame1();
break;
case 3: PlayGame2();
break;
case 5: PlayGame3();
break;
}
}
oled.clear();
oled.home();
oled.setCursor(0, 1); oled.print(F(" PingPong\n"));
oled.setCursor(0, 3); oled.print(F(" Fish on Hook\n"));
oled.setCursor(0, 5); oled.print(F(" Info\n"));
oled.setCursor(0, pointer);
oled.print(F(" >>"));
oled.setCursor(112, pointer);
oled.print(F("<<"));
oled.update();
}
void buttonsSetting() {
ok.setDebounce(1);
up.setDebounce(1);
down.setDebounce(1);
left.setDebounce(1);
right.setDebounce(1);
ok.setTimeout(200);
up.setTimeout(200);
down.setTimeout(200);
left.setTimeout(200);
right.setTimeout(200);
ok.setClickTimeout(5);
up.setClickTimeout(5);
down.setClickTimeout(5);
left.setClickTimeout(5);
right.setClickTimeout(5);
}
void buttonsTick() {
ok.tick();
up.tick();
down.tick();
left.tick();
right.tick();
}
void PlayGame1() {
uint8_t pointerInGame1 = 1;
while(true) {
buttonsTick();
if(up.isClick() or up.isStep()) {
pointerInGame1 = constrain(pointerInGame1 - 2, 1, 5);
}
if(down.isClick() or down.isStep()) {
pointerInGame1 = constrain(pointerInGame1 + 2, 1, 5);
}
if(ok.isClick() or ok.isStep()) {
switch (pointerInGame1) {
case 1: PlayGame1Mode1();
break;
case 3: PlayGame1Mode2();
break;
case 5: return;
break;
}
}
oled.clear();
oled.home();
oled.setCursor(0, 1); oled.print(F(" PL vr PL\n"));
oled.setCursor(0, 3); oled.print(F(" vr Bot\n"));
oled.setCursor(0, 5); oled.print(F(" Main menu\n"));
oled.setCursor(0, pointerInGame1);
oled.print(F(" >>"));
oled.setCursor(112, pointerInGame1);
oled.print(F("<<"));
oled.update();
}
}
void PlayGame1Mode1() {
byte speedMove = 2;
byte leftWin = 0;
byte rightWin = 0;
byte xPlatform1 = 9;
byte xPlatform2 = 9;
byte yPlatform1 = 5;
byte yPlatform2 = 5;
byte x = 100;
byte y = 25;
byte xCubeSize = 4;
byte yCubeSize = 4;
bool movePlatformDown = true;
bool moveRight;
bool moveDown;
while(true) {
buttonsTick();
// Input // ----------------------------------------------------
if(leftWin >= 7){
oled.clear();
oled.setCursor(44, 3); oled.print(F("P1 WIN"));
oled.update();
delay(2000);
break;
}
else if(rightWin >= 7){
oled.clear();
oled.setCursor(44, 3); oled.print(F("P2 WIN"));
oled.update();
delay(2000);
break;
}
if(ok.isClick() or ok.isStep()){
break;
}
if(((right.isClick() or right.isStep() or right.isHold())) and (yPlatform2 < 53 - yCubeSize * 2)){
yPlatform2++;
}
if(((down.isClick() or down.isStep() or down.isHold())) and (yPlatform1 < 53 - yCubeSize * 2)){
yPlatform1++;
}
if(((up.isClick() or up.isStep() or up.isHold())) and (yPlatform1 > 0)){
yPlatform1--;
}
if(((left.isClick() or left.isStep() or left.isHold())) and (yPlatform2 > 0)){
yPlatform2--;
}
// Draw // ----------------------------------------------------
oled.clear();
oled.line(0, 0, 127, 0);
oled.line(0, 53, 127, 53);
oled.line(xPlatform2, yPlatform2, xPlatform2, yPlatform2 + yCubeSize * 2);
oled.line(128 - xPlatform1, yPlatform1, 128 - xPlatform1, yPlatform1 + yCubeSize * 2);
//oled.rect(x, y, x+xCubeSize, y+yCubeSize, OLED_FILL);
oled.drawBitmap(x, y, boll, 4, 4);
for(byte i = 0; i < leftWin; i++){
oled.rect(12+7*i, 57, 15+7*i, 60, OLED_FILL);}
for(byte i = 0; i < rightWin; i++){
oled.rect(112-7*i, 57, 115-7*i, 60, OLED_FILL);}
oled.setCursor(4, 7);
oled.print(leftWin);
oled.setCursor(120, 7);
oled.print(rightWin);
// Boll move // ----------------------------------------------------
// x
if(moveRight == true) {
if ((x < 126 - xPlatform1 - xCubeSize))
x = x + speedMove;
else if((x < 128 - xPlatform1 - xCubeSize) and ((y >= yPlatform1 - 5) and (y <= yPlatform1 + yCubeSize * 2))) {
moveRight = false;
x = x - speedMove;
}
else if(x > 124 - xCubeSize){
leftWin++;
moveRight = false;
}
else{
x = x + speedMove;
}
}
else {
if ((x > xPlatform1 + 1))
x = x - speedMove;
else if((x > xPlatform1 - 1) and ((y >= yPlatform2 - 5) and (y <= yPlatform2 + yCubeSize * 2))) {
moveRight = true;
x = x + speedMove;
}
else if(x < 2){
rightWin++;
moveRight = true;
}
else {
x = x - speedMove;
}
}
//y
if(moveDown == true) {
if (y < 53 - yCubeSize)
y++;
else if(y > yCubeSize) {
moveDown = false;
y--;
}
}
else {
if (y > 0)
y--;
else {
moveDown = true;
y++;
}
}
oled.update();
} // -----------------------------------------------------------------------------------
}
void PlayGame1Mode2() {
byte leftWin = 0;
byte rightWin = 0;
byte speedMove = 2;
byte xPlatform1 = 9;
byte xPlatform2 = 9;
byte yPlatform1 = 5;
byte yPlatform2 = 5;
byte x = 100;
byte y = 25;
byte xCubeSize = 4;
byte yCubeSize = 4;
bool botSpeadTick = true;
bool movePlatformDown = true;
bool moveRight = false;
bool moveDown;
while(true) {
buttonsTick();
// Input // ----------------------------------------------------
if(leftWin >= 7){
oled.clear();
oled.setCursor(44, 3); oled.print(F("P1 WIN"));
oled.update();
delay(2000);
break;
}
else if(rightWin >= 7){
oled.clear();
oled.setCursor(44, 3); oled.print(F("BOT WIN"));
oled.update();
delay(2000);
break;
}
if(ok.isClick() or ok.isStep()){
break;
}
if(((down.isClick() or down.isStep() or down.isHold())) and (yPlatform2 < 53 - yCubeSize * 2)){
yPlatform2++;
}
if(((up.isClick() or up.isStep() or up.isHold())) and (yPlatform2 > 0)){
yPlatform2--;
}
// ------ BOT intelligence ------ //
if(botSpeadTick){
if((y - yPlatform1 - 2 < 0) and (yPlatform1 > 0))
yPlatform1--;
else if(yPlatform1 < 53 - yCubeSize * 2){
yPlatform1++;
}
botSpeadTick = false;
}
else{
botSpeadTick = true;
}
// ------ BOT intelligence ------ //
// Draw // ----------------------------------------------------
oled.clear();
oled.line(0, 0, 127, 0);
oled.line(0, 53, 127, 53);
oled.line(xPlatform2, yPlatform2, xPlatform2, yPlatform2 + yCubeSize * 2);
oled.line(128 - xPlatform1, yPlatform1, 128 - xPlatform1, yPlatform1 + yCubeSize * 2);
//oled.rect(x, y, x+xCubeSize, y+yCubeSize, OLED_FILL);
oled.drawBitmap(x, y, boll, 4, 4);
for(byte i = 0; i < leftWin; i++){
oled.rect(12+7*i, 57, 15+7*i, 60, OLED_FILL);}
for(byte i = 0; i < rightWin; i++){
oled.rect(112-7*i, 57, 115-7*i, 60, OLED_FILL);}
oled.setCursor(4, 7);
oled.print(leftWin);
oled.setCursor(120, 7);
oled.print(rightWin);
// Boll move // ----------------------------------------------------
// x
if(moveRight == true) {
if ((x < 126 - xPlatform1 - xCubeSize))
x = x + speedMove;
else if((x < 128 - xPlatform1 - xCubeSize) and ((y >= yPlatform1 - 5) and (y <= yPlatform1 + yCubeSize * 2))) {
moveRight = false;
x = x - speedMove;
}
else if(x > 124 - xCubeSize){
leftWin++;
moveRight = false;
}
else{
x = x + speedMove;
}
}
else {
if ((x > xPlatform1 + 1))
x = x - speedMove;
else if((x > xPlatform1 - 1) and ((y >= yPlatform2 - 5) and (y <= yPlatform2 + yCubeSize * 2))) {
moveRight = true;
x = x + speedMove;
}
else if(x < 2){
rightWin++;
moveRight = true;
}
else {
x = x - speedMove;
}
}
//y
if(moveDown == true) {
if (y < 53 - yCubeSize)
y++;
else if(y > yCubeSize) {
moveDown = false;
y--;
}
}
else {
if (y > 0)
y--;
else {
moveDown = true;
y++;
}
}
oled.update();
} // -----------------------------------------------------------------------------------
}
void PlayGame2() {
int score = 0;
short int hp = 100;
byte x = 25;
byte xHook = 25;
byte yHook = 25;
uint8_t x_FishRight = 125;
uint8_t x_FishLeft = -10;
byte y_FishRight = 40;
byte y_FishLeft = 40;
byte FishSpeadTick = 0;
//bool FishSpeadTick = true;
bool botSpeadTick = true;
while(true) {
// Input // ----------------------------------------------------
buttonsTick();
if(hp >= 100){
hp = 100;
}
if( (ok.isClick() or ok.isStep() ) || (hp <= 0) ){
break;
}
else if(((right.isClick() or right.isStep() or right.isHold())) and (x <= 115)){
x++;
}
else if(((left.isClick() or left.isStep() or left.isHold())) and (x >= 2)){
x--;
}
if(((down.isClick() or down.isStep() or down.isHold())) and (yHook <= 44)){
yHook++;
}
else if(((up.isClick() or up.isStep() or up.isHold())) and (yHook > 2)){
yHook--;
}
// Hook //
if((botSpeadTick || abs(x - xHook) >= 18) and ( abs(x - xHook) >= 3) ){
if(xHook < x)
xHook++;
else
xHook--;
botSpeadTick = false;
}
else{
botSpeadTick = true;
}
// Fish Right //
if(FishSpeadTick >=4 )
FishSpeadTick = 0;
else
FishSpeadTick++;
// x
if (x_FishRight <= 0){
hp = hp - 30;
x_FishRight = random(125, 135);
y_FishRight = random(3, 45); }
else if ((abs(y_FishRight - yHook) <= 3) && ((abs(xHook - x_FishRight-3) <= 4))){
score++;
hp++;
x_FishRight = random(125, 135);
y_FishRight = random(3, 45);
}
else
x_FishRight--;
// y
if ( (abs(y_FishRight - yHook) <= 3) && (y_FishRight - yHook <= 0) )
y_FishRight = constrain(y_FishRight - 1, 3, 45);
else if (abs(y_FishRight - yHook) <= 3)
y_FishRight = constrain(y_FishRight + 1, 3, 45);
// Fish Left //
// x
if (x_FishLeft == 127){
hp = hp - 30;
x_FishLeft = random(-20, -10);
y_FishLeft = random(3, 45); }
else if ((abs(y_FishLeft - yHook) <= 3) && ((abs(xHook - x_FishLeft+3) <= 4))){
x_FishLeft = random(-20, -10);
y_FishLeft = random(3, 45);
score++;
hp++; }
else
x_FishLeft++;
// y
if ( (abs(y_FishLeft - yHook) <= 3) && (y_FishLeft - yHook <= 0) )
y_FishLeft = constrain(y_FishLeft - 1, 3, 45);
else if (abs(y_FishLeft - yHook) <= 3)
y_FishLeft = constrain(y_FishLeft + 1, 3, 45);
// Draw // ----------------------------------------------------
oled.clear();
oled.rect(0, 0, 127, 54, OLED_STROKE);
oled.line(x+3, 1, xHook+3, yHook);
oled.setCursor(2, 7); oled.print(score);
oled.rect(21, 57, 121, 61, OLED_STROKE);
oled.rect(122-hp, 58, 120, 60, OLED_FILL);
// Hook //
if(xHook <= x){
if(abs(x - xHook <= 10))
oled.drawBitmap(xHook, yHook, FOH_hookRight, 8, 8);
else
oled.drawBitmap(xHook, yHook, FOH_hookRight2, 8, 8);
}
else{
if(abs(xHook - x <= 10))
oled.drawBitmap(xHook, yHook, FOH_hookLeft, 8, 8);
else
oled.drawBitmap(xHook, yHook, FOH_hookLeft2, 8, 8);
}
// Fish Right //
oled.drawBitmap(x_FishRight, y_FishRight, FOH_Face_1, 8, 8);
if(FishSpeadTick > 2)
oled.drawBitmap(x_FishRight + 8, y_FishRight, FOH_Tail_Right_1, 8, 8);
else
oled.drawBitmap(x_FishRight + 8, y_FishRight, FOH_Tail_Right_2, 8, 8);
// Fish Left //
oled.drawBitmap(x_FishLeft, y_FishLeft, FOH_Face_2, 8, 8);
if(FishSpeadTick > 2)
oled.drawBitmap(x_FishLeft - 8, y_FishLeft, FOH_Tail_Left_1, 8, 8);
else
oled.drawBitmap(x_FishLeft - 8, y_FishLeft, FOH_Tail_Left_2, 8, 8);
oled.update();
}
oled.clear();
oled.setCursor(10, 2); oled.print(F("Your worm is WASTED"));
oled.setCursor(40, 4); oled.print(F("SCORE:"));
oled.setCursor(80, 4); oled.print(score);
oled.update();
delay(3000);
}
void PlayGame3(){
byte x1 = 21;
byte y1 = 54;
byte x2 = 71;
byte y2 = 54;
bool mooveRight1 = true;
bool mooveRight2 = false;
x1 = random(11, 107);
x2 = random(11, 107);
if(x1 > 59)
mooveRight1 = false;
if(x2 > 59)
mooveRight2 = false;
while(true) {
// Input // ----------------------------------------------------
buttonsTick();
if(ok.isClick() or ok.isStep() ){
break;
}
if(mooveRight1)
x1++;
else
x1--;
if(mooveRight2)
x2++;
else
x2--;
if(x1 >= 107)
mooveRight1 = false;
else if(x1 <= 11)
mooveRight1 = true;
if(x2 >= 107)
mooveRight2 = false;
else if(x2 <= 11)
mooveRight2 = true;
// Draw // ----------------------------------------------------
oled.clear();
oled.clear();
oled.setCursor(1, 2); oled.print("Made by KhPI students");
oled.setCursor(48, 1); oled.print("E-120A");
oled.setCursor(2, 4); oled.print("Novakov M."); oled.setCursor(62, 4); oled.print("Shcherbak V.");
oled.setCursor(2, 5); oled.print("Novakov D."); oled.setCursor(62, 5); oled.print("Striletc O.");
//oled.rect(21, 53, 108, 60, OLED_STROKE);
oled.rect(x1+1, y1-2, x1+9, y1+2, OLED_STROKE);
//oled.rect(x2+1, y2, x2+10, y2+4, OLED_STROKE);
oled.circle(x2, y2, 4, OLED_STROKE);
oled.update();
}
}
void oledEnable() {
oled.init();
Wire.setClock(800000L); // макс. 800'000
}