Rules Screen add

This commit is contained in:
Mathieu 2020-03-27 17:39:47 +01:00
parent 4661f365a1
commit adb0631328
6 changed files with 47 additions and 11 deletions

View File

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -21,7 +21,7 @@ body {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
background: url(./grass.png); background: url(./map/grass.png);
} }
#backlayer { #backlayer {
@ -63,3 +63,8 @@ a:hover {
canvas { canvas {
margin-bottom: 20px; margin-bottom: 20px;
} }
#rulesScreen {
text-align: center;
z-index: 2;
}

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -17,6 +17,7 @@
<ul id="levelChoice"></ul> <ul id="levelChoice"></ul>
<p>Use the arrows to navigate. Press p to make a pause.</p> <p>Use the arrows to navigate. Press p to make a pause.</p>
<a href=#-1 id="rulesBtn" >Rules</a>
</div> </div>
@ -25,7 +26,14 @@
<div id="canvasTarget"></div> <div id="canvasTarget"></div>
<a href=# id="stopGameBtn" value="Stop game">Stop Game</a> <a href=# id="menuBtn">Stop Game</a>
</div>
<div id="rulesScreen">
<h1>Rules</h1>
<a href=# id="menuBtn">Go back to menu</a>
</div> </div>
<script src="script.js"></script> <script src="script.js"></script>

View File

@ -67,19 +67,26 @@ function playAudio(url) {
// Get elements // Get elements
const startScreen = byId("startScreen") const startScreen = byId("startScreen")
const gameScreen = byId("gameScreen") const gameScreen = byId("gameScreen")
const rulesScreen = byId("rulesScreen")
const levelChoicesTarget = byId("levelChoice") const levelChoicesTarget = byId("levelChoice")
const stopGameBtn = byId("stopGameBtn") const stopGameBtn = byId("menuBtn")
const canvasTarget = byId("canvasTarget") const canvasTarget = byId("canvasTarget")
const scoreTarget = byId("scoreTarget") const scoreTarget = byId("scoreTarget")
const rulesBtn = byId("rulesBtn")
// Get images // Get map texture
const imgGrass = new Image(); const imgGrass = new Image();
imgGrass.src = './assets/grass.png'; imgGrass.src = './assets/map/grass.png';
const imgWall = new Image();
imgWall.src = './assets/wall.jpg';
const imgApple = new Image();
imgApple.src = './assets/apple.png';
// Get wall texture
const imgWall = new Image();
imgWall.src = './assets/wall/wall.jpg';
// Get food texture
const imgApple = new Image();
imgApple.src = './assets/food/apple.png';
// Get snake texture
let imgSnakeHeadUp = new Image(); let imgSnakeHeadUp = new Image();
imgSnakeHeadUp.src = './assets/snake/snake_head_up.png'; imgSnakeHeadUp.src = './assets/snake/snake_head_up.png';
let imgSnakeHeadLeft = new Image(); let imgSnakeHeadLeft = new Image();
@ -98,8 +105,19 @@ imgSnakeBody.src = './assets/snake/snake_body.png';
function showMainScreen() { function showMainScreen() {
startScreen.style.display = "unset"; startScreen.style.display = "unset";
gameScreen.style.display = "none"; gameScreen.style.display = "none";
rulesScreen.style.display = "none";
} }
/**
* Show rules screen
*/
function showRulesScreen() {
startScreen.style.display = "none";
gameScreen.style.display = "none";
rulesScreen.style.display = "unset";
}
/** /**
* Start a new game * Start a new game
* *
@ -109,6 +127,7 @@ function showMainScreen() {
async function startGame(gameID) { async function startGame(gameID) {
startScreen.style.display = "none"; startScreen.style.display = "none";
gameScreen.style.display = "unset"; gameScreen.style.display = "unset";
rulesScreen.style.display = "none";
// Fetch level information // Fetch level information
let level; let level;
@ -403,9 +422,13 @@ function changeWindow() {
if(gameID > 0) if(gameID > 0)
startGame(gameID); startGame(gameID);
else{
if(gameID == -1)
showRulesScreen();
else else
showMainScreen(); showMainScreen();
} }
}