another attempt to fix crouch bug

added a crouch check to prevent move the head when it's already out of position
also using setPosition to move player head instead of translate
This commit is contained in:
landgreen
2020-12-22 14:53:12 -08:00
parent 60e59a858a
commit b2fff5274a
6 changed files with 137 additions and 77 deletions

View File

@@ -1853,7 +1853,7 @@ const b = {
bullet[me].endCycle = game.cycle + 60 + 18 * Math.random(); bullet[me].endCycle = game.cycle + 60 + 18 * Math.random();
bullet[me].dmg = dmg bullet[me].dmg = dmg
bullet[me].beforeDmg = function(who) { //beforeDmg is rewritten with ice crystal mod bullet[me].beforeDmg = function(who) { //beforeDmg is rewritten with ice crystal mod
if (mod.isNailPoison) mobs.statusDoT(who, dmg * 0.22, 120) // one tick every 30 cycles if (mod.isNailPoison) mobs.statusDoT(who, dmg * 0.24, 120) // one tick every 30 cycles
if (mod.isNailCrit && !who.shield && Vector.dot(Vector.normalise(Vector.sub(who.position, this.position)), Vector.normalise(this.velocity)) > 0.99) this.dmg *= 5 //crit if hit near center if (mod.isNailCrit && !who.shield && Vector.dot(Vector.normalise(Vector.sub(who.position, this.position)), Vector.normalise(this.velocity)) > 0.99) this.dmg *= 5 //crit if hit near center
}; };
bullet[me].do = function() {}; bullet[me].do = function() {};
@@ -2482,6 +2482,27 @@ const b = {
} }
game.makeGunHUD(); game.makeGunHUD();
}, },
removeGun(gun, isRemoveSelection = false) {
for (let i = 0; i < b.guns.length; i++) {
if (b.guns[i].name === gun) {
b.guns[i].have = false
for (let j = 0; j < b.inventory.length; j++) {
if (b.inventory[j] === i) {
b.inventory.splice(j, 1)
break
}
}
if (b.inventory.length) {
b.activeGun = b.inventory[0];
} else {
b.activeGun = null;
}
game.makeGunHUD();
if (isRemoveSelection) b.guns.splice(i, 1) //also remove gun from gun pool array
break
}
}
},
guns: [{ guns: [{
name: "nail gun", name: "nail gun",
description: "use compressed air to fire a stream of <strong>nails</strong><br><strong>delay</strong> after firing <strong>decreases</strong> as you shoot", description: "use compressed air to fire a stream of <strong>nails</strong><br><strong>delay</strong> after firing <strong>decreases</strong> as you shoot",
@@ -2550,7 +2571,7 @@ const b = {
if (mod.isIceCrystals) { if (mod.isIceCrystals) {
bullet[bullet.length - 1].beforeDmg = function(who) { bullet[bullet.length - 1].beforeDmg = function(who) {
mobs.statusSlow(who, 30) mobs.statusSlow(who, 30)
if (mod.isNailPoison) mobs.statusDoT(who, dmg * 0.22, 120) // one tick every 30 cycles if (mod.isNailPoison) mobs.statusDoT(who, dmg * 0.24, 120) // one tick every 30 cycles
if (mod.isNailCrit && !who.shield && Vector.dot(Vector.normalise(Vector.sub(who.position, this.position)), Vector.normalise(this.velocity)) > 0.99) this.dmg *= 5 //crit if hit near center if (mod.isNailCrit && !who.shield && Vector.dot(Vector.normalise(Vector.sub(who.position, this.position)), Vector.normalise(this.velocity)) > 0.99) this.dmg *= 5 //crit if hit near center
}; };
@@ -3778,18 +3799,19 @@ const b = {
isRewinding: false, isRewinding: false,
lastFireCycle: 0, lastFireCycle: 0,
holdCount: 0, holdCount: 0,
activeGunIndex: null,
fire() { fire() {
if (this.lastFireCycle === mech.cycle - 1) { //button has been held down if (this.lastFireCycle === mech.cycle - 1) { //button has been held down
this.rewindCount += 7; this.rewindCount += 8;
const DRAIN = 0.01 const DRAIN = 0.01
if (this.rewindCount > 599 || mech.energy < DRAIN) { let history = mech.history[(mech.cycle - this.rewindCount) % 600]
if (this.rewindCount > 599 || mech.energy < DRAIN || history.activeGun !== this.activeGunIndex) {
this.rewindCount = 0; this.rewindCount = 0;
mech.resetHistory(); mech.resetHistory();
mech.fireCDcycle = mech.cycle + Math.floor(60 * b.fireCD); // cool down mech.fireCDcycle = mech.cycle + Math.floor(120 * b.fireCD); // cool down
} else { } else {
mech.energy -= DRAIN mech.energy -= DRAIN
mech.immuneCycle = mech.cycle + 5; //player is immune to collision damage for 5 cycles mech.immuneCycle = mech.cycle + 30; //player is immune to collision damage for 5 cycles
let history = mech.history[(mech.cycle - this.rewindCount) % 600]
Matter.Body.setPosition(player, history.position); Matter.Body.setPosition(player, history.position);
Matter.Body.setVelocity(player, { x: history.velocity.x, y: history.velocity.y }); Matter.Body.setVelocity(player, { x: history.velocity.x, y: history.velocity.y });
if (mech.health !== history.health) { if (mech.health !== history.health) {
@@ -3799,6 +3821,7 @@ const b = {
} }
} else { //button is held the first time } else { //button is held the first time
this.rewindCount = 0; this.rewindCount = 0;
this.activeGunIndex = b.activeGun
} }
this.lastFireCycle = mech.cycle; this.lastFireCycle = mech.cycle;
} }

View File

@@ -203,19 +203,16 @@ const build = {
</svg> </svg>
</div>`; </div>`;
let countGuns = 0 for (let i = 0, len = b.inventory.length; i < len; i++) {
let countMods = 0 text += `<div class="pause-grid-module"><div class="grid-title"><div class="circle-grid gun"></div> &nbsp; ${b.guns[b.inventory[i]].name} - <span style="font-size:100%;font-weight: 100;">${b.guns[b.inventory[i]].ammo}</span></div> ${b.guns[b.inventory[i]].description}</div>`
for (let i = 0, len = b.guns.length; i < len; i++) {
if (b.guns[i].have) {
text += `<div class="pause-grid-module"><div class="grid-title"><div class="circle-grid gun"></div> &nbsp; ${b.guns[i].name} - <span style="font-size:100%;font-weight: 100;">${b.guns[i].ammo}</span></div> ${b.guns[i].description}</div>`
countGuns++
}
} }
let el = document.getElementById("pause-grid-left") let el = document.getElementById("pause-grid-left")
el.style.display = "grid" el.style.display = "grid"
el.innerHTML = text el.innerHTML = text
text = ""; text = "";
text += `<div class="pause-grid-module"><div class="grid-title"><div class="circle-grid field"></div> &nbsp; ${mech.fieldUpgrades[mech.fieldMode].name}</div> ${mech.fieldUpgrades[mech.fieldMode].description}</div>` text += `<div class="pause-grid-module"><div class="grid-title"><div class="circle-grid field"></div> &nbsp; ${mech.fieldUpgrades[mech.fieldMode].name}</div> ${mech.fieldUpgrades[mech.fieldMode].description}</div>`
let countMods = 0
for (let i = 0, len = mod.mods.length; i < len; i++) { for (let i = 0, len = mod.mods.length; i < len; i++) {
if (mod.mods[i].count > 0) { if (mod.mods[i].count > 0) {
const isCount = mod.mods[i].count > 1 ? `(${mod.mods[i].count}x)` : ""; const isCount = mod.mods[i].count > 1 ? `(${mod.mods[i].count}x)` : "";
@@ -248,7 +245,7 @@ const build = {
el = document.getElementById("pause-grid-right") el = document.getElementById("pause-grid-right")
el.style.display = "grid" el.style.display = "grid"
el.innerHTML = text el.innerHTML = text
if (countMods > 5 || countGuns > 6) { if (countMods > 5 || b.inventory.length > 6) {
document.body.style.overflowY = "scroll"; document.body.style.overflowY = "scroll";
document.body.style.overflowX = "hidden"; document.body.style.overflowX = "hidden";
} }

View File

@@ -3805,7 +3805,8 @@ const level = {
} }
}, },
nextLevel() { nextLevel() {
if (level.bossKilled) level.levelsCleared++; // if (level.bossKilled)
level.levelsCleared++;
// level.difficultyIncrease(game.difficultyMode) //increase difficulty based on modes // level.difficultyIncrease(game.difficultyMode) //increase difficulty based on modes
//difficulty is increased 5 times when finalBoss dies //difficulty is increased 5 times when finalBoss dies

View File

@@ -1054,7 +1054,7 @@ const mod = {
}, },
{ {
name: "CPT reversal", name: "CPT reversal",
description: "<strong class='color-rewind'>rewind</strong> <strong>1.5 - 5</strong> seconds to avoid <strong class='color-harm'>harm</strong><br>drains <strong>66 - 220</strong> <strong class='color-f'>energy</strong>", description: "<strong>charge</strong>, <strong>parity</strong>, and <strong>time</strong> invert to undo <strong class='color-harm'>harm</strong><br><strong class='color-rewind'>rewind</strong> <strong>(1.5—5)</strong> seconds for <strong>(66—220)</strong> <strong class='color-f'>energy</strong>",
maxCount: 1, maxCount: 1,
count: 0, count: 0,
allowed() { //&& (mech.fieldUpgrades[mech.fieldMode].name !== "nano-scale manufacturing" || mech.maxEnergy > 1) allowed() { //&& (mech.fieldUpgrades[mech.fieldMode].name !== "nano-scale manufacturing" || mech.maxEnergy > 1)
@@ -1406,9 +1406,9 @@ const mod = {
maxCount: 1, maxCount: 1,
count: 0, count: 0,
allowed() { allowed() {
return true return mod.duplicationChance() < 1
}, },
requires: "", requires: "below 100% duplication chance",
effect: () => { effect: () => {
mod.isBayesian = true mod.isBayesian = true
game.draw.powerUp = game.draw.powerUpBonus //change power up draw game.draw.powerUp = game.draw.powerUpBonus //change power up draw
@@ -1424,9 +1424,9 @@ const mod = {
maxCount: 9, maxCount: 9,
count: 0, count: 0,
allowed() { allowed() {
return true return mod.duplicationChance() < 1
}, },
requires: "", requires: "below 100% duplication chance",
effect() { effect() {
mod.duplicateChance += 0.07 mod.duplicateChance += 0.07
game.draw.powerUp = game.draw.powerUpBonus //change power up draw game.draw.powerUp = game.draw.powerUpBonus //change power up draw
@@ -1442,9 +1442,9 @@ const mod = {
maxCount: 1, maxCount: 1,
count: 0, count: 0,
allowed() { allowed() {
return !mod.isDeterminism return mod.duplicationChance() < 1 && !mod.isDeterminism
}, },
requires: "not determinism", requires: "below 100% duplication chance, not determinism",
effect() { effect() {
mod.isCancelDuplication = true mod.isCancelDuplication = true
mod.cancelCount = 0 mod.cancelCount = 0
@@ -1927,7 +1927,7 @@ const mod = {
maxCount: 1, maxCount: 1,
count: 0, count: 0,
allowed() { allowed() {
return (mod.totalBots() > 5 || mech.fieldUpgrades[mech.fieldMode].name === "nano-scale manufacturing" || mech.fieldUpgrades[mech.fieldMode].name === "plasma torch" || mech.fieldUpgrades[mech.fieldMode].name === "pilot wave") && !mod.isEnergyHealth && !mod.isRewindAvoidDeath return (mod.totalBots() > 5 || mech.fieldUpgrades[mech.fieldMode].name === "nano-scale manufacturing" || mech.fieldUpgrades[mech.fieldMode].name === "plasma torch" || mech.fieldUpgrades[mech.fieldMode].name === "pilot wave") && !mod.isEnergyHealth && !mod.isRewindAvoidDeath //build.isCustomSelection ||
}, },
requires: "bots > 5, plasma torch, nano-scale, pilot wave, not mass-energy equivalence, CPT", requires: "bots > 5, plasma torch, nano-scale, pilot wave, not mass-energy equivalence, CPT",
effect() { effect() {
@@ -1937,25 +1937,27 @@ const mod = {
}, },
remove() { remove() {
if (mod.isRewindGun) { if (mod.isRewindGun) {
for (let i = 0; i < b.guns.length; i++) { b.removeGun("CPT gun", true)
if (b.guns[i].name === "CPT gun") { // for (let i = 0; i < b.guns.length; i++) {
for (let j = 0; j < b.inventory.length; j++) { // if (b.guns[i].name === "CPT gun") {
if (b.inventory[j] === i) { // b.guns[i].have = false
b.inventory.splice(j, 1) // for (let j = 0; j < b.inventory.length; j++) {
break // if (b.inventory[j] === i) {
} // b.inventory.splice(j, 1)
} // break
if (b.inventory.length) { // }
b.activeGun = b.inventory[0]; // }
} else { // if (b.inventory.length) {
b.activeGun = null; // b.activeGun = b.inventory[0];
} // } else {
game.makeGunHUD(); // b.activeGun = null;
// }
// game.makeGunHUD();
b.guns.splice(i, 1) //also remove CPT gun from gun pool array // b.guns.splice(i, 1) //also remove CPT gun from gun pool array
break // break
} // }
} // }
mod.isRewindGun = false mod.isRewindGun = false
} }
} }
@@ -2619,7 +2621,7 @@ const mod = {
}, },
{ {
name: "railroad ties", name: "railroad ties",
description: "<strong>nails</strong> are <strong>50%</strong> <strong>larger</strong><br>increases physical <strong class='color-d'>damage</strong> by about <strong>25%</strong>", description: "<strong>nails</strong> are <strong>40%</strong> <strong>larger</strong><br>increases physical <strong class='color-d'>damage</strong> by about <strong>20%</strong>",
isGunMod: true, isGunMod: true,
maxCount: 1, maxCount: 1,
count: 0, count: 0,
@@ -2628,7 +2630,7 @@ const mod = {
}, },
requires: "nails", requires: "nails",
effect() { effect() {
mod.biggerNails += 0.5 mod.biggerNails += 0.33
}, },
remove() { remove() {
mod.biggerNails = 1 mod.biggerNails = 1

View File

@@ -7,14 +7,14 @@ const mech = {
//load player in matter.js physic engine //load player in matter.js physic engine
// let vector = Vertices.fromPath("0 40 50 40 50 115 0 115 30 130 20 130"); //player as a series of vertices // let vector = Vertices.fromPath("0 40 50 40 50 115 0 115 30 130 20 130"); //player as a series of vertices
let vertices = Vertices.fromPath("0,40, 50,40, 50,115, 30,130, 20,130, 0,115, 0,40"); //player as a series of vertices let vertices = Vertices.fromPath("0,40, 50,40, 50,115, 30,130, 20,130, 0,115, 0,40"); //player as a series of vertices
playerBody = Matter.Bodies.fromVertices(0, 0, vertices); playerBody = Bodies.fromVertices(0, 0, vertices);
jumpSensor = Bodies.rectangle(0, 46, 36, 6, { jumpSensor = Bodies.rectangle(0, 46, 36, 6, {
//this sensor check if the player is on the ground to enable jumping //this sensor check if the player is on the ground to enable jumping
sleepThreshold: 99999999999, sleepThreshold: 99999999999,
isSensor: true isSensor: true
}); });
vertices = Vertices.fromPath("16 -82 2 -66 2 -37 43 -37 43 -66 30 -82"); vertices = Vertices.fromPath("16 -82 2 -66 2 -37 43 -37 43 -66 30 -82");
playerHead = Matter.Bodies.fromVertices(0, -55, vertices); //this part of the player lowers on crouch playerHead = Bodies.fromVertices(0, -55, vertices); //this part of the player lowers on crouch
headSensor = Bodies.rectangle(0, -57, 48, 45, { headSensor = Bodies.rectangle(0, -57, 48, 45, {
//senses if the player's head is empty and can return after crouching //senses if the player's head is empty and can return after crouching
sleepThreshold: 99999999999, sleepThreshold: 99999999999,
@@ -172,6 +172,7 @@ const mech = {
angle: mech.angle, angle: mech.angle,
health: mech.health, health: mech.health,
energy: mech.energy, energy: mech.energy,
activeGun: b.activeGun
}); });
// const back = 59 // 59 looks at 1 second ago //29 looks at 1/2 a second ago // const back = 59 // 59 looks at 1 second ago //29 looks at 1/2 a second ago
// historyIndex = (mech.cycle - back) % 60 // historyIndex = (mech.cycle - back) % 60
@@ -198,20 +199,53 @@ const mech = {
if (!mech.crouch) { if (!mech.crouch) {
mech.crouch = true; mech.crouch = true;
mech.yOffGoal = mech.yOffWhen.crouch; mech.yOffGoal = mech.yOffWhen.crouch;
Matter.Body.translate(playerHead, { if ((playerHead.position.y - player.position.y) < 0) {
x: 0,
y: 40 Matter.Body.setPosition(playerHead, {
}); x: player.position.x,
y: player.position.y + 9.1740767
})
// Matter.Body.translate(playerHead, {
// x: 0,
// y: 40
// });
}
// playerHead.collisionFilter.group = -1
// playerHead.collisionFilter.category = 0
// playerHead.collisionFilter.mask = -1
// playerHead.isSensor = true; //works, but has a 2 second lag...
// collisionFilter: {
// group: 0,
// category: cat.player,
// mask: cat.body | cat.map | cat.mob | cat.mobBullet | cat.mobShield
// },
} }
}, },
undoCrouch() { undoCrouch() {
if (mech.crouch) { if (mech.crouch) {
mech.crouch = false; mech.crouch = false;
mech.yOffGoal = mech.yOffWhen.stand; mech.yOffGoal = mech.yOffWhen.stand;
Matter.Body.translate(playerHead, { if ((playerHead.position.y - player.position.y) > 0) {
x: 0, Matter.Body.setPosition(playerHead, {
y: -40 x: player.position.x,
}); y: player.position.y - 30.28592321
})
// Matter.Body.translate(playerHead, {
// x: 0,
// y: -40
// });
}
// playerHead.collisionFilter = {
// group: 0,
// category: cat.player,
// mask: cat.body | cat.map | cat.mob | cat.mobBullet | cat.mobShield
// }
// playerHead.isSensor = false;
// playerHead.collisionFilter.category = cat.player
// playerHead.collisionFilter.mask = cat.body | cat.map | cat.mob | cat.mobBullet | cat.mobShield
} }
}, },
hardLandCD: 0, hardLandCD: 0,
@@ -498,6 +532,12 @@ const mech = {
let history = mech.history[(mech.cycle - steps) % 600] let history = mech.history[(mech.cycle - steps) % 600]
Matter.Body.setPosition(player, history.position); Matter.Body.setPosition(player, history.position);
Matter.Body.setVelocity(player, { x: history.velocity.x, y: history.velocity.y }); Matter.Body.setVelocity(player, { x: history.velocity.x, y: history.velocity.y });
b.activeGun = history.activeGun
for (let i = 0; i < b.inventory.length; i++) {
if (b.inventory[i] === b.activeGun) b.inventoryGun = i
}
game.updateGunHUD();
game.boldActiveGunHUD();
// move bots to follow player // move bots to follow player
for (let i = 0; i < bullet.length; i++) { for (let i = 0; i < bullet.length; i++) {
if (bullet[i].botType) { if (bullet[i].botType) {

View File

@@ -1,10 +1,7 @@
******************************************************** NEXT PATCH ******************************************************** ******************************************************** NEXT PATCH ********************************************************
new level boss that fires 2 streams of small bullets that chase you added a crouch check to prevent move the head when it's already out of position
also using setPosition to move player head instead of translate
mod: add a CPT gun to your inventory that rewinds your history, reverts your health, position, velocity for 10 seconds
I expect that spamming rewind has some overpowered combos.
Let me know what you find, and your ideas on balance.
******************************************************** BUGS ******************************************************** ******************************************************** BUGS ********************************************************
@@ -40,13 +37,13 @@ mod and mob are too similar
******************************************************** TODO ******************************************************** ******************************************************** TODO ********************************************************
mod: laser beams push like plasma torch pushes with directional force CPT gun seems a bit weak right now. How to buff the gun?
mod: worm hole - you move through time instead of space. (field click to rewind) mob ability bombs/bullets that suck in player
add support for eating blocks, and damaging mobs that are nearby when you rewind
allow those mods mod where you can't stop firing, how to code?
mod might not work as is because player needs to be able to pick up and move blocks sometimes
what about as a gun that uses energy not bullets? mod: laser beams push like plasma torch pushes with directional force
mechanic: technological dead end - add mods to the mod pool with a dumb effect mechanic: technological dead end - add mods to the mod pool with a dumb effect
don't show up in custom? don't show up in custom?
@@ -67,6 +64,10 @@ mechanic: technological dead end - add mods to the mod pool with a dumb effect
remove your bots (requires you to have some bots) remove your bots (requires you to have some bots)
your bots are changed to random bots your bots are changed to random bots
Mod: "Expansion Formula": Permanently increase the size of Negative Mass field by 16%(Max 96%)
Mod: "Circadian Rhythm": Become immune to harm for 1 second every 10 seconds while playing.
Mod: "High Risk": Spawn two bosses per level. Mod: "High Risk": Spawn two bosses per level.
maybe limit to just the power up boss and spawn it at the exit every time to keep it simple maybe limit to just the power up boss and spawn it at the exit every time to keep it simple
also weaken the player also weaken the player
@@ -386,21 +387,17 @@ AI doesn't know about:
modern pop culture modern pop culture
outside the lab outside the lab
robot AI communication in game console
output to output all console.log code //find starter code for this at the end of index.js
bottom left message
tab title?
style style
output console.log?
make it look like a computer terminal make it look like a computer terminal
track multiple lines, like your vocoder program track multiple lines, like your vocoder program
messages about heal, ammo, mods, that just list internal computer code messages about heal, ammo, mods, that just list internal computer code
example: a heal would be mech.health += 12 example: a heal would be mech.health += 12
mono space font mono space font
square edges square edges
black text on bottom right with no background? black text on bottom right with no background?
or white text, or yellow or white text, or yellow
end each message with a hexadecimal encryption code/hash
message after selecting each new (mod / gun / field) message after selecting each new (mod / gun / field)
put messages in (mod / gun / field) method put messages in (mod / gun / field) method
at start of run at start of run