added zodes? tyto games
This commit is contained in:
1 parent
2caf389cf2
commit
c79a293dc3
13 files changed
+423
No files matched your search
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
build
|
||||
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Roguelike</title>
|
||||
<style>
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
background: #222;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
canvas {
|
||||
width: 100vmin;
|
||||
height: 100vmin;
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script src='build/index.js'></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,75 @@
|
||||
const socket = require('socket.io-client/dist/socket.io.min.js')()
|
||||
|
||||
const Stage = require('../engine/stage')
|
||||
const { update } = Stage
|
||||
|
||||
const Actor = require('../engine/actor')
|
||||
const { spawn, destroy, move } = Actor
|
||||
|
||||
const render = require('./render')
|
||||
|
||||
const controls = {
|
||||
ArrowLeft: 'left',
|
||||
ArrowUp: 'up',
|
||||
ArrowRight: 'right',
|
||||
ArrowDown: 'down',
|
||||
KeyA: 'left',
|
||||
KeyW: 'up',
|
||||
KeyD: 'right',
|
||||
KeyS: 'down'
|
||||
}
|
||||
|
||||
let stage
|
||||
let actor
|
||||
let canvas
|
||||
|
||||
socket.on('stage', (data) => {
|
||||
let opts = Stage.parse(data)
|
||||
stage = Stage(opts)
|
||||
actor = stage.actors[socket.id]
|
||||
if (canvas) {
|
||||
document.body.removeChild(canvas)
|
||||
}
|
||||
canvas = render(stage, socket.id)
|
||||
document.body.appendChild(canvas)
|
||||
window.addEventListener('keydown', function respond (event) {
|
||||
let direction = controls[event.code]
|
||||
if (direction) {
|
||||
move(actor, direction)
|
||||
socket.emit('move', direction)
|
||||
}
|
||||
})
|
||||
next()
|
||||
})
|
||||
|
||||
socket.on('join', (id, data) => {
|
||||
let opts = Actor.parse(data)
|
||||
let actor = Actor(opts)
|
||||
actor.stage = stage
|
||||
stage.actors[id] = actor
|
||||
})
|
||||
|
||||
socket.on('leave', (id) => {
|
||||
let actor = stage.actors[id]
|
||||
if (actor) {
|
||||
destroy(actor)
|
||||
delete stage.actors[id]
|
||||
}
|
||||
})
|
||||
|
||||
socket.on('move', (id, direction) => {
|
||||
let actor = stage.actors[id]
|
||||
if (actor) {
|
||||
move(actor, direction)
|
||||
}
|
||||
})
|
||||
|
||||
function tick () {
|
||||
update(stage)
|
||||
render(stage, socket.id, canvas)
|
||||
next()
|
||||
}
|
||||
|
||||
function next () {
|
||||
requestAnimationFrame(tick)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
module.exports = render
|
||||
|
||||
const Stage = require('../engine/stage')
|
||||
const { at } = Stage
|
||||
|
||||
const colors = {
|
||||
floor: 'black',
|
||||
wall: 'white',
|
||||
hero: 'lime',
|
||||
enemy: 'red'
|
||||
}
|
||||
|
||||
function render (stage, me, canvas) {
|
||||
if (!canvas) {
|
||||
canvas = document.createElement('canvas')
|
||||
}
|
||||
canvas.width = stage.width
|
||||
canvas.height = stage.height
|
||||
let context = canvas.getContext('2d')
|
||||
for (let y = stage.height; y--;) {
|
||||
for (let x = stage.width; x--;) {
|
||||
context.fillStyle = colors[at(stage, x, y)]
|
||||
context.fillRect(x, y, 1, 1)
|
||||
}
|
||||
}
|
||||
for (let id in stage.actors) {
|
||||
let actor = stage.actors[id]
|
||||
let [x, y] = actor.cell
|
||||
if (id === me) {
|
||||
context.fillStyle = colors.hero
|
||||
} else {
|
||||
context.fillStyle = colors.enemy
|
||||
}
|
||||
context.fillRect(x, y, 1, 1)
|
||||
}
|
||||
return canvas
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
module.exports = Actor
|
||||
Actor.serialize = serialize
|
||||
Actor.parse = parse
|
||||
Actor.spawn = spawn
|
||||
Actor.destroy = destroy
|
||||
Actor.move = move
|
||||
|
||||
const Stage = require('../stage')
|
||||
const { at } = Stage
|
||||
|
||||
const Direction = require('../utils/direction')
|
||||
const { resolve } = Direction
|
||||
|
||||
const Vector2D = require('../utils/vector2d')
|
||||
const { add } = Vector2D
|
||||
|
||||
function Actor (opts) {
|
||||
let actor = {
|
||||
stage: null,
|
||||
cell: null
|
||||
}
|
||||
Object.assign(actor, opts)
|
||||
return actor
|
||||
}
|
||||
|
||||
function serialize (actor) {
|
||||
return actor.cell.toString()
|
||||
}
|
||||
|
||||
function parse (data) {
|
||||
return Actor({ cell: data.split(',').map(Number) })
|
||||
}
|
||||
|
||||
function spawn (actor, stage, x, y) {
|
||||
actor.stage = stage
|
||||
actor.cell = [x, y]
|
||||
return true
|
||||
}
|
||||
|
||||
function destroy (actor) {
|
||||
actor.stage = null
|
||||
actor.cell = null
|
||||
return true
|
||||
}
|
||||
|
||||
function move (actor, direction) {
|
||||
let delta = resolve(direction)
|
||||
if (delta) {
|
||||
let target = add(actor.cell, delta)
|
||||
if (at(actor.stage, ...target) === 'floor') {
|
||||
actor.cell = target
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
module.exports = Stage
|
||||
Stage.serialize = serialize
|
||||
Stage.parse = parse
|
||||
Stage.contains = contains
|
||||
Stage.at = at
|
||||
Stage.update = update
|
||||
|
||||
const Actor = require('../actor')
|
||||
|
||||
function Stage (opts) {
|
||||
let stage = {
|
||||
width: null,
|
||||
height: null,
|
||||
tiles: null,
|
||||
actors: {}
|
||||
}
|
||||
Object.assign(stage, opts)
|
||||
return stage
|
||||
}
|
||||
|
||||
function serialize (stage) {
|
||||
return JSON.stringify({
|
||||
width: stage.width,
|
||||
height: stage.height,
|
||||
tiles: stage.tiles,
|
||||
actors: Object.keys(stage.actors).reduce((actors, id) => {
|
||||
actors[id] = Actor.serialize(stage.actors[id])
|
||||
return actors
|
||||
}, {})
|
||||
})
|
||||
}
|
||||
|
||||
function parse (data) {
|
||||
let opts = JSON.parse(data)
|
||||
let stage = Stage(opts)
|
||||
stage.actors = Object.keys(stage.actors).reduce((actors, id) => {
|
||||
let actor = Actor.parse(opts.actors[id])
|
||||
actor.stage = stage
|
||||
actors[id] = actor
|
||||
return actors
|
||||
}, {})
|
||||
return stage
|
||||
}
|
||||
|
||||
function contains (stage, x, y) {
|
||||
return x >= 0 && y >= 0 && x < stage.width && y < stage.height
|
||||
}
|
||||
|
||||
function at (stage, x, y) {
|
||||
if (contains(stage, x, y)) {
|
||||
return stage.tiles[y * stage.width + x]
|
||||
}
|
||||
}
|
||||
|
||||
function update (stage) {
|
||||
// for (let id in stage.actors) {
|
||||
// let actor = stage.actors[id]
|
||||
// // ...
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
const values = ['left', 'up', 'right', 'down']
|
||||
|
||||
const vectors = {
|
||||
left: [-1, 0],
|
||||
up: [0, -1],
|
||||
right: [1, 0],
|
||||
down: [0, 1]
|
||||
}
|
||||
|
||||
module.exports = { values, resolve, opposite }
|
||||
|
||||
function opposite (direction) {
|
||||
switch (direction) {
|
||||
case 'left':
|
||||
return 'right'
|
||||
case 'up':
|
||||
return 'down'
|
||||
case 'right':
|
||||
return 'left'
|
||||
case 'down':
|
||||
return 'up'
|
||||
}
|
||||
}
|
||||
|
||||
function resolve (direction) {
|
||||
return vectors[direction]
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
module.exports = {
|
||||
float: float,
|
||||
int: int,
|
||||
boolean: boolean,
|
||||
sample: sample,
|
||||
shuffle: shuffle
|
||||
}
|
||||
|
||||
function float(min, max) {
|
||||
return function generate(seed) {
|
||||
var x = Math.sin(seed.value++) * 0xFFFFFF
|
||||
return (x - Math.floor(x)) * (max - min) + min
|
||||
}
|
||||
}
|
||||
|
||||
function int(min, max) {
|
||||
return function generate(seed) {
|
||||
return Math.round(float(0, 1)(seed) * (max - min)) + min
|
||||
}
|
||||
}
|
||||
|
||||
function boolean(seed) {
|
||||
return float(0, 1)(seed) < 0.5
|
||||
}
|
||||
|
||||
function sample(array) {
|
||||
return function generate(seed) {
|
||||
return array[int(0, array.length - 1)(seed)]
|
||||
}
|
||||
}
|
||||
|
||||
function shuffle(array) {
|
||||
return function generate(seed) {
|
||||
return array.sort(function random(a, b) {
|
||||
return boolean(seed)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
module.exports = Vector2D
|
||||
Vector2D.add = add
|
||||
|
||||
function Vector2D (x, y) {
|
||||
return [x, y]
|
||||
}
|
||||
|
||||
function add ([x1, y1], [x2, y2]) {
|
||||
return [x1 + x2, y1 + y2]
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "nazi",
|
||||
"version": "0.0.0",
|
||||
"description": "Multiplayer roguelike",
|
||||
"license": "MIT",
|
||||
"author": "Brandon Semilla <[email protected]>",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/kbve/nazi.git"
|
||||
},
|
||||
"scripts": {
|
||||
"watch": "watchify client -o client/build/index.js -v"
|
||||
},
|
||||
"dependencies": {
|
||||
"bel": "^4.6.0",
|
||||
"server": "github:semibran/server#v1.0.0",
|
||||
"socket.io": "^1.7.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"watchify": "^3.9.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
const path = require('path').join(__dirname, '../client')
|
||||
const server = require('server')(path).listen(8080)
|
||||
const io = require('socket.io')(server)
|
||||
|
||||
const Stage = require('../engine/stage')
|
||||
const { update } = Stage
|
||||
|
||||
const Actor = require('../engine/actor')
|
||||
const { spawn, destroy, move } = Actor
|
||||
|
||||
const Random = require('../engine/utils/random')
|
||||
|
||||
const opts = require('./stage')
|
||||
|
||||
let stage = Stage(opts)
|
||||
let seed = { value: Math.random() }
|
||||
|
||||
io.on('connection', socket => {
|
||||
|
||||
let actor = Actor()
|
||||
let cell = [Random.int(1, 23)(seed), Random.int(1, 23)(seed)]
|
||||
spawn(actor, stage, ...cell)
|
||||
stage.actors[socket.id] = actor
|
||||
|
||||
console.log(Object.keys(stage.actors).map(id => stage.actors[id].cell))
|
||||
|
||||
socket.emit('stage', Stage.serialize(stage))
|
||||
socket.broadcast.emit('join', socket.id, Actor.serialize(actor))
|
||||
|
||||
socket.on('move', (direction) => {
|
||||
move(actor, direction)
|
||||
socket.broadcast.emit('move', socket.id, direction)
|
||||
})
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
destroy(actor)
|
||||
delete stage.actors[socket.id]
|
||||
socket.broadcast.emit('leave', socket.id)
|
||||
})
|
||||
})
|
||||
|
||||
next()
|
||||
|
||||
function loop () {
|
||||
update(stage)
|
||||
next()
|
||||
}
|
||||
|
||||
function next () {
|
||||
setTimeout(loop, 1000 / 60)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
module.exports = {
|
||||
width: 25,
|
||||
height: 25,
|
||||
tiles: ((width, height) => {
|
||||
let tiles = Array(width * height)
|
||||
for (let y = height; y--;) {
|
||||
for (let x = width; x--;) {
|
||||
let tile = 'floor'
|
||||
if (!x || !y || x === width - 1 || y === height - 1) {
|
||||
tile = 'wall'
|
||||
}
|
||||
tiles[y * width + x] = tile
|
||||
}
|
||||
}
|
||||
return tiles
|
||||
})(25, 25)
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
<h4>info now</h4>
|
||||
<a href="https://www.dropbox.com/scl/fi/vr5b5ytwks0vrk1ro1a2l/update-Made-with-Clipchamp_1727326030635.mp4?rlkey=nuek47rhs21gdt8erv6pjofsx&st=22g30ukz&dl=0>"info now></a>
|
||||
<a href="/games/gun-mayhem-main/gun-mayhem-main/index.html"></a>
|
||||
<a href="/games/old-rouge-like-master/old-rouge-like-master/client/index.html">zomdeys?</a>
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
Reference in new issue
Block a user