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

2014/4/30

Pacman game

dangwang dangwang

2014/4/30

#
Hello all. I'm creating a pacman based game for my project at school and I've bumped into a little problem. I am able to make clara move with the directional buttons however unable to make her move continuously in one direction. I do not want to post my code up as misconduct is very strict at my school. also i have set the integer value of the command move(int) to 1 but it is too fast. is the any way to slow the speed of clara? Any suggestions is appreciated. :)
danpost danpost

2014/4/30

#
Both of these issues, continuous movement and speed, can be solved by using instance fields. *** background info Fields declared within the class, but outside any methods. Each instance created in the class is given a separate field with the names provided to hold a value for that particular instance (each instance can have a different value for a field given them with the same name). *** An 'int' field can be used to hold the current (or last) direction that the pacman had moved and used to set the continuing movement in that direction if not directed or is unable to change directions. Set the field each time a move is made to the direction moved. An 'int' field can be used as a timer to slow down or 'restrict' when to move. Increment the field, when a certain value is reached, allow movement and reset the field back to zero.
You need to login to post a reply.