Graphics!!!
This commit is contained in:
parent
7101277cb8
commit
a96752100a
BIN
database/auth.db
BIN
database/auth.db
Binary file not shown.
BIN
database/live.db
BIN
database/live.db
Binary file not shown.
|
@ -531,6 +531,31 @@ body::-webkit-scrollbar-thumb {
|
||||||
image-rendering: pixelated;
|
image-rendering: pixelated;
|
||||||
image-rendering: crisp-edges;
|
image-rendering: crisp-edges;
|
||||||
image-rendering: -webkit-optimize-contrast;
|
image-rendering: -webkit-optimize-contrast;
|
||||||
background-color: rgba(0, 0, 0, 0.5);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.char-icon {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
background-image: url('/assets/img/world/rogues.png');
|
||||||
|
|
||||||
|
&.index-0 {
|
||||||
|
background-position: 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.index-1 {
|
||||||
|
background-position: -32px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.index-2 {
|
||||||
|
background-position: -64px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.index-3 {
|
||||||
|
background-position: -96px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.index-4 {
|
||||||
|
background-position: -128px 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,10 @@
|
||||||
& > span.selected {
|
& > span.selected {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
& > .char-icon {
|
||||||
|
margin-right: 0.25rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.active > label {
|
&.active > label {
|
||||||
|
|
BIN
public/assets/img/world/rogues.png
Normal file
BIN
public/assets/img/world/rogues.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.9 KiB |
BIN
public/assets/img/world/tiles.jpg
Normal file
BIN
public/assets/img/world/tiles.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.6 KiB |
|
@ -12,22 +12,37 @@
|
||||||
csrf: '<?= csrf() ?>',
|
csrf: '<?= csrf() ?>',
|
||||||
tiles: {
|
tiles: {
|
||||||
size: 32,
|
size: 32,
|
||||||
colors: {
|
img: new Image(),
|
||||||
0: '#fff',
|
cols: 3
|
||||||
1: '#f00'
|
},
|
||||||
}
|
sprites: {
|
||||||
|
size: 32,
|
||||||
|
img: new Image(),
|
||||||
|
cols: 6
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const map = [
|
const map = [
|
||||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
[0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
[0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
@ -40,10 +55,19 @@
|
||||||
y: document.getElementById('char_y')
|
y: document.getElementById('char_y')
|
||||||
}
|
}
|
||||||
|
|
||||||
let player = { x: <?= location('x') ?>, y: <?= location('y') ?> }
|
let player = { x: <?= location('x') ?>, y: <?= location('y') ?>, char: 23, sprite: { x: 0, y: 0 } }
|
||||||
let camera = { x: 0, y: 0 }
|
let camera = { x: 0, y: 0 }
|
||||||
let visible = { x: 0, y: 0 }
|
let visible = { x: 0, y: 0 }
|
||||||
|
|
||||||
|
game.tiles.img.src = '/assets/img/world/tiles.jpg';
|
||||||
|
game.sprites.img.src = '/assets/img/world/rogues.png';
|
||||||
|
|
||||||
|
function getPlayerSprite() {
|
||||||
|
let col = player.char % game.sprites.cols
|
||||||
|
let row = Math.floor(player.char / game.sprites.cols)
|
||||||
|
player.sprite = { x: col * game.sprites.size, y: row * game.sprites.size }
|
||||||
|
}
|
||||||
|
|
||||||
function updateCanvasSize() {
|
function updateCanvasSize() {
|
||||||
game.canvas.width = game.canvas.clientWidth
|
game.canvas.width = game.canvas.clientWidth
|
||||||
game.canvas.height = game.canvas.clientHeight
|
game.canvas.height = game.canvas.clientHeight
|
||||||
|
@ -75,18 +99,19 @@
|
||||||
'ArrowRight': 3
|
'ArrowRight': 3
|
||||||
}[e.key];
|
}[e.key];
|
||||||
|
|
||||||
if (direction !== undefined) {
|
// Direction vectors: [up, down, left, right]
|
||||||
// If player would move outside map bounds, return early
|
const dx = [0, 0, -1, 1];
|
||||||
if (direction === 0 && player.y === 0) return;
|
const dy = [-1, 1, 0, 0];
|
||||||
if (direction === 1 && player.y === map.length - 1) return;
|
|
||||||
if (direction === 2 && player.x === 0) return;
|
|
||||||
if (direction === 3 && player.x === map[0].length - 1) return;
|
|
||||||
|
|
||||||
// Return early if the player is trying to move into a wall
|
// Calculate new position
|
||||||
if (direction === 0 && map[player.y - 1][player.x] === 2) return;
|
const newX = player.x + dx[direction];
|
||||||
if (direction === 1 && map[player.y + 1][player.x] === 2) return;
|
const newY = player.y + dy[direction];
|
||||||
if (direction === 2 && map[player.y][player.x - 1] === 2) return;
|
|
||||||
if (direction === 3 && map[player.y][player.x + 1] === 2) return;
|
if (direction !== undefined) {
|
||||||
|
// Check if the new position is outside the map bounds
|
||||||
|
if (newX < 0 || newX >= map[0].length || newY < 0 || newY >= map.length) return;
|
||||||
|
|
||||||
|
if (map[newY][newX] !== 0) return;
|
||||||
|
|
||||||
// Execute a POST request to /move. If successful, the server will return a new x,y position
|
// Execute a POST request to /move. If successful, the server will return a new x,y position
|
||||||
fetch('/move', {
|
fetch('/move', {
|
||||||
|
@ -99,9 +124,8 @@
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
response.json().then(data => {
|
response.json().then(data => {
|
||||||
map[player.y][player.x] = 0
|
player.x = data.x
|
||||||
map[data.y][data.x] = 1
|
player.y = data.y
|
||||||
player = data
|
|
||||||
loc_span.x.textContent = player.x
|
loc_span.x.textContent = player.x
|
||||||
loc_span.y.textContent = player.y
|
loc_span.y.textContent = player.y
|
||||||
updateCamera()
|
updateCamera()
|
||||||
|
@ -148,27 +172,19 @@
|
||||||
const screenX = x * game.tiles.size - camera.x
|
const screenX = x * game.tiles.size - camera.x
|
||||||
const screenY = y * game.tiles.size - camera.y
|
const screenY = y * game.tiles.size - camera.y
|
||||||
|
|
||||||
if (map[y][x] === 1) {
|
ctx.drawImage(game.tiles.img, map[y][x] * game.tiles.size, 0, game.tiles.size, game.tiles.size,
|
||||||
// Draw player
|
screenX, screenY, game.tiles.size, game.tiles.size)
|
||||||
ctx.fillStyle = 'red';
|
|
||||||
ctx.fillRect(screenX, screenY, game.tiles.size, game.tiles.size)
|
|
||||||
} else if (map[y][x] === 2) {
|
|
||||||
// Draw wall
|
|
||||||
ctx.fillStyle = 'black';
|
|
||||||
ctx.fillRect(screenX, screenY, game.tiles.size, game.tiles.size)
|
|
||||||
} else {
|
|
||||||
// Draw empty tile
|
|
||||||
ctx.strokeStyle = 'gray';
|
|
||||||
ctx.fillStyle = 'white';
|
|
||||||
ctx.fillRect(screenX, screenY, game.tiles.size, game.tiles.size)
|
|
||||||
ctx.strokeRect(screenX, screenY, game.tiles.size, game.tiles.size)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render the player on top of the map using their current position
|
||||||
|
ctx.drawImage(game.sprites.img, player.sprite.x, player.sprite.y, game.sprites.size, game.sprites.size,
|
||||||
|
(player.x * game.sprites.size) - camera.x, (player.y * game.sprites.size) - camera.y,
|
||||||
|
game.sprites.size, game.sprites.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
map[player.y][player.x] = 1
|
getPlayerSprite()
|
||||||
updateCanvasSize()
|
updateCanvasSize()
|
||||||
setupEventListeners()
|
setupEventListeners()
|
||||||
render()
|
render()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user