/*Title: Sailboat
By: Alex Olechnowicz
Date Submitted: October 4, 2017
Description: The sailboat moves horizontaly towards the mouse. The clouds loop through randomly.
When clicking in the water, the third that was clicked with corespond with eithor R,G, or B
and will tint that colour. Three lines are drawn towards where the mouse clicks in the water.*/
//Sail variables (most things are based on these)
int x1TrianglePos = 210;
int x2TrianglePos = 230;
int x3TrianglePos = 220;
int y1TrianglePos = 340;
int y2TrianglePos = 340;
int y3TrianglePos = 320;
//Cloud variables
float speed = 3;
int wind = 0;
//Default no tint
char colour = 'c';
//Initilization
void setup() {
size(400, 400);
frameRate(30);
}
//Draw function
void draw() {
background(random(10, 30), random(10, 30), random(150, 180));
fill(255);
playerMovement();
boat();
sky();
clouds();
colourWater();
}
//Sky assets
void sky() {
noStroke();
fill(random(100, 150), random(175, 225), random(205, 250)); //Random shading
rect(width-width, height-height, width, height/2.5); //Sky
}
//Movement controls
void playerMovement() {
//Moves right toward mouse
if (mouseX > x3TrianglePos && x2TrianglePos < width) {
x1TrianglePos += speed;
x2TrianglePos += speed;
x3TrianglePos += speed;
}
//Moves Left toward mouse
if (mouseX < x3TrianglePos && x1TrianglePos > 0) {
x1TrianglePos -= speed;
x2TrianglePos -= speed;
x3TrianglePos -= speed;
}
}
//Boat assets
void boat() {
triangle(x1TrianglePos, y1TrianglePos, x2TrianglePos, y2TrianglePos, x3TrianglePos, y3TrianglePos);
stroke(1);
line(x3TrianglePos, y1TrianglePos, x3TrianglePos, y1TrianglePos+5);
fill(102, 51, 0);
quad(x1TrianglePos-10, y1TrianglePos+5, x2TrianglePos+10, y2TrianglePos+5, x2TrianglePos+5, y2TrianglePos+15, x1TrianglePos-5, y1TrianglePos+15);
}
//Cloud assets
void clouds() {
ellipseMode(CORNER);
if (wind > width) {
wind =0;
} else {
wind += 1;
}
for (int i = 0; i < 100; i++) {
fill(150);
noStroke();
ellipse(random(-400+wind, 400+wind), random(0, 120), random(55, 70), random(20, 40));
}
}
//Tinted water assets
void colourWater() {
stroke(0);
if (colour == 'c') {
noFill();
}
if (colour == 'r') {
fill(255, 0, 0, 75);
rect(0, height/2.5, width/3, 239);
}
if (colour == 'g') {
fill(0, 255, 0, 75);
rect(width/3, height/2.5, width/3, 239);
}
if (colour == 'b') {
fill(0, 0, 255, 75);
rect(width/3*2, height/2.5, width/3, 239);
}
}
//Runs when mouse is pressed
void mousePressed() {
fill(0);
stroke(0);
if (mouseX > 0 && mouseX < 400 && mouseY > 150) {
float xSpot = mouseX;
float ySpot = mouseY;
line(xSpot, ySpot, x3TrianglePos, y3TrianglePos);
line(xSpot, ySpot, x2TrianglePos, y2TrianglePos);
line(xSpot, ySpot, x1TrianglePos, y1TrianglePos);
if (mouseX < width/3 && mouseY > 150) {
colour = 'r';
} else if (mouseX > width/3 && mouseX < width/3*2 && mouseY >150) {
colour = 'g';
} else if (mouseX > width/3*2 && mouseY >150) {
colour = 'b';
}
}
}