20243197 #12
BIN
assets/Text_IS_0.webp
Normal file
BIN
assets/Text_IS_0.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 296 B |
|
@ -5,9 +5,12 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<link rel="stylesheet" href="./style.css">
|
||||
|
||||
<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/addons/p5.sound.min.js"></script>
|
||||
<!-- <script src="lib/p5.play.js" type="text/javascript"></script> -->
|
||||
<script src="https://cdn.jsdelivr.net/gh/molleindustria/p5.play/lib/p5.play.js"></script>
|
||||
<script src="./main.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>
|
||||
|
|
75
main.js
75
main.js
|
@ -2,18 +2,27 @@
|
|||
const tileSize = 16;
|
||||
|
||||
// Sprites
|
||||
const baba = 2;
|
||||
let baba;
|
||||
let tile, wall, rock, water, lava, flag;
|
||||
let win, you, move, stop;
|
||||
|
||||
// CaracterMove
|
||||
const babaX = 0;
|
||||
const babaY = 0;
|
||||
let babaX = 0;
|
||||
let babaY = 0;
|
||||
|
||||
// Sounds
|
||||
let bgm, winSound;
|
||||
let isPlaying = false;
|
||||
|
||||
function preload(){
|
||||
bgm = loadSound("/assets/Baba Is You OST - Baba Is You Theme.mp3")
|
||||
bgm = loadSound("/assets/Baba Is You OST - Baba Is You Theme.mp3");
|
||||
baba = loadImage("/assets/Baba.webp");
|
||||
tile = loadImage("/assets/Tile.webp");
|
||||
wall = loadImage("/assets/Wall.webp");
|
||||
rock = loadImage("/assets/Rock.webp");
|
||||
water = loadImage("/assets/Water.webp");
|
||||
lava = loadImage("/assets/Lava.webp");
|
||||
flag = loadImage("/assets/Flag.webp");
|
||||
}
|
||||
|
||||
function setup(){
|
||||
|
@ -23,8 +32,10 @@ function setup(){
|
|||
|
||||
function draw(){
|
||||
// backgroundMusic();
|
||||
background(51);
|
||||
fill(255, 204, 0);
|
||||
square(babaX, babaY, 16);
|
||||
image(baba, babaX, babaY, tileSize, tileSize);
|
||||
// squasre(babaX, babaY, tileSize);
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,38 +57,40 @@ function mousePressed(){
|
|||
// Move ASDW
|
||||
function keyPressed(){
|
||||
console.log(`key ${key} is pressed.`)
|
||||
if(keyCode == 32){
|
||||
if(isPlaying){
|
||||
isPlaying = false;
|
||||
}else{
|
||||
isPlaying = true;
|
||||
}
|
||||
console.log(isPlaying);
|
||||
}
|
||||
// if(keyCode == 32){
|
||||
// if(isPlaying){
|
||||
// isPlaying = false;
|
||||
// }else{
|
||||
// isPlaying = true;
|
||||
// }
|
||||
// console.log(isPlaying);
|
||||
// }
|
||||
|
||||
const maxX = width - tileSize;
|
||||
const maxY = height - tileSize;
|
||||
|
||||
if(key=='a'||key=='A') {
|
||||
babaX -= tileSize;
|
||||
console.log('Left');
|
||||
if (babaX - tileSize >= 0) {
|
||||
babaX -= tileSize;
|
||||
console.log('Left');
|
||||
}
|
||||
}
|
||||
if(key=='s'||key=='S') {
|
||||
babaY -= tileSize;
|
||||
console.log('Down');
|
||||
if (babaY + tileSize <= maxY) {
|
||||
babaY += tileSize;
|
||||
console.log('Down');
|
||||
}
|
||||
}
|
||||
if(key=='d'||key=='D') {
|
||||
babaX += tileSize;
|
||||
console.log('Right');
|
||||
if (babaX + tileSize <= maxX) {
|
||||
babaX += tileSize;
|
||||
console.log('Right');
|
||||
}
|
||||
}
|
||||
if(key=='w'||key=='W') {
|
||||
babaY += tileSize;
|
||||
console.log('Up');
|
||||
if(babaY - tileSize >= 0){
|
||||
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