20243197 #12

Closed
20243197 wants to merge 30 commits from 20243197/20243197:20243197 into 20243197
2 changed files with 66 additions and 22 deletions
Showing only changes of commit c18bde89bd - Show all commits

View File

@ -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?

83
main.js
View File

@ -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';
}