Skip to content

Commit e6f1e6e

Browse files
Fixed position bug for teleport
Corrected the teleport placement, which was off by 0.5f resulting in the player being put into walls. Fixed a similar problem with the check of who should be teleported which was off by the same amount. Also, additional documentation, clean up, and reuse of an existing method (getting max floor height).
1 parent 465298c commit e6f1e6e

File tree

1 file changed

+13
-28
lines changed
  • Dungeoneer/src/com/interrupt/dungeoneer/entities/spells

1 file changed

+13
-28
lines changed

Dungeoneer/src/com/interrupt/dungeoneer/entities/spells/Teleport.java

+13-28
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
import com.interrupt.dungeoneer.entities.Door;
1010
import com.interrupt.dungeoneer.entities.DynamicLight;
1111
import com.interrupt.dungeoneer.entities.Entity;
12-
import com.interrupt.dungeoneer.entities.Monster;
1312
import com.interrupt.dungeoneer.entities.Mover;
1413
import com.interrupt.dungeoneer.entities.Particle;
1514
import com.interrupt.dungeoneer.entities.Player;
16-
import com.interrupt.dungeoneer.entities.PositionedSound;
1715
import com.interrupt.dungeoneer.entities.items.Weapon.DamageType;
1816
import com.interrupt.dungeoneer.entities.triggers.Trigger;
1917
import com.interrupt.dungeoneer.game.Game;
@@ -30,12 +28,13 @@ public Teleport(DamageType damageType) {
3028
this.damageType = damageType;
3129
}
3230

31+
/** Handles individual teleport (ex. casting a spell from a scroll). */
3332
@Override
3433
public void doCast(Entity owner, Vector3 direction, Vector3 position) {
35-
Vector3 pos = new Vector3(owner.x, owner.y, owner.z);
3634
teleport(owner, Game.rand.nextInt());
3735
}
3836

37+
/** Handles teleport for every actor, including the player, within a certain radius (ex. stepping on a pressure plate trap). */
3938
public void doCast(Vector3 pos, Vector3 direction) {
4039
Level level = Game.GetLevel();
4140

@@ -48,12 +47,16 @@ public void doCast(Vector3 pos, Vector3 direction) {
4847
}
4948

5049
Player p = Game.instance.player;
51-
if(Math.abs(p.x + 0.5f - pos.x) < 0.5f + p.collision.x && Math.abs(p.y + 0.5f - pos.y) < 0.5f + p.collision.y) {
50+
if(Math.abs(p.x - pos.x) < 0.5f + p.collision.x && Math.abs(p.y - pos.y) < 0.5f + p.collision.y) {
5251
teleport(p, seed);
5352
p.history.teleported();
5453
}
5554
}
5655

56+
/**
57+
* Teleports the specified entity to a random location based on the provided seed number. Providing the same seed
58+
* will result in the same location. Any actor entity, such as a monster, already at that location will be killed.
59+
*/
5760
public void teleport(Entity e, int seed) {
5861
Level level = Game.GetLevel();
5962
if(level.dungeonLevel == 0) return;
@@ -67,32 +70,14 @@ public void teleport(Entity e, int seed) {
6770
if(checkTile.CanSpawnHere()) {
6871
e.x = checkX + 0.5f;
6972
e.y = checkY + 0.5f;
70-
71-
float height1 = checkTile.getFloorHeight(e.x - e.collision.x, e.y - e.collision.y);
72-
float height2 = checkTile.getFloorHeight(e.x - e.collision.x, e.y + e.collision.y);
73-
float height3 = checkTile.getFloorHeight(e.x + e.collision.x, e.y - e.collision.y);
74-
float height4 = checkTile.getFloorHeight(e.x + e.collision.x, e.y + e.collision.y);
75-
float max = Math.max(height4, Math.max(height3, Math.max(height1, height2)));
76-
77-
e.z = max + 0.5f;
78-
79-
if(e instanceof Player) {
80-
e.x -= 0.5;
81-
e.y -= 0.5;
82-
}
83-
73+
e.z = level.maxFloorHeight(e.x, e.y, 0, e.collision.x) + 0.5f; // Assumes collision.x and y are the same.
74+
8475
Entity toFrag = level.checkEntityCollision(e.x, e.y, e.z, e.collision, e);
85-
if(toFrag != null && toFrag instanceof Actor) {
86-
((Actor)toFrag).hp = 0;
76+
if (toFrag == null || toFrag instanceof Actor) {
77+
if (toFrag instanceof Actor) ((Actor)toFrag).hp = 0; // Kill an actor already in that position.
78+
doCastEffect(new Vector3(e.x, e.y, e.z), level, e);
79+
return;
8780
}
88-
else if(toFrag != null) {
89-
// this didn't work out, try again
90-
continue;
91-
}
92-
93-
doCastEffect(new Vector3((float)checkX + 0.5f, (float)checkY + 0.5f, checkTile.floorHeight + 0.5f), level, e);
94-
95-
return;
9681
}
9782
}
9883
}

0 commit comments

Comments
 (0)