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

2013/12/10

Problem with enemy

Nooyi Nooyi

2013/12/10

#
Hey, I want to include an enemy in my game. The Problem: the enemy is running into trees (most not, but sometimes) and so I'm searching for my fault - but haven't found it yet. The thing is, my enemy sometimes thinks that there is a tree e.g. to his right, but there isn't (I found this out by step-by-step controlling). Maybe you could help me, please? :) This is the Code for treeRight (same for left, up and down (except for the names and the koordinates)): public boolean treeRight() { int x = getX(); int y = getY(); if(getObjectsAtOffset(x+1, y, tree.class) == null) { return false; } else { return true; } thank you a lot! :)
danpost danpost

2013/12/10

#
Does your world have a cellsize greater than one?
Nooyi Nooyi

2013/12/10

#
yes, it has. it's 60 (for a 10x8 field)
danpost danpost

2013/12/11

#
The method you provided will return the correct boolean value. Your problem is elsewhere. You may have to show the entire class for help.
You need to login to post a reply.