// Project: chair
// Created: 2017-12-15
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "twister" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 0,0, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
plane = CreateObjectPlane(30000,30000)
SetObjectRotation(plane,90,0,0)
SetObjectPosition(plane,0,-100,0)
//SetObjectColor(plane,0,255,0,100)
SetObjectImage(plane,CreateTexture(128,128,MakeColor(0,255,0),240,255),1)
player = CreateObjectSphere(1,20,20)
type _engine
arm
roof
legs as integer[4]
camera
endtype
global enginearm as _engine
type _stairs
id
x#
y#
z#
colorred
colorgreen
colorblue
coloralpha
stepid as integer[4]
endtype
global stairs as _stairs[12]
global stairblocks as integer[48] // each stairs has 4 steps and 12 sets of stairs around the permimeter of the ride - 4 x 12 = 48 steps
global barriers as integer[ 48]
global platforms as integer[12]
global currentplatform=1
global stepsize#
global cashier as integer
global currentbarrier=1
SetCameraRange(1,1,100000)
stepsize#=800
stairs[0].id = CreateObjectSphere(30,30,30)
stairs[0].colorblue=255 : stairs[0].colorgreen = 255 : stairs[0].colorred=255
stairs[1].id = createobject(stepsize#,"stairs",4, 0, 0, 255)
stairs[1].colorred=255 : stairs[1].colorgreen=255 : stairs[1].colorblue=0 : stairs[1].coloralpha=255
for a=2 to 12
if (mod(a,2)=0)
stairs[a].colorred=0
stairs[a].colorgreen=0
stairs[a].colorblue=255
stairs[a].coloralpha=255
else
stairs[a].colorred=255
stairs[a].colorgreen=255
stairs[a].colorblue=0
stairs[a].coloralpha=255
endif
stairs[a].id = createobject(stepsize#,"stairs",4, stairs[a].colorred, stairs[a].colorgreen, stairs[a].colorblue)
next
buildcashunit()
buildengine()
ridespeed#=0 : speed#=.1
angx#=0: angy#=0:angz#=0
camx#=0: camy#=0:camz#=0
rotation#=0 : rot#=0 : enginerotation#=0:currentbarrier=1:camera#=0
do
// place the player
SetObjectPosition(player,camx#,camy#,camz#)
// Rotate the steps and platforms
x#=0: z#=0
staircount=0
rotation#=90
for a=0 to 360 step 30
// position the steps and platforms
x#=stepsize# + (stepsize#*4) * cos(a)
z#=stepsize# + (stepsize#*4) * sin(a)
y#=(rotation#) + sin(a) // turn the steps around the perimeter in 3D space = 30 degrees for 12 rotations around 360 degs
SetObjectPosition(stairs[staircount].id,x#,0,z#)
SetObjectRotation(stairs[staircount].id,450,y#,0)
SetObjectColor(stairs[staircount].id,stairs[staircount].colorred,stairs[staircount].colorgreen,stairs[staircount].colorblue,stairs[staircount].coloralpha)
// move the platforms
if staircount>0
SetObjectPosition(platforms[staircount],0,getobjecty(stairs[staircount].id)/3-(stepsize#*2)-30,-10)
SetObjectRotation(platforms[staircount],180,90,90)
endif
inc staircount
inc rotation#,-30
if staircount>12 then staircount=0
next
for a=camera# to camera#+360
// position the steps and platforms
x#=stepsize# + (stepsize#*4) * cos(a*speed#)
z#=stepsize# + (stepsize#*4) * sin(a*speed#)
y#=(rotation#) + sin(a) // turn the steps around the perimeter in 3D space = 30 degrees for 12 rotations around 360 degs
next
SetCameraPosition(1,getobjectx(enginearm.legs[1])+x#,getobjecty (enginearm.legs[1])+stepsize#+y#,getobjectz(enginearm.legs[1])-stepsize#+z#)
SetCameraRotation(1,(camera#)/100,(camera#)+y#/100,0)
inc camera#
// rotate the engine arm
dec enginerotation#,2
SetObjectPosition(enginearm.arm, stepsize#, stepsize#,stepsize#)
SetObjectRotation(enginearm.arm,0,enginerotation#,0)
//SetObjectColor(enginearm.roof, random(1,255),Random(1,255),random(1,255),255)
SetObjectPosition(cashier,-stepsize#*3,stepsize#,0)
// change barrier colours
for a=1 to 12
SetObjectColor(barriers[a],0,255,255,255/(a*12))
next
SetObjectColor(barriers[currentbarrier],255,0,0,255)
inc currentbarrier
if currentbarrier>12 then currentbarrier=1
//end of barrier colour changes
// Position pictureangz#)
inc angx#,0
inc angz#,0
inc angy#,0
inc rot#, 3
if GetRawKeyState(81) then ridespeed#=.1
if GetRawKeyState(65) then dec ridespeed#,.002
inc speed#, .001
if GetRawKeyState(38) then inc camz#,50
if GetRawKeyState(40) then dec camz#,50
if GetRawKeyState(37) then dec camx#,50
if GetRawKeyState(39) then inc camx#,50
// SetCameraLookAt(1,getobjectx(enginearm.legs[2])*100,getobjecty(enginearm.legs[2]), getobjectz(enginearm.legs[2])*100,1)
Print ("Press cursors to move around")
Print( ScreenFPS() )
print(getobjectx(enginearm.legs[1])+x#)
print(getobjecty(enginearm.legs[1])+y#)
print(getobjectz(enginearm.legs[1])+z#)
print( GetRawLastKey())
Sync()
loop
function movearmsup()
SetObjectRotation(enginearm.legs[1],GetObjectAngleX(enginearm.legs[1])-.5, GetObjectAngleY(enginearm.legs[1]), getobjectz(enginearm.legs[1]))
SetObjectRotation(enginearm.legs[2],GetObjectAngleX(enginearm.legs[2])-.5, GetObjectAngleY(enginearm.legs[2]), getobjectz(enginearm.legs[2]))
SetObjectRotation(enginearm.legs[3],GetObjectAngleX(enginearm.legs[3])-.5, GetObjectAngleY(enginearm.legs[3]), getobjectz(enginearm.legs[3]))
endfunction
function createobject(size#, seat as string, howmany, colorred, colorgreen, colorblue as integer)
if seat="stairs"
position#=0
for loops=1 to howmany
stairblocks[loops]=CreateObjectBox(size#*2, size#/2, 90)
if loops=1 then SetObjectPosition(stairblocks[loops],0,0,0)
if loops>1
SetObjectPosition(stairblocks[loops],getobjectx(stairblocks[loops-1]),getobjecty(stairblocks[loops-1])+GetObjectSizeMaxY(stairblocks[1]),getobjectz(stairblocks[loops-1])+GetObjectSizeMaxZ(stairblocks[1]))
SetObjectColor(stairblocks[loops],colorred,colorgreen,colorblue,255)
FixObjectToObject(stairblocks[loops],stairblocks[1])
endif
next
chair = stairblocks[1]
platforms[currentplatform] = CreateObjectBox(size#*4,.1,size#*2)
// SetObjectColor(platforms[currentplatform], 100,100,100,255)
SetObjectImage(platforms[currentplatform], createtexture(64,64,MakeColor(100,100,100),50,255),1)
FixObjectToObject(platforms[currentplatform],chair)
barriers[currentbarrier] = CreateObjectCylinder(200,50,50)
SetObjectRotation(barriers[currentbarrier],90,0,0)
//SetObjectImage(barriers[currentbarrier],Createtexture(64,64,MakeColor(255,0,0),100,255),1)
FixObjectToObject(barriers[currentbarrier], chair)
inc currentplatform
inc currentbarrier
// SetObjectRotation(chair,90,90,0)
endif
endfunction chair
function buildcashunit()
cashier= CreateObjectBox(100,200,100)
endfunction
function buildengine()
enginearm.arm = CreateObjectCylinder(stepsize#*2,stepsize#/2,50)
SetObjectImage(enginearm.arm,createtexture(64,64,MakeColor(255,255,0),200,255),1)
enginearm.legs[1]= CreateObjectCylinder(stepsize#*2,stepsize#/4,50)
SetObjectImage(enginearm.legs[1],createtexture(64,64,MakeColor(0,100,255),200,255),1)
SetObjectRotation(enginearm.legs[1],90,0,0)
SetObjectPosition(enginearm.legs[1],0,stepsize#,stepsize#)
FixObjectToObject(enginearm.legs[1], enginearm.arm)
enginearm.camera=CreateObjectSphere(10,10,10)
FixObjectToObject(enginearm.camera, enginearm.legs[1])
enginearm.legs[2]= CreateObjectCylinder(stepsize#*2,stepsize#/4,50)
SetObjectImage(enginearm.legs[2],createtexture(64,64,MakeColor(0,100,255),200,255),1)
SetObjectRotation(enginearm.legs[2],90,120,0)
SetObjectPosition(enginearm.legs[2],getobjectx(enginearm.arm)+(stepsize#),getobjecty(enginearm.arm)+stepsize#,getobjectz(enginearm.arm)-stepsize#/2)
FixObjectToObject(enginearm.legs[2], enginearm.arm)
enginearm.legs[3]= CreateObjectCylinder(stepsize#*2,stepsize#/4,50)
SetObjectImage(enginearm.legs[3],createtexture(64,64,MakeColor(0,100,255),200,255),1)
SetObjectRotation(enginearm.legs[3],90,240,0)
SetObjectPosition(enginearm.legs[3],getobjectx(enginearm.arm)-(stepsize#),getobjecty(enginearm.arm)+stepsize#,getobjectz(enginearm.arm)-stepsize#/2)
FixObjectToObject(enginearm.legs[3], enginearm.arm)
//enginearm.legs[3]= CreateObjectCylinder(stepsize#*2,stepsize#/4,50)
//SetObjectImage(enginearm.legs[3],createtexture(64,64,MakeColor(0,100,255),200,255),1)
//SetObjectRotation(enginearm.legs[3],90,360,0)
//SetObjectPosition(enginearm.legs[3],stepsize#,stepsize#,stepsize#/3)
//FixObjectToObject(enginearm.legs[3], enginearm.arm)
enginearm.roof = CreateObjectCone(stepsize#,stepsize#,50)
SetObjectPosition(enginearm.roof, 0, stepsize#*1.5, 0)
SetObjectColor(enginearm.roof,255,0,0,255)
FixObjectToObject(enginearm.roof, enginearm.arm)
endfunction
// Function to create a texture
//
// Inputs - Sizex - size of the texture to create - width
// Sizey - size of the texture to create - height
// Color - is the main color of the image
// Denisity - is a the depth of the texture - the lower the value, the more detail. higher value = no detail
//
// Returns the image for the resulting texture
//
// EG. CreateTexture ( 100, 100, makecolor(0,0,255), 100)
// This could create a DEEP water effect texture?
function createtexture(sizex# as float, sizey# as float, color, density, alpha as integer)
swap()
drawbox(0,0,sizex#, sizey#, color, color,color,color, 1)
render()
img = getimage(0,0,sizex#, sizey#)
memblockid = CreateMemblockFromImage (img)
imgwidth = GetMemblockInt(memblockid, 0)
imgheight = GetMemblockInt(memblockid, 4)
size=GetMemblockSize(memblockid)
for offset=12 to size-4 step 4
r=GetMemblockByte(memblockid, offset)
g=GetMemblockByte(memblockid, offset+1)
b=GetMemblockByte(memblockid, offset+2)
a=GetMemblockByte(memblockid, offset+3)
strength=random(1,density)
SetMemblockByte (memblockid, offset, r-strength)
SetMemblockByte (memblockid, offset+1, g-strength)
SetMemblockByte (memblockid, offset+2, b-strength )
SetMemblockByte (memblockid, offset+3, alpha)
next
deleteimage (img)
img = CreateImageFromMemblock(memblockid)
DeleteMemblock(memblockid)
endfunction img
Granddad memories - he was a fun fair builder so im sorry going back to that
Tier 1 Developer