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

2012/12/23

Making and using a list

Minion1 Minion1

2012/12/23

#
So I admit that in class, the list part just went straight over my head. I'm still not certain what the difference is between an ArrayList and a List, and I apparently don't remember how to implement a list. Here's what I need to do: I need to create a list of all the "Tile" class objects in the world. I then need to use that list to remove all of those particular objects. Unless anyone here knows of a better way to remove all of a particular class of object from the world?
Minion1 Minion1

2012/12/23

#
AH HA! Never mind this question, I figured it out with the help of another thread here in the forum. Now I have a new question: I need to make the tiles on my game "obstacles" so that no enemy or hero can walk through them. I would like to have a blanket code encompass every tile on the game, meaning that any and all tiles are obstacles and cannot be walked over or under. I'm searching for an answer right now. I know how to implement collision detection, but I don't know how to tell my hero to NOT go into the tiles.
danpost danpost

2012/12/23

#
Check what possible methods might come in handy in the World class documentation of greenfoot.
Minion1 Minion1

2012/12/23

#
Sounds suspiciously like, "This should be obvious." Lol. I've been looking. I can see plenty of collision detection methods, but I can't seem to place my finger on a method that will prevent the mixing of two objects.
Minion1 Minion1

2012/12/23

#
By the by, danpost, you are a real help to people on this forum. It seems you make a dedicated habit out of trying to assist people. Thank you for that.
Minion1 Minion1

2012/12/23

#
I'm hoping that I don't have to specify to my moving classes that if they hit a Tile they'll need to reverse their direction, or some such. That's busy work code. There's got to be a method that just prevents actors from intersecting altogether...
Minion1 Minion1

2012/12/23

#
I have found a solution, though it's not the solution I was hoping for. Greenfoot doesn't seem to have any sort of a "prevent intersection" method, so for the time being I'm just telling each moving character to negate their speed when they hit a Tile. Again, not the solution I was hoping for.. but acceptable.
danpost danpost

2012/12/23

#
The Actor class does have a 'getOneObjectAtOffset(dx, dy, class)' method and a 'getObjectsAtOffset(dx, dy, class)' method which could be used for just that purpose.
JimmyFake JimmyFake

2012/12/24

#
You could also store the current location of your Hero(,each moving Charakter, whatever) with methods like getX(), getY() and eventually getRotation(). After the Hero takes one step you check for Collision and restore his old position with methods like setLocation(), setRotation().
danpost danpost

2012/12/24

#
@JimmyFake, Minion1 was looking for a way to check for possible future intersections; he called what he was looking for a 'prevent intersection' method.
JimmyFake JimmyFake

2012/12/24

#
Sorry, I did understand, that he wants to make every Tile an obstacle ( not passable by an character or something else). What I posted would have the effect in game, as you wouldn't see how the charakter moves a bit into the obstacle and is then set back. Sorry, for misleading hints, if I misunderstood ^^
Minion1 Minion1

2012/12/24

#
JimmyFake, thanks for the help. It seems that the option I'm using is the best one for now, although it does have drawbacks. My hero and enemies occasionally get "stuck" on the side of the tiles. For instance, if I approach the square tile from above, touch it, then immediately turn left or right, I can't move. I have to move upwards a pinch to free up the character. It's not perfect, but any attempt to set the character back a pinch results in the occasional bug of enemies and the hero getting stuck, then turning around, then passing slowly through the tiles. It's so awkward. Lol.
Minion1 Minion1

2012/12/24

#
The game is shaping up pretty nicely! I'm very proud even if it is not really much of a game. For my second game ever, it's not too bad. The hero can now move seamlessly between 9 areas, with 4 different monsters, one item to pick up, and even some music I added. I'm having a good time with this.
You need to login to post a reply.