int colorR;
int [] coordinates = new int[2];
boolean down, left, right;
float gravity = 0.5, velY = 0;
int snowFlakesNumber = 50;
float fallingCounter;
float posX[] = new float[snowFlakesNumber];
float posY[] = new float[snowFlakesNumber];
int c1 = 60, c2 = 120;
float bigWidth[] = new float[5];
float bigHeight[] = new float[5];
float smallWidth[] = new float[5];
float smallHeight[] = new float[5];
int snowmanCount = 0;
float snowManPosY[] = new float[5];
float snowManPosX[] = new float[5];
void setup()
{
size(800, 600);
coordinates[0] = 300;
}
void draw()
{
//BackGround
background(0, c1, c2);
noStroke();
//Ground
fill(255);
rect(0, 450, 800, 200);
//Scenario
scenario();
//Snowman Main Character
fill(255);
ellipse(coordinates[0], coordinates[1], 50, 50);
ellipse(coordinates[0], coordinates[1] - 35, 25, 25);
fill(255, 146, 13);
triangle(coordinates[0], coordinates[1] -15, coordinates[0] - 5, coordinates[1] - 30, coordinates[0] +5, coordinates[1] - 30);
fill(0);
ellipse(coordinates[0]-4, coordinates[1] -36, 5, 5);
ellipse(coordinates[0]+4, coordinates[1] -36, 5, 5);
//SnowManNPCMaker
fill(255);
ellipse(mouseX, mouseY, 20, 20);
ellipse(mouseX, mouseY-10, 10, 10);
createSnowManNPC();
//SnowFlakes
createSnowFlakes();
//snowManMovement
snowManMovement();
}
void scenario()
{
fill(118, 69, 76);
rect(500, 350, 200, 100);
rect(100, 300, 35, 150);
fill(23, 95, 13);
ellipse(100, 300, 100, 100);
ellipse(120, 270, 100, 100);
ellipse(140, 300, 100, 100);
fill(48, 255, 100);
rect(530, 400, 30, 50);
fill(0);
ellipse(540, 425, 10, 10);
fill(160, 221, 227);
stroke(1);
rect(615, 370, 30, 30);
noStroke();
fill(224, 59, 73);
triangle(600, 300, 500, 350, 700, 350);
fill(255);
}
void createSnowManNPC()
{
// Creates a snow man using the mouseX position
for (int i = 0; i < snowmanCount; i++)
{
if (snowManPosX[i] == 0)
snowManPosX[i] = mouseX;
else
{
ellipse(snowManPosX[i], snowManPosY[i], bigWidth[i], bigHeight[i]);
ellipse(snowManPosX[i], snowManPosY[i] - (0.6 * bigWidth[i]), smallWidth[i], smallHeight[i]);
}
// Stops the snowman when it hits the ground (position 425 on y-axis)
if (snowManPosY[i] > 0 && snowManPosY[i] < 425)
{
snowManPosY[i]+= random(1, 2);
}
}
}
void createSnowFlakes()
{
// creates snowflakes using the maximum snowflakes number which is currentlly 50
for (int i = 0; i < snowFlakesNumber; i++)
{
//randomizes a position for the flakes
if (posX[i] == 0)
{
float rNX = random(0, 800);
float rNY = random(0, 500) - 600;
ellipse(rNX, rNY, 5, 5);
posX[i] = rNX;
posY[i] = rNY;
}
else
ellipse(posX[i], posY[i], 5, 5);
//moves the snowflakes down
posY[i]+= random(0, 2);
//if they hit the ground, move them back to the top
if (posY[i] >= 450)
posY[i] = 0;
}
}
void mouseDragged()
{
// sets the size of the snowman's body when you drag the mouse
if (snowmanCount < 5)
{
bigWidth[snowmanCount]++;
bigHeight[snowmanCount]++;
smallWidth[snowmanCount]++;
smallHeight[snowmanCount]++;
}
}
// creates the snowman based on the size that was dragged.
void mouseReleased()
{
for (int k = 0; k < 5; k++)
{
if (snowManPosY[k]==0)
snowManPosY[k] = mouseY;
}
//makes the head a little bit smaller
smallWidth[snowmanCount]-= bigHeight[snowmanCount] /2;
smallHeight[snowmanCount]-=smallHeight[snowmanCount] /2;
snowmanCount++;
//resets the amount of snowmans on screen
if (snowmanCount == 5)
{
for (int k = 0; k < snowmanCount; k++)
{
snowManPosY[k] = 0;
}
snowmanCount = 0;
}
for (int j = 0; j < 5; j++)
{
if (bigWidth[j] == 0)
break;
// resets the sizes of the snowmans.
else
{
bigWidth[snowmanCount] = 0;
bigHeight[snowmanCount] = 0;
smallWidth[snowmanCount] = 0;
smallHeight[snowmanCount] = 0;
}
}
}
// When you move the mouse, the snowflakes move together and the color of the background changes
void mouseMoved()
{
for (int k = 0; k < snowFlakesNumber; k++)
{
if (posX[k] > 0)
{
posX[k]+= mouseX - pmouseX;
if (posX[k] > 800)
posX[k] -= 800;
if (posX[k] < 0)
posX[k] += 800;
}
}
// changes the background color
if (mouseY < 200 && c1 < 60)
{
c1+=1;
c2+=2;
} else if (c2 > 0)
{
c1 -=1;
c2 -=2;
}
}
// Moves the snowman with the arrows input
void snowManMovement()
{
if (down)
coordinates[1] += 5;
if (left)
coordinates[0] -= 5;
if (right)
coordinates[0] += 5;
//accelerates the snowman with gravity and increases it every frame
velY += gravity;
coordinates[1] += velY;
if (coordinates[1] >= 440)
{
coordinates[1] = 440;
velY = 0;
}
}
//Main snowman's controls
void keyPressed()
{
switch(keyCode)
{
case DOWN:
down = true;
break;
case LEFT:
left = true;
break;
case RIGHT:
right = true;
break;
case UP:
velY = -10;
break;
}
}
//Main snowman's controls
void keyReleased()
{
if (keyCode == DOWN)
down = false;
if (keyCode == LEFT)
left = false;
if (keyCode == RIGHT)
right = false;
}