xxxxxxxxxx
101
let BennyFish;
let bennyWidth;
let bennyHeight;
let Logo;
let logoWidth;
let x;
let y;
let speed = 5;
function preload() {
BennyFish = loadImage("Media/BennyFish.png");
Logo = loadImage("Media/Logo.PNG");
}
function setup() {
createCanvas(600, 500);
imageMode(CENTER);
bennyWidth = 70;
bennyHeight = 50;
x = width / 2;
y = height * 0.65;
logoWidth = 450;
}
function draw() {
background(255);
// BOUNDS //////////////////////////////////////////
//LEFT BOUND
if (x < bennyWidth/2+4){
x += (speed+0.2);
//BUMP SOUND HERE
}
//RIGHT BOUND
if (x > width-((bennyWidth/2)+4)){
x -= (speed+0.2);
//BUMP SOUND HERE
}
//UPPER BOUND
if (y < bennyHeight/2+4){
y += (speed+0.2);
//BUMP SOUND HERE
}
//RIGHT BOUND
if (y > height-((bennyHeight/2)+4)){
y -= (speed+0.2);
//BUMP SOUND HERE
}
// BOUNDS //////////////////////////////////////////
// CONTROLS ///////////////////////////////////////
if (isKeyPressed == true) {
if (keyCode == UP_ARROW) {
y -= speed;
}
if (keyCode == DOWN_ARROW) {
y += speed;
}
if (keyCode == LEFT_ARROW) {
x -= speed;
}
if (keyCode == RIGHT_ARROW) {
x += speed;
}
}
// CONTROLS ///////////////////////////////////////
image(Logo, width/2, height*0.35, logoWidth, logoWidth);
image(BennyFish, x, y, bennyWidth, bennyHeight);
// INSTRUCTIONS /////////////////////////////////////
push()
textFont("Courier New");
textSize(20);
textAlign(CENTER);
text("use the keyboard arrows", width*0.5, height*0.80);
text(" to help Benny reach the sea", width*0.5, height*0.85);
pop()
// INSTRUCTIONS /////////////////////////////////////
}
let value = 0;
function keyPressed() {
if (value === 0) {
// display:none;
}
}