/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.Sh3gwshMUqyD/rev.4838
*
* authors:
* TrobiiX
* fabi
*
* Sebastian Rieger
* Thomas
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
startscreen ss = new startscreen();
player p = new player();
entity e = new entity();
textfeld tf = new textfeld();
score s = new score();
boolean[] keys = new boolean[4];
keys[0] = false;
keys[1] = false;
keys[2] = false;
keys[3] = false;
void setup() {
size(1000, 500);
webImg = loadImage("https://www.google.de/imgres?imgurl=http%3A%2F%2Fhd-hintergrundbilder.com%2Ffahrzeuge%2Flamborghinitron.jpg&imgrefurl=http%3A%2F%2Fhd-hintergrundbilder.com%2F&docid=7_83-7FiVo8-6M&tbnid=6VVJoXEPMNXgLM%3A&vet=10ahUKEwjP_7LNo-_UAhUrAcAKHR-nBGcQMwg-KAgwCA..i&w=1920&h=1080&bih=969&biw=1920&q=hintergrundbilder%20hd&ved=0ahUKEwjP_7LNo-_UAhUrAcAKHR-nBGcQMwg-KAgwCA&iact=mrc&uact=8");
}
void keyPressed(){
if(key =='l'){
keys[0] = true;
}
if(key =='o'){
keys[1] = true;
}
if(key=='s'){
keys[2] = true;
}
if(key =='w'){
keys[3] = true;
}
}
void keyReleased(){
if(key =='l'){
keys[0] = false;
}
if(key =='o'){
keys[1] = false;
}
if(key=='s'){
keys[2] = false;
}
if(key =='w'){
keys[3] = false;
}
if(key =='UP'){
keys[0] = false;
}
if(key =='DOWN'){
keys[1] = false;
}
}
void draw(){
if(keys[0]){
p.s2.y+=7;
}
if(keys[1]){
p.s2.y-=7;
}
if(keys[2]){
p.s1.y+=7;
}
if(keys[3]){
p.s1.y-=7;
}
if (ss.text == false) {
background(0);
e.zeichne();
p.zeichne();
tf.display();
}
if (ss.text == true) {
background(0);
fill(255, 0, 0);//textfarbe
textSize(32);//textgrösse
text("Click to Play", 450, 100);//text hahah
text("LEFT PLAYER ", 100, 200);
text("UP = w", 100, 250);
text("DOWN = s", 100, 300),
text("RIGHT PLAYER", 700, 200);
text("UP = o", 700, 250);
text("DOWN = s", 700, 300);
}
}
void mouseReleased() {
ss.text = false;
}
class player {
spieler1 s1;
spieler2 s2;
player() {
s1 = new spieler1();
s2 = new spieler2();
}
void zeichne() {
s1.display();
s2.display();
}
}
class spieler1 {
int rot;
int gruen;
int blau;
double x;
double y;
double hoehe;
double breite;
spieler1() {
hoehe = 80;
breite = 10;
y = 250;
x = 30;
rot = 0;
gruen = 139;
blau = 139;
}
void display() {
fill(rot,gruen,blau);
rect(x,y,breite,hoehe);
}
}
class spieler2 {
int rot;
int gruen;
int blau;
double x;
double y;
double hoehe;
double breite;
spieler2() {
hoehe = 80;
breite = 10;
y = 250;
x = 965;
rot = 255;
gruen = 0;
blau = 0;
}
void display() {
fill(rot,gruen,blau);
rect(x,y,breite,hoehe);
}
}
class entity {
ball b;
entity() {
b = new ball();
}
void zeichne() {
b.display();
}
}
class ball {
int durchmesser;
double radius = durchmesser/2;
int rot;
int grün;
int blau;
double vX;
doubele vY;
double speed;
ball() {
rot = Math.random()*5+Math.random()*100;
gruen = Math.random()*5+Math.random()*500;
blau = Math.random()*5+Math.random()*500;
vX = 350;
vY = 250;
//speed = 3;
speedx = random( 5, 6); //randomSpeed(); // Math.random()*-5+Math.random()*5;
speedy = random(4, 6); //randomSpeed(); // Math.random()*-5+Math.random()*5;
}
void kollidiereIch() {
double abstand = Math.sqrt(Math.pow((vX - p.s1.x),2)+Math.pow((vY-p.s1.y),2));
double abstandY = Math.abs(vY-p.s1.y-p.s1.hoehe/2);
double abstandX = Math.abs(vX-p.s1.x-p.s1.breite/2);
if (abstandX<radius+(p.s1.breite)+10 && abstandY< radius+(p.s1.hoehe/2)+10) {
speedx= speedx*-1;
}
}
void kollidiereIch2() {
double abstand = Math.sqrt(Math.pow((vX - p.s2.x),2)+Math.pow((vY-p.s2.y),2));
double abstandY = Math.abs(vY-p.s2.y-p.s2.hoehe/2);
double abstandX = Math.abs(vX-p.s2.x-p.s2.breite/2);
if (abstandX<radius+(p.s2.breite)+10 && abstandY< radius+(p.s2.hoehe/2)+10) {
speedx= speedx*-1;
}
}
void display (){
vX+=speedx;
vY+=speedy;
kollidiereIch();
kollidiereIch2();
if (vY>=475-radius ||vY<=25+radius ){
speedy= speedy*-1;
}
if (vX>= 700 ||vX<= 0 ){
//delay(100);
//vX = 350; //350
//vY = 250;
//speedx = //Math.random()*-5+Math.random()*5;
//speedy = //Math.random()*-5+Math.random()*5;
}
if (vX>=990) {
s.sc1 = s.sc1+1;
vX = 800; //350
vY = 250;
speedx = random( -5, -6);//-6; //Math.random()*-5+Math.random()*5;
speedy = random(4, 6); //6;//Math.random()*-5+Math.random()*5;
}
if (vX<=10) {
s.sc2 = s.sc2+1;
vX = 200; //350
vY = 250;
speedx = random( 5, 6);//6;//Math.random()*-5+Math.random()*5;
speedy = random(4, 6); //6;//Math.random()*-5+Math.random()*5;
}
fill(rot,gruen,blau);
ellipse(vX,vY,30,30);
}
}
class score {
int sc1;
int sc2;
score() {
//sc1 = 0;
//sc2 = 0;
//sc1plus();
//sc2plus();
}
}
class textfeld {
int rot = 255;
int gruen = 255;
int blau = 255;
void display() {
fill(rot,gruen,blau);
textSize(20);
text(": Score :", 475, 20);
text(s.sc1,450,20); //Links
text(s.sc2,555,20); //Rechts
ausgleich2();
ausgleich();
ausgleich3();
}
void ausgleich() {
if(s.sc1>s.sc2+ 2 ){
p.s1.hoehe = 50;
}
}
void ausgleich2() {
if(s.sc1 +2 < s.sc2) {
p.s2.hoehe = 50;
}
}
void ausgleich3() {
if(s.sc1 == s.sc2){
p.s1.hoehe = 80;
p.s2.hoehe = 80;
}
}
}
class startscreen{
boolean text = true;
}
int randomSpeed (){
int speed = random(1.7,3);
return speed;
}