
-----------------------------------
metachief
Mon Feb 04, 2008 5:47 pm

sprite help again corrected
-----------------------------------
what my code does is: whn i press either 'a' or 'd' then i hvae a bunch of pictures drawn (movement of a character).
PROBLE: the problem is that when i press one of the two keys it draws the pictures nonstop untill the last one is drawn.
For example:

if key ('a') then 

loop 
right := false 
left := true 

Pic.Draw (pic1l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic2l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic3l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic4l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic5l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic6l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic7l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic8l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic9l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic10l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 
exit 
end loop 
end if 

in this it will exit when picture "pic10l" is drawn.

WHAT I WANT IT TO DO: i wan it to stop drawing when the key that i press is released.
so for example when it is on picture "pic5l", i want it to stop on the picture when i let go of the button i pressed.









The whle code------> :


proc game 

Window.Hide (main_win) 
campaign_win := Window.Open ("position:centre,centre,graphics:850,610,title:CAMPAIGN") 

var left, right : boolean := false 
const grav := 1 
const jump_s := 1.2 
var run_s : real 
var x, y : real 
var vel_y : real 
var jump : boolean 
var key : array char of boolean 

run_s := 13 
x := 400 
y := 8 
jump := false 

View.Set ("offscreenonly") 

loop 

Input.KeyDown (key) 

if key ('a') then 

loop 
right := false 
left := true 

Pic.Draw (pic1l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic2l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic3l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic4l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic5l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic6l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic7l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic8l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic9l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic10l, round (x - 70), round (y), picMerge) 
x := x - run_s 
delay (60) 
View.Update 
cls 
exit 
end loop 
end if 

if key ('d') then 
loop 
left := false 
right := true 
Pic.Draw (pic1r, round (x), round (y), picMerge) 
x := x + run_s 
delay (60) 
View.Update 
cls 


Pic.Draw (pic2r, round (x), round (y), picMerge) 
x := x + run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic3r, round (x), round (y), picMerge) 
x := x + run_s 
delay (60) 
View.Update 
cls 


Pic.Draw (pic4r, round (x), round (y), picMerge) 
x := x + run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic5r, round (x), round (y), picMerge) 
x := x + run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic6r, round (x), round (y), picMerge) 
x := x + run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic7r, round (x), round (y), picMerge) 
x := x + run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic8r, round (x), round (y), picMerge) 
x := x + run_s 
delay (60) 
View.Update 
cls 


Pic.Draw (pic9r, round (x), round (y), picMerge) 
x := x + run_s 
delay (60) 
View.Update 
cls 

Pic.Draw (pic10r, round (x), round (y), picMerge) 
x := x + run_s 
delay (60) 
View.Update 
cls 
exit 
end loop 
end if 

if key ('w') and jump = false then 
jump := true 
vel_y := jump_s 
Pic.Draw (pic11r, round (x), round (y), picMerge) 
View.Update 
cls 
end if 

if jump = true then 
if y < 200 then 
jump := false 
end if 
y := y + vel_y 
vel_y := vel_y - grav 
end if 

end loop 

Window.Close (campaign_win) 
Window.Show (main_win) 
Window.SetActive (main_win) 

end game

-----------------------------------
StealthArcher
Mon Feb 04, 2008 6:04 pm

RE:sprite help again corrected
-----------------------------------
Please use the code tags.

-----------------------------------
Zampano
Mon Feb 04, 2008 6:40 pm

Re: sprite help again corrected
-----------------------------------
When the user presses 'a', look what will happen between the if and the end if: you will enter an loop and in it you will draw each picture in sequence, then exit the loop (which you've gone through once), and only them will you continue checking if 'a' is down. Thus, if the key is pressed once, the whole group of Pic.Draws acts; but since you want to keep the stream of sprites if the button is kept down, you will have to check if the button WAS down a second ago when you last checked the keyboard and still IS down now. Thus, you will have have to store information regarding the last state of the computer in the memory. Think of how to do that, then figure out how you could recall which sprite it is you want to draw and how you could manipulate that value to act as it should if the the key is held down.
