Alright after much trial and error Ive come up with this solution, I think the maths setup is better, i can control direction with pvx and pvy. I still dont know how to change direction when it goes outside screen, I'm guessing a getposition test, but i don't know how to reverse my equation to go in the opposite, i suppose ill have to keep working on it. Does anyone know why my input screens dont always show up?
Global px,py,pvx,py,a,t,h,g,xtx,vtx,xty,vty,A$,B$,C$,T$,h$,ship,line,liney,srx,sry
Procedure init()
InitSprite()
InitKeyboard()
srx=800
sry=600
px=0
py=0
pvx=1;velocity
pvy= 0
tmax=500
a = 0
t=0
h=0.5
g=-9.81 ; gravity
;g=-1.00 ; gravity
OpenScreen(srx,sry,32,"PBWINDOW")
UsePNGImageDecoder()
UseJPEGImageDecoder()
ship= LoadSprite(#PB_Any,"Crystal.png")
line = LoadSprite(#PB_Any,"line.png")
liney = LoadSprite(#PB_Any,"liney.png")
EndProcedure
init()
;ElapsedMilliseconds()%1000
;Repeat
Procedure movement()
t = t+1
moveflag = 0
t = t+1
xtx=px+pvx*t
xty=py+pvy*t
vtx=pvx+a*t
vty=pvy+a*t
x=xtv+vtx
y=xty+vty
A$=Str(xtx)
B$=Str(vty)
C$=Str(g)
T$=Str(t)
h$=Str(h)
h=h-0.5
g=g-9.81
;g=g-1.00
EndProcedure
Procedure draw()
TransparentSpriteColor(ship, #White)
DisplayTransparentSprite(ship,xtx-h,vty-g)
DisplaySprite(line,0,30)
DisplaySprite(liney,400,0)
;DisplayTransparentSprite(ship,0,-g)
;DisplayTransparentSprite(ship,xtx,xty-g)
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(xtx-h+80,vty-g, "xtx vtyy -g "+ A$+B$ ,#White); RGB(Random(255), Random(255), Random(255)))
; DrawText(xtx,xty, "xtx xty -g "+ A$ +A$ +C$,#Red) ; RGB(Random(255), Random(255), Random(255)))
DrawText(0,0,T$,#White)
StopDrawing()
EndProcedure
Define velocity.s
Define accel.s
CreateImage(0, 800, 600, 32,black)
Delay(100)
;ForEver
Question:
ClearScreen(0)
velocity = InputRequester("","enter velocity","")
accel=InputRequester("","enter acceleration","")
ac=Val(accel)
a=ac
z=Val(velocity)
pvx=z
Repeat
; Debug vty
; Debug xt
; Debug vt
; Debug g
ClearScreen(0)
ExamineKeyboard()
movement()
draw()
h=h-0.5
;g=g-9.81
; g=g-1.00
FlipBuffers()
Delay(40)
If xtx>800
px=0
py=0
pvx=1;velocity
pvy= 0
tmax=500
a = 0
t=0
h=0.5
g=-9.81 ; gravity
Goto Question
EndIf
If g<-600
px=0
py=0
pvx=1;velocity
pvy= 0
tmax=500
a = 0
t=0
h=0.5
g=-9.81 ; gravity
Goto Question
EndIf
If KeyboardPushed(#PB_Key_Up)
g=g+20
EndIf
If KeyboardReleased(#PB_Key_Up)
EndIf
If KeyboardPushed(#PB_Key_Left)
pvx=-1
EndIf
If KeyboardPushed(#PB_Key_Right)
EndIf
Until KeyboardPushed (#PB_Key_Escape)
End