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

2017/8/15

how can i make my character move only on a particular space

NAMYA1403 NAMYA1403

2017/8/15

#
i have been wanting to develop a game something like the snake but the
if (Greenfoot. isKeyDown("left"))
{
turn(-3)
}
doesnt just follow the background squares and keep moving over them PS= Sorry for such questions, i'm a beginner :)
danpost danpost

2017/8/15

#
Not enough information is given to properly help you. Supplying how your world is created (its dimensions and cell size) would shed some light on how the actors are contained within the world. Supplying how the images of the background squares are set may also be needed. Posting your subclass of World may aid within these. And what do you mean by "moving over them". It kind of sounds like you have code for a non-grid world that you are trying to use for a grid world (a world whose cell size is much larger than one). You should also state what kind of world you are trying to create and exactly what you want the various key presses to accomplish. This can help to verify that the code you already have is actually what you are wanting. Showing the code to the subclass of Actor for the snake would also help in this regard.
Venbha Venbha

2017/8/15

#
@NAMYA1403, Why not try
if(Greenfoot. isKeyDown("left"))
{
        setRotation(180);
         move(5);
}
Whenever you press left key, it sets rotation only to 180* degrees. PS= It would rotate the actor 180*. I mean the image of the actor is turned, and the actor will move 5 cells backward per second. PPS= I wanted to give you some information to help you. PPPS= If some thing is wrong, ask me and I will figure the right code!
NAMYA1403 NAMYA1403

2017/8/15

#
Venbha wrote...
@NAMYA1403, Why not try
if(Greenfoot. isKeyDown("left"))
{
        setRotation(180);
         move(5);
}
Whenever you press left key, it sets rotation only to 180* degrees. PS= It would rotate the actor 180*. I mean the image of the actor is turned, and the actor will move 5 cells backward per second. PPS= I wanted to give you some information to help you. PPPS= If some thing is wrong, ask me and I will figure the right code!
thnx Venbha but this is not exactly what im wanting, should i make the background consisting of severaal different squares as characters and allow movement only on collision?'
danpost danpost

2017/8/15

#
NAMYA1403 wrote...
should i make the background consisting of severaal different squares as characters and allow movement only on collision?'
As I now perceive what you are trying to do, yes -- that would help. To move 5 squares per second, you will need an act counter and move one square every time the counter reaches 12 (resetting the counter to zero when you move). All movement controls should be taken in together and then a determination as to any given direction can be established. That is, if more than one key is down, no movement or no change in movement, depending on what you want, should be allowed.
You need to login to post a reply.