This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-04-13 13:00:25

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

Diagonal movement help.

I'm making this game where the sprite can move using the arrow keys. The sprite can move at 3 different speeds.
Normal speed (nothing extra pressed)
Slow speed (while holding "v")
Fast speed (while holding "b")

I want the sprite to be able to move diagonally if two keys are held down. This works perfectly fine at normal speed but diagonal movement is partly restricted on slow and fast speed.

On slow speed the Sprite can move Diagonally up-right and down-right but not up-left and down-left.

On fast speed, the sprite can move diagonally up-right and up-left but not down-right and down-left. Please help thanks. Here's the script;

when gf clicked
<forever>
if <key[up arrow]pressed>
if <key[b]pressed>
change y by (5)
else
if <key[v]pressed>
change y by (1)
else
change y by (3)
end
end
end
if <key[down arrow]pressed>
if <key[b]pressed>
change y by (-5)
else
if <key[v]pressed>
change y by (-1)
else
change y by (-3)
end
end
end
end
when gf clicked
<forever>
if <key[right arrow]pressed>
if <key[b]pressed>
change x by (5)
else
if <key[v]pressed>
change x by (1)
else
change x by (3)
end
end
end
if <key[left arrow]pressed>
if <key[b]pressed>
change x by (-5)
else
if <key[v]pressed>
change x by (-1)
else
change x by (-3)
end
end
end
end


http://i46.tinypic.com/ao03lk.png

Offline

 

#2 2012-04-13 14:39:32

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Diagonal movement help.

Just do "if up AND right arrow clicked," and then separate for each key, for example:

forever
 if < < key [up arrow v] pressed > and < key [right arrow v] pressed > >
  if < key [b] pressed >
   forever if < < key [b] pressed > and < key [up arrow v] pressed > >
    change y by (5)
    change x by (5)
 
And so on, doing that separate for each block. You need to remeber to put the green AND block into the hexagon. This takes a lot of scripting, but it works.

Last edited by mythbusteranimator (2012-04-13 14:40:55)


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#3 2012-04-15 08:47:56

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: Diagonal movement help.

PhirripSyrrip wrote:

I'm making this game where the sprite can move using the arrow keys. The sprite can move at 3 different speeds.
Normal speed (nothing extra pressed)
Slow speed (while holding "v")
Fast speed (while holding "b")

I want the sprite to be able to move diagonally if two keys are held down. This works perfectly fine at normal speed but diagonal movement is partly restricted on slow and fast speed.

On slow speed the Sprite can move Diagonally up-right and down-right but not up-left and down-left.

On fast speed, the sprite can move diagonally up-right and up-left but not down-right and down-left. Please help thanks. Here's the script;

when gf clicked
<forever>
if <key[up arrow v]pressed ?>
if <key[b v]pressed ?>
change y by (5)
else
if <key[v v]pressed ?>
change y by (1)
else
change y by (3)
end
end
end
if <key[down arrow v]pressed ?>
if <key[b v]pressed ?>
change y by (-5)
else
if <key[v v]pressed ?>
change y by (-1)
else
change y by (-3)
end
end
end
end
when gf clicked
<forever>
if <key[right arrow v]pressed ?>
if <key[b v]pressed ?>
change x by (5)
else
if <key[v v]pressed ?>
change x by (1)
else
change x by (3)
end
end
end
if <key[left arrow v]pressed ?>
if <key[b v]pressed ?>
change x by (-5)
else
if <key[v v]pressed ?>
change x by (-1)
else
change x by (-3)
end
end
end
end

Fixed your script. Should be easier to read now.  big_smile

Last edited by jontmy00 (2012-04-15 08:48:26)


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#4 2012-04-15 09:29:03

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Diagonal movement help.

mythbusteranimator wrote:

Just do "if up AND right arrow clicked," and then separate for each key, for example:

forever
 if < < key [up arrow v] pressed > and < key [right arrow v] pressed > >
  if < key [b] pressed >
   forever if < < key [b] pressed > and < key [up arrow v] pressed > >
    change y by (5)
    change x by (5)
 
And so on, doing that separate for each block. You need to remeber to put the green AND block into the hexagon. This takes a lot of scripting, but it works.

Should be this

repeat until <<<not <key [b v] pressed?>> or <not <key [up arrow v] pressed?>>> or <not <key [right arrow v] pressed?>>>
change y by (5)
change x by (5)
end


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer