; This code is for my upcoming entry in the acoders competition, pllllease dont steal it.. besides
; its Not that hard To make yourself :)
; the problem im having is, time doesnt rewind quite far enough. if you need to see what i mean
; run the example, move forwards (up) and then hit enter. You probally wont get back to 0, 0, 0
Graphics3D 800, 600
SetBuffer BackBuffer()
Type Motion
Field TimeOffset ; Used to say how much time into the rewind this motion takes place
Field Length ; How long it should last
Field MotionType ; 1 - Move, 2 - Rotate
Field Vel#[2] ; Vectors
End Type
Global ActiveMove.Motion, ActiveRotate.Motion ;With Input
Global K200_State, K203_State, K205_State, K208_State
Global cube = CreateCube()
Global camera = CreateCamera()
MoveEntity camera, 0, 0, -5
SetFont LoadFont("Arial", 13)
allowingInput = True
While Not KeyHit(1)
Cls
loopStart = MilliSecs()
UpdateKeys()
If allowingInput
For m.motion = Each motion
m\timeoffset = m\timeoffset + lastLoopElapsed
If m\timeoffset > 10 * 1000 Then Delete m
Next
If KeyHit(28)
allowingInput = False: rewindTime = True: rewindTimeStart = MilliSecs()
beganRewind = MilliSecs()
EndIf
If movingTimeS = 0 Then movingTimeS = MilliSecs()
;;;; This is movement forwards and backwards ;;;;
If K200_State = 1 And K208_State = 0
ActiveMove = New Motion
ActiveMove\MotionType = 1
ActiveMove\Vel[2] = .1
MoveEntity cube, 0, 0, .1
ElseIf K200_State = 2 And K208_State = 0
If ActiveMove = Null
ActiveMove = New Motion
ActiveMove\MotionType = 1
ActiveMove\Vel[2] = -.1
EndIf
If ActiveMove\Vel[2] <> .1 Or activemove = Null
ActiveMove = New Motion
ActiveMove\MotionType = 1
ActiveMove\Vel[2] = .1
EndIf
ActiveMove\Length = ActiveMove\Length + lastLoopElapsed
ActiveMove\TimeOffset = 0
MoveEntity cube, 0, 0, .1
EndIf
If K208_State = 1 And K200_State = 0
ActiveMove = New Motion
ActiveMove\MotionType = 1
ActiveMove\Vel[2] = -.1
MoveEntity cube, 0, 0, -.1
ElseIf K208_State = 2 And K200_State = 0
If ActiveMove = Null
ActiveMove = New Motion
ActiveMove\MotionType = 1
ActiveMove\Vel[2] = -.1
EndIf
If ActiveMove\Vel[2] <> -.1
ActiveMove = New Motion
ActiveMove\MotionType = 1
ActiveMove\Vel[2] = -.1
EndIf
ActiveMove\Length = ActiveMove\Length + lastLoopElapsed
ActiveMove\TimeOffset = 0
MoveEntity cube, 0, 0, -.1
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; This is turning ;;;;
; If K203_State = 1 And K205_State = 0
; ActiveRotate = New Motion
; ActiveRotate\MotionType = 2
; ActiveRotate\Vel[2] = 2
; ElseIf K203_State = 2 And K205_State = 0
; ActiveRotate\Length = ActiveRotate\Length + lastLoopElapsed
; ActiveRotate\TimeOffset = 0
; EndIf
;
; If K205_State = 1 And K203_State = 0
; ActiveRotate = New Motion
; ActiveRotate\MotionType = 2
; ActiveRotate\Vel[2] = -2
; ElseIf K205_State = 2 And K203_State = 0
; ActiveRotate\Length = ActiveRotate\Length + lastLoopElapsed
; ActiveRotate\TimeOffset = 0
; EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EndIf
If rewindTime
If MilliSecs() > rewindTimeStart + 10 * 1000
rewindTime = False
allowingInput = True
EndIf
m.motion = Last motion
While m.motion <> Null
If MilliSecs() - rewindTimeStart > m\TimeOffset
Select m\MotionType
Case 1 MoveEntity cube, -m\vel[0], -m\vel[1], -m\vel[2]
Case 2 TurnEntity cube, -m\vel[0], -m\vel[1], -m\vel[2]
End Select
DebugLog "Should last for: " + m\length
If MilliSecs() - rewindTimeStart - m\timeOffset > m\length Then Deletemotion=True
EndIf
If deletemotion Then delm.motion = m
m = Before m
If deletemotion Then Delete delm: deletemotion = False
Wend
count = 0
For m.motion = Each motion
count = count + 1
Next
If count = 0
rewindTime = False
allowingInput = True
DebugLog MilliSecs() - beganRewind
EndIf
EndIf
UpdateWorld
RenderWorld
Text 0, 0, EntityX(cube)
Text 0, 10, EntityY(cube)
Text 0, 20, EntityZ(cube)
Text 0, 30, "Move system is as follows:"
y = 40
For m.motion = Each motion
If m\MotionType = 1 Then move$ = "move" Else move$ = "rotate"
Text 0, y, m\TimeOffset + " milliseconds into the motion " + move + " the player by the vector " + m\Vel[0] + ", " + m\Vel[1] + ", " + m\Vel[2] + " for " + m\length + " milliseconds (" + (Int(m\length / 1000)) + " seconds)"
y = y + 10
Next
loopEnd = MilliSecs()
lastLoopElapsed = loopEnd - loopStart
Flip
Wend
Function UpdateKeys()
keydown200 = KeyDown(200)
Select K200_State
Case 0 If keydown200 Then K200_State = 1
Case 1 If keydown200 Then K200_State = 2 Else K200_State = 0
Case 2 If keydown200 Then K200_State = 2 Else K200_State = 3
Case 3 K200_State = 0
End Select
keydown203 = KeyDown(203)
Select K203_State
Case 0 If keydown203 Then K203_State = 1
Case 1 If keydown203 Then K203_State = 2 Else K203_State = 0
Case 2 If keydown203 Then K203_State = 2 Else K203_State = 3
Case 3 K203_State = 0
End Select
keydown205 = KeyDown(205)
Select K205_State
Case 0 If keydown205 Then K205_State = 1
Case 1 If keydown205 Then K205_State = 2 Else K205_State = 0
Case 2 If keydown205 Then K205_State = 2 Else K205_State = 3
Case 3 K205_State = 0
End Select
keydown208 = KeyDown(208)
Select K208_State
Case 0 If keydown208 Then K208_State = 1
Case 1 If keydown208 Then K208_State = 2 Else K208_State = 0
Case 2 If keydown208 Then K208_State = 2 Else K208_State = 3
Case 3 K208_State = 0
End Select
End Function
|