Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
on arrowKey direction
movePerso direction
end arrowKey
command movePerso pDirection
if pDirection is "right" then
set the right of graphic "rectangle" to (the right of graphic "rectangle"" +10)
else if pDirection is "left" then
set the left of the graphic "rectangle" to (the left of graphic "rectangle" - 10)
end if
--if the left of graphic "rectangle" < 0 then
--set the left of the graphic "rectangle" to 0
--end if
end movePerso
on keyDown touche
if touche is space then
Jump
--else
-- put touche
end if
end keyDown
command Jump
put 0 into varUp
repeat until varUp = 5
wait 25 milliseconds
set the top of graphic "rectangle" to (the top of graphic "rectangle" - 20)
add 1 to varUp
end repeat
wait 100 milliseconds
put 0 into varDown
repeat until varDown = 5
wait 75 milliseconds
set the top of graphic "rectangle" to (the top of graphic "rectangle" + 20)
add 1 to varDown
end repeat
end Jump
I don't know how i can do for move the rectangle at the same time jump or jump and move.
Last edited by problème on Sat Nov 21, 2015 9:57 pm, edited 1 time in total.
I can't understand how do I proceed because when the command Jump is using , i don't know how know if the key left or right is using.
(i don't undersand the code in the mini-game ^^)
To jump and move or to jump in the direction that you were moving, you have a number of options.
1. When your dog (rectangle) moves left or right, save that in a global. Then when the dog jumps, also move it in the same direction as the last move. In your jump code when you move him up, do a "movePerso pDirection" and when you move him down, do another "movePerso pDirection" that will have him jump and move in the same direction he was moving in.
2. Instead of using "set the top..." Get the current loc of your graphic, and add a value to each axis (+ or - 10 to the x value and 20 to the y value) then use a "set the loc..." with the new x and y values
3. For smoother motion, use a "move..." instead of " set the loc...".
Experiment, play around with each of those and see which you prefer
problème wrote:I can't understand how do I proceed because when the command Jump is using , i don't know how know if the key left or right is using. (i don't undersand the code in the mini-game ^^)
The best way to understand source code is
printing it in paper and add explanatory
and meaningful comments to it.
Of course, you could do exactly
the same thing in the computer.
My personal preference is to keep working
and relieve eye strain, wherever I get
the chance...
Hello,
I do this but, it don't really work. I don't know how i know if the rectangle is moving for do a normal jump vertical without direction. And when i do a jump with direction, during the jump i can't do right of left
global speed, speedJump, direction, isMove
on arrowKey d
movePerso d
end arrowKey
on keyDown touche
if touche is space then
movePerso "Jump"
end if
end keyDown
on movePerso pDirection
if pDirection is "right" then
move graphic "Rectangle" relative speed,0 without waiting
put "right" into direction
else if pDirection is "left" then
move graphic "Rectangle" relative -speed,0 without waiting
put "left" into direction
end if
put true into isMove
end movePerso
on Jump
put 0 into varS
repeat until varS = 5
wait 25 milliseconds
set the location of graphic "rectangle" to (item 1 of the location of graphic "Rectangle", item 2 of the location of graphic "Rectangle" - speedJump)
movePerso direction
add 1 to varS
end repeat
wait 100 milliseconds
put 0 into varD
repeat until varD = 5
wait 75 milliseconds
set the location of graphic "rectangle" to (item 1 of the location of graphic "Rectangle", item 2 of the location of graphic "Rectangle" + speedJump)
movePerso direction
add 1 to varD
end repeat
end Jump
When code is not working as you expect, it is good to learn to "debug" your code. In most cases, the value of some variable is not what you expect it to be or you are not even getting into your code.
With most languages, you put print statements in your code to see what is happening. In the case of LiveCode, you insert "answer" statements throughout your code to see what is actually happening. In your case add statements like "answer speed", "answer direction", 'answer "in jump routine" ', etc. That way you can see where you are going and what the values are.
The better way is to get familiar with LiveCode's debugger. You can set breakpoints, look at all your variables and even step through your program one line at a time.
Try it and see if you can find the problem. If you can't, I will tell you the answer. (hint: your code is good)
Sorry, I changed some lines but i forgot to edit my message ^^
So the code work but during the jump i can't move left or right, i have wait the jump finish for choose a direction
global speed, speedJump, direction, isMove
global moveR, moveL
on preOpenCard
set the location of graphic "Rectangle" to 169,303
put 10 into speed
put 20 into speedJump
put "right" into moveR
put "left" into moveL
end preOpenCard
on arrowKey d
movePerso d
end arrowKey
on keyDown touche
if touche is space then
Jump
--else
-- put touche
--movePerso touche
end if
end keyDown
on movePerso pDirection
if pDirection is moveR then
move graphic "Rectangle" relative speed,0 without waiting
put moveR into direction
else if pDirection is moveL then
move graphic "Rectangle" relative -speed,0 without waiting
put moveL into direction
end if
end movePerso
on Jump
put 0 into varS
repeat until varS = 5
wait 25 milliseconds
set the location of graphic "rectangle" to (item 1 of the location of graphic "Rectangle", item 2 of the location of graphic "Rectangle" - speedJump)
movePerso direction
add 1 to varS
end repeat
wait 100 milliseconds
put 0 into varD
repeat until varD = 5
wait 75 milliseconds
set the location of graphic "rectangle" to (item 1 of the location of graphic "Rectangle", item 2 of the location of graphic "Rectangle" + speedJump)
movePerso direction
add 1 to varD
end repeat
end Jump
Your biggest problem are the waits in your code. Can you remove them, or make them smaller?
I also do not use the "move" command in games because in past versions of LiveCode, it tended to be slower. I have not tested it in the latest versions of LiveCode. There have been some major code changes in LiveCode so whatever specific advice that I give you may not necessarily apply in the version that you are using.
Otherwise, try different things, experiment. Try using different commands. Often there are different ways to code the same functions and some commands/ways are faster than others.
Finally see where you can simplify your code. That sometimes helps.
I try to do this, it's work, i can move during the jump.
I want to do too a normal jump without move. I can do this when the player press space key + a arrow key up or down. but if the player want to press only space key how can i do this ?
global speed, speedJump, direction --, isDogMove
global moveR, moveL
global _jumpUp
global _jumpDown
global _isJump
on preOpenCard
set the location of graphic "Rectangle" to 169,303
put 10 into speed
put 35 into speedJump
put "right" into moveR
put "left" into moveL
put 0 into _jumpUp
put 0 into _jumpDown
put false into _isJump
end preOpenCard
on arrowKey d
put d into direction
movePerso d
end arrowKey
on keyDown touche
if touche is space then
put _isJump
if _isJump is false then
Jump
end if
else
movePerso touche
end if
end keyDown
on movePerso pDirection
if pDirection is moveR then
set the location of graphic "Rectangle" to (item 1 of the location of graphic "Rectangle" + speed, item 2 of the location of graphic "Rectangle")
--put moveR into direction
else if pDirection is moveL then
set the location of graphic "Rectangle" to (item 1 of the location of graphic "Rectangle" - speed, item 2 of the location of graphic "Rectangle")
--put moveL into direction
end if
end movePerso
command JumpUp
put true into _isJump
movePerso direction
if _jumpUp <= 5 then
set the location of graphic "rectangle" to (item 1 of the location of graphic "Rectangle", item 2 of the location of graphic "Rectangle" - speedJump)
send "JumpUp" to me in 25 milliseconds
add 1 to _jumpUp
else
put 0 into _jumpUp
end if
end JumpUp
command JumpDown
put true into _isJump
movePerso direction
if _jumpDown <= 5 then
set the location of graphic "rectangle" to (item 1 of the location of graphic "Rectangle", item 2 of the location of graphic "Rectangle" + speedJump)
send "JumpDown" to me in 75 milliseconds
add 1 to _jumpDown
else
put 0 into _jumpDown
put false into _isJump
end if
end JumpDown
on Jump
JumpUp
wait 100 milliseconds
JumpDown
end Jump
I think i use the up arrow it is easier indeed ^^.
The problem I asked myself with the jump was this one : i will use the down arrow key for put a image "image2" which look like dog's head which look at the floor ( it hang his head), and i have a image "image1" when the dog do nothing.
So when i press down key -> i put image 2.
I want to do, when the down key was not press anymore -> put image 1