- Joined
- Jan 2, 2020
- Messages
- 1,280
This is a simple way of recording motion into an array to be used later. You could save this array and load in your game to use as raw material
for the motion of enemies or anything. Or you could could just toy around with it to see how much you can record into a tight space.
Here we use 65535 integers to record about 1092 seconds (A little bit more than 18min) of motion!
We play it back backwards from where you left off the last time recording as that is
a really nice way to get new kinds of motions.
for the motion of enemies or anything. Or you could could just toy around with it to see how much you can record into a tight space.
Here we use 65535 integers to record about 1092 seconds (A little bit more than 18min) of motion!
We play it back backwards from where you left off the last time recording as that is
a really nice way to get new kinds of motions.
Cerberus:
Strict
Import mojo2
Global data : Int[65535] ' Create some space to record motion.
Global sp:Int = 32768 ' 65535 gives us 1092 seconds @ 60 fps. Set pointer in the middle.
Function Main:Int()
New Game
Return 0
End
Class Game Extends App
Field canvas:Canvas
Method OnCreate:Int()
canvas=New Canvas
SetSwapInterval 1 ; SetUpdateRate 0
Return 0
End
Method OnRender:Int()
canvas.Clear 0,0,0,0
' Record ------------------
Local xxx:Float = MouseX()
Local yyy:Float = MouseY()
If MouseDown(0) = False ' Record motion when not holding down mousebutton.
canvas.SetColor 1,0,0
If (Millisecs()/100) Mod 10 > 5 Then canvas.DrawText "Recording",0,0 ' Blink the text recording
canvas.SetColor 1,1,1
' Save position
sp = sp - 1 ; data[sp] = ( (xxx Shl 14) + yyy)
If sp = 0 Then sp = 65535 ' Make sure so stackpointer is within range
' --------------------------
Else
' Playback ------ ' Playback motion (not from start but backwards from the moment you just recorded!) when not holding down mousebutton.
' Restore position
xxx = (data[sp] Shr 14) & 16383 ; yyy = data[sp] & 16383 ; sp = sp + 1
If sp = 65535 Then sp = 0 ' Make sure so stackpointer is within range
canvas.SetColor 0,1,0
canvas.DrawText "Playback",0,0
' -----------------------------
Endif
canvas.SetColor 1,1,1
canvas.DrawRect xxx-16,yyy-16,32,32 ' Draw centered box
canvas.Flush
Return 0
End
End
Last edited: