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

Discussions

You need to login to take part
Rss

Current Discussions

ye-roon

setDirection

By ye-roon, with no replies.
Hello everyone, I'm quite new to all this and i dont know how to properly explain it, but i will try my best. Also, this would probably work best if i could upload the whole scenario somewhere, but i can not seem to find the upload button. My problem is as follows, i am currently creating a simple game, where a nerdy guy/loser needs to get to school. The main blueprint is done, and he can move and if he hits the wrong obstacle he fails. The powerups are in place but currently do not do anything, this was just done to see where they would be. Its for a school project and we were designated team L, hence the Loser ^^. The loser has 2 different kinds of moving enemies and 1 kind that is stationary(they are girls! so stationary is scary enough for our nerd). The moving enemies consist of a couple of Dogs and some Jocks that are always eager to make our Losers life misarable. So i was digging around in some code and i found that i could re-use some code from the wombat game to make our Enemies move. I made North 0, and South 1 and removed East and West since its a topdown game and the enemies do not have to move in another direction for now. Maybe if we expand on this project in the future, for now moving up and down is enough. So i changed the code from the wombat scenario in such a way that the enemy will turn around when he hits a piece of Furnature, we have put all our immovable objects as a subclass of Furnature(so walls, the doghouse, school tables). The reason for this is it makes it easier to program, for i can now just use: (Furnature.class), rather then having to make different statements for every piece of furnature. Our walls are set in a maze like pattern. The dogs move between their doghouses and the outerwall of the school. What it does now is: it will automaticly move towards the South. When it hits the the wall in the south, its set the direction to the North and they will happily move north. But then when they hit the north wall they get stuck in a loop and the only thing you can see is the image changing from setDirection(180) to setDirection(0). It doesnt move down anymore. I have tried this with both the isTouching() method and the getOneIntersectingObject() but both end up with the same problem. So i thought, well the images have different pixel sizes, what if i change one with a 30x30 image. But that didnt work either. I will paste the code below. So if anyone has an idea where this goes amiss, that will be gladly appreciated. Also, english is not my native language, so excuse my grammar/spelling mistakes, if applicable. Kind regards, ye-roon <Code Omitted>