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

2017/8/3

How to add collision to a top down greenfoot game?

lava1234567890 lava1234567890

2017/8/3

#
I am making a top down shooter where the map moves around the player to keep the player in the centre of the screen at all times, however, i want to add collision to the map. The link to view the whole project is here: https://drive.google.com/open?id=0B26Bk-TJYqm-VjVWR2htbnpqWHM
danpost danpost

2017/8/3

#
Usually, the player's movement is done normally (in the class of the player; with collision checking to follow), then the world moves everything (the map and all actors) to place the player back in the middle. However, I guess you could call a method in the class of the player to see if it can move somewhere and, depending on a returned boolean value, have the map move (or not). Still, the player will need to move and all actors will need to be moved (including the player, again) when the map moves (to keep everything with respect to one another).
lava1234567890 lava1234567890

2017/8/3

#
How would i detect that a player has reached a certain area if the map moves instead of the player?
lava1234567890 lava1234567890

2017/8/3

#
How would i also anchor actors with the map actor so it would move when the map moves?
Agent40 Agent40

2017/8/4

#
There are a few ways you can make a player stay in the middle of the world including setting up an un-bound world and creating a tracker for the player that moves the world around the player instead of the player itself (Different if you're making a side scroller, e.i Jumping). Now for Collision of the Environment, you can rather use this code here:
Actor ActorName = getOneIntersectingObject( ActorName.class); 
            if (ActorName != null)                                                     
                setLocation(getX() Number/Varible, getY() Number/Varible);
or set up a more specific method that will look for a certain point on the un-bound world using x,y locations. Now on the other hand to "Anchor" actors you can use a 2d array which will lock those Actors into place unless moved using a certain bound key or dragging while paused. P.S. Didn't see you had already set up the un-bound world, Nice.
danpost danpost

2017/8/4

#
You may want to check out my scrolling tutorial to see how it all is accomplished.
You need to login to post a reply.