add map
This commit is contained in:
parent
7fbe113061
commit
8278445e88
4 changed files with 140 additions and 2 deletions
|
@ -11,6 +11,8 @@ class GameBasic {
|
|||
|
||||
this.player = player;
|
||||
this.entities = entities;
|
||||
|
||||
this.width = this.height = 2500;
|
||||
}
|
||||
main() {
|
||||
let { entities } = this;
|
||||
|
|
|
@ -50,7 +50,7 @@ Player.prototype.bump = function () {
|
|||
}
|
||||
|
||||
Player.prototype.handleTick = function (game) {
|
||||
let { entities } = game;
|
||||
let { entities, width, height } = game;
|
||||
|
||||
let ent = this;
|
||||
|
||||
|
@ -59,6 +59,9 @@ Player.prototype.handleTick = function (game) {
|
|||
ent.pos.x += ent.vel.x;
|
||||
ent.pos.y += ent.vel.y;
|
||||
|
||||
ent.pos.x = Math.max(Math.min(ent.pos.x, width / 2), - width / 2);
|
||||
ent.pos.y = Math.max(Math.min(ent.pos.y, height / 2), - height / 2);
|
||||
|
||||
ent.vel.x *= 0.9;
|
||||
ent.vel.y *= 0.9;
|
||||
|
||||
|
|
130
static/assets/map.svg
Normal file
130
static/assets/map.svg
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="120"
|
||||
height="120"
|
||||
viewBox="0 0 120 120"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
inkscape:version="1.3.2 (091e20ef0f, 2023-11-25, custom)"
|
||||
sodipodi:docname="map.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#000000"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="px"
|
||||
inkscape:zoom="4.1121712"
|
||||
inkscape:cx="73.562113"
|
||||
inkscape:cy="79.276856"
|
||||
inkscape:window-width="1860"
|
||||
inkscape:window-height="1004"
|
||||
inkscape:window-x="30"
|
||||
inkscape:window-y="46"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false" />
|
||||
<defs
|
||||
id="defs1">
|
||||
<pattern
|
||||
inkscape:collect="always"
|
||||
xlink:href="#Checkerboard"
|
||||
preserveAspectRatio="xMidYMid"
|
||||
id="pattern7"
|
||||
patternTransform="scale(1.3963947)"
|
||||
x="0"
|
||||
y="0" />
|
||||
<pattern
|
||||
inkscape:collect="always"
|
||||
style="fill:#ffffff"
|
||||
patternUnits="userSpaceOnUse"
|
||||
width="2"
|
||||
height="2"
|
||||
patternTransform="translate(0,0) scale(10,10)"
|
||||
id="Checkerboard"
|
||||
inkscape:stockid="Checkerboard"
|
||||
preserveAspectRatio="xMidYMid"
|
||||
inkscape:isstock="true"
|
||||
inkscape:label="Checkerboard">
|
||||
<rect
|
||||
style="stroke:none"
|
||||
x="0"
|
||||
y="0"
|
||||
width="1"
|
||||
height="1"
|
||||
id="rect209" />
|
||||
|
||||
<rect
|
||||
style="stroke:none"
|
||||
x="1"
|
||||
y="1"
|
||||
width="1"
|
||||
height="1"
|
||||
id="rect211" />
|
||||
|
||||
</pattern>
|
||||
</defs>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(10,10)">
|
||||
<path
|
||||
id="rect1"
|
||||
style="fill:#e8a6a6;stroke-width:10;stroke-linecap:round;stroke-linejoin:round;paint-order:stroke fill markers;fill-opacity:1"
|
||||
d="M -9.1635035,-10 H 109.1635 C 109.62692,-10 110,-9.6269226 110,-9.1635035 V 109.1635 C 110,109.62692 109.62692,110 109.1635,110 H -9.1635035 C -9.6269226,110 -10,109.62692 -10,109.1635 V -9.1635035 C -10,-9.6269226 -9.6269226,-10 -9.1635035,-10 Z" />
|
||||
<rect
|
||||
style="fill:#2f3dff;fill-opacity:0.50628048;stroke-width:10;stroke-linecap:round;stroke-linejoin:round;paint-order:stroke fill markers"
|
||||
id="rect2"
|
||||
width="60"
|
||||
height="120"
|
||||
x="50"
|
||||
y="-10"
|
||||
ry="0" />
|
||||
<rect
|
||||
style="fill:#13ff7c;fill-opacity:0.44583464;stroke-width:10;stroke-linecap:round;stroke-linejoin:round;paint-order:stroke fill markers"
|
||||
id="rect3"
|
||||
width="60"
|
||||
height="120"
|
||||
x="50"
|
||||
y="-110"
|
||||
ry="0"
|
||||
transform="rotate(90)" />
|
||||
<rect
|
||||
style="fill:#000000;fill-opacity:0.50628;stroke:#ffffff;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;paint-order:stroke fill markers;stroke-dasharray:none"
|
||||
id="rect4"
|
||||
width="1.75e-06"
|
||||
height="120"
|
||||
x="50"
|
||||
y="-10" />
|
||||
<rect
|
||||
style="fill:#000000;fill-opacity:0.50628;stroke:#ffffff;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;paint-order:stroke fill markers;stroke-dasharray:none"
|
||||
id="rect5"
|
||||
width="1.75e-06"
|
||||
height="120"
|
||||
x="50"
|
||||
y="-110"
|
||||
transform="rotate(90)" />
|
||||
<rect
|
||||
style="fill:#d0ca51;fill-opacity:1;stroke:#ffffff;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
|
||||
id="rect6"
|
||||
width="14.414423"
|
||||
height="14.414423"
|
||||
x="42.792789"
|
||||
y="42.792789" />
|
||||
<path
|
||||
id="path6"
|
||||
style="opacity:0.148174;fill:url(#pattern7);fill-opacity:1;stroke-width:10;stroke-linecap:round;stroke-linejoin:round;paint-order:stroke fill markers"
|
||||
d="M -9.1635035,-10 H 109.1635 C 109.62692,-10 110,-9.6269226 110,-9.1635035 V 109.1635 C 110,109.62692 109.62692,110 109.1635,110 H -9.1635035 C -9.6269226,110 -10,109.62692 -10,109.1635 V -9.1635035 C -10,-9.6269226 -9.6269226,-10 -9.1635035,-10 Z" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 4.4 KiB |
|
@ -5,6 +5,7 @@ const cs = 1024;
|
|||
const assets = [
|
||||
'assets/player.svg',
|
||||
'assets/head.svg',
|
||||
'assets/map.svg'
|
||||
];
|
||||
|
||||
class Game extends GameBasic {
|
||||
|
@ -27,7 +28,7 @@ class Game extends GameBasic {
|
|||
this.assetsIn = assetsIn;
|
||||
}
|
||||
render() {
|
||||
let { ctx, assetsIn, entities, player } = this;
|
||||
let { ctx, assetsIn, entities, player, width, height } = this;
|
||||
|
||||
ctx.clearRect(0, 0, cs, cs);
|
||||
|
||||
|
@ -35,6 +36,8 @@ class Game extends GameBasic {
|
|||
|
||||
ctx.translate(player.camera.x + cs / 2, player.camera.y + cs / 2);
|
||||
|
||||
ctx.drawImage(assetsIn[2],-width/2,-height/2,width,height);
|
||||
|
||||
for (let ent of entities) {
|
||||
if (ent.health <= 0) continue;
|
||||
|
||||
|
|
Loading…
Reference in a new issue