83 lines
1.5 KiB
JavaScript
83 lines
1.5 KiB
JavaScript
// alert("hello world");
|
|
const tileSize = 16;
|
|
|
|
// Sprites
|
|
const baba = 2;
|
|
|
|
// CaracterMove
|
|
const babaX = 0;
|
|
const babaY = 0;
|
|
|
|
// Sounds
|
|
let bgm, winSound;
|
|
let isPlaying = false;
|
|
|
|
function preload(){
|
|
bgm = loadSound("/assets/Baba Is You OST - Baba Is You Theme.mp3")
|
|
}
|
|
|
|
function setup(){
|
|
createCanvas(800, 400);
|
|
background(51);
|
|
}
|
|
|
|
function draw(){
|
|
// backgroundMusic();
|
|
fill(255, 204, 0);
|
|
square(babaX, babaY, 16);
|
|
}
|
|
|
|
|
|
// Background Music & Soundeffects
|
|
function backgroundMusic(){
|
|
|
|
}
|
|
|
|
function mousePressed(){
|
|
if (isPlaying) {
|
|
bgm.pause();
|
|
isPlaying = false;
|
|
} else {
|
|
bgm.play();
|
|
isPlaying = true;
|
|
}
|
|
}
|
|
|
|
// Move ASDW
|
|
function keyPressed(){
|
|
console.log(`key ${key} is pressed.`)
|
|
if(keyCode == 32){
|
|
if(isPlaying){
|
|
isPlaying = false;
|
|
}else{
|
|
isPlaying = true;
|
|
}
|
|
console.log(isPlaying);
|
|
}
|
|
if(key=='a'||key=='A') {
|
|
babaX -= tileSize;
|
|
console.log('Left');
|
|
}
|
|
if(key=='s'||key=='S') {
|
|
babaY -= tileSize;
|
|
console.log('Down');
|
|
}
|
|
if(key=='d'||key=='D') {
|
|
babaX += tileSize;
|
|
console.log('Right');
|
|
}
|
|
if(key=='w'||key=='W') {
|
|
babaY += tileSize;
|
|
console.log('Up');
|
|
}
|
|
|
|
//limit BABA's movements
|
|
// if(ghost.position.x < 0)
|
|
// ghost.position.x = 0;
|
|
// if(ghost.position.y < 0)
|
|
// ghost.position.y = 0;
|
|
// if(ghost.position.x > SCENE_W)
|
|
// ghost.position.x = SCENE_W;
|
|
// if(ghost.position.y > SCENE_H)
|
|
// ghost.position.y = SCENE_H;
|
|
} |