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

2015/3/4

Please!!!! Help im stuck with this

RICHJAMA RICHJAMA

2015/3/4

#
Create a new sub-class of the Animal class, called Hunter. These are the requirements for the hunter: Find a picture online that you would like to use for your hunter. Ensure that you shrink the picture enough that your hunter is appropriately sized. Add controls to the hunter that allow him to move in all four directions. When he turns left or right I want him to turn by 7 degrees, when you press back I want him to walk backwards. Ensure that the hunter doesn't run into any of the trees (if he does, he will turn 180 degrees). Ensure that the hunter doesn't walk off the edge of the world. Create a new sub-class of the Animal class called Predator. These are the requirements for the hunter: Find a picture online that you would like to use for your predator (bear, mountain lion, etc.). Ensure that you shrink the picture enough that your hunter is appropriately sized. Add random movement to your predator. Ensure that the predator doesn't run into any of the trees (if he does, he will turn 17 degrees). Ensure that the predator doesn't walk off the edge of the world. If you predator "sees" your hunter, then he will eat your hunter, play an appropriate sound, and the game is over.
RICHJAMA RICHJAMA

2015/3/4

#
I mainly need help on the random movement, ensuring they (both predator and hunter) doesn't run into the tree and turning at the edge of the world. THANK YOU!!!
danpost danpost

2015/3/4

#
Sorry. We do not do projects or assignments. We mainly help fix pre-existing code. If you have a specific problem while attempting to create code for your project or assignment, we can help. However, you should post the attempted code and explain what it does (in detail) and how that is different from what you want it to do. Use the 'code' link below the reply box to insert any codes into your posts.
RICHJAMA RICHJAMA

2015/3/4

#
import greenfoot.*; /** * Write a description of class Hunter here. * * @author (your name) * @version (a version number or a date) */ public class Hunter extends Actor { /** * Act - do whatever the Hunter wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(17); turnAtEdge(); moveWithArrows(); } /** * * */ public void moveWithArrows() { if(Greenfoot.isKeyDown("right")) { turn(7); } if(Greenfoot.isKeyDown("left")) { turn(-7); } if(Greenfoot.isKeyDown("down")) { turn(-7); } } /** * * */ public void turnAtTree() { if(Can.seeTree) turn(180); } /** * turning at worlds edge * */ public void turnAtEdge() { move(180); } } this is what i have so far what am i doing wrong
RICHJAMA RICHJAMA

2015/3/4

#
this code is making my character move irregularly and not smooth and when it hit the world it clings onto the edge as im pushing the arrow for it to move
danpost danpost

2015/3/5

#
It sure seems strange that a method that is named 'turnAtEdge' is moving the object instead of turning it. Also '17' is awfully quick for an actor to be moving (see first line in act method). Also seems silly to have two different 'if' conditions do the same action (see "left" and "down" key detection blocks).
RICHJAMA RICHJAMA

2015/3/5

#
oky thank you so much im new to green foot so my methods be out of whack. i have changed the 'if' statements and also the '17' and it helped tremendously.
You need to login to post a reply.