diff --git a/PROPOSAL_20243197.md b/PROPOSAL_20243197.md index 74bd8cf..2664876 100644 --- a/PROPOSAL_20243197.md +++ b/PROPOSAL_20243197.md @@ -34,19 +34,18 @@ User Contol: ASDW | Wall(initailly blocking) | ![wall](assets/Wall.webp) | | | lava | ![(lava)](assets/Lava.webp) | | | Water | ![(water)](assets/Water.webp) | | - - etc.. +|- etc.. | ### Properties (Action) | Objects | Image | Instructions | | :------ | :---: | :----------- | | IS | ![is](assets/Text_IS_0.webp) | Operator | -| :------ | :---: | :----------- | | You | ![you](assets/You.webp) | | | Move | ![Move](assets/Move.webp) | | | Stop | ![Stop](assets/Stop.webp) | | | Hot | ![Hot](assets/Hot.webp) | | | Win | ![win](assets/Win.webp) | | - etc +| etc... ### How will the game look like? diff --git a/main.js b/main.js index d6888ac..c55f6a1 100644 --- a/main.js +++ b/main.js @@ -10,12 +10,12 @@ let is_img; // Map let tileMap = [ ' ', - 'w wwwwwwwwwwwwww', - 'w w ttw', - 'w r ll ttw', - 'w ll ttw', - 'w aa w ttw', - 'w aa w ttw', + 'wtwwwwwwwwwwwwww', + 'wt ttwtttt ttttw', + 'wttt rtt llt ttw', + 'wtt ttt ll ttfw', + 'w tttaa ttwt ttw', + 'wttt aatt wttttw', 'wwwwwwwwwwwwwwww', ]; @@ -34,6 +34,10 @@ let babaY = 0; let bgm, winSound; let isPlaying = false; +// Game State +let isGameOver = false; +let isWin = false; + function preload(){ // BGM bgm = loadSound("/assets/Baba Is You OST - Baba Is You Theme.mp3"); @@ -67,6 +71,14 @@ function setup(){ tile.tile = "t"; tile.scale = tileSize/tile_img.width; + // Flag + let flag = new Group(); + flag.img = flag_img; + flag.collider = 'none'; + flag.tile = "f"; + flag.scale = tileSize/flag_img.width; + + // WALL let wall = new Group(); wall.img = wall_img; @@ -105,12 +117,20 @@ function setup(){ } function draw(){ - // backgroundMusic(); background(51); drawSprites(); - // fill(255, 204, 0); - // image(baba_img, babaX, babaY, tileSize, tileSize); - // squasre(babaX, babaY, tileSize); + + if (isGameOver) { + fill(255); + textSize(32); + text("Game Over! Press R to Restart", width / 4, height / 4); + } + + if(isWin){ + fill(255); + textSize(32); + text("Congratulations! Press R to Restart", width / 4, height / 4); + } } @@ -132,14 +152,13 @@ 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(isGameOver || isWin){ + if(key=='r'||key=='R'){ + resetGame(); + } + return; + } const maxX = width - tileSize; const maxY = height - tileSize; @@ -180,10 +199,36 @@ function isOpen(x,y){ } let tile = tileMap[j][i]; - if (tile == ' '){ + if (tile == ' ' || tile == 't'){ + return true; + } else if (tile == 'a'|| tile=='l'){ + gameOver(); + return true; + } else if (tile == 'f'){ + win(); return true; } else { console.log('blocked'); return false; } +} + +function win(){ + isWin = true; + baba.remove(); +} + +function gameOver(){ + isGameOver = true; + baba.remove(); +} + +function resetGame(){ + isGameOver = false; + isWin = false; + + baba = new Sprite(tileSize/2, tileSize/2, tileSize, tileSize); + baba.img = baba_img; + baba.scale = tileSize / baba_img.width; + baba.label = 'you'; } \ No newline at end of file