xxxxxxxxxx
312
let spritesheet;
let sprites = [];
let direction = 1;
let step = 0;
let x;
let y;
let speed = 4.5;
let stepSpeed = 60;
let animationTimer;
let mountain1;
let mountain2;
let mountain3;
let currentBackground = 1;
function preload() {
soundFormats('mp3');
spritesheet = loadImage("walking.png");
mountain1 = loadImage("PRE_ORIG_SIZE-1.png");
mountain2 = loadImage("PRE_ORIG_SIZE.png");
mountain3 = loadImage("PRE_ORIG_SIZE-2.png");
mountain4 = loadImage("PRE_ORIG_SIZE-3.png");
summer1 = loadImage("Summer1.png");
summer2 = loadImage("Summer2.png");
summer3 = loadImage("Summer3.png");
summer4 = loadImage("Summer4.png");
summer5 = loadImage("Summer5.png");
summer7 = loadImage("Summer7.png");
summer8 = loadImage("Summer8.png");
summer1end = loadImage("Summer1end.png");
// walking_sound = loadSound("walkingsound.mp3")
wind_sound = loadSound("wind.mp3")
nature_sound = loadSound("naturesounds.mp3")
}
function setup() {
createCanvas(innerWidth, innerHeight);
imageMode(CENTER);
// natureSound.play();
// natureSound.loop();
// natureSound.setVolume(0.7);
// get the width and hieght of each sprite
let w = spritesheet.width / 12;
let h = spritesheet.height / 4;
// spritesheet functionality
for (let y = 0; y < 4; y++) {
sprites[y] = [];
for (let x = 0; x < 12; x++) {
sprites[y][x] = spritesheet.get(x * w, y * h, w, h);
}
}
for (let i = 0; i < wind_sound.length; i++) {
wind_sound[i].loop();
}
for (let i = 0; i < nature_sound.length; i++) {
nature_sound[i].loop();
}
x = width / 2;
y = height / 2;
// resize 'summer' images
summer2.resize(width,0);
summer3.resize(width,0);
summer4.resize(width,0);
summer5.resize(width,0);
summer7.resize(width,0);
summer8.resize(width,0);
summer1.resize(width,0);
summer1end.resize(width,0);
mountain1.resize(width,0);
mountain2.resize(width,0);
mountain3.resize(width,0);
mountain4.resize(width,0);
// font and layout
textFont("Courier New", 20);
fill(255);
// textAlign(CENTER, TOP);
nature_sound.play();
nature_sound.loop();
nature_sound.setVolume(0.7);
}
function draw() {
background(255);
push();
imageMode(CENTER);
// change background
if (currentBackground === 1) {
image(summer1,width/2,height/2-100);
text("you've been at home for a while, take a walk by pressing the arrow keys", 50, height/3);
}
if (currentBackground === 2) {
image(summer3,width/2,height/2-100);
}
if (currentBackground === 3) {
image(summer8,width/2,height/2-100);
}
if (currentBackground === 4) {
image(mountain2,width/2,height/2-100);
text('press space to think', 100, 100)
// if (keyCode === SPACE){
// text("I wonder if anoyne's reached the top", 100, 150)
// }
}
if (currentBackground === 5) {
image(summer7,width/2,height/2-100);
}
if (currentBackground === 6) {
image(summer5,width/2,height/2-100);
}
if (currentBackground === 7) {
image(summer2,width/2,height/2-100);
text('press space to think', 100, 100)
text("clouds... nice", 100, 150)
}
if (currentBackground === 8) {
image(summer4,width/2,height/2-100);
}
if (currentBackground === 9) {
image(summer7,width/2,height/2-100);
}
if (currentBackground === 10) {
image(summer8,width/2,height/2-100);
}
if (currentBackground === 11) {
image(mountain1,width/2,height/2-100);
text("press space to think", 100, 200)
text("if i was a mountain, idk how i'd feel about people climbing me", 100, 150)
}
if (currentBackground === 12) {
image(mountain3,width/2,height/2-100);
}
if (currentBackground === 13) {
image(mountain4,width/2,height/2-100);
}
if (currentBackground === 14) {
text('Welcome home, maybe I should do this in real life every once in a while.', 100, 100);
image(summer1end,width/2,height/2-100);
}
pop();
// movement
if (isKeyPressed == true) {
if (keyCode == LEFT_ARROW) {
direction = 1;
x -= speed;
}
if (keyCode == RIGHT_ARROW) {
direction = 2;
x += speed;
}
}
// change background
if (x > width) {
x = 0;
updateBackground();
} else if (x < 0) {
x = width;
updateBackground();
}
// Draw the character sprite
image(sprites[direction][step], x, summer1.height - 150);
// displayText();
// if(keyCode === SPACEBAR) {
// displayText();
// } else {
// displayText();
// }
}
function advanceStep() {
step = (step + 1) % 12;
}
function updateBackground() {
// Cycle through the backgrounds
currentBackground = (currentBackground % 14) + 1;
}
function displayText() {
push();
textSize(32);
textAlign(CENTER);
text("I wonder if anyone's reached the top", 500, 500)
pop();
}
function keyPressed() {
// walking animation and functionality
walking_sound.play();
clearInterval(animationTimer)
// if(keyCode === SPACEBAR) {
// switch(currentBackground) {
// case 1:
// background(0);
// break;
// case 2:
// break;
// case 3:
// break;
// case 4:
// break;
// case 5:
// break;
// case 6:
// break;
// case 7:
// break;
// case 8:
// break;
// case 9:
// break;
// case 10:
// break;
// case 11:
// break;
// case 12:
// break;
// case 13:
// break;
// case 14:
// break;
// default:
// break;
// }
// }
// if(currentBackground === 4 && keyCode === SPACEBAR) {
// displayText();
// }
animationTimer = setInterval(advanceStep, stepSpeed);
}
function keyReleased() {
// walking movement + sound stops when a key is released
clearInterval(animationTimer);
///// press space to think /////
}