changement de textures

This commit is contained in:
nbillard 2022-12-05 15:29:26 +01:00
parent 1247b129f2
commit d54d8f333d
11 changed files with 22 additions and 7 deletions

View file

@ -19,7 +19,6 @@
your experience. your experience.
</p> </p>
<![endif]--> <![endif]-->
Coucou
<canvas id="canvas" width="800" height="400"></canvas> <canvas id="canvas" width="800" height="400"></canvas>
</body> </body>
<!-- <script type="module" src="./modules/ressources.mjs"></script> --> <!-- <script type="module" src="./modules/ressources.mjs"></script> -->

View file

@ -2,5 +2,18 @@ import { Square } from '/modules/enums.mjs';
// Blueprint for the first level // Blueprint for the first level
export const level1Blueprint = [[ Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall ], export const level1Blueprint = [[ Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall ],
[ Square.Wall, Square.Destination, Square.Box, Square.Floor, Square.Player, Square.Wall ], [ Square.Wall, Square.Destination, Square.Box, Square.Floor, Square.Player, Square.Wall ],
[ Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall ]]; [ Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall ]];
export const level2Blueprint = [
[Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Floor, Square.Floor ],
[Square.Wall, Square.Destination, Square.Destination, Square.Floor, Square.Floor, Square.Wall, Square.Floor, Square.Floor, Square.Floor, Square.Floor, Square.Floor, Square.Wall, Square.Wall, Square.Wall],
[Square.Wall, Square.Destination, Square.Destination, Square.Floor, Square.Floor, Square.Wall, Square.Floor, Square.Box, Square.Floor, Square.Floor, Square.Box, Square.Floor, Square.Floor, Square.Wall],
[Square.Wall, Square.Destination, Square.Destination, Square.Floor, Square.Floor, Square.Wall, Square.Box, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Floor, Square.Floor, Square.Wall],
[Square.Wall, Square.Destination, Square.Destination, Square.Floor, Square.Floor, Square.Floor, Square.Floor, Square.Player, Square.Floor, Square.Wall, Square.Wall, Square.Floor, Square.Floor, Square.Wall],
[Square.Wall, Square.Destination, Square.Destination, Square.Floor, Square.Floor, Square.Wall, Square.Floor, Square.Wall, Square.Floor, Square.Floor, Square.Box, Square.Floor, Square.Wall, Square.Wall],
[Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Floor, Square.Wall, Square.Wall, Square.Box, Square.Floor, Square.Box, Square.Floor, Square.Floor ],
[Square.Floor, Square.Floor, Square.Wall, Square.Floor, Square.Box, Square.Floor, Square.Floor, Square.Box, Square.Floor, Square.Box, Square.Floor, Square.Box, Square.Floor, Square.Floor ],
[Square.Floor, Square.Floor, Square.Wall, Square.Floor, Square.Floor, Square.Floor, Square.Floor, Square.Wall, Square.Floor, Square.Floor, Square.Floor, Square.Floor, Square.Floor, Square.Floor ],
[Square.Floor, Square.Floor, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall ],
];

View file

@ -40,8 +40,8 @@ export const generatePlayground = (levelBlueprint, canvasWidth, canvasHeight) =>
default: default:
break; break;
} }
foreground[indexRow].push(new ForegroundTile(square, indexColumn * tileWidth, indexRow * tileHeight, tileWidth, tileHeight));
background[indexRow].push(new BackgroundTile(square, indexColumn * tileWidth, indexRow * tileHeight, tileWidth, tileHeight)); background[indexRow].push(new BackgroundTile(square, indexColumn * tileWidth, indexRow * tileHeight, tileWidth, tileHeight));
foreground[indexRow].push(new ForegroundTile(square, indexColumn * tileWidth, indexRow * tileHeight, tileWidth, tileHeight));
}); });
}); });
if (boxCount != destinationCount) { if (boxCount != destinationCount) {

View file

@ -1,7 +1,7 @@
export const images = { export const images = {
wall: '/res/wall.png', wall: '/res/wall.png',
floor: '/res/floor.png', floor: '/res/floor.png',
player: '/res/mario.png', player: '/res/player.png',
box: '/res/box.png', box: '/res/box.png',
destination: '/res/destination.png', destination: '/res/destination.png',
empty: '/res/empty.png', empty: '/res/empty.png',

View file

@ -29,6 +29,9 @@ class Tile {
setImageSrc(src) { setImageSrc(src) {
this.image.src = src; this.image.src = src;
this.image.addEventListener('load', () => {
this.imageReady = true;
}, false);
} }
} }

BIN
res/box.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

BIN
res/destination.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

BIN
res/empty.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 B

BIN
res/floor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

BIN
res/player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 725 B

View file

@ -1,11 +1,11 @@
import { generatePlayground } from '/modules/playground.mjs' import { generatePlayground } from '/modules/playground.mjs'
import { level1Blueprint } from '/modules/levels.mjs' import { level1Blueprint, level2Blueprint } from '/modules/levels.mjs'
import { MoveDirection } from '/modules/enums.mjs' import { MoveDirection } from '/modules/enums.mjs'
let canvas = document.getElementById('canvas'); let canvas = document.getElementById('canvas');
let ctx = canvas.getContext('2d'); let ctx = canvas.getContext('2d');
window.ctx = ctx window.ctx = ctx
let playground = generatePlayground(level1Blueprint, canvas.width, canvas.height); let playground = generatePlayground(level2Blueprint, canvas.width, canvas.height);
window.addEventListener("keydown", (event) => { window.addEventListener("keydown", (event) => {
if (!event.defaultPrevented) { if (!event.defaultPrevented) {
switch (event.key) { switch (event.key) {