From 24c9a9968bfbacc9752c046c328c78d2d53687c8 Mon Sep 17 00:00:00 2001 From: Jee Youn Kim Date: Sun, 20 Apr 2025 03:54:59 +0900 Subject: [PATCH] is Add --- assets/Text_IS_0.webp | Bin 0 -> 296 bytes index.html | 7 ++-- main.js | 75 +++++++++++++++++++++++++----------------- 3 files changed, 49 insertions(+), 33 deletions(-) create mode 100644 assets/Text_IS_0.webp diff --git a/assets/Text_IS_0.webp b/assets/Text_IS_0.webp new file mode 100644 index 0000000000000000000000000000000000000000..d310516fa26b91f4f394cf6d278c947e0e315ba4 GIT binary patch literal 296 zcmWIYbaPW+WMBw)bqWXzu!!JdU|<*U|?oo;A3Fm zW?(o0He_jf5)>5Kmx_$KUg zne21X_xtkr`y71;|7JWD^6fcm$bzR@aCSRL*S831gZy z;mBtGOU8MgXT?R9FB2 literal 0 HcmV?d00001 diff --git a/index.html b/index.html index 0428ebc..458abea 100644 --- a/index.html +++ b/index.html @@ -5,9 +5,12 @@ Document + + + + + - - diff --git a/main.js b/main.js index 13e66c2..2730399 100644 --- a/main.js +++ b/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; } \ No newline at end of file