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

2014/5/29

nothing happen until is key is pressed

sumrandom sumrandom

2014/5/29

#
How to make it that nothing moves until the left,right,up or down key is pressed?
danpost danpost

2014/5/29

#
I think you need to be a bit more specific as to what you are trying to do. Like, give info as to when you are trying to do this; whether you will be doing this just once at whatever time or multiple times at specified times include what specified times); whether the arrow keys are supposed to control a specific object or not; etc.
lordhershey lordhershey

2014/5/29

#
I think he is just looking for a variable that makes sure no one acts until the player moves. I have done something like this:
class Player extends Actor{
static boolean hasMoved = false;

  void act()
  {
    //input code here and if input has happened then set hasMoved to true
    hasMoved = true;

    //never set it back to false, until the player dies.

  }
}
in every monster or anything that can move or do something act method:
//every other act (not the player class) in the universe has this in it:
void act()
{
  if(!Player.hasMoved)
  {
    return;
  }
  // the rest of your act routine goes here
}
sumrandom sumrandom

2014/5/30

#
cheers
AntonB AntonB

2014/5/30

#
Hello Lord Hershey. Thank you for being so kind and informative to a new programmer- however, I must inform you that this is most likely a student who is doing the course I coordinate (Programming Fundamentals) at the University of Western Sydney (UWS). For their major assignment, I have assigned my students the task of recreating the popular 'Pac man' game in Greenfoot, and I have given them a few methods pre-written to help them out. The lectures I have given, and the information supplied online at the UWS site are more than enough to be able to complete this assignment, and I am disappointed they are seeking help online- especially at such a late date, given that the assignment's final submission date is in 4 hours. Please do not assist my students in the future. To the student, 'sumrandom', if I do find this code in any assignment you will be investigated for further plagiarism. Kind regards, Anton Bogdanovych.
lordhershey lordhershey

2014/5/30

#
@Anton investigate away, it cannot be plagiarism if I wrote the code. I will assist anyone who asks anything if I can answer it. I do not appreciate veiled threats. Thanks.
AntonB AntonB

2014/5/30

#
Hi Lord Hershey, thanks for your response. I did not intend at all to reprimand you- my concerns were to my student, "sumrandom". In the UWS handbook, the code of conduct contains a section about plagiarism. Unless otherwise specified, all work is to be the student's original contribution. If he were to take your code and insert it into his major assignment, I would be forced to penalise him and contact the university administration. Thanks for being understanding, Anton Bogdanovych.
lordhershey lordhershey

2014/5/30

#
I can understand that, if you want to check for illicit collaboration use a tool like JPlag there are others out there as well. Sometimes a regular diff on an object file will reveal cheating, or you can use a printout of javap: C:\Users\JohnHershey\Desktop\greenfoot\scenarios\DragonFire>javap Dragon Compiled from "Dragon.java" public class Dragon extends greenfoot.Actor { static greenfoot.GreenfootImage image; static greenfoot.GreenfootImage imagefire; public greenfoot.GreenfootImage use_image; public greenfoot.GreenfootImage use_imagefire; boolean goLeft; int walkcounter; int headupcount; public int firecounter; public int speed; public int firecounterreset; public int walkcountermax; public int walkcounterdivisor; public int bulletspeed; Dragon$State playerState; public Dragon(); public void act(); static {}; } even if they change the variable or routine names you will be able to see similar structures, if they don't then that just makes your job much easier.
AntonB AntonB

2014/5/30

#
Fortunately, the UWS administration is in possession of very advanced heuristic systems to detect plagiarism- specifically, those to detect similarities in the underlying code structure regardless of changes in variables names and ordering of various things. Anton Bogdanovych
You need to login to post a reply.