yeah stage is made, now need to work with modul rules
This commit is contained in:
parent
c4502d453a
commit
c18bde89bd
|
@ -34,19 +34,18 @@ User Contol: ASDW
|
||||||
| Wall(initailly blocking) |  | |
|
| Wall(initailly blocking) |  | |
|
||||||
| lava |  | |
|
| lava |  | |
|
||||||
| Water |  | |
|
| Water |  | |
|
||||||
- etc..
|
|- etc.. |
|
||||||
|
|
||||||
### Properties (Action)
|
### Properties (Action)
|
||||||
| Objects | Image | Instructions |
|
| Objects | Image | Instructions |
|
||||||
| :------ | :---: | :----------- |
|
| :------ | :---: | :----------- |
|
||||||
| IS |  | Operator |
|
| IS |  | Operator |
|
||||||
| :------ | :---: | :----------- |
|
|
||||||
| You |  | |
|
| You |  | |
|
||||||
| Move |  | |
|
| Move |  | |
|
||||||
| Stop |  | |
|
| Stop |  | |
|
||||||
| Hot |  | |
|
| Hot |  | |
|
||||||
| Win |  | |
|
| Win |  | |
|
||||||
etc
|
| etc...
|
||||||
|
|
||||||
|
|
||||||
### How will the game look like?
|
### How will the game look like?
|
||||||
|
|
83
main.js
83
main.js
|
@ -10,12 +10,12 @@ let is_img;
|
||||||
// Map
|
// Map
|
||||||
let tileMap = [
|
let tileMap = [
|
||||||
' ',
|
' ',
|
||||||
'w wwwwwwwwwwwwww',
|
'wtwwwwwwwwwwwwww',
|
||||||
'w w ttw',
|
'wt ttwtttt ttttw',
|
||||||
'w r ll ttw',
|
'wttt rtt llt ttw',
|
||||||
'w ll ttw',
|
'wtt ttt ll ttfw',
|
||||||
'w aa w ttw',
|
'w tttaa ttwt ttw',
|
||||||
'w aa w ttw',
|
'wttt aatt wttttw',
|
||||||
'wwwwwwwwwwwwwwww',
|
'wwwwwwwwwwwwwwww',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -34,6 +34,10 @@ let babaY = 0;
|
||||||
let bgm, winSound;
|
let bgm, winSound;
|
||||||
let isPlaying = false;
|
let isPlaying = false;
|
||||||
|
|
||||||
|
// Game State
|
||||||
|
let isGameOver = false;
|
||||||
|
let isWin = false;
|
||||||
|
|
||||||
function preload(){
|
function preload(){
|
||||||
// BGM
|
// BGM
|
||||||
bgm = loadSound("/assets/Baba Is You OST - Baba Is You Theme.mp3");
|
bgm = loadSound("/assets/Baba Is You OST - Baba Is You Theme.mp3");
|
||||||
|
@ -67,6 +71,14 @@ function setup(){
|
||||||
tile.tile = "t";
|
tile.tile = "t";
|
||||||
tile.scale = tileSize/tile_img.width;
|
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
|
// WALL
|
||||||
let wall = new Group();
|
let wall = new Group();
|
||||||
wall.img = wall_img;
|
wall.img = wall_img;
|
||||||
|
@ -105,12 +117,20 @@ function setup(){
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw(){
|
function draw(){
|
||||||
// backgroundMusic();
|
|
||||||
background(51);
|
background(51);
|
||||||
drawSprites();
|
drawSprites();
|
||||||
// fill(255, 204, 0);
|
|
||||||
// image(baba_img, babaX, babaY, tileSize, tileSize);
|
if (isGameOver) {
|
||||||
// squasre(babaX, babaY, tileSize);
|
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
|
// Move ASDW
|
||||||
function keyPressed(){
|
function keyPressed(){
|
||||||
console.log(`key ${key} is pressed.`)
|
console.log(`key ${key} is pressed.`)
|
||||||
// if(keyCode == 32){
|
|
||||||
// if(isPlaying){
|
if(isGameOver || isWin){
|
||||||
// isPlaying = false;
|
if(key=='r'||key=='R'){
|
||||||
// }else{
|
resetGame();
|
||||||
// isPlaying = true;
|
}
|
||||||
// }
|
return;
|
||||||
// console.log(isPlaying);
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
const maxX = width - tileSize;
|
const maxX = width - tileSize;
|
||||||
const maxY = height - tileSize;
|
const maxY = height - tileSize;
|
||||||
|
@ -180,10 +199,36 @@ function isOpen(x,y){
|
||||||
}
|
}
|
||||||
|
|
||||||
let tile = tileMap[j][i];
|
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;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
console.log('blocked');
|
console.log('blocked');
|
||||||
return false;
|
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