gravity increase for blocks and portal integration

This commit is contained in:
landgreen
2020-07-30 11:00:03 -07:00
parent 1308c9c187
commit 738bdcabd6
7 changed files with 71 additions and 34 deletions

View File

@@ -196,7 +196,6 @@ function collisionChecks(event) {
color: game.mobDmgColor, color: game.mobDmgColor,
time: game.drawTime time: game.drawTime
}); });
} }
return; return;
// } // }

View File

@@ -110,7 +110,7 @@ const game = {
x: 0, x: 0,
y: 0 y: 0
}, },
g: 0.001, g: 0.0024, // applies to player, bodies, and power ups (not mobs)
onTitlePage: true, onTitlePage: true,
paused: false, paused: false,
isChoosing: false, isChoosing: false,
@@ -493,7 +493,7 @@ const game = {
} }
addGravity(powerUp, game.g); addGravity(powerUp, game.g);
addGravity(body, game.g); addGravity(body, game.g);
player.force.y += player.mass * mech.gravity; player.force.y += player.mass * game.g;
}, },
reset() { //run on first run, and each later run after you die reset() { //run on first run, and each later run after you die
b.removeAllGuns(); b.removeAllGuns();

View File

@@ -12,7 +12,7 @@ const level = {
if (build.isURLBuild && level.levelsCleared === 0) build.onLoadPowerUps(); if (build.isURLBuild && level.levelsCleared === 0) build.onLoadPowerUps();
if (level.levelsCleared === 0) { //this code only runs on the first level if (level.levelsCleared === 0) { //this code only runs on the first level
// level.difficultyIncrease(4) // level.difficultyIncrease(4)
game.enableConstructMode() //used to build maps in testing mode // game.enableConstructMode() //used to build maps in testing mode
// game.zoomScale = 1000; // game.zoomScale = 1000;
// game.setZoom(); // game.setZoom();
// mech.isStealth = true; // mech.isStealth = true;
@@ -22,8 +22,9 @@ const level = {
// mech.setField("plasma torch") // mech.setField("plasma torch")
level.intro(); //starting level level.intro(); //starting level
// level.testing(); // level.testing(); //not in rotation
// level.testChamber() // level.template() //not in rotation
// level.testChamber() //less mobs, more puzzle
// level.sewers(); // level.sewers();
// level.satellite(); // level.satellite();
// level.skyscrapers(); // level.skyscrapers();
@@ -32,8 +33,7 @@ const level = {
// level.warehouse(); // level.warehouse();
// level.highrise(); // level.highrise();
// level.office(); // level.office();
// level.bosses(); // level.bosses(); //only fighting, very simple map
// level.template()
// level.stronghold() //fan level // level.stronghold() //fan level
} else { } else {
spawn.setSpawnList(); //picks a couple mobs types for a themed random mob spawns spawn.setSpawnList(); //picks a couple mobs types for a themed random mob spawns
@@ -1771,7 +1771,7 @@ const level = {
y: -500 y: -500
}, },
bodyB: body[body.length - 1], bodyB: body[body.length - 1],
stiffness: 0.000076, stiffness: 0.0001815,
length: 1 length: 1
}); });
@@ -1783,7 +1783,7 @@ const level = {
y: 100 y: 100
}, },
bodyB: body[body.length - 1], bodyB: body[body.length - 1],
stiffness: 0.000076, stiffness: 0.0001815,
length: 1 length: 1
}); });
@@ -1796,7 +1796,7 @@ const level = {
y: 150 y: 150
}, },
bodyB: body[body.length - 1], bodyB: body[body.length - 1],
stiffness: 0.0002, stiffness: 0.0005,
length: 566 length: 566
}); });
@@ -2764,8 +2764,8 @@ const level = {
} else if (player.isInPortal !== this) { //touching player } else if (player.isInPortal !== this) { //touching player
if (mech.buttonCD_jump === mech.cycle) player.force.y = 0 // undo a jump right before entering the portal if (mech.buttonCD_jump === mech.cycle) player.force.y = 0 // undo a jump right before entering the portal
mech.buttonCD_jump = 0 //disable short jumps when letting go of jump key mech.buttonCD_jump = 0 //disable short jumps when letting go of jump key
//teleport
player.isInPortal = this.portalPair player.isInPortal = this.portalPair
//teleport
if (this.portalPair.angle % (Math.PI / 2)) { //if left, right up or down if (this.portalPair.angle % (Math.PI / 2)) { //if left, right up or down
Matter.Body.setPosition(player, this.portalPair.portal.position); Matter.Body.setPosition(player, this.portalPair.portal.position);
} else { //if at some odd angle } else { //if at some odd angle
@@ -2791,22 +2791,53 @@ const level = {
} }
} }
} }
//remove block if touching
if (body.length) { if (body.length) {
touching = Matter.Query.collides(this, body) for (let i = 0, len = body.length; i < len; i++) {
for (let i = 0; i < touching.length; i++) { if (body[i] !== mech.holdingTarget) {
if (touching[i].bodyB !== mech.holdingTarget) { // body[i].bounds.max.x - body[i].bounds.min.x < 100 && body[i].bounds.max.y - body[i].bounds.min.y < 100
for (let j = 0, len = body.length; j < len; j++) { if (Matter.Query.collides(this, [body[i]]).length === 0) {
if (body[j] === touching[i].bodyB) { if (body[i].isInPortal === this) body[i].isInPortal = null
body.splice(j, 1); } else if (body[i].isInPortal !== this) {
len-- body[i].isInPortal = this.portalPair
Matter.World.remove(engine.world, touching[i].bodyB); //teleport
break; if (this.portalPair.angle % (Math.PI / 2)) { //if left, right up or down
Matter.Body.setPosition(body[i], this.portalPair.portal.position);
} else { //if at some odd angle
Matter.Body.setPosition(body[i], this.portalPair.position);
} }
//rotate velocity
let mag
if (this.portalPair.angle !== 0 && this.portalPair.angle !== Math.PI) { //portal that fires the player up
mag = Math.max(10, Math.min(50, body[i].velocity.y * 0.8)) + 11
} else {
mag = Math.max(6, Math.min(50, Vector.magnitude(body[i].velocity)))
}
let v = Vector.mult(this.portalPair.unit, mag)
Matter.Body.setVelocity(body[i], v);
} }
} }
} }
} }
//remove block if touching
// if (body.length) {
// touching = Matter.Query.collides(this, body)
// for (let i = 0; i < touching.length; i++) {
// if (touching[i].bodyB !== mech.holdingTarget) {
// for (let j = 0, len = body.length; j < len; j++) {
// if (body[j] === touching[i].bodyB) {
// body.splice(j, 1);
// len--
// Matter.World.remove(engine.world, touching[i].bodyB);
// break;
// }
// }
// }
// }
// }
// if (touching.length !== 0 && touching[0].bodyB !== mech.holdingTarget) { // if (touching.length !== 0 && touching[0].bodyB !== mech.holdingTarget) {
// if (body.length) { // if (body.length) {
// for (let i = 0; i < body.length; i++) { // for (let i = 0; i < body.length; i++) {
@@ -2835,7 +2866,7 @@ const level = {
const mapA = composite[composite.length] = Bodies.rectangle(centerA.x - 0.5 * unitA.x * mapWidth, centerA.y - 0.5 * unitA.y * mapWidth, mapWidth, height + 10, { const mapA = composite[composite.length] = Bodies.rectangle(centerA.x - 0.5 * unitA.x * mapWidth, centerA.y - 0.5 * unitA.y * mapWidth, mapWidth, height + 10, {
collisionFilter: { collisionFilter: {
category: cat.map, category: cat.map,
mask: cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet mask: cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet
}, },
unit: unitA, unit: unitA,
angle: angleA, angle: angleA,
@@ -2850,7 +2881,7 @@ const level = {
const mapB = composite[composite.length] = Bodies.rectangle(centerB.x - 0.5 * unitB.x * mapWidth, centerB.y - 0.5 * unitB.y * mapWidth, mapWidth, height + 10, { const mapB = composite[composite.length] = Bodies.rectangle(centerB.x - 0.5 * unitB.x * mapWidth, centerB.y - 0.5 * unitB.y * mapWidth, mapWidth, height + 10, {
collisionFilter: { collisionFilter: {
category: cat.map, category: cat.map,
mask: cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet mask: cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet
}, },
unit: unitB, unit: unitB,
angle: angleB, angle: angleB,

View File

@@ -626,7 +626,7 @@ const mobs = {
}, },
curl(range = 1000, mag = -10) { curl(range = 1000, mag = -10) {
//cause all mobs, and bodies to rotate in a circle //cause all mobs, and bodies to rotate in a circle
applyCurl = function (center, array) { applyCurl = function (center, array, isAntiGravity = true) {
for (let i = 0; i < array.length; ++i) { for (let i = 0; i < array.length; ++i) {
const sub = Vector.sub(center, array[i].position) const sub = Vector.sub(center, array[i].position)
const radius2 = Vector.magnitudeSquared(sub); const radius2 = Vector.magnitudeSquared(sub);
@@ -639,7 +639,8 @@ const mobs = {
x: array[i].velocity.x * 0.94 + curlVector.x * 0.06, x: array[i].velocity.x * 0.94 + curlVector.x * 0.06,
y: array[i].velocity.y * 0.94 + curlVector.y * 0.06 y: array[i].velocity.y * 0.94 + curlVector.y * 0.06
}) })
// //draw curl if (isAntiGravity) array[i].force.y -= 0.8 * game.g * array[i].mass
// //draw curl, for debugging
// ctx.beginPath(); // ctx.beginPath();
// ctx.moveTo(array[i].position.x, array[i].position.y); // ctx.moveTo(array[i].position.x, array[i].position.y);
// ctx.lineTo(array[i].position.x + curlVector.x * 10, array[i].position.y + curlVector.y * 10); // ctx.lineTo(array[i].position.x + curlVector.x * 10, array[i].position.y + curlVector.y * 10);
@@ -649,7 +650,7 @@ const mobs = {
} }
} }
} }
applyCurl(this.position, mob); applyCurl(this.position, mob, false);
applyCurl(this.position, body); applyCurl(this.position, body);
applyCurl(this.position, powerUp); applyCurl(this.position, powerUp);
// applyCurl(this.position, bullet); // too powerful, just stops all bullets need to write a curl function just for bullets // applyCurl(this.position, bullet); // too powerful, just stops all bullets need to write a curl function just for bullets

View File

@@ -97,7 +97,7 @@ const mech = {
Sy: 0, //adds a smoothing effect to vertical only Sy: 0, //adds a smoothing effect to vertical only
Vx: 0, Vx: 0,
Vy: 0, Vy: 0,
gravity: 0.0024, //0.0019 //game.g is 0.001
friction: { friction: {
ground: 0.01, ground: 0.01,
air: 0.0025 air: 0.0025
@@ -862,7 +862,8 @@ const mech = {
setTimeout(solid, 150, mech.holdingTarget); setTimeout(solid, 150, mech.holdingTarget);
const charge = Math.min(mech.throwCharge / 5, 1) const charge = Math.min(mech.throwCharge / 5, 1)
let speed = charge * Math.min(80, 64 / Math.pow(mech.holdingTarget.mass, 0.25)); //***** scale throw speed with the first number, 80 *****
let speed = 80 * charge * Math.min(1, 0.8 / Math.pow(mech.holdingTarget.mass, 0.25));
if (Matter.Query.collides(mech.holdingTarget, map).length !== 0) { if (Matter.Query.collides(mech.holdingTarget, map).length !== 0) {
speed *= 0.7 //drop speed by 30% if touching map speed *= 0.7 //drop speed by 30% if touching map
@@ -1407,20 +1408,20 @@ const mech = {
// zeroG(mob); //mobs are too irregular to make this work? // zeroG(mob); //mobs are too irregular to make this work?
if (keys[83] || keys[40]) { //down if (keys[83] || keys[40]) { //down
player.force.y -= 0.5 * player.mass * mech.gravity; player.force.y -= 0.5 * player.mass * game.g;
this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 400 * 0.03; this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 400 * 0.03;
zeroG(powerUp, this.fieldDrawRadius, 0.7); zeroG(powerUp, this.fieldDrawRadius, 0.7);
zeroG(body, this.fieldDrawRadius, 0.7); zeroG(body, this.fieldDrawRadius, 0.7);
} else if (keys[87] || keys[38]) { //up } else if (keys[87] || keys[38]) { //up
mech.energy -= 5 * DRAIN; mech.energy -= 5 * DRAIN;
this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 850 * 0.03; this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 850 * 0.03;
player.force.y -= 1.45 * player.mass * mech.gravity; player.force.y -= 1.45 * player.mass * game.g;
zeroG(powerUp, this.fieldDrawRadius, 1.38); zeroG(powerUp, this.fieldDrawRadius, 1.38);
zeroG(body, this.fieldDrawRadius, 1.38); zeroG(body, this.fieldDrawRadius, 1.38);
} else { } else {
mech.energy -= DRAIN; mech.energy -= DRAIN;
this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 650 * 0.03; this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 650 * 0.03;
player.force.y -= 1.07 * player.mass * mech.gravity; // slow upward drift player.force.y -= 1.07 * player.mass * game.g; // slow upward drift
zeroG(powerUp, this.fieldDrawRadius); zeroG(powerUp, this.fieldDrawRadius);
zeroG(body, this.fieldDrawRadius); zeroG(body, this.fieldDrawRadius);
} }

View File

@@ -2559,7 +2559,7 @@ const spawn = {
}, },
bodyRect(x, y, width, height, chance = 1, properties = { bodyRect(x, y, width, height, chance = 1, properties = {
friction: 0.05, friction: 0.05,
frictionAir: 0.01 frictionAir: 0.001,
}) { }) {
if (Math.random() < chance) body[body.length] = Bodies.rectangle(x + width / 2, y + height / 2, width, height, properties); if (Math.random() < chance) body[body.length] = Bodies.rectangle(x + width / 2, y + height / 2, width, height, properties);
}, },

View File

@@ -1,7 +1,12 @@
added doors controlled by a button (office level) block air friction is now the same as the player (lower)
block and power up gravity is now the same as the player (higher)
portals now affect blocks (high speed and large blocks are unpredictable)
************** TODO - n-gon ************** ************** TODO - n-gon **************
test block gravity increase
test throw damage
atmosphere levels atmosphere levels
change the pace, give the user a rest between combat change the pace, give the user a rest between combat
low or no combat, but more graphics low or no combat, but more graphics