Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Game
Browse files Browse the repository at this point in the history
  • Loading branch information
Blueforcer committed Apr 20, 2018
1 parent 3a2eec8 commit 8273a80
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/Applications/PongApp.cpp
Expand Up @@ -28,7 +28,7 @@ void PongApp::render(DisplayManager& display) {
oldPaddleY = paddleY;
display.show();

if (currentMillis - prevMillis >= 100) {
if (currentMillis - prevMillis >= 150) {
prevMillis = currentMillis;

if (ballX > 32 - 1 || ballX < 0) {
Expand Down
32 changes: 10 additions & 22 deletions lib/Applications/SnakeApp.cpp
Expand Up @@ -6,12 +6,9 @@ const int RIGHT = 1;
const int BOTTOM = 2;
const int LEFT = 3;

// Snake
const int MAX_SNAKE_LENGTH = 15;

// Variables

// direction of movement
int snakeX[MAX_SNAKE_LENGTH]; // X-coordinates of snake
int snakeY[MAX_SNAKE_LENGTH]; // Y-coordinates of snake
int snakeLength = 1; // nr of parts of snake
Expand All @@ -26,23 +23,18 @@ int matrixColor;


void userLose(){


//toDo
snakeLength = 1;

}

void userWin(){



//toDo
snakeLength = 1;

}


boolean inPlayField(int x, int y){
return (x>=0) && (x<32) && (y>=0) && (y<8);
return (x>=1) && (x<32) && (y>=1) && (y<8);
}

boolean isPartOfSnake(int x, int y){
Expand All @@ -58,7 +50,7 @@ boolean isPartOfSnake(int x, int y){
void snakeCheck(){
for(int i=1; i<snakeLength; i++)
{
// snake touches itself

if((snakeX[0] == snakeX[i]) && (snakeY[0] == snakeY[i]))
userLose();
}
Expand All @@ -68,11 +60,11 @@ void snakeCheck(){

void makeFruit(){
int x, y;
x = random(0, 32);
y = random(0, 8);
x = random(1, 32);
y = random(1, 8);
while(isPartOfSnake(x, y)){
x = random(0, 32);
y = random(0, 8);
x = random(1, 32);
y = random(1, 8);
}
fruitX = x;
fruitY = y;
Expand All @@ -83,14 +75,14 @@ void makeFruit(){
void nextstep(){
for(int i = snakeLength; i > 0; i--)
{
if((direction == RIGHT) && (snakeX[0]-snakeLength == 31))
if((direction == RIGHT) && (snakeX[0]-snakeLength == 32))
snakeX[0] = -1;
else if((direction == LEFT) && (snakeX[0]+ snakeLength == 0))
snakeX[0] = 32;
else
snakeX[i] = snakeX[i-1];

if((direction == TOP) && (snakeY[0]+snakeLength == 0))
if((direction == TOP) && (snakeY[0]+snakeLength == 1))
snakeY[0] = 8;
else if((direction == BOTTOM) && (snakeY[0]-snakeLength == 7))
snakeY[0] = -1;
Expand Down Expand Up @@ -153,14 +145,10 @@ void SnakeApp::render(DisplayManager& display) {
unsigned long currenttime = millis();
if(currenttime - fruitPrevTime >= fruitBlinkTime)
{
//fruitLed = (fruitLed == LED_RED) ? LED_OFF : LED_RED;
fruitPrevTime = currenttime;
}
display.drawPixel(fruitX, fruitY, {255,0,0});
}



display.show();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Applications/WeatherApp.h
Expand Up @@ -9,8 +9,8 @@
class WeatherApp : public IApplication
{
private:
int temperature;
int humidity;
float temperature;
float humidity;
String icon;
String city;

Expand Down
9 changes: 6 additions & 3 deletions lib/Applications/YoutubeApp.cpp
Expand Up @@ -37,10 +37,13 @@ void YoutubeApp::enable() {
JsonObject& root = jsonBuffer.parseObject(response);
jsonBuffer.clear();
if (!root.success()) {
Serial.println("Failed parsing API response");
Serial.println("Failed parsing API response. Use last response");
}

subscribers = root["items"][0]["statistics"]["subscriberCount"];
int sub = root["items"][0]["statistics"]["subscriberCount"];
if (sub>0){
subscribers = sub;
}

}


4 changes: 1 addition & 3 deletions platformio.ini
Expand Up @@ -20,11 +20,9 @@ lib_deps =
PubSubClient
Adafruit NeoMatrix
Adafruit NeoPixel
Adafruit GFX Library
https://github.com/Blueforcer/Adafruit-GFX-Library
Adafruit Unified Sensor
WifiManager
thinger.io
WeatherStation
JsonStreamingParser
DHT sensor library
ArduinoJson
Expand Down
6 changes: 6 additions & 0 deletions src/main.cpp
Expand Up @@ -20,6 +20,8 @@ ApplicationManager& applications = ApplicationManager::getInstance();
AwtrixSettings& settings = AwtrixSettings::getInstance();

void setup() {
ESP.wdtDisable();
ESP.wdtEnable(WDTO_8S);
Serial.begin(115200);
Serial1.begin(9800);
settings.loadSPIFFS();
Expand Down Expand Up @@ -57,7 +59,11 @@ void loop() {
wifi.loop();
udp.loop();
if (MQTT_ACTIVE) mqtt.loop();



if (SETTINGS_FOUND) applications.loop();

if (BLYNK_ACTIVE) ESPblynk.loop();
if (AUTO_BRIGHTNESS) DisplayManager::getInstance().checkLight();
}
Expand Down

0 comments on commit 8273a80

Please sign in to comment.