danpost wrote...
I missed the 'getImage()' call in the last statement. Refer to the break-down above.
if (xOff < 0 ||
yOff < 0 ||
xOff >= actor.getImage().getWidth())
return 0;
if (yOff >= actor.getImage().getHeight()) return 255;if (xOff < 0 ||
yOff < 0 ||
xOff >= actor.getImage().getWidth())
return 0;
if (yOff >= actor.getImage().getHeight()) return 255;public void act()
{
setImage(imageOfShot);
setRotation(shotDirection);
if (!WorldOption.menuDisplayed)move(10);
Enemy enemy = (Enemy)getOneIntersectingObject(Enemy.class);
Boss1Part1 boss1Part1 = (Boss1Part1)getOneIntersectingObject(Boss1Part1.class);
Boss1Part2 boss1Part2 = (Boss1Part2)getOneIntersectingObject(Boss1Part2.class);
Boss1Part3 boss1Part3 = (Boss1Part3)getOneIntersectingObject(Boss1Part3.class);
Boss1Part4 boss1Part4 = (Boss1Part4)getOneIntersectingObject(Boss1Part4.class);
Boss1Part5 boss1Part5 = (Boss1Part5)getOneIntersectingObject(Boss1Part5.class);
if (enemy != null)
{
enemy.hit(shotStrengh);
getWorld().removeObject(this);
}
else if (boss1Part1 != null)
{
if (getAlphaAtFoot(boss1Part1) > 200)
{
boss1Part1.hit(shotStrengh);
getWorld().removeObject(this);
}
}
else if (boss1Part2 != null)
{
if (getAlphaAtFoot(boss1Part2) > 200)
{
boss1Part2.hit(shotStrengh);
getWorld().removeObject(this);
}
}
else if (boss1Part3 != null)
{
if (getAlphaAtFoot(boss1Part3) > 200)
{
boss1Part3.hit(shotStrengh);
getWorld().removeObject(this);
}
}
else if (boss1Part4 != null)
{
if (getAlphaAtFoot(boss1Part4) > 200)
{
boss1Part4.hit(shotStrengh);
getWorld().removeObject(this);
}
}
else if (boss1Part5 != null)
{
if (getAlphaAtFoot(boss1Part5) > 200)
{
boss1Part5.hit(shotStrengh);
getWorld().removeObject(this);
}
}
else if (getX() >= 1190 || getY() >= 856 || getY() <= 0 )
{
getWorld().removeObject(this);
}
}
private int getAlphaAtFoot(Actor actor) // actor is the platform in your case
{
int playerX = getX(); // the x at center of player
int playerY = getY()+getImage().getHeight()/2; // the y at foot of player
int xDiff = actor.getX()-playerX; // the difference along the x-axis
int yDiff = actor.getY()-playerY; // and y-axis of the two actors
int xOff = actor.getImage().getWidth()/2-xDiff; // the pixel's x
int yOff = actor.getImage().getHeight()/2-yDiff; // and y offsets in the image
if (xOff < 0 ||
yOff < 0 ||
xOff >= actor.getImage().getWidth())
return 0;
if (yOff >= actor.getImage().getHeight()) return 255;
return actor.getImage().getColorAt(xOff, yOff).getAlpha(); // return the alpha of that pixel's color
}