Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Hareesun

Hey.

Basically I'm making a laser beam (sort of like that other post on here all those months ago) Only this laser changes direction (up, down, left, right) and uses collisionMap.trace to get to the wall of the direction it's facing.

This all works great, it's the Checking that doesn't work so good. It works fine when the laser is facing right, and down, but when it's facing up or left it doesn't. From what I can tell it's not working because when it's facing left or up it's actually in the negative sizes.

Bellow is a snippet of the code that im using to make laser entity's size what it needs to be. Thought it might demonstrate what im trying to do a little better. :)
this.trY = ig.game.collisionMap.trace(this.pos.x, this.pos.y, 0, ig.system.height, 4,4);
this.trY2 = ig.game.collisionMap.trace(this.pos.x, this.pos.y, 0, ig.system.height*-1, 4,4);
this.trX = ig.game.collisionMap.trace(this.pos.x, this.pos.y, ig.system.width, 0, 4,4);
this.trX2 = ig.game.collisionMap.trace(this.pos.x, this.pos.y, ig.system.width*-1, 0, 4,4);
      
if (this.direction == "up") {
  this.size = {x:16, y: this.trY2.pos.y - this.pos.y};
  this.pos = {x:this.whatX-4, y:this.whatY};
} else if (this.direction == "down") {
  this.size = {x:16, y: this.trY.pos.y - this.pos.y + 4};
  this.pos = {x:this.whatX-4, y:this.whatY+8};
} else if (this.direction == "left") {
  this.size = {x:this.trX2.pos.x - this.pos.x, y: 16};
  this.pos = {x:this.whatX, y:this.whatY-4};
} else if (this.direction == "right") {
  this.size = {x:this.trX.pos.x - this.pos.x + 4, y: 16};
  this.pos = {x:this.whatX+8, y:this.whatY-4};
}

Has anyone figured a way to work around this issue before? Whatever you've got might help. :) Thanks!

1 decade ago by gxxaxx

To make this work, I think you will need to use a conditional statement to determine when the player is facing up or left.

Then, use absolute value to calculate the height, in addition, you will need to change the offset.

A better approach might be to use a small entity as the projectile. Then in the projectile's draw method use a special function that draws a line from the player to the entity.

This would give you a laser that could be very fast, or very slow. You can have the head of the laser be a sparkly bit and you can even change the color of the laser as it gets longer etc.

If you want to keep your current approach, just use absolute values when calculating the size AND also look into modifying the position and/or offset to compensate for the shift in size.

Good luck. I hope it looks great in your game.
Page 1 of 1
« first « previous next › last »