Skip to content
Snippets Groups Projects
Commit 15d17c47 authored by HoelShare's avatar HoelShare
Browse files

GPN

parent 6857b5e7
No related branches found
No related tags found
No related merge requests found
...@@ -189,9 +189,9 @@ void loop() { ...@@ -189,9 +189,9 @@ void loop() {
pixels.show(); pixels.show();
if (server) { if (server) {
Serial.println("Loop - Server"); // Serial.println("Loop - Server");
server->update(); server->update();
Serial.println("Loop - Server - Ende"); // Serial.println("Loop - Server - Ende");
} }
if (client) { if (client) {
client->update(); client->update();
...@@ -201,12 +201,17 @@ void loop() { ...@@ -201,12 +201,17 @@ void loop() {
char *loadNick() { char *loadNick() {
if (SPIFFS.exists("/nick.conf")) { if (SPIFFS.exists("/nick.conf")) {
UrlDecode nickUrlDecode("/nick.conf"); Serial.println("Load nick");
File nickConf = SPIFFS.open("/nick.conf", "r");
String configString;
while (nickConf.available()) {
configString += char(nickConf.read());
}
nickConf.close();
UrlDecode nickUrlDecode(configString.c_str());
char *nick = nickUrlDecode.getKey("nick"); char *nick = nickUrlDecode.getKey("nick");
#ifdef DEBUG
Serial.printf("loaded nickname %s!\n", nick); Serial.printf("loaded nickname %s!\n", nick);
#endif
return nick; return nick;
} }
return "otter"; return "otter";
......
...@@ -17,22 +17,20 @@ void GameClient::createUIGameStart() { ...@@ -17,22 +17,20 @@ void GameClient::createUIGameStart() {
playerList->setDownAction([=]() { this->player->reload(); }); playerList->setDownAction([=]() { this->player->reload(); });
playerList->setEnterAction([=]() { this->player->shot(); }); playerList->setEnterAction([=]() { this->player->shot(); });
Serial.println("GameClient::createUIGameStart - set Lambdas"); Serial.println("GameClient::createUIGameStart - set Lambdas");
LaserMenuItem *healthMI = new LaserMenuItem([]() {}, "/heart.bmp"); MenuItem *healthMI = new MenuItem("100%", []() {});
LaserMenuItem *armorMI = new LaserMenuItem([]() {}, "/armor.bmp"); MenuItem *armorMI = new MenuItem("100%", []() {});
LaserMenuItem *ammoMI = new LaserMenuItem([]() {}, "/ammo1.bmp"); MenuItem *ammoMI = new MenuItem("10/10", []() {});
LaserMenuItem *nameMI = new LaserMenuItem([]() {}, nullptr); MenuItem *nameMI = new MenuItem(player->getNickname(), []() {});
player->setHealthMenuItem(healthMI); player->setHealthMenuItem(healthMI);
player->setArmorMenuItem(armorMI); player->setArmorMenuItem(armorMI);
player->setAmmoMenuItem(ammoMI); player->setAmmoMenuItem(ammoMI);
playerList->addMenuItem(new MenuItem("% Otter", []() {}));
playerList->addMenuItem(healthMI); playerList->addMenuItem(healthMI);
playerList->addMenuItem(armorMI); // playerList->addMenuItem(armorMI);
playerList->addMenuItem(ammoMI); // playerList->addMenuItem(ammoMI);
playerList->addMenuItem(nameMI); playerList->addMenuItem(nameMI);
Serial.println("GameClient::createUIGameStart - added Lambdas"); Serial.println("GameClient::createUIGameStart - added Lambdas");
nameMI->setText(player->getNickname()); ui->open(playerList);
Serial.println("GameClient::createUIGameStart - set Nickname");
playerList->setDirty();
reopen = true;
Serial.println("GameClient::createUIGameStart - Ende"); Serial.println("GameClient::createUIGameStart - Ende");
} }
...@@ -60,7 +58,7 @@ void GameClient::joinGame(String ip) { ...@@ -60,7 +58,7 @@ void GameClient::joinGame(String ip) {
//client->connect(ip.c_str(), SERVER_PORT); //client->connect(ip.c_str(), SERVER_PORT);
Serial.printf("Trying to conncet!\n"); Serial.printf("Trying to conncet!\n");
if (!client->connect("192.168.42.175", 4803)){ if (!client->connect("192.168.42.175", 4803)) {
Serial.printf("Connect failed!\n"); Serial.printf("Connect failed!\n");
} }
Serial.printf("client->connect\n"); Serial.printf("client->connect\n");
...@@ -76,7 +74,7 @@ void GameClient::joinGame(String ip) { ...@@ -76,7 +74,7 @@ void GameClient::joinGame(String ip) {
void GameClient::update() { void GameClient::update() {
Serial.println("GameClient - Update"); // Serial.println("GameClient - Update");
// String lastHitBy; // String lastHitBy;
// int lastDamage; // int lastDamage;
...@@ -88,10 +86,10 @@ void GameClient::update() { ...@@ -88,10 +86,10 @@ void GameClient::update() {
// tft.print("Hit by " + lastHitBy); // tft.print("Hit by " + lastHitBy);
// } // }
Serial.println("GameClient - Update - Ende"); // Serial.println("GameClient - Update - Ende");
} }
bool GameClient::wasHit(String* nick, int* damage, bool enable) { bool GameClient::wasHit(String *nick, int *damage, bool enable) {
// TODO: Write 'real' code // TODO: Write 'real' code
*nick = "otter"; *nick = "otter";
*damage = 10; *damage = 10;
......
...@@ -21,20 +21,20 @@ void GameServer::secureQuestion() { ...@@ -21,20 +21,20 @@ void GameServer::secureQuestion() {
#ifdef AUSGABE #ifdef AUSGABE
Serial.printf("Sicherheitsabfrage!"); Serial.printf("Sicherheitsabfrage!");
#endif #endif
secureMenu = new PlayerListMenu(4); //secureMenu = new PlayerListMenu(4);
secureMenu->addMenuItem(new MenuItem("Start?", [=]() { this->startGame(); Serial.println("Lambda Start - Ende"); })); //secureMenu->addMenuItem(new MenuItem("Start?", [=]() { this->startGame(); Serial.println("Lambda Start - Ende"); }));
secureMenu->addMenuItem(new MenuItem("Cancel?", [=]() { //secureMenu->addMenuItem(new MenuItem("Cancel?", [=]() {
ui->dispatchInput(badge->getJoystickState()); // ui->dispatchInput(badge->getJoystickState());
ui->closeCurrent(); // ui->closeCurrent();
ui->draw(); // ui->draw();
})); //}));
secureMenu->setRightAction([=]() { //secureMenu->setRightAction([=]() {
ui->dispatchInput(badge->getJoystickState()); // ui->dispatchInput(badge->getJoystickState());
ui->closeCurrent(); // ui->closeCurrent();
ui->draw(); // ui->draw();
}); //});
secureMenu->setLeftAction([=]() { this->startGame(); }); //secureMenu->setLeftAction([=]() { this->startGame(); });
ui->open(secureMenu); //ui->open(secureMenu);
} }
void GameServer::kick() { void GameServer::kick() {
...@@ -54,12 +54,13 @@ void GameServer::update() { ...@@ -54,12 +54,13 @@ void GameServer::update() {
handleWelcome(&(serverClients[numConnections]), numConnections); handleWelcome(&(serverClients[numConnections]), numConnections);
} }
} else { } else {
Serial.println("Waiting for packets"); // Serial.println("Waiting for packets");
for (short i = 0; i < numConnections; i++) { //iterate throu the slots for (short i = 0; i < numConnections; i++) { //iterate throu the slots
if (serverClients[i].connected() && serverClients[i].available()) { //skip unconnected slots if (serverClients[i].connected() && serverClients[i].available()) { //skip unconnected slots
String message = serverClients[i].readStringUntil('\n'); String message = serverClients[i].readStringUntil('\n');
UrlDecode decode(message.c_str()); UrlDecode decode(message.c_str());
String strTyp = String(decode.getKey("typ")); String strTyp = String(decode.getKey("typ"));
Serial.println(message);
if (strTyp == "hit") { if (strTyp == "hit") {
HitPacket *packet = HitPacket::read(message); HitPacket *packet = HitPacket::read(message);
sendHit(packet); sendHit(packet);
...@@ -133,7 +134,7 @@ void GameServer::startGame() { ...@@ -133,7 +134,7 @@ void GameServer::startGame() {
config.health = HEALTH; config.health = HEALTH;
String value = config.serial() + "\n"; String value = config.serial() + "\n";
sendAll(value); sendAll(value);
sendAll(this->buildPlayerList()); sendAll(buildPlayerList());
this->gameStarted = true; this->gameStarted = true;
if (gameStartCallback) { if (gameStartCallback) {
Serial.println("Start Game - GameServer - call Callback"); Serial.println("Start Game - GameServer - call Callback");
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <GPNBadge.hpp> #include <GPNBadge.hpp>
#include "BadgeUI.h" #include "BadgeUI.h"
#include "HitPacket.hpp" #include "HitPacket.hpp"
#include "LaserMenuItem.hpp"
#include "PlayerListMenu.hpp" #include "PlayerListMenu.hpp"
#include "RemotePlayer.hpp" #include "RemotePlayer.hpp"
...@@ -58,11 +57,10 @@ public: ...@@ -58,11 +57,10 @@ public:
Serial.printf("Opened menu\n"); Serial.printf("Opened menu\n");
#endif #endif
playerList = new PlayerListMenu(9); playerList = new PlayerListMenu(9);
LaserMenuItem *item = new LaserMenuItem([]() {}, nullptr); MenuItem *item = new MenuItem("Playerlist", []() {});
item->setText("Playerlist");
playerList->addMenuItem(item); playerList->addMenuItem(item);
playerList->setLeftAction([=]() { this->kick(); }); playerList->setLeftAction([=]() { this->kick(); });
playerList->setRightAction([=]() { this->secureQuestion(); }); playerList->setRightAction([=]() { this->startGame(); });
playerList->setEnterAction([=]() { this->sendIP(); }); playerList->setEnterAction([=]() { this->sendIP(); });
ui->open(playerList); ui->open(playerList);
ui->dispatchInput(badge->getJoystickState()); ui->dispatchInput(badge->getJoystickState());
......
//
// Created by hoelshare on 21.05.17.
//
#include "LaserMenuItem.hpp"
#include <FS.h>
#include <TFT_ILI9163C.h>
#include "BadgeUI.h"
uint32_t read32(File &f);
uint16_t read16(File &f);
void LaserMenuItem::bmpDraw(uint8_t x, uint16_t y, TFT_ILI9163C *tft) {
Serial.println("LaserMenuItem::bmpDraw");
if (this->imagePath) {
File bmpFile;
uint16_t bmpWidth, bmpHeight; // W+H in pixels
uint8_t bmpDepth; // Bit depth (currently must be 24)
uint32_t bmpImageoffset; // Start of image data in file
uint32_t rowSize; // Not always = bmpWidth; may have padding
uint8_t sdbufferLen = BUFFPIXEL * 3;
uint8_t sdbuffer[sdbufferLen]; // pixel buffer (R+G+B per pixel)
uint8_t buffidx = sdbufferLen; // Current position in sdbuffer
boolean goodBmp = false; // Set to true on valid header parse
boolean flip = true; // BMP is stored bottom-to-top
uint16_t w, h, row, col;
uint8_t r, g, b;
uint32_t pos = 0;
if ((x >= tft->width()) || (y >= tft->height())) return;
// Open requested file on SD card
if ((bmpFile = SPIFFS.open(this->imagePath, "r")) == NULL) {
// TODO Download File
return;
}
// Parse BMP header
if (read16(bmpFile) == 0x4D42) { // BMP signature
read32(bmpFile);
(void) read32(bmpFile); // Read & ignore creator bytes
bmpImageoffset = read32(bmpFile); // Start of image data
// Read DIB header
read32(bmpFile);
bmpWidth = read32(bmpFile);
bmpHeight = read32(bmpFile);
if (read16(bmpFile) == 1) { // # planes -- must be '1'
bmpDepth = read16(bmpFile); // bits per pixel
if ((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
goodBmp = true; // Supported BMP format -- proceed!
rowSize = (bmpWidth * 3 + 3) & ~3;// BMP rows are padded (if needed) to 4-byte boundary
if (bmpHeight < 0) {
bmpHeight = -bmpHeight;
flip = false;
}
// Crop area to be loaded
w = bmpWidth;
h = bmpHeight;
if ((x + w - 1) >= tft->width()) w = tft->width() - x;
if ((y + h - 1) >= tft->height()) h = tft->height() - y;
//tft->startPushData(x, y, x+w-1, y+h-1);
for (row = 0; row < h; row++) { // For each scanline...
uint8_t row_data[w * 2];
if (flip) { // Bitmap is stored bottom-to-top order (normal BMP)
pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
} else { // Bitmap is stored top-to-bottom
pos = bmpImageoffset + row * rowSize;
}
if (bmpFile.position() != pos) { // Need seek?
bmpFile.seek(pos, SeekSet);
buffidx = sdbufferLen; // Force buffer reload
}
for (col = 0; col < w; col++) { // For each pixel...
// Time to read more pixel data?
if (buffidx >= sdbufferLen) { // Indeed
bmpFile.read(sdbuffer, sdbufferLen);
buffidx = 0; // Set index to beginning
}
// Convert pixel from BMP to TFT format, push to display
b = sdbuffer[buffidx++];
g = sdbuffer[buffidx++];
r = sdbuffer[buffidx++];
uint16_t val = tft->Color565(r, g, b);
row_data[2 * col + 1] = (uint8_t) val;
row_data[2 * col] = *(((uint8_t * ) & val) + 1);
} // end pixel
tft->writeRow(y + row, x, w, row_data);
} // end scanline
//tft->endPushData();
} // end goodBmp
}
}
bmpFile.close();
if (!goodBmp) {
tft->setCursor(20, 20);
tft->print("file unrecognized!");
}
}
Serial.println("LaserMenuItem::bmpDraw - Ende");
}
//
// Created by hoelshare on 21.05.17.
//
#ifndef GPN_LASERTAG_LASERMENUITEM_HPP
#define GPN_LASERTAG_LASERMENUITEM_HPP
#include <GPNBadge.hpp>
#include <FS.h>
#include "UIThemes.h"
#include "BadgeUI.h"
class LaserMenuItem : public MenuItem {
public:
LaserMenuItem(std::function<void(void)> trigger, const char* imagePath) :
MenuItem("100%", trigger), imagePath(imagePath) {
};
void setImagePath(String imagePath) { this->imagePath = imagePath.c_str(); }
private:
const char *imagePath;
void bmpDraw(uint8_t, uint16_t, TFT_ILI9163C*);
};
#endif //GPN_LASERTAG_LASERMENUITEM_HPP
...@@ -50,7 +50,7 @@ void Player::updateArmorMenuItem() { ...@@ -50,7 +50,7 @@ void Player::updateArmorMenuItem() {
String percentage = buff; String percentage = buff;
delete[] buff; delete[] buff;
this->armorMenuItem->setText(percentage); this->armorMenuItem->setText(percentage);
this->armorMenuItem->setImagePath(String("/ammo" + String(this->weaponIndex) + ".bmp")); // this->armorMenuItem->setImagePath(String("/ammo" + String(this->weaponIndex) + ".bmp"));
} }
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef GPN_LASERTAG_PLAYER_HPP #ifndef GPN_LASERTAG_PLAYER_HPP
#define GPN_LASERTAG_PLAYER_HPP #define GPN_LASERTAG_PLAYER_HPP
#include "LaserMenuItem.hpp" #include "BadgeUI.h"
class Player { class Player {
public: public:
...@@ -36,17 +36,17 @@ public: ...@@ -36,17 +36,17 @@ public:
void setTeamID(unsigned short tID) { this->tID = tID; } void setTeamID(unsigned short tID) { this->tID = tID; }
void setHealthMenuItem(LaserMenuItem *healthMenuItem) { void setHealthMenuItem(MenuItem *healthMenuItem) {
if (healthMenuItem) { delete healthMenuItem; } if (healthMenuItem) { delete healthMenuItem; }
this->healthMenuItem = healthMenuItem; this->healthMenuItem = healthMenuItem;
} }
void setArmorMenuItem(LaserMenuItem *armorMenuItem) { void setArmorMenuItem(MenuItem *armorMenuItem) {
if (armorMenuItem) { delete armorMenuItem; } if (armorMenuItem) { delete armorMenuItem; }
this->armorMenuItem = armorMenuItem; this->armorMenuItem = armorMenuItem;
} }
void setAmmoMenuItem(LaserMenuItem *ammoMenuItem) { void setAmmoMenuItem(MenuItem *ammoMenuItem) {
if (ammoMenuItem) { delete ammoMenuItem; } if (ammoMenuItem) { delete ammoMenuItem; }
this->ammoMenuItem = ammoMenuItem; this->ammoMenuItem = ammoMenuItem;
} }
...@@ -91,8 +91,8 @@ protected: ...@@ -91,8 +91,8 @@ protected:
void updateAmmoMenuItem(); void updateAmmoMenuItem();
LaserMenuItem *healthMenuItem; MenuItem *healthMenuItem;
LaserMenuItem *armorMenuItem; MenuItem *armorMenuItem;
LaserMenuItem *ammoMenuItem; MenuItem *ammoMenuItem;
}; };
#endif //GPN_LASERTAG_PLAYER_HPP #endif //GPN_LASERTAG_PLAYER_HPP
...@@ -86,11 +86,6 @@ public: ...@@ -86,11 +86,6 @@ public:
} }
}; };
void addMenuItem(MenuItem *item) {
numItems++;
Menu::addMenuItem(item);
}
private: private:
std::function<void(void)> leftAction; std::function<void(void)> leftAction;
std::function<void(void)> rightAction; std::function<void(void)> rightAction;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment