Two objects in my game are not colliding and I have no idea why…
I have one Entity for all the background objects and one for the player. One of the props is a door and it has collision associated with it that allows for the player to open the door and move to the next area.
Here’s the code for the Prop entity:
import net.flashpunk.Entity;
import net.flashpunk.Graphic;
import net.flashpunk.utils.*;
import net.flashpunk.graphics.Image;
public class Prop extends Entity
{
[Embed('assets/props/bedsidetable.png')]
private const BEDSIDETABLE:Class;
[Embed('assets/backgrounds/apartment.png')]
private const APARTMENT:Class;
[Embed('assets/props/door.png')]
private const DOOR:Class;
public function Prop(x:Number,y:Number,type:String)
{
super(x,y);
if(type == "bedsidetable")
{
graphic = new Image(BEDSIDETABLE);
}
if(type == 'apartmentB')
{
graphic = new Image(APARTMENT);
}
if(type == 'door')
{
graphic = new Image(DOOR);
setHitbox(50,100);
type = 'doorO';
}
}
}
and here is the code for the Player
import net.flashpunk.Entity;
import net.flashpunk.graphics.Image;
import net.flashpunk.Graphic;
import net.flashpunk.utils.*;
import net.flashpunk.Sfx;
import net.flashpunk.FP;
import net.flashpunk.*;
public class Hero extends Entity{
public var sprintDistance:Number = 100;
public var speed:Number = 1;
public static var xRestrictionOne:Number = 30;
public static var xRestrictionTwo:Number = 725;
[Embed('assets/protagonist/idle.png')] private const TEST:Class;
public function Hero(setx:Number,sety:Number,type:String) {
graphic = new Image(TEST);
super(setx,sety);
if(type == 'hero')
{
setHitbox(38,82);
type = 'protag';
}
}
override public function update():void
{
if(Input.check(Key.RIGHT))
{
if(this.x < xRestrictionTwo)
{
this.x += speed;
}
}
if (this.collide('door',x,y))
{
trace('test');
}
if(Input.check(Key.LEFT))
{
if(this.x > xRestrictionOne)
{
this.x -= speed;
}
}
if(Input.check(Key.SHIFT))
{
if(sprintDistance > 0)
{
if(Input.check(Key.RIGHT) || Input.check(Key.LEFT))
{
sprintDistance -= 1;
if(speed < 4)
{
speed += 1;
}
}
}
if(sprintDistance == 0)
{
speed = 1;
}
}
if(!Input.check(Key.SHIFT))
{
speed = 1;
if(sprintDistance < 100)
{
sprintDistance += 1;
}
}
if(this.x > xRestrictionTwo)
{
this.x = xRestrictionTwo;
}
if(this.x < xRestrictionOne)
{
this.x = xRestrictionOne;
}
}
}
Thank you for any help you can offer.