Added Code

This commit is contained in:
DerCrafter
2021-07-15 19:27:13 +02:00
commit 5db287dacb
34 changed files with 1884 additions and 0 deletions

520
Server_new/Draw.pde Normal file
View File

@@ -0,0 +1,520 @@
void draw()
{
status_server = status;
//STARTSCREEN
if (status==0)
{
if (mousePressed && mouseX>100 && mouseX<300 && mouseY>10 && mouseY<60 && player_character_server !=0)
{
status = 1;
background(255);
heal_server = 100000;
if (!serverRunning)
{
s = new Server(this, 4444); // starte den Server
serverRunning = true;
}
}
//Background
image(Background_Start, 0, 0);
//character abfrage für vorschau
if (mousePressed && mouseX>175 && mouseX<225 && mouseY>400 && mouseY<450)
{
player_character_server = 1;
}
if (mousePressed && mouseX>100 && mouseX<150 && mouseY>400 && mouseY<450)
{
player_character_server = 2;
}
if (mousePressed && mouseX>250 && mouseX<300 && mouseY>400 && mouseY<450)
{
player_character_server= 3;
}
//Menu button
if (mousePressed && mouseX>1800 && mouseX<1900 && mouseY>100 && mouseY<200 )
{
status=2;
}
//character vorschau mainscreen
fill(255);
textSize(22);
text("Character auswahl", 110, 150);
textSize(12);
//Defaultcharacter IMAGE
if (player_character_server == 1)
{
fill(#FAAB00);
ellipse(200, 230, 64, 64);
fill(255);
fill(0);
}
//Mario
if (player_character_server == 2)
{
image(Mario_character, 175, 200);
}
//Luigi
if (player_character_server == 3)
{
image(Luigi_character, 175, 200);
}
//Namen Text Feld
switch (state) {
case 0:
fill(0);
textSize(32);
text("Gib deinem charakter einen namen \n" + ": "+player_name_server, 600, 100);
textSize(12);
noFill();
break;
case 1:
fill(255, 2, 2);
textSize(32);
text ("Dein name ist \n"+":"+player_name_server, 600, 100);
textSize(12);
fill(0);
noFill();
break;
}
textSize(22);
text("!!Du darfst nur 8 Buchstaben / Zahlen verwenden!!", 620, 200);
textSize(12);
//Server Start button
fill(#00E7FA);
rect(100, 10, 200, 40);
fill(0);
text("Starte Multiplayer Server", 120, 35);
noFill();
//Mario select button
fill(#F50A0A);
rect(100, 400, 50, 50);
fill(0);
text("Mario", 110, 430);
noFill();
//Luigi select button
fill(#08FA4E);
rect(250, 400, 50, 50);
fill(0);
text("Luigi", 260, 430);
noFill();
//Default select button
fill(#FFB108);
rect(175, 400, 50, 50);
fill(0);
text("Balli", 185, 430);
noFill();
//Menu
fill(#FF1F1F);
image(menu, 1800, 100);
fill(0);
textSize(32);
fill(#05C7FF);
text("Menü", 1805, 100);
fill(0);
textSize(12);
if (!Startmusik.isPlaying() && soundon == true)
{
Startmusik.play();
}
if (soundon == false)
{
Startmusik.stop();
}
//IP Show
textSize(20);
text("IP : " + Server.ip(), 100, 800);
textSize(12);
fill(#00F4FF);
ellipse(mouseX, mouseY, 10, 10);
}
//MAIN GAME---------------------------MAINGAME------------------------------------------------------------------------------------------------------
if (status==1)
{
image(backgroundgame, 0, 0);
Startmusik.stop();
//BOARDER
noFill();
strokeWeight(4);
rect(110, 100, 1540, 900);
strokeWeight(1);
//Player SHOW INGAME--SERVER------------
if (player_character_server == 1)
{
fill(#FAAB00);
ellipse(server_x, server_y, 64, 64);
fill(255);
noFill();
}
if (player_character_server == 2)
{
image(Mario_character, server_x-20, server_y-20);
}
if (player_character_server == 3)
{
image(Luigi_character, server_x-20, server_y-20);
}
//Player SHOW INGAME--CLIENT------------
if (player_character_client == 1)
{
fill(#FAAB00);
ellipse(client_x, client_y, 64, 64);
fill(255);
noFill();
}
if (player_character_client== 2)
{
image(Mario_character, client_x-20, client_y-20);
}
if (player_character_client == 3)
{
image(Luigi_character, client_x-20, client_y-20);
}
//debug
if (debug == true)
{
rect(server_x-5, server_y-5, 10, 10);
rect(client_x-5, client_y-5, 10, 10);
}
// TEXT ZEICHNEN SERVER
if (player_character_server !=0)
{
fill(0, 0, 0);
textSize(22);
text(player_name_server, server_x-10, server_y-20);
textSize(12);
}
// TEXT ZEICHNEN CLIENT
if (player_character_client !=0)
{
fill(0, 0, 0);
textSize(22);
text(player_name_client, client_x-10, client_y-20);
textSize(12);
}
//MINIMAP
fill(#766D6D);
rect(1699, 19, 201, 201);
fill(#870CF5);
image(backgroundminimap, 1700, 20);
ellipse(server_x/9.6+1700, server_y/5.4+20, 16, 16);
if (player_character_client != 0)
{
fill(#FF0303);
ellipse(client_x/9.6+1700, client_y/5.4+20, 16, 16);
}
noFill();
//Heal Bar
fill(#1BF078);
//player_heal
rect(100, 30, heal_server/500, 10);
noFill();
if (player_character_client !=0)
{
fill(#FF1A12);
rect(client_x -30, client_y -50, heal_client/1000, 10);
noFill();
}
if (heal_server <= 100)
{
status = 4;
player_character_server = 0;
heal_server = 100000;
}
if (heal_client <= 100)
{
player_character_client = 0;
heal_client = 100000;
points++;
}
// Punktesystem
textSize(20);
text(points, 400, 50);
textSize(12);
//Menu
fill(#FF1F1F);
image(menu, 10, 980);
menu.resize(0, 50);
fill(0);
textSize(22);
fill(255);
text("Menü", 10, 980);
fill(0);
textSize(12);
//button trigger menu ingame
if (mousePressed && mouseX>10 && mouseX<60 && mouseY>980 && mouseY<1030)
{
menu_ingame = true;
}
//ENABLE SHOOTINGS SERVER SIDE
mouseX_server = mouseX;
mouseY_server = mouseY;
for (int n=0; n<50; n++)
{
fill(50);
ellipse(KugelX_server[n], KugelY_server[n], 10, 10);
KugelX_server[n] += cos(radians(KugelRichtung_server[n]))*5;
KugelY_server[n] += sin(radians(KugelRichtung_server[n]))*5;
}
if (mousepressed_server == 1 && player_character_server !=0)
{
KugelX_server[nummer_server] = server_x+25;
KugelY_server[nummer_server] = server_y+25;
KugelRichtung_server[nummer_server] = richtungMaus_server(server_x, server_y);
nummer_server = (nummer_server+1)%50;
}
// ENABLE SHOOTINGS CLIENT
for (int n=0; n<50; n++)
{
fill(50);
ellipse(KugelX_client[n], KugelY_client[n], 10, 10);
KugelX_client[n] += cos(radians(KugelRichtung_client[n]))*5;
KugelY_client[n] += sin(radians(KugelRichtung_client[n]))*5;
//abstand von kugel berechnen und leben abziehen
for (int i=0; i<50; i++)
{
if (abstand(x_server[i], y_server[i], KugelX_server[n], KugelY_server[n]) < 60&& player_character_client !=0)
{
heal_client = heal_client -1;
}
}
}
for (int n=0; n<50; n++)
{
x_server[n] = client_x;
y_server[n] = client_y;
}
if (mousepressed_client == 1 && player_character_client !=0)
{
KugelX_client[nummer_client] = client_x+25;
KugelY_client[nummer_client] = client_y+25;
KugelRichtung_client[nummer_client] = richtungMaus_client(client_x, client_y);
nummer_client = (nummer_client+1)%50;
}
//Gun
spielerZeichnen_server(server_x+25, server_y+25);
if (player_character_client !=0)
{
spielerZeichnen_client(client_x+25, client_y+25);
}
fill(#00F4FF);
ellipse(mouseX, mouseY, 10, 10);
}
//Menu-------------------------------STARTSCREEN--------MENUUUUUUU----------------------------
if (status==2)
{
image(Background_Start, 0, 0);
fill(255);
rect(810, 390, 300, 300);
fill(0);
textSize(22);
text("MENÜ", 920, 430);
fill(0);
textSize(12);
//SOUNDBUTTON true or false
rect(840, 450, 49, 49);
if (buttonCooldown > 0) buttonCooldown --;
if ( mousePressed && mouseX>840 && mouseX<890 && mouseY>450 && mouseY<500 && buttonCooldown == 0)
{
buttonCooldown = 30;
if (soundon == true)
{
soundon=false;
} else if (soundon == false)
{
soundon=true;
}
}
if (soundon==true)
{
image(y, 840, 450);
fill(0);
textSize(18);
text("Musik ist AN!", 910, 480);
textSize(12);
if (!Startmusik.isPlaying())
{
Startmusik.play();
}
}
if (soundon==false)
{
image(x, 840, 450);
fill(0);
textSize(18);
text("Musik ist AUS!", 910, 480);
textSize(12);
Startmusik.stop();
}
//buton exit
fill(#0FDBCC);
rect(1040, 630, 50, 50);
fill(0);
textSize(14);
text("Zurück", 1040, 660);
textSize(12);
//button trigger
if (mousePressed && mouseX>1040 && mouseX<1090 && mouseY>630 && mouseY<680)
{
status = 0;
}
}
//Menu ingame-----------------------------------------------------------------------------------------------------
if (menu_ingame)
{
fill(255);
rect(810, 390, 300, 300);
fill(0);
textSize(22);
text("MENÜ", 920, 430);
fill(0);
textSize(12);
//buton exit
fill(#0FDBCC);
rect(1040, 630, 50, 50);
fill(0);
textSize(14);
text("Zurück", 1040, 660);
textSize(12);
if (mousePressed && mouseX>1040 && mouseX<1090 && mouseY>630 && mouseY<680)
{
menu_ingame = false;
status = 1;
}
//Server Close
fill(255);
rect(840, 450, 49, 49);
fill(0);
//server on or off
if (serverRunning == true)
{
image(y, 840, 450);
fill(0);
textSize(18);
text("Server ist ON!", 910, 480);
textSize(12);
}
if (serverRunning == false)
{
image(x, 840, 450);
fill(0);
textSize(18);
text("Server ist OFF!", 910, 480);
textSize(12);
}
if (debug == true)
{
if (buttonCooldown > 0) buttonCooldown --;
if (mousePressed && mouseX>840 && mouseX<890 && mouseY>450 && mouseY<500 && buttonCooldown == 0)
{
buttonCooldown = 30;
if (serverRunning == true)
{
serverRunning = false;
} else if (serverRunning == false)
{
serverRunning=true;
}
}
}
}
//---------------------------Loosing screen-------------------------------------------------------
if (status == 4)
{
points = 0;
image(Background_Start, 0, 0);
fill(#391A7C);
rect(300, 300, 200, 50);
textSize(15);
fill(0);
text("Click here to Respawn", 300, 350);
textSize(12);
state = 0;
noFill();
if (mousePressed && mouseX>300 && mouseX<500 && mouseY>300 && mouseY<350)
{
status = 0;
player_character_server = 0;
heal_server = 100000;
heal_client = 100000;
}
}
//----------------------------------------------------------------------------------
if (serverRunning)
{
datenLesenServer();
if (taste[0] && server_y>100) {
server_y= server_y-5*(60/frameRate);
}
if (taste[1] && server_x>110) {
server_x= server_x-5*(60/frameRate);
}
if (taste[2] && server_y<1000) {
server_y= server_y+5*(60/frameRate);
}
if (taste[3] && server_x<1650) {
server_x= server_x+5*(60/frameRate);
}
datenSchreibenServer();
}
//DEBUG MODE
if (debug == true && status == 1)
{
fill(#FF0000);
text(frameRate, 1600, 20);
text(frameCount, 1600, 40);
text(server_x, 1300, 20);
text(server_y, 1400, 20);
text(mouseX_server, 1200, 20);
text(mouseY_server, 1100, 20);
text(heal_server, 1000, 20);
text(status, 900, 20);
text(client_x, 1300, 40);
text(client_y, 1400, 40);
text(mouseX_client, 1200, 40);
text(mouseY_client, 1100, 40);
text(heal_client, 1000, 40);
fill(0);
}
fill(#00F4FF);
ellipse(mouseX, mouseY, 10, 10);
}

20
Server_new/Server_new.pde Normal file
View File

@@ -0,0 +1,20 @@
void setup()
{
size(1920, 1080);
serverRunning = false;
backgroundgame = loadImage("backgroundgame.png");
Mario_character = loadImage("Mario.png");
Luigi_character = loadImage("Luigi.png");
gun = loadImage("gun.png");
Background_Start =loadImage("Status0.png");
menu =loadImage("Menubutton.png");
x = loadImage("x.png");
y = loadImage("y.png");
backgroundminimap = loadImage("backgroundminimap.png");
Startmusik = new SoundFile(this, "LoadingScreenMusic.mp3");
soundon = true;
noCursor();
}

80
Server_new/Variable.pde Normal file
View File

@@ -0,0 +1,80 @@
//OtherLibrarys
import processing.sound.*;
import processing.video.*;
//Network Library
import processing.net.*;
Server s;
Client c;
boolean serverRunning;
int playernummer = 0;
Client[] server_c = new Client[16];
//PlayerVariable/Eigenmschaften
float server_x= 100; // x-Koordinate
float server_y= 100; // y-Koordinate
float client_x= 1550; // x-Koordinate
float client_y= 900; // y-Koordinate
//mousevariable
float mouseX_server=70;
float mouseY_server= 80;
float mouseX_client= 1650;
float mouseY_client= 1000;
//playercharacter variable
float player_character_server = 0;
float player_character_client = 0;
//playername
String player_name_server="";
String player_name_client="";
//statusfrom server
int status_server;
//Heal
int heal_server = 100000;
int heal_client = 100000;
//ImageDeklarieren
PImage Mario_character, Luigi_character;
PImage gun;
PImage Background_Start;
PImage backgroundgame;
PImage backgroundminimap;
//DEBUG
boolean debug;
//TastenSteuerung
boolean[] taste = new boolean[4];
int state;
//punktesystem
int points;
//MENU
PImage menu;
PImage x;
PImage y;
//berechnung von abstand player kugeln
float[] x_server = new float[100];
float[] y_server = new float[100];
//INGAME MENU
//STATUS Anzeige
int status;
boolean menu_ingame = false;
//Musik
SoundFile Startmusik;
boolean soundon;
int buttonCooldown;
//SHOOTINGS
float playerRichtung_server;
float[] KugelX_server = new float[50];
float[] KugelY_server = new float[50];
float[] KugelRichtung_server = new float[50];
int nummer_server=0;
float mousepressed_server;
float playerRichtung_client;
float[] KugelX_client = new float[50];
float[] KugelY_client = new float[50];
float[] KugelRichtung_client = new float[50];
int nummer_client=0;
float mousepressed_client;

View File

@@ -0,0 +1,163 @@
// VOID KEY PRESSED
void keyPressed()
{
if (key == 49)
{
debug = true;
}
if (key == 50)
{
debug = false;
}
if (status==1)
{
switch(key)
{
case 'w':
taste[0] = true;
break;
case 'W':
taste[0] = true;
break;
case 'a':
taste[1] = true;
break;
case 'A':
taste[1] = true;
break;
case 's':
taste[2] = true;
break;
case 'S':
taste[2] = true;
break;
case 'd':
taste[3] = true;
break;
case 'D':
taste[3] = true;
break;
}
}
if (status==0)
{
if (key==ENTER || key==RETURN)
{
if (player_name_server.length()!=0)
{
state=1;
return;
}
}
if (keyCode == 32)
{
return;
}
if (state==0)
{
if (player_name_server.length()<8)
{
player_name_server = player_name_server + key;
}
if (keyCode == 8 && player_name_server.length()>1)
{
player_name_server = player_name_server.substring(0, player_name_server.length() - 2);
}
}
}
//SOUND TOGGLE
if (status == 2)
{
if (keyCode == 32)
{
if (soundon == true)
{
soundon=false;
} else
{
if (soundon == false)
{
soundon=true;
}
}
}
}
//OPTIONS SERVER INGAME
if (menu_ingame)
{
if ( keyCode == 32 && debug == true)
{
if (serverRunning == true)
{
serverRunning=false;
} else
{
if (serverRunning == false)
{
serverRunning=true;
}
}
}
}
}
// VOID KEY RELEASED
void keyReleased()
{
if (status==1)
{
switch(key)
{
case 'w':
taste[0] = false;
break;
case 'W':
taste[0] = false;
break;
case 'a':
taste[1] = false;
break;
case 'A':
taste[1] = false;
break;
case 's':
taste[2] = false;
break;
case 'S':
taste[2] = false;
break;
case 'd':
taste[3] = false;
break;
case 'D':
taste[3] = false;
break;
}
}
}
void mousePressed()
{
if (status == 1&& menu_ingame == false)
{
mousepressed_server = 1;
}
}
void mouseReleased()
{
if (status == 1)
{
mousepressed_server = 0;
}
}

View File

@@ -0,0 +1,36 @@
void datenLesenServer()
{
String input;
String data[];
String zeile[];
c = s.available(); // erster Client aktivieren
while (c != null)
{
input = c.readString();
data = split(input, '\n'); // Split values into an array
for (String n : data)
{
zeile = split(n, ' ');
if (zeile[0].equals("Spieler"))
{
client_x = float(zeile[1]);
client_y = float(zeile[2]);
player_character_client = float(zeile[3]);
playerRichtung_client = float(zeile[4]);
mousepressed_client = float(zeile[5]);
nummer_client = int(zeile[6]);
mouseX_client = int(zeile[7]);
mouseY_client = int(zeile[8]);
player_name_client = zeile[9];
heal_server = int(zeile[10]);
}
}
c = s.available(); // zweiter, dritter,... Client aktivieren
}
}
void datenSchreibenServer()
{
String text = "Spieler "+server_x+" "+server_y+" "+player_character_server+" "+playerRichtung_server+" "+mousepressed_server+" "+nummer_server+" "+mouseX_server+" "+mouseY_server+" "+player_name_server+" "+heal_client+" "+status_server+"\n";
s.write(text);
}

View File

@@ -0,0 +1,83 @@
float richtungMaus_server(float x, float y)
{
float winkel;
float difx = mouseX-x;
float dify = mouseY-y;
winkel = degrees(atan(dify/difx));
if (difx<0) {
winkel = winkel+180;
}
winkel = (winkel+360)%360;
return(winkel);
}
float richtungMaus_client(float x, float y)
{
float winkel;
float difx = mouseX_client-x;
float dify = mouseY_client-y;
winkel = degrees(atan(dify/difx));
if (difx<0) {
winkel = winkel+180;
}
winkel = (winkel+360)%360;
return(winkel);
}
void spielerZeichnen_server(float x, float y)
{
translate(x, y);
rotate(radians(richtungMaus_server(server_x, server_y)-90));
image(gun, -15, -15, 30, 30);
rotate(-radians(richtungMaus_server(server_x, server_y)-90));
translate(-x, -y);
}
void spielerZeichnen_client(float x, float y)
{
if (status == 1)
{
translate(x, y);
rotate(radians(richtungMaus_client(client_x, client_y)-90));
image(gun, -15, -15, 30, 30);
rotate(-radians(richtungMaus_client(client_x, client_y)-90));
translate(-x, -y);
}
}
float abstand(float x1, float y1, float x2, float y2)
{
float wert;
wert = sqrt(sq(x1-x2)+sq(y1-y2));
return(wert);
}

Binary file not shown.

BIN
Server_new/data/Luigi.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
Server_new/data/Mario.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
Server_new/data/Status0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
Server_new/data/Thumbs.db Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 892 B

BIN
Server_new/data/gun.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
Server_new/data/x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
Server_new/data/y.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB