Skip to content

Commit

Permalink
Generate grid for tile map
Browse files Browse the repository at this point in the history
  • Loading branch information
rmkubik committed Jun 17, 2019
1 parent 0a8408b commit 71fa3c2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Binary file modified raw/images/sprites.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/pyxels/sprites.pyxel
Binary file not shown.
22 changes: 18 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ import {
import sprites from "../raw/images/sprites.png";
import "./styles/index.css";

const createTiles = (height, width) => {
let count = 0;

return Array(height * width)
.fill(5)
.map(val => {
if (Math.floor(count / width) % 2 === 0) {
return count++ % 2 === 0 ? val : 6;
} else {
return count++ % 2 === 0 ? 6 : val;
}
});
};

const { canvas } = init("game");

initKeys();
Expand Down Expand Up @@ -37,7 +51,7 @@ image.onload = () => {
y: 0,
width: 1000,
height: 1000,
color: "#008751"
color: "#29adff"
});

sprite = Sprite({
Expand Down Expand Up @@ -65,8 +79,8 @@ image.onload = () => {
let tileEngine = TileEngine({
tilewidth: 8,
tileheight: 8,
width: 3,
height: 3,
width: 16,
height: 16,
tilesets: [
{
firstgid: 0,
Expand All @@ -78,7 +92,7 @@ image.onload = () => {
layers: [
{
name: "ground",
data: [5, 5, 5, 5, 5, 5, 5, 5, 5]
data: createTiles(16, 16)
}
]
});
Expand Down

0 comments on commit 71fa3c2

Please sign in to comment.