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

2013/9/11

plz help

manish123 manish123

2013/9/11

#
hello! i am having trouble getting my character(which is a block) turn sharp corners like in the game tron and the only turn command i know is turn(); which is not of much use because my block turns in a circle- where i want it to cut sharp can someone plz help me with this?
manish123 manish123

2013/9/11

#
in case anybody is wondering this is what i have so far in my character class: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class redBlock here. * * @author (your name) * @version (a version number or a date) */ public class redBlock extends platformMover { /** * Act - do whatever the redBlock wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(3); if(getOneIntersectingObject(blueBlock.class) != null) { die(); } if(getOneIntersectingObject(blueWall.class) != null) { die(); } } public void die() { World world ; world = getWorld(); world.removeObject(this); } }
danpost danpost

2013/9/11

#
The code given does not show any 'turn' or 'setRotation' method calls. If they are in the platformMover class, you should be showing that class.
manish123 manish123

2013/9/11

#
oops you're right danpost! i must have erased that method and forgot about it ill post it now import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class redBlock here. * * @author (your name) * @version (a version number or a date) */ public class redBlock extends platformMover { /** * Act - do whatever the redBlock wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(3); if(getOneIntersectingObject(blueBlock.class) != null) { die(); } if(getOneIntersectingObject(blueWall.class) != null) { die(); } if(Greenfoot.isKeyDown("left")) { turn(90); //this is the problem, all the block does is turn in a circle but i want it to turn sharp } }
danpost danpost

2013/9/11

#
The 'isKeyDown' method is returning 'true' every act method that the key is held down, causing your actor to rapidly move in a very tight circle. Three ways to correct it are: (1) use the 'getKey' method which only returns 'true' once each time the key is pressed and released; or (2) add a timer to what you have, to increase the size of the circuit the actor takes (3) add a boolean to the instance to track whether the key has been found pressed or not; and code something like the following: if the boolean for last key state is false and the key is found down, then turn and set the Boolean to true if the boolean for last key state is true and the key is found not down, then set boolean back to false (1) and (3) will act similar except that the turn action will occur when the key is pressed in (3) and when the key is released in (1).
manish123 manish123

2013/9/11

#
ok ill try these solutions, thanks!
You need to login to post a reply.