play lib add

This commit is contained in:
Jee Yeon Kim 2025-04-17 01:38:11 +09:00
parent dfc9c55db4
commit 1c4c1a8250
3 changed files with 6811 additions and 1 deletions

View File

@ -6,7 +6,9 @@
<title>Document</title>
<link rel="stylesheet" href="./style.css">
<script src="./main.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.2/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.2/p5.js"></script>
<script language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.8/addons/p5.sound.js"></script>
</head>
<body>

6764
lib/p5.play.js Normal file

File diff suppressed because it is too large Load Diff

44
main.js
View File

@ -1,8 +1,20 @@
// 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);
@ -10,16 +22,38 @@ function setup(){
}
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');
@ -36,4 +70,14 @@ function keyPressed(){
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;
}