Spot my error "Eating dots"

Blitz3D Forums/Blitz3D Beginners Area/Spot my error "Eating dots"

Imperium(Posted 2013) [#1]
I sat down and typed this dot muncher example from a pdf. I cannot understand why when I try and move the dot with the keyboard it just keeps going to the right. I must have a error in my code:


[Using IDEal]



xlsior(Posted 2013) [#2]
Don't know what you're trying to do with the if keydown <-0.5 and such -- keydown() will return either TRUE (1) or FALSE (0), no fractional or negative values...

removing that part of the keydown lines will be the same as if keydown(200) is true, then...

[CODE];eat the dots

Graphics 640,480,16,0
SetBuffer BackBuffer()
Global status=0,x#=0,y#=0,speed#=0,dir=1

;Main loop
While Not KeyHit(1)

;refresh screen
Flip
Cls
Color 255,255,0
Rect 0,0,600,400,0
;select state
Select status
Case 0
Locate 100,100
Print "Press Enter to Start"
If KeyHit(28) InitGame()
Case 1
UpdatePlayer()
End Select
Wend

Function InitGame()

x = 320
y = 240
speed = 1
dir = 1
status = 1

End Function

Function UpdatePlayer()
;steer player
If KeyDown(200) dir=0
If KeyDown(205) dir=1
If KeyDown(208) dir=2
If KeyDown(203) dir=3

;move player
Select dir
Case 0 y=y -speed
Case 1 x=x +speed
Case 2 y=y +speed
Case 3 x=x -speed
End Select
;draw player
Color 255,255,255
Rect x,y,10,10
End Function[/CODE]


Imperium(Posted 2013) [#3]
The tutorial had both key presses and a joystick as a method for control. I should have left out "<-0.5" as you pointed out.

Thanks!