20243197 #12
|
@ -6,7 +6,9 @@
|
||||||
<title>Document</title>
|
<title>Document</title>
|
||||||
<link rel="stylesheet" href="./style.css">
|
<link rel="stylesheet" href="./style.css">
|
||||||
<script src="./main.js"></script>
|
<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>
|
</head>
|
||||||
<body>
|
<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");
|
// alert("hello world");
|
||||||
const tileSize = 16;
|
const tileSize = 16;
|
||||||
|
|
||||||
|
// Sprites
|
||||||
|
const baba = 2;
|
||||||
|
|
||||||
|
// CaracterMove
|
||||||
const babaX = 0;
|
const babaX = 0;
|
||||||
const babaY = 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(){
|
function setup(){
|
||||||
createCanvas(800, 400);
|
createCanvas(800, 400);
|
||||||
|
@ -10,16 +22,38 @@ function setup(){
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw(){
|
function draw(){
|
||||||
|
// backgroundMusic();
|
||||||
fill(255, 204, 0);
|
fill(255, 204, 0);
|
||||||
square(babaX, babaY, 16);
|
square(babaX, babaY, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Background Music & Soundeffects
|
||||||
|
function backgroundMusic(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function mousePressed(){
|
||||||
|
if (isPlaying) {
|
||||||
|
bgm.pause();
|
||||||
|
isPlaying = false;
|
||||||
|
} else {
|
||||||
|
bgm.play();
|
||||||
|
isPlaying = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Move ASDW
|
// Move ASDW
|
||||||
function keyPressed(){
|
function keyPressed(){
|
||||||
console.log(`key ${key} is pressed.`)
|
console.log(`key ${key} is pressed.`)
|
||||||
|
if(keyCode == 32){
|
||||||
|
if(isPlaying){
|
||||||
|
isPlaying = false;
|
||||||
|
}else{
|
||||||
|
isPlaying = true;
|
||||||
|
}
|
||||||
|
console.log(isPlaying);
|
||||||
|
}
|
||||||
if(key=='a'||key=='A') {
|
if(key=='a'||key=='A') {
|
||||||
babaX -= tileSize;
|
babaX -= tileSize;
|
||||||
console.log('Left');
|
console.log('Left');
|
||||||
|
@ -36,4 +70,14 @@ function keyPressed(){
|
||||||
babaY += tileSize;
|
babaY += tileSize;
|
||||||
console.log('Up');
|
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