20243197 #12
|
@ -34,19 +34,18 @@ User Contol: ASDW
|
|||
| Wall(initailly blocking) |  | |
|
||||
| lava |  | |
|
||||
| Water |  | |
|
||||
- etc..
|
||||
|- etc.. |
|
||||
|
||||
### Properties (Action)
|
||||
| Objects | Image | Instructions |
|
||||
| :------ | :---: | :----------- |
|
||||
| IS |  | Operator |
|
||||
| :------ | :---: | :----------- |
|
||||
| You |  | |
|
||||
| Move |  | |
|
||||
| Stop |  | |
|
||||
| Hot |  | |
|
||||
| Win |  | |
|
||||
etc
|
||||
| etc...
|
||||
|
||||
|
||||
### How will the game look like?
|
||||
|
|
83
main.js
83
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';
|
||||
}
|
Loading…
Reference in New Issue
Block a user