construct mode mob spawns

This commit is contained in:
landgreen
2020-05-03 04:38:48 -07:00
parent 222c95af67
commit a64b969186
5 changed files with 45 additions and 49 deletions

View File

@@ -40,7 +40,8 @@
<div id="health"></div> <div id="health"></div>
<div id="dmg"></div> <div id="dmg"></div>
<div id="choose-background"></div> <div id="choose-background"></div>
<div id='construct' contenteditable="true"></div> <div id='construct'></div>
<!-- contenteditable="true" -->
<!-- guns --> <!-- guns -->
<!-- <audio id="snare2" src="sounds\guns\snare2.ogg" preload="auto"></audio> <!-- <audio id="snare2" src="sounds\guns\snare2.ogg" preload="auto"></audio>

View File

@@ -1029,15 +1029,16 @@ const game = {
} }
const x = round(game.constructMouseDownPosition.x) const x = round(game.constructMouseDownPosition.x)
const y = round(game.constructMouseDownPosition.y) const y = round(game.constructMouseDownPosition.y)
const dx = round(game.mouseInGame.x) - x const dx = Math.max(25, round(game.mouseInGame.x) - x)
const dy = round(game.mouseInGame.y) - y const dy = Math.max(25, round(game.mouseInGame.y) - y)
ctx.strokeStyle = "#000" ctx.strokeStyle = "#000"
ctx.lineWidth = 2; ctx.lineWidth = 2;
ctx.strokeRect(x, y, dx, dy); ctx.strokeRect(x, y, dx, dy);
} }
}, },
outputMapString() { outputMapString(string) {
if (string) game.constructMapString.push(string) //store command as a string in the next element of an array
let out = "" //combine set of map strings to one string let out = "" //combine set of map strings to one string
let outHTML = "" let outHTML = ""
for (let i = 0, len = game.constructMapString.length; i < len; i++) { for (let i = 0, len = game.constructMapString.length; i < len; i++) {
@@ -1052,49 +1053,50 @@ const game = {
game.isAutoZoom = false; game.isAutoZoom = false;
document.body.addEventListener("mouseup", (e) => { document.body.addEventListener("mouseup", (e) => {
if (game.testing && game.constructMouseDownPosition && game.mouseInGame.x > game.constructMouseDownPosition.x && game.mouseInGame.y > game.constructMouseDownPosition.y) { //make sure that the width and height are positive if (game.testing && game.constructMouseDownPosition) {
function round(num, round = 25) { function round(num, round = 25) {
return Math.ceil(num / round) * round; return Math.ceil(num / round) * round;
} }
//clean up positions //clean up positions
const x = round(game.constructMouseDownPosition.x) const x = round(game.constructMouseDownPosition.x)
const y = round(game.constructMouseDownPosition.y) const y = round(game.constructMouseDownPosition.y)
const dx = round(game.mouseInGame.x) - x const dx = Math.max(25, round(game.mouseInGame.x) - x)
const dy = round(game.mouseInGame.y) - y const dy = Math.max(25, round(game.mouseInGame.y) - y)
console.log(e.which) if (e.which === 2) {
if (e.which === 1) { //add map game.outputMapString(`spawn.randomMob(${x}, ${y},0.5);`);
game.constructMapString.push(`spawn.mapRect(${x}, ${y}, ${dx}, ${dy});`) //store command as a string in the next element of an array } else if (game.mouseInGame.x > game.constructMouseDownPosition.x && game.mouseInGame.y > game.constructMouseDownPosition.y) { //make sure that the width and height are positive
game.outputMapString(); if (e.which === 1) { //add map
game.outputMapString(`spawn.mapRect(${x}, ${y}, ${dx}, ${dy});`);
//see map in world //see map in world
spawn.mapRect(x, y, dx, dy); spawn.mapRect(x, y, dx, dy);
len = map.length - 1 len = map.length - 1
map[len].collisionFilter.category = cat.map; map[len].collisionFilter.category = cat.map;
map[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; map[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet;
Matter.Body.setStatic(map[len], true); //make static Matter.Body.setStatic(map[len], true); //make static
World.add(engine.world, map[len]); //add to world World.add(engine.world, map[len]); //add to world
game.draw.setPaths() //update map graphics game.draw.setPaths() //update map graphics
} else if (e.which === 3) { //add body } else if (e.which === 3) { //add body
game.constructMapString.push(`spawn.bodyRect(${x}, ${y}, ${dx}, ${dy});`) //store command as a string in the next element of an array game.outputMapString(`spawn.bodyRect(${x}, ${y}, ${dx}, ${dy});`);
game.outputMapString();
//see map in world //see map in world
spawn.bodyRect(x, y, dx, dy); spawn.bodyRect(x, y, dx, dy);
len = body.length - 1 len = body.length - 1
body[len].collisionFilter.category = cat.body; body[len].collisionFilter.category = cat.body;
body[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet body[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet
World.add(engine.world, body[len]); //add to world World.add(engine.world, body[len]); //add to world
body[len].classType = "body"
}
} }
} }
game.constructMouseDownPosition.x = undefined game.constructMouseDownPosition.x = undefined
game.constructMouseDownPosition.y = undefined game.constructMouseDownPosition.y = undefined
}); });
game.constructMouseDownPosition.x = undefined game.constructMouseDownPosition.x = undefined
game.constructMouseDownPosition.y = undefined game.constructMouseDownPosition.y = undefined
document.body.addEventListener("mousedown", () => { document.body.addEventListener("mousedown", (e) => {
if (game.testing) { if (game.testing) {
game.constructMouseDownPosition.x = game.mouseInGame.x game.constructMouseDownPosition.x = game.mouseInGame.x
game.constructMouseDownPosition.y = game.mouseInGame.y game.constructMouseDownPosition.y = game.mouseInGame.y
@@ -1103,22 +1105,18 @@ const game = {
document.body.addEventListener("keydown", (e) => { // e.keyCode z=90 m=77 b=66 shift = 16 c = 67 document.body.addEventListener("keydown", (e) => { // e.keyCode z=90 m=77 b=66 shift = 16 c = 67
if (game.testing && e.keyCode === 90 && game.constructMapString.length) { if (game.testing && e.keyCode === 90 && game.constructMapString.length) {
if (game.constructMapString[game.constructMapString.length - 1][6] === 'm') { //remove map if (game.constructMapString[game.constructMapString.length - 1][6] === 'm') { //remove map from current level
game.constructMapString.pop();
game.outputMapString();
//remove from current level
const index = map.length - 1 const index = map.length - 1
Matter.World.remove(engine.world, map[index]); Matter.World.remove(engine.world, map[index]);
map.splice(index, 1); map.splice(index, 1);
game.draw.setPaths() //update map graphics game.draw.setPaths() //update map graphics
} else if (game.constructMapString[game.constructMapString.length - 1][6] === 'b') { //remove body } else if (game.constructMapString[game.constructMapString.length - 1][6] === 'b') { //remove body from current level
game.constructMapString.pop();
game.outputMapString();
//remove from current level
const index = body.length - 1 const index = body.length - 1
Matter.World.remove(engine.world, body[index]); Matter.World.remove(engine.world, body[index]);
body.splice(index, 1); body.splice(index, 1);
} }
game.constructMapString.pop();
game.outputMapString();
} }
}); });
} }

View File

@@ -14,13 +14,13 @@ const level = {
start() { start() {
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
game.enableConstructMode() //used to build maps in testing mode // game.enableConstructMode() //used to build maps in testing mode
// level.difficultyIncrease(9) // level.difficultyIncrease(9)
// b.giveGuns("foam") // b.giveGuns("foam")
// mech.setField("time dilation field") // mech.setField("time dilation field")
// b.giveMod("renormalization"); // b.giveMod("renormalization");
// b.giveMod("impact shear"); // b.giveMod("impact shear");
b.giveMod("clock gating"); // b.giveMod("clock gating");
// b.giveGuns("mine") // b.giveGuns("mine")
// mech.setField("pilot wave") // mech.setField("pilot wave")
// mech.setField("perfect diamagnetism") // mech.setField("perfect diamagnetism")

View File

@@ -101,17 +101,17 @@ summary {
bottom: 0%; bottom: 0%;
right: 0%; right: 0%;
z-index: 1; z-index: 1;
width: 300px; width: 250px;
height: 320px; height: 200px;
background-color: #fff; background-color: #fff;
color: #000; color: #000;
font-size: 0.9em; font-size: 0.9em;
user-select: text; /* user-select: text; */
white-space: pre; white-space: pre;
padding: 3px; padding: 3px;
overflow: scroll; /* overflow: scroll; */
/* border-radius: 0px; */ /* border-radius: 0px; */
border: 2px #333 solid; border: 1px #333 solid;
} }
#choose-grid { #choose-grid {

View File

@@ -1,9 +1,6 @@
cardinality now gives 2 selection choices
+20% laser damage
Mod: When damaged, time slows down
************** TODO - n-gon ************** ************** TODO - n-gon **************
let people know about n-gon n-gon outreach ideas
blips - errant signal on youtube blips - errant signal on youtube
reddit - r/IndieGaming reddit - r/IndieGaming
hacker news - show hacker news post hacker news - show hacker news post