int spikesPerPlatform = 10;
float leftPlatformLeftEdge = 50;
float leftPlatformRightEdge = 150;
float rightPlatformLeftEdge = 200;
float rightPlatformRightEdge = 350;
spikesL = new Spike[spikesPerPlatform];
spikesR = new Spike[spikesPerPlatform];
for (int i=0; i<spikesPerPlatform; i++) {
spikesL[i] = new Spike(leftPlatformLeftEdge+i*(leftPlatformRightEdge - leftPlatformLeftEdge)/spikesPerPlatform, 0);
spikesR[i] = new Spike(rightPlatformLeftEdge+i*(rightPlatformRightEdge - rightPlatformLeftEdge)/spikesPerPlatform, 0);
player = new Player((leftPlatformRightEdge + leftPlatformLeftEdge)/2);
for (int i=0; i<spikesPerPlatform; i++) {
Spike spikeL = spikesL[i];
points += (abs(spikeL.x1 - player.positionVector.x)<10 && spikeL.y1 > player.positionVector.y)? 1 : 0;
Spike spikeR = spikesR[i];
points += (abs(spikeR.x1 - player.positionVector.x)<10 && spikeR.y1 > player.positionVector.y)? 1 : 0;
void creditPoints(int amt){
text("Score: "+totalPoints, leftPlatformRightEdge+5, 25);
rect(leftPlatformLeftEdge, height-100, (leftPlatformRightEdge-leftPlatformLeftEdge), 100);
rect(rightPlatformLeftEdge, height-100, (rightPlatformRightEdge-rightPlatformLeftEdge), 100);
player.setJump(mouseX, mouseY);
positionVector = new PVector(startX, height-110);
gravity = new PVector(0, g);
jumpVector = new PVector(0, 0);
rect(positionVector.x-5, positionVector.y-2, 10, height-positionVector.y);
ellipse(positionVector.x, positionVector.y, 10, 10);
if (positionVector.y>height-100) {
positionVector.y = height-110;
if((positionVector.x < leftPlatformLeftEdge || positionVector.x >= rightPlatformRightEdge) ||
(positionVector.x > leftPlatformRightEdge && positionVector.x < rightPlatformLeftEdge)){
positionVector.x = (leftPlatformRightEdge + leftPlatformLeftEdge)/2;
positionVector.add(jumpVector);
void setJump(float xmouse, float ymouse) {
float vertexX = xmouse - positionVector.x;
float vertexY = abs(positionVector.y - ymouse);
float velocity = sqrt(2*g*vertexY)*sqrt(4*vertexY*vertexY+vertexX*vertexX)/(2*vertexY);
jumpVector = new PVector(sqrt(2*g*vertexY)*(vertexX/(2*vertexY)), -sqrt(2*g*vertexY));
Spike(float startX, float startY) {
if (age > random(maxSpikeAge)+200)