xxxxxxxxxx
177
let g = 1;
let f = 1;
let x = 1;
let z = 1;
let y = 1;
let speed = 0;
function preload() {
bluewallpaper = loadImage('bluewallpaper1.jpg');
wood = loadImage('wood.jpeg');
ceiling = loadImage('ceiling.jpg');
ghost = loadImage('cute ghost.png');
}
function setup() {
createCanvas(600, 400, WEBGL);
angleMode(DEGREES);
ghost.resize(90, 80);
}
function draw() {
background('OldLace');
noLights();
translate(-width / 2, -height / 2);
//walls
push();
rotateY(90);
image(bluewallpaper, 0, 0);
pop();
push();
translate(600, 0, 0);
rotateY(90);
image(bluewallpaper, 0, 0);
pop();
//door
push();
fill(0);
translate(550, 210, 0);
rotateY(90);
rect(0, 0, 100, 160);
pop();
//wall
push();
translate(125, 60, -60);
image(bluewallpaper, 0, 0);
pop();
//door
push();
fill(0);
translate(265, 220, -60);
rect(0, 0, 85, 100);
pop();
//second level doors
push();
fill(0);
translate(140, 110, -60);
rect(0, 0, 40, 80);
translate(250, 0, 0);
rect(0, 0, 40, 80);
pop();
//flooring
push();
translate(150, 300, 0);
rotateX(90);
texture(wood);
textureMode(NORMAL);
rect(0, 0, 300, 400);
pop();
//ceiling
push();
translate(150, 100, 0);
rotateX(90);
texture(ceiling);
textureMode(NORMAL);
rect(0, 0, 300, 400);
pop();
//second floor
push();
translate(300, 190, 20);
texture(wood);
textureMode(NORMAL);
box(300, 7, 7);
pop();
//beams
push();
translate(350, 150, 20);
texture(wood);
textureMode(NORMAL);
box(205, 7, 7);
pop();
for (let post = 0; post < 14; post++) {
push();
translate(250 + post * 15, 170, 20);
texture(wood);
textureMode(NORMAL);
box(5, 30, 7);
pop();
}
//stairs
for (let stair = 0; stair < 18; stair++) {
push();
translate(200, 190 + stair * 7, 20 + stair * 7);
texture(wood);
textureMode(NORMAL);
box(100, 7, 7);
pop();
}
//ghosts
push();
translate(265 + x, 225, -70 + g)
image(ghost, 0, 0);
pop();
push();
translate(550 - f, 240 + y, -80);
image(ghost, 0, 0);
pop();
push();
translate(150 + z, 240 - f, 50);
image(ghost, 0, 0);
pop();
if (mouseIsPressed) {
//ghost move
g = g + 0.9;
f = f + 0.7;
if (g > 250) {
g = 0;
}
if (f > 200) {
f = 0;
}
} else {
//ghost glitch
x += speed;
z += speed;
y += speed;
if (x > 5) {
speed = -3;
} else if (x < 270) {
speed = 3;
}
if (z > 5) {
speed = -3;
} else if (z < 140) {
speed = 3;
}
if (y > 5) {
speed = -3;
} else if (y < 270) {
speed = 3;
}
}
print(mouseX, mouseY);
}