Skip to content

Instantly share code, notes, and snippets.

Created January 8, 2017 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2420ad559a929c827dad72ba9b7f081d to your computer and use it in GitHub Desktop.
Save anonymous/2420ad559a929c827dad72ba9b7f081d to your computer and use it in GitHub Desktop.
StopWatchTimer sw;
ArrayList xPositions = new ArrayList();
ArrayList yPositions = new ArrayList();
float xRect = 50; // Začetna x pozicija igrišča (pravokotnika)
float yRect = 75; // Začetna y pozicija igrišča (pravokotnika)
boolean [] keys = new boolean[128];
int homeScore = 0;
int awayScore = 0;
void setup() {
size(700, 550); // Velikost Sketcha
frameRate(60); // Tells draw() loop how many times to be called every second. This function tells us how many times per secound should code repeat throug loop. It's recommended to use it.
sw = new StopWatchTimer();
sw.start();
}
void draw() {
background(0, 128, 0); // Ozadje Sketcha
scoreBoard("FC Pablo Escobar", "FC El Chapo");
soccerField(); // Igrišče
time(); // Čas
//connectingBallLine(); // Linija, ki povezuje žogi
ball(); // Žoga
}
void mousePressed() {
xPositions.add( mouseX );
yPositions.add( mouseY );
}
void soccerField() {
// 5 px = 1 meter
int sirinaIgrisca = 600; // x
int visinaIgrisca = 400; // y
float sirinaGola = 32.5; // yGola
float polovicaGola = sirinaGola / 2; // 16.25
float xPenaltyBox = 82.5;
float yPenaltyBox = 179.1;
float halfPenaltyBox = yPenaltyBox / 2; //89.5
float xGoalBox = 27.5;
float yGoalBox = 91.5;
float halfGoalBox = yGoalBox / 2;
int centerCircleDiameter = 95;
int penaltyPointSize = 5;
//float xPenaltySpotA = xRect + 55;
//float xPenaltySpotB = xRect + sirinaIgrisca - 55;
// Out lines
noFill(); // Brez polnila igrišče
stroke(255); // Bela obraba
rect(xRect, yRect, sirinaIgrisca, visinaIgrisca);
// Half-way line
//stroke(255);
line(width / 2, yRect, width / 2, height - yRect);
// Centre Circle
//noFill();
arc(width / 2, height / 2, centerCircleDiameter, centerCircleDiameter, 0, PI * 2);
//ellipse(width / 2, height / 2, centreCircleRadius, centreCircleRadius);
// Goal A
rect(xRect, height/2 - polovicaGola, -20, sirinaGola);
// Goal B
rect(xRect + sirinaIgrisca, height/2 - polovicaGola, 20, sirinaGola);
// Penalty box A
rect(xRect, height/2 - halfPenaltyBox, xPenaltyBox, yPenaltyBox);
// Penalty box B
rect(xRect + sirinaIgrisca, height/2 - halfPenaltyBox, -xPenaltyBox, yPenaltyBox);
//Goal box A
rect(xRect, height/2 - halfGoalBox, xGoalBox, yGoalBox);
// Goal box B
rect(xRect + sirinaIgrisca, height/2 - halfGoalBox, -xGoalBox, yGoalBox);
// Penalty spot A
fill(255);
ellipse(xRect + 55, height / 2, penaltyPointSize, penaltyPointSize);
// Penalty spot B
fill(255);
ellipse(xRect + sirinaIgrisca - 55, height / 2, penaltyPointSize, penaltyPointSize);
// Top Penalty Box A
//arc(xPenaltySpotA, height / 2, centerCircleDiameter, centerCircleDiameter, 0, PI * 2);
// Top Penalty Box A
//arc(xPenaltySpotB, height / 2, centerCircleDiameter, centerCircleDiameter, 0, PI * 2);
}
void scoreBoard(String homeTeam, String awayTeam) {
fill(0);
textAlign(CENTER);
textSize(15);
text(homeTeam + " " + homeScore + "-" + awayScore + " " + awayTeam, width / 2, yRect / 3);
if(homeScore <= 0)
homeScore = 0;
if(awayScore <= 0)
awayScore = 0;
}
void time() {
fill(0); // Barva števca
textAlign(RIGHT);
textSize(15); // Velikost časa
text(nf(sw.minute(), 2)+":"+nf(sw.second(), 2), width - xRect, yRect / 3); // WTF is nf???
}
void ball() {
int ballRadius = 8; // Velikost žoge
// Začetna žoga
stroke(0);
fill(255);
ellipse(width / 2, height / 2, ballRadius, ballRadius);
connectingBallLine();
stroke(0); // Barva obrobe žoge
fill(255); // Barva žoge
for ( int i = 0; i < xPositions.size(); i++) {
//ellipse( (int) xPositions.get(i), (int) yPositions.get(i), ballRadius, ballRadius);
ellipse( (int) xPositions.get(xPositions.size()-1), (int) yPositions.get(xPositions.size()-1), ballRadius, ballRadius);
}
}
void connectingBallLine() {
stroke(0, 0, 255); // Barva linije
for ( int i = 0; i < xPositions.size()-1; i++) {
//line( (int) xPositions.get(xPositions.size()-1), (int) yPositions.get(yPositions.size()-1), (int) xPositions.get(xPositions.size()-2), (int) yPositions.get(yPositions.size()-2) );
arrow((int) xPositions.get(xPositions.size()-2), (int) yPositions.get(yPositions.size()-2), (int) xPositions.get(xPositions.size()-1), (int) yPositions.get(yPositions.size()-1), 8);
}
}
void arrow(float x1, float y1, float x2, float y2, float s) {
line(x1, y1, x2, y2);
pushMatrix();
translate(x2, y2);
float a = atan2(x1-x2, y2-y1); // 70, 360
rotate(a);
line(0, 0, -s, -s);
line(0, 0, s, -s);
popMatrix();
}
void keyPressed() {
/////////////////////// Key for Starting time //////////////////////////////
keys[key] = true;
if (key == 't') {
sw.start();
}
/////////////////////// Keys for Starting time //////////////////////////////
/////////////////////// Keys for Scoreboard //////////////////////////////
if (key == 'q') {
homeScore = homeScore + 1;
} else if (key == 'a') {
homeScore = homeScore - 1;
}
if (key == 'w') {
awayScore = awayScore + 1;
} else if (key == 's') {
awayScore = awayScore - 1;
}
/////////////////////// Keys for Scoreboard //////////////////////////////
if (key == 'c'){
ellipse(100, 100, 20, 20);
}
}
//////////Class//////////////////
class StopWatchTimer {
int startTime = 0, stopTime = 0;
boolean running = false;
void start() {
startTime = millis();
running = true;
}
void stop() {
stopTime = millis();
running = false;
}
int getElapsedTime() {
int elapsed;
if (running) {
elapsed = (millis() - startTime);
}
else {
elapsed = (stopTime - startTime);
}
return elapsed;
}
int second() {
return (getElapsedTime() / 1000) % 60;
}
int minute() {
return (getElapsedTime() / (1000*60)) % 60;
}
}
// ====================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment