play lib add
This commit is contained in:
parent
dfc9c55db4
commit
1c4c1a8250
|
@ -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
6764
lib/p5.play.js
Normal file
File diff suppressed because it is too large
Load Diff
44
main.js
44
main.js
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user