Skip to content

Commit 2983f85

Browse files
committed
ant loss fix, ants are slower in dirt
1 parent ea68d6f commit 2983f85

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

game/classes/brain.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class Brain {
143143
}
144144

145145
findTarget(){
146+
if(this.obj == null) return;
146147
this.targetEntity = null;
147148

148149
//sort players from closest to furthest
@@ -180,6 +181,11 @@ class Brain {
180181
moveObjTowards(x,y,speed){
181182
//TODO: collishion
182183
let oldChunkPos = testMap.globalToChunk(this.obj.pos.x, this.obj.pos.y);
184+
let xTile = floor(this.obj.pos.x / TILESIZE) - (oldChunkPos.x * CHUNKSIZE);
185+
let yTile = floor(this.obj.pos.y / TILESIZE) - (oldChunkPos.y * CHUNKSIZE);
186+
if(testMap.chunks[oldChunkPos.x+","+oldChunkPos.y].data[xTile + (yTile / CHUNKSIZE)] > 0){
187+
speed = speed/2;
188+
}
183189
this.obj.pos.add(createVector(x,y).sub(this.obj.pos).setMag(speed));
184190

185191
socket.emit("update_obj", {
@@ -216,6 +222,9 @@ class Brain {
216222
})
217223
this.obj = temp;
218224
}
225+
else{
226+
this.obj = null;
227+
}
219228
}
220229
}
221230

game/classes/objects.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,17 @@ class Entity extends Placeable{
928928
if(this.hp <= 0){
929929
this.deleteTag = true;
930930
let chunkPos = testMap.globalToChunk(this.pos.x,this.pos.y);
931-
socket.emit("delete_obj", {cx: chunkPos.x, cy: chunkPos.y, objName: this.objName, pos: {x: this.pos.x, y: this.pos.y}, z: this.z, cost: objDic[this.objName].cost});
931+
let cost = objDic[this.objName].cost
932+
if(random() < 0.3){
933+
cost.push(["Philosopher's Stone", 1]);
934+
}
935+
socket.emit("delete_obj", {
936+
cx: chunkPos.x, cy: chunkPos.y,
937+
objName: this.objName,
938+
pos: {x: this.pos.x, y: this.pos.y},
939+
z: this.z,
940+
cost: cost
941+
});
932942

933943
for(let i=testMap.brains.length-1; i>=0; i--){
934944
if(testMap.brains[i].id == this.brainID){

game/socket.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,22 @@ function socketSetup(){
482482
testMap.chunks[data.x+","+data.y].projectiles.push(temp);
483483
}
484484
}
485+
486+
for(let i=0; i<testMap.brains.length; i++){
487+
if(testMap.brains[i].obj == null){
488+
if(
489+
testMap.brains[i].target.x > data.x * CHUNKSIZE * TILESIZE &&
490+
testMap.brains[i].target.x < (data.x+1) * CHUNKSIZE * TILESIZE &&
491+
testMap.brains[i].target.y > data.y * CHUNKSIZE * TILESIZE &&
492+
testMap.brains[i].target.y < (data.y+1) * CHUNKSIZE * TILESIZE
493+
){
494+
let temp = createObject("Ant", testMap.brains[i].target.x, testMap.brains[i].target.y, 0, 0, "", "Server", testMap.brains[i].id);
495+
testMap.chunks[data.x+","+data.y].objects.push(temp);
496+
testMap.chunks[data.x+","+data.y].objects.sort((a,b) => a.pos.y - b.pos.y);
497+
testMap.chunks[data.x+","+data.y].objects.sort((a,b) => a.z - b.z);
498+
}
499+
}
500+
}
485501
});
486502

487503
socket.on("GIVE_PORTALS", (data) => {

0 commit comments

Comments
 (0)