This site requires JavaScript, please enable it in your browser!
Greenfoot back
ewc0707
ewc0707 wrote ...

2013/11/20

Explosions aren't showing up where they should!

ewc0707 ewc0707

2013/11/20

#
I have a mario type game with a scrolling world. When my character intersects with a bomb an explostion is suppossed to appear but when he hits a bomb after scrolling through the world the explosion is not added in the right spot. I have observed that it is added but only where the first bomb is no matter which one he intersects. Any suggestions on how to fix this?
danpost danpost

2013/11/20

#
Please show the code for the intersection of character and bomb; plus the Bomb class.
ewc0707 ewc0707

2013/11/21

#
public class Bomb extends Actor { /** * Act - do whatever the Bomb wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { checkCollision(); } public void checkCollision() { Actor a = getOneIntersectingObject(Steve.class); if (a != null) { World world = getWorld(); world.addObject(new Explosion(), getX(), getY()); world.removeObject(this); } }
ewc0707 ewc0707

2013/11/21

#
I also have this to remove the character(Steve) private void checkCollision2() { Actor a = getOneIntersectingObject(Explosion.class); if (a != null) { World world = getWorld(); world.removeObject(this); }
danpost danpost

2013/11/21

#
I do not see anything here that would cause the behavior you stated above. Please supply the code you are using to add the objects into the world (the world constructor and any method it calls).
ewc0707 ewc0707

2013/11/25

#
public class Level1 extends Sworld { public Level1() { this (new Steve()); } /** * Creates a scrolling world using a main actor, a background, some obstacles, and a non-scrolling score. */ public Level1(Steve steve) { super(900, 600, 1, 2000); addMainActor(new Steve(), 50, 520, 250, 300); GreenfootImage bg = new GreenfootImage("sky.jpg"); setScrollingBackground(bg); int i = 0; while (i < 100) { Block Block = new Block(); addObject (Block, i*50 + 25, 575); i = i + 1; } addObject(new Block2(), 1400, 445); addObject(new Block2(), 1450, 445, true); addObject(new Block2(), 1500, 445, true); addObject(new Block2(), 1550, 445, true); addObject(new Score(), 40, 40, false); //Bananas addObject(new Bananas(), 150, 540); addObject(new Bananas(), 225, 540); addObject(new Bananas(), 350, 440); addObject(new Bananas(), 450, 340); addObject(new Bananas(), 900, 240); addObject(new Bananas(), 1100, 540); addObject(new Bananas(), 1400, 540); addObject(new Bananas(), 1400, 415); addObject(new Bananas(), 1550, 415); addObject(new Bananas(), 1670, 540); addObject(new Bananas(), 1850, 540); //First set of stairs addObject(new Block2(), 300, 525, true); addObject(new Block2(), 300, 475, true); addObject(new Block2(), 350, 525, true); addObject(new Block2(), 350, 475, true); addObject(new Block2(), 400, 525, true); addObject(new Block2(), 400, 475, true); addObject(new Block2(), 400, 425, true); addObject(new Block2(), 400, 375, true); addObject(new Block2(), 450, 525, true); addObject(new Block2(), 450, 475, true); addObject(new Block2(), 450, 425, true); addObject(new Block2(), 450, 375, true); addObject(new Block2(), 500, 525, true); addObject(new Block2(), 500, 475, true); addObject(new Block2(), 500, 425, true); addObject(new Block2(), 500, 375, true); addObject(new Block2(), 500, 325, true); addObject(new Block2(), 500, 275, true); addObject(new Block2(), 550, 275, true); //Last platform addObject(new Block2(), 900, 525, true); addObject(new Block2(), 900, 475, true); addObject(new Block2(), 900, 425, true); addObject(new Block2(), 900, 375, true); addObject(new Block2(), 900, 325, true); addObject(new Block2(), 900, 275, true); addObject(new Block2(), 950, 525, true); addObject(new Block2(), 950, 475, true); addObject(new Block2(), 950, 425, true); addObject(new Block2(), 950, 375, true); addObject(new Block2(), 950, 325, true); addObject(new Block2(), 950, 275, true); addObject(new Block2(), 1000, 525, true); addObject(new Block2(), 1000, 475, true); addObject(new Block2(), 1000, 425, true); addObject(new Block2(), 1000, 375, true); addObject(new Block2(), 1000, 325, true); addObject(new Block2(), 1000, 275, true); addObject(new Platform(), 750, 275); i = 0; //Bombs while (i < 5) { Bomb Bomb = new Bomb(); addObject (Bomb, i*75 + 550, 525); i = i + 1; } addObject(new Bomb(), 1250, 525, true); addObject(new Bomb(), 1720, 525, true); //Flys addObject(new Fly(), 10+Greenfoot.getRandomNumber(2000), Greenfoot.getRandomNumber(600)); addObject(new Fly(), 10+Greenfoot.getRandomNumber(2000), Greenfoot.getRandomNumber(600)); addObject(new Fly(), 10+Greenfoot.getRandomNumber(2000), Greenfoot.getRandomNumber(600)); addObject(new Fly(), 10+Greenfoot.getRandomNumber(2000), Greenfoot.getRandomNumber(600)); addObject(new Fly(), 10+Greenfoot.getRandomNumber(2000), Greenfoot.getRandomNumber(600)); addObject(new Fly(), 10+Greenfoot.getRandomNumber(2000), Greenfoot.getRandomNumber(600)); addObject(new Fly(), 10+Greenfoot.getRandomNumber(2000), Greenfoot.getRandomNumber(600)); addObject(new Fly(), 10+Greenfoot.getRandomNumber(2000), Greenfoot.getRandomNumber(600)); addObject(new Fly(), 10+Greenfoot.getRandomNumber(2000), Greenfoot.getRandomNumber(600)); addObject(new Fly(), 10+Greenfoot.getRandomNumber(2000), Greenfoot.getRandomNumber(600));
danpost danpost

2013/11/25

#
To add a scrolling object (bomb) in an actor class, you need to do this:
((Sworld)getWorld).addObject(new Bomb(), getX(), getY());
The '((Sworld)getWorld)' part makes the bomb a scrolling object.
ewc0707 ewc0707

2013/11/26

#
I dont't want the bomb to scroll, I want the explosion to.
danpost danpost

2013/11/26

#
Then use that same format for adding the new Explosions into the world (instead of the Bombs as I suggested above).
ewc0707 ewc0707

2013/11/26

#
Ok thank you very much.
You need to login to post a reply.