Browse Source

neat things

master
mort 8 years ago
parent
commit
f23f54faf6
4 changed files with 26 additions and 11 deletions
  1. 3
    0
      conf.js
  2. 20
    10
      es/game.js
  3. 1
    1
      es/script.js
  4. 2
    0
      index.html

+ 3
- 0
conf.js View File

@@ -0,0 +1,3 @@
window.conf = {
address: "ws://weblet.mort.coffee:8085"
}

+ 20
- 10
es/game.js View File

@@ -169,9 +169,6 @@ class Bullet extends Entity {
this.imgs = BulletImgs;
this.vel.set(vel.x, vel.y);
this.ownerId = ownerId;

if (ownerId == game.id)
game.screenShake(10, 0);
}

draw(ctx, selfId) {
@@ -254,6 +251,12 @@ class Player extends Entity {
this.thrustAnim.y = this.pos.y;
this.thrustAnim.offsetX = -this.thrustAnim.dwidth/2;
this.thrustAnim.offsetY = this.thrustAnim.dwidth/2;

if (this.keys.sprint) {
this.thrustAnim.dheight = 100;
} else {
this.thrustAnim.dheight = 64;
}
}

ctx.beginPath();
@@ -302,7 +305,7 @@ class Player extends Entity {
this.health = obj.health;

if (this.id == this.game.id && lastHealth > obj.health) {
this.game.screenShake(200);
this.game.screenShake(50);
}
}

@@ -323,13 +326,15 @@ class Player extends Entity {
y: this.pos.y,
width: 64,
height: 64,
dwidth: 128,
dheight: 128,
offsetX: -64,
offsetY: -64,
dwidth: 256,
dheight: 256,
offsetX: -128,
offsetY: -128,
wsteps: 5,
hsteps: 5
}));
this.thrustAnim.visible = false;
this.thrustAnim.loop = false;
}
}

@@ -370,6 +375,7 @@ export default class Game {
this.keymap[65] = "left";
this.keymap[68] = "right";
this.keymap[32] = "shoot";
this.keymap[16] = "sprint";

this.entities = [];
this.animations = [];
@@ -397,14 +403,18 @@ export default class Game {
this.entities[msg.id].despawn();
delete this.entities[msg.id];
if (msg.id == this.id) {
alert("You died.");
this.stop();
this.screenShake(400);
setTimeout(() => {
alert("You died.");
this.stop();
}, 1200);
}
});

window.addEventListener("keydown", (evt) => {
if (this.keymap[evt.keyCode]) {
evt.preventDefault();
evt.stopPropagation();
this.sock.send("keydown", {
key: this.keymap[evt.keyCode]
});

+ 1
- 1
es/script.js View File

@@ -2,7 +2,7 @@ let Game = require("./game");

document.querySelector("#startGameBtn").addEventListener("click", () => {
view("game");
let sock = new SockSugar("ws://serve.mort.coffee:89");
let sock = new SockSugar(conf.address);
let game = new Game(sock, document.getElementById("canvas"));

sock.on("close", () => {

+ 2
- 0
index.html View File

@@ -25,6 +25,7 @@
.view.pre.current {
max-width: 900px;
margin: auto;
line-height: 1.5;
}

x-script {
@@ -47,6 +48,7 @@
<canvas id="canvas">Your browser is bad and you should feel bad.</canvas>
</div>

<script src="conf.js"></script>
<script src="js/view.js"></script>
<script src="node_modules/socksugar/client.js"></script>
<script src="bundle.js"></script>

Loading…
Cancel
Save