several fixes

added more testings options
fixed momentum bug
camera no scroll on new level
This commit is contained in:
lilgreenland
2019-12-19 13:40:25 -08:00
parent 27018e6253
commit 2544bb96c3
4 changed files with 78 additions and 42 deletions

View File

@@ -1039,7 +1039,7 @@ const b = {
name: "super balls", //4 name: "super balls", //4
description: "fire balls that <strong>bounce</strong> with no momentum loss", description: "fire balls that <strong>bounce</strong> with no momentum loss",
ammo: 0, ammo: 0,
ammoPack: 11, ammoPack: 14,
have: false, have: false,
isStarterGun: true, isStarterGun: true,
fire() { fire() {
@@ -1050,12 +1050,12 @@ const b = {
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
const me = bullet.length; const me = bullet.length;
bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 7 * b.modBulletSize, b.fireAttributes(dir, false)); bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 7 * b.modBulletSize, b.fireAttributes(dir, false));
b.fireProps(mech.crouch ? 40 : 20, mech.crouch ? 34 : 26, dir, me); //cd , speed b.fireProps(mech.crouch ? 30 : 12, mech.crouch ? 38 : 30, dir, me); //cd , speed
Matter.Body.setDensity(bullet[me], 0.0001); Matter.Body.setDensity(bullet[me], 0.0001);
bullet[me].endCycle = game.cycle + Math.floor(360 * b.isModBulletsLastLonger); bullet[me].endCycle = game.cycle + Math.floor(300 * b.isModBulletsLastLonger);
bullet[me].dmg = 0.5 + b.modExtraDmg; bullet[me].dmg = 0.25 + b.modExtraDmg;
bullet[me].minDmgSpeed = 0; bullet[me].minDmgSpeed = 0;
bullet[me].restitution = 0.96; bullet[me].restitution = 0.98;
bullet[me].friction = 0; bullet[me].friction = 0;
bullet[me].do = function () { bullet[me].do = function () {
this.force.y += this.mass * 0.001; this.force.y += this.mass * 0.001;
@@ -1737,7 +1737,7 @@ const b = {
fire() { fire() {
const me = bullet.length; const me = bullet.length;
const dir = mech.angle + 0.2 * (Math.random() - 0.5) const dir = mech.angle + 0.2 * (Math.random() - 0.5)
const RADIUS = (6 + 16 * Math.random()) * b.modBulletSize const RADIUS = (8 + 16 * Math.random()) * b.modBulletSize
bullet[me] = Bodies.polygon(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 25, RADIUS, { bullet[me] = Bodies.polygon(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 25, RADIUS, {
angle: dir, angle: dir,
density: 0.000005, // 0.001 is normal density density: 0.000005, // 0.001 is normal density
@@ -1749,19 +1749,30 @@ const b = {
classType: "bullet", classType: "bullet",
collisionFilter: { collisionFilter: {
category: cat.bullet, category: cat.bullet,
mask: cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield mask: cat.map | cat.body | cat.mob | cat.mobShield
}, },
minDmgSpeed: 0, minDmgSpeed: 0,
endCycle: Infinity, //game.cycle + Math.floor(265 * b.isModBulletsLastLonger), endCycle: Infinity, //game.cycle + Math.floor(265 * b.isModBulletsLastLonger),
count: 0, count: 0,
radius: RADIUS, radius: RADIUS,
target: null, target: null,
targetSub: null, targetVertex: null,
onDmg(who) { onDmg(who) {
if (!this.target && who.alive && who.dropPowerUp) { if (!this.target && who.alive && who.dropPowerUp) {
this.target = who; this.target = who;
// this.targetSub = Matter.Vector.sub(this.position, this.target.position) this.collisionFilter.category = cat.body;
this.collisionFilter.category = 0; this.collisionFilter.mask = cat.player
let bestVertexDistance = Infinity
let bestVertex = null
for (let i = 0; i < this.target.vertices.length; i++) {
const dist = Matter.Vector.magnitude(Matter.Vector.sub(this.position, this.target.vertices[i]));
if (dist < bestVertexDistance) {
bestVertex = i
bestVertexDistance = dist
}
}
this.targetVertex = bestVertex
} }
}, },
onEnd() {}, onEnd() {},
@@ -1773,6 +1784,7 @@ const b = {
if (!mech.isBodiesAsleep) { //if time dilation isn't active if (!mech.isBodiesAsleep) { //if time dilation isn't active
this.force.y += this.mass * 0.00006; //gravity this.force.y += this.mass * 0.00006; //gravity
if (this.count < 17) { if (this.count < 17) {
this.count++ this.count++
//grow //grow
@@ -1781,21 +1793,21 @@ const b = {
this.radius *= SCALE; this.radius *= SCALE;
} else { } else {
//shrink //shrink
const SCALE = 1 - 0.007 / b.isModBulletsLastLonger const SCALE = 1 - 0.006 / b.isModBulletsLastLonger
Matter.Body.scale(this, SCALE, SCALE); Matter.Body.scale(this, SCALE, SCALE);
this.radius *= SCALE; this.radius *= SCALE;
if (this.radius < 11) this.endCycle = 0; if (this.radius < 11) this.endCycle = 0;
} }
if (this.target && this.target.alive) { //if stuck to a target if (this.target && this.target.alive) { //if stuck to a target
// Matter.Body.setPosition(this, Matter.Vector.add(this.target.position, this.targetSub)) Matter.Body.setPosition(this, this.target.vertices[this.targetVertex])
Matter.Body.setPosition(this, this.target.position)
Matter.Body.setVelocity(this.target, Matter.Vector.mult(this.target.velocity, 0.94)) Matter.Body.setVelocity(this.target, Matter.Vector.mult(this.target.velocity, 0.94))
Matter.Body.setAngularVelocity(this.target, this.target.angularVelocity * 0.94) Matter.Body.setAngularVelocity(this.target, this.target.angularVelocity * 0.94)
this.target.damage(b.dmgScale * 0.0045); this.target.damage(b.dmgScale * 0.0025);
} else if (this.target !== null) { //look for a new target } else if (this.target !== null) { //look for a new target
this.target = null this.target = null
this.collisionFilter.category = cat.bullet; this.collisionFilter.category = cat.bullet;
this.collisionFilter.mask = cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield
} }
} }
} }
@@ -1807,7 +1819,6 @@ const b = {
x: SPEED * Math.cos(dir), x: SPEED * Math.cos(dir),
y: SPEED * Math.sin(dir) y: SPEED * Math.sin(dir)
}); });
// bullet[me].direction = Matter.Vector.perp(bullet[me].velocity)
} }
}, },
// { // {

View File

@@ -287,36 +287,49 @@ const game = {
} else { } else {
this.testing = true; this.testing = true;
} }
} else if (this.testing) { }
//only in testing mode //in testing mode
if (this.testing) {
if (keys[70]) { //cycle fields with F if (keys[49]) { // give power ups with 1
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "heal");
} else if (keys[50]) { // 2
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "ammo");
} else if (keys[51]) { // 3
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "gun");
} else if (keys[52]) { // 4
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "field");
} else if (keys[53]) { // 5
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "mod");
} else if (keys[54]) { // 6 spawn mob
const pick = spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)];
spawn[pick](game.mouseInGame.x, game.mouseInGame.y);
} else if (keys[55]) { // 7 spawn body
index = body.length
spawn.bodyRect(game.mouseInGame.x, game.mouseInGame.y, 50, 50);
body[index].collisionFilter.category = cat.body;
body[index].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet
body[index].classType = "body";
World.add(engine.world, body[index]); //add to world
} else if (keys[70]) { //cycle fields with F
if (mech.fieldMode === mech.fieldUpgrades.length - 1) { if (mech.fieldMode === mech.fieldUpgrades.length - 1) {
mech.fieldUpgrades[0].effect() mech.fieldUpgrades[0].effect()
} else { } else {
mech.fieldUpgrades[mech.fieldMode + 1].effect() mech.fieldUpgrades[mech.fieldMode + 1].effect()
} }
} } else if (keys[71]) { // give all guns with G
if (keys[71]) { // give all guns with G
// b.giveGuns("all", 1000) // b.giveGuns("all", 1000)
powerUps.gun.effect() powerUps.gun.effect()
} } else if (keys[72]) { // power ups with H
if (keys[72]) { // power ups with H mech.addHealth(Infinity)
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "gun"); } else if (keys[89]) { //add all mods with y
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "ammo");
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "field");
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "heal");
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "mod");
}
if (keys[89]) { //add all mods with y
powerUps.mod.effect() powerUps.mod.effect()
} } else if (keys[82]) { // teleport to mouse with R
if (keys[82]) { // teleport to mouse with R
Matter.Body.setPosition(player, this.mouseInGame); Matter.Body.setPosition(player, this.mouseInGame);
Matter.Body.setVelocity(player, { Matter.Body.setVelocity(player, {
x: 0, x: 0,
y: 0 y: 0
}); });
// game.noCameraScroll()
} }
} }
}, },
@@ -326,6 +339,16 @@ const game = {
game.zoomScale = zoomScale game.zoomScale = zoomScale
game.zoom = canvas.height / zoomScale; //sets starting zoom scale game.zoom = canvas.height / zoomScale; //sets starting zoom scale
}, },
noCameraScroll() {
// makes the camera not scroll after changing locations
mech.pos.x = player.position.x;
mech.pos.y = playerBody.position.y - mech.yOff;
const scale = 0.8;
mech.transSmoothX = canvas.width2 - mech.pos.x - (game.mouse.x - canvas.width2) * scale;
mech.transSmoothY = canvas.height2 - mech.pos.y - (game.mouse.y - canvas.height2) * scale;
mech.transX += (mech.transSmoothX - mech.transX) * 1;
mech.transY += (mech.transSmoothY - mech.transY) * 1;
},
zoomTransition(newZoomScale, step = 2) { zoomTransition(newZoomScale, step = 2) {
const isBigger = (newZoomScale - game.zoomScale > 0) ? true : false; const isBigger = (newZoomScale - game.zoomScale > 0) ? true : false;
requestAnimationFrame(zLoop); requestAnimationFrame(zLoop);
@@ -649,7 +672,9 @@ const game = {
line += 20; line += 20;
ctx.fillText("G: give all guns", x, line); ctx.fillText("G: give all guns", x, line);
line += 20; line += 20;
ctx.fillText("H: spawn power ups", x, line); ctx.fillText("H: heal", x, line);
line += 20;
ctx.fillText("1-7: spawn things", x, line);
line += 30; line += 30;
ctx.fillText("cycle: " + game.cycle, x, line); ctx.fillText("cycle: " + game.cycle, x, line);

View File

@@ -14,7 +14,7 @@ const level = {
start() { start() {
if (level.levelsCleared === 0) { if (level.levelsCleared === 0) {
// game.difficulty = 6; //for testing to simulate possible mobs spawns // game.difficulty = 6; //for testing to simulate possible mobs spawns
b.giveGuns(12) // b.giveGuns(15)
// mech.fieldUpgrades[1].effect(); // mech.fieldUpgrades[1].effect();
// b.giveMod(21) // b.giveMod(21)
@@ -32,6 +32,7 @@ const level = {
level[level.levels[level.onLevel]](); //picks the current map from the the levels array level[level.levels[level.onLevel]](); //picks the current map from the the levels array
level.levelAnnounce(); level.levelAnnounce();
} }
game.noCameraScroll();
game.setZoom(); game.setZoom();
level.addToWorld(); //add bodies to game engine level.addToWorld(); //add bodies to game engine
game.draw.setPaths(); game.draw.setPaths();

View File

@@ -98,6 +98,8 @@ const mech = {
player.force.y = 0; player.force.y = 0;
Matter.Body.setPosition(player, this.spawnPos); Matter.Body.setPosition(player, this.spawnPos);
Matter.Body.setVelocity(player, this.spawnVel); Matter.Body.setVelocity(player, this.spawnVel);
// mech.transX = -player.position.x
// mech.transY = player.position.y
}, },
Sy: 0, //adds a smoothing effect to vertical only Sy: 0, //adds a smoothing effect to vertical only
Vx: 0, Vx: 0,
@@ -995,17 +997,14 @@ const mech = {
pickUp() { pickUp() {
//triggers when a hold target exits and field button is released //triggers when a hold target exits and field button is released
this.isHolding = true; this.isHolding = true;
//conserve momentum when player mass changes
totalMomentum = Matter.Vector.add(Matter.Vector.mult(player.velocity, player.mass), Matter.Vector.mult(this.holdingTarget.velocity, this.holdingTarget.mass))
Matter.Body.setVelocity(player, Matter.Vector.mult(totalMomentum, 1 / (mech.defaultMass + this.holdingTarget.mass)));
this.definePlayerMass(mech.defaultMass + this.holdingTarget.mass * this.holdingMassScale) this.definePlayerMass(mech.defaultMass + this.holdingTarget.mass * this.holdingMassScale)
//collide with nothing //make block collide with nothing
this.holdingTarget.collisionFilter.category = 0; this.holdingTarget.collisionFilter.category = 0;
this.holdingTarget.collisionFilter.mask = 0; this.holdingTarget.collisionFilter.mask = 0;
// combine momentum // this doesn't feel right in game
// const px = player.velocity.x * player.mass + this.holdingTarget.velocity.x * this.holdingTarget.mass;
// const py = player.velocity.y * player.mass + this.holdingTarget.velocity.y * this.holdingTarget.mass;
// Matter.Body.setVelocity(player, {
// x: px / (player.mass + this.holdingTarget.mass),
// y: py / (player.mass + this.holdingTarget.mass)
// });
}, },
wakeCheck() { wakeCheck() {
if (mech.isBodiesAsleep) { if (mech.isBodiesAsleep) {