| Input.KeyDown Troubles 
 
	 
	
		| Author | Message |   
		| Flashkicks 
 
  
 
 
 | 
			
				|  Posted: Tue Nov 23, 2004 12:37 pm    Post subject: Input.KeyDown Troubles |  |   
				| 
 |  
				| Hey ppl's.  yes, it is I; Fashkicks, and I am stuck.  You may find this exceedingly funny but I havent programmed in a VERY LONG time and I was told to make a proggy that just simply makes a spaceship fly around in a window and when the up arrow is pressed the velocity [speed] is increased by one and when the down arrow is pressed the velocity is decreased by one.  I started and am having trouble bcuz my "array subscript is out of range" ..  I hate that problem cuz I rememebr ALWAYS getting that  Anyways, any help would be appreciated and yes- I DO realize my horrible style  ..lol.  If you think you can clean it up a bit then by all means, do so.  In the mean time- it sure would be ncie just to see my program run  ..lol.. ~Flashkicks
 
 PS:  Yes I DO realize also that my View.Update is messing up- I was going to fix that once I got everything werking..
 
 	  | code: |  	  | var bg : int := Pic.FileNew ("mountain_background.jpg")
var pic : int := Pic.FileNew ("spaceship.bmp")
 var x, y, dirx, diry : int := 0
 dirx := 5
 diry := -5
 randint (x, 0, maxx)
 randint (y, 0, maxy)
 % Pic.SetTransparentColor (pic, brightred)
 Pic.Draw (bg, 0, 0, picCopy)
 setscreen ("graphics:768;512")
 setscreen ("offscreenonly")
 
 process Control
 var input : array char of boolean
 loop
 Input.KeyDown (input)
 if input (KEY_UP_ARROW) then
 dirx := dirx + 1
 diry := diry + 1
 elsif input (KEY_DOWN_ARROW) then
 dirx := dirx - 1
 diry := diry - 1
 end if
 end loop
 end Control
 fork Control
 
 loop
 Pic.Draw (pic, x, y, picMerge)
 x := x + dirx
 y := y + diry
 if x < 0 or x > maxx then
 dirx := -dirx
 delay (15)
 end if
 if y < 0 or y > maxy then
 diry := -diry
 delay (15)
 end if
 % Pic.Draw (pic, x, y, picMerge)
 View.Update
 end loop
 
 | 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| Delos 
 
  
 
 
 | 
			
				|  Posted: Tue Nov 23, 2004 2:56 pm    Post subject: (No subject) |  |   
				| 
 |  
				| 	  | code: |  	  | 
if input (KEY_UP_ARROW) then
 
 | 
 
 Also, you don't need a process to run Input.KeyDown(), just incorporate it directly into your main loop.
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Flashkicks 
 
  
 
 
 | 
			
				|  Posted: Wed Nov 24, 2004 1:24 pm    Post subject: (No subject) |  |   
				| 
 |  
				|  Haha.  Okay, that was as dumb mistake on my behalf.  But if you have actually comiled this then you would see that the program still messes up.  It continually goes faster and then just stops running...  Umm..  You guys are still welcome to help:D..lol.. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Flashkicks 
 
  
 
 
 | 
			
				|  Posted: Fri Nov 26, 2004 1:34 pm    Post subject: (No subject) |  |   
				| 
 |  
				| Three days have passed and still; no one has been able to help...  Is there seriously anyone out there who cant figure this out??..  Cuz if so-thats sad..  I know this should be pieces of cake for you guys...  Anyhoo- Ill keep trying..  Tony, it would be nice to hear from you  .. ~Flaskicks
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Delos 
 
  
 
 
 | 
			
				|  Posted: Fri Nov 26, 2004 2:41 pm    Post subject: (No subject) |  |   
				| 
 |  
				| Try adding a delay() to your control process. 
 Even better yet, trash the process and incorporate your movement into your main loop.  And add a delay() to that.
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		|  |  
 |