Ok im done been hectic I get so involved in programming once I start I forget what real life is about lol
I tidied up my code allot and made some improvements to the bonus level and the book. Had a few
issues with the moving walls but sorted now. Had to use two types of collision detection raycasting
and get physicsobjectcontact with the game.
Ide like to thank
basicFanatic for this wonderful concept of a
Game Jam which gave me a
chance to use my code created media and latest learnt principles that ive been itching to use
My words "book splendid and tunnel"
Here is my final
//Definition of a porthole
//A porthole consists of at least two structural components and is, in its simplest form,
//similar to any other type of window in design and purpose. The porthole is primarily a
//circular glass disk, known as a 'portlight', encased in a metal frame that is bolted
//securely into the side of a ship's hull.
//by definition a porthole is a tunnel for light
//The word "portal" in science fiction and fantasy generally refers to a technological or
//magical doorway that connects two distant locations separated by spacetime. It usually
//consists of two or more gateways, with an object entering one gateway leaving via the
//other instantaneously.
#constant screenWidth =1024 //The screemwidth
#constant screenHeight=768 //the screen height
#constant KEY_LEFT = 37 //the left arrow key scancode
#constant KEY_UP = 38 //the up arrow key scancode
#constant KEY_RIGHT = 39 //the right arrow key scancode
#constant KEY_DOWN = 40 //the down arrow key scancode
#constant KEY_A = 65 //the scan code for the "a" key
#constant KEY_D = 68 //the scan code for the "d" key
#constant KEY_S = 83 //the scan code for the "s" key
#constant KEY_W = 87 //the scan code for the "w" key
#constant KEY_Z = 90 //the scan code for the "z" key
#constant KEY_SPACE = 32 //the space bar
#constant KEY_ENTER = 13 //the enter key
#constant KEY_ESCAPE = 27 //the escape key used to exit program
#constant KEY_T = 84
#constant leftWall = 1 //object ID of left wall
#constant rightWall = 2 //object ID of right wall
#constant ground = 3 //object ID of ground
#constant backWall = 4 //object ID of back wall
#constant frontWall = 5 //object ID of front wall
#constant portal = 6 //start objects id there are 4 in total
#constant bonusLeftWall = 10 //object ID of the bonus level left wall
#constant bonusRightWall= 11 //object ID of the bonus level right wall
#constant bonusGround = 12 //object ID of the bonus level ground
#constant bonusPortal = 13 //object ID of the bonus level ground
#constant fruitStart = 600 //Where bonus fruit IDs start
#constant obstacleStart = 700 //where the obstacle IDs on the bonus level start
#constant shrubStart = 14 //where shrub object ids start
#constant shrubCount = 40 //how many shrubs there are
#constant treeStart = 216 //where tree object ids start NOTE starts 1 greater than (shrubcount*5)+shrubstart
#constant treeCount = 20 //how many tree objects there are
#constant playerObj = 500 //object ID of player
#constant crossHair = 1 //The Cross Hair mouse sprite ID
#constant radarSpr = 2 //the square white box used for radar
#constant playerSpr = 3 //Player sprite on the radar ID
#constant bookFront = 400//object ID of the book front cover
#constant bookCoverImg = 400//the image Id of the book front cover
#constant bookPages1 = 401//object ID of book page 1
#constant bookPages1Img= 401//The image ID of book page 1
#constant bookPages2 = 402//object ID of the book page 2
#constant bookPages2Img= 402//The image ID of the book page 2
#constant bookPages3 = 403//object ID of the book page 3
#constant bookPages3Img= 403//The image Id of the book page 3
#constant bookPages4 = 404//object ID of the book page 4
#constant bookPages4Img= 404//The image Id of the book page 4
#constant bookBack = 405//object ID of the back cover of the book
#constant bookBackImg = 405//the image ID of the back cover of book
#constant playerGunObj = 501//The player gun object ID its invisible but location is used to shooy from
#constant bulletLife = 3 //time to keep bullets alive
#constant Shader = 1 //the shader ID
#constant textLevel = 1 //current level text id
#Constant helpMessage = 2 //help messages starter iD there are 3
#constant camOff_y# =15 //Camera y offset
#constant spawnStartTime=5.0//The start time to wait for spawning enemies
#constant spawnMinTime=1.0 //the minimum enemies have to wait before spawning
#constant killsToLevel=5 //ammount of kills needed for level increase
#constant texture1 =500//ground texture ID
#constant texture2 =501//the brick texture ID
#constant texture3 =502//the particles texture ID
#constant texture4 =503//an ellipse surrounded by transparency imageID used for portals (texture1 of the shader masking layer)
#constant texture5 =504//Just a texture ID used with the shader used for portals (texture2 of the shader is used to replaced transparent part in texture1)
SetWindowTitle( "The Splendid Book of Portals" )
SetScreenResolution(screenWidth,screenHeight)
Setvirtualresolution(screenWidth,screenHeight)
create3DPhysicsWorld()
//the type used for bonus fruit
type object
objMesh as integer
objMem as integer
maxVertex as integer
endtype
//used for the moving obstacles in the bonus tunnel
type obstacle
ID as integer
direction as integer
endtype
// the type used for bullets
type bullet
ID as integer
time as float // a time used because bullets die over time
endtype
//the type used for enemy
type enemy
ID as integer //the ID of the spawned enemy
sprID as integer //the sprite ID so as its location on radar can be shown
endtype
global myBullet as bullet[0] //we start with no bullets but use an array that we can insert more
global myEnemy as enemy[0] //we start with no enemy but use an array that we can insert more
global myObstacles as obstacle[0]
global bulletCount=0 //keeps track of the ammount of bullets currently alive used for processing
global enemyCount=0 //keeps track of the ammount of enemy currently alive used for processing
//used for camera angle on the yAxis
global camAngle_x# //the x angle of the camera
global camAngle_y# //the y angle of the camera
camAngle_x#=wrapvalue(GetPointerY()) //get the pointer y location and wrap in a 360 degree range
camAngle_y#=wrapvalue(GetPointerX()) //get the pointer x location and wrap in a 360 degree range
createShader() //used to create the shader
LoadShader(Shader, "Kaliset.vs","Kaliset.ps" ) //shaders need to be loaded
startStory():SetPrintColor(255,255,255) //display book and set print color back to white
createtexture(texture1,512,512, makecolor(55,155,55),256) //creates the ground texture
createWallTexture(texture2) //creates a brick texture
createEllipse(texture3) //creates particle explosion texture
createEllipseForPortals(texture4)
CreateWindow(texture5) //creates the texture for around the edge of portals in arena
createArena() //creates play game arena
CreateCharacterController(200):Step3DPhysicsWorld()
//Set the shader to all of the porthole objects there are 4
for num = 0 to 3
SetObjectShader(portal+num,Shader)
next num
SetShaderConstantByName( Shader,"iResolution",100,100,0,0 ) //set the dimentions of the shader
SetObjectShader(bonusPortal,Shader)
//create some shrubs and randomly position then in play arena
for num = shrubStart to (shrubCount*5)+shrubStart step 5
CreateShrub(num,30,30) //there are 4 objects that make up a tree therefore the second must start at 5
SetObjectPosition(num,random2(-200,200),-15,random2(100,500))
SetObjectCollisionMode(num,0)
SetObjectCollisionMode(num+1,0)
SetObjectCollisionMode(num+2,0)
SetObjectCollisionMode(num+3,0)
next num
//create some trees and position them randomly in the arena
for num = treeStart to (treeCount*5)+treeStart step 5
CreateTree(num,60,80) //there are 4 objects that make up a tree therefore the second must start at 5
SetObjectPosition(num,random2(-200,200),0,random2(100,500))
SetObjectCollisionMode(num,0)
SetObjectCollisionMode(num+1,0)
SetObjectCollisionMode(num+2,0)
SetObjectCollisionMode(num+3,0)
//Create a collision object
//CreateObjectCylinder(num+1+(treeCount*5),20,4,20)
//SetObjectPosition(num+1+(treeCount*5),GetObjectX(num),GetObjectY(num)-10,GetObjectZ(num))
//SetObjectVisible(num+1+(treeCount*5),0)
//SetObjectCollisionMode(num+1+(treeCount*5),1)
//Create3DPhysicsStaticBody(num+1+(treeCount*5))
//SetObject3DPhysicsRestitution(num+1+(treeCount*5),10)
next num
SetRawMousePosition(screenWidth*.5,screenheight*.5) //position the pointer at the centre of screen
global messagesFlag=1 //the variable used for displaying the messages in game set to zero for no messages
repeat
if getpointerpressed()
If GetSpriteExists(radarSpr) then SetSpriteVisible(radarSpr,1)
If GetSpriteExists(playerSpr) then SetSpriteVisible(playerSpr,1)
playGame()
endif
sync()
until GetRawKeyState(KEY_ESCAPE)
end
function playGame()
radarImg=radar()
createSprite(radarSpr,radarImg)
SetSpritePosition(radarSpr,screenWidth-101,1)
CreateSprite(playerSpr,0):SetSpriteImage(playerSpr,createPlayerSprImage()):SetSpriteSize(playerSpr,5,5):SetSpriteColor(playerSpr,0,255,0,255):SetSpriteTransparency(playerSpr,1)
SetRawMouseVisible(0) //hide the mouse pointer
SetCameraRotation(1,0,0,0) //set the camera locations so as we can see the book
SetCameraPosition(1,0,0,-20)
teleport(-1) //teleport =1 for clockwise =-1 for anticlockwise
DeleteSprite(crossHair):CreateSprite(crossHair,createCrossHair())
SetSpritePositionByOffset(crossHair,screenWidth*.5,ScreenHeight*.5)
for num3=1 to enemyCount //make sure there are no enemies left from previous game
DeleteObject(myEnemy[num3].ID)
DeleteSprite(myEnemy[num3].sprID)
myEnemy.remove(num3)
dec enemyCount
next num3
for num=1 to bulletCount //delete any left over bullets from previous game
DeleteObject(myBullet[num].ID)
myBullet.remove(num)
dec bulletCount
next num
//create a fading level text
CreateText(textLevel,"Level ")
SetTextSize(textLevel,50)
SetTextPosition(textLevel,(screenWidth*.5)-75,300)
SetTextColor(textLevel,255,255,255,255)
SetTextVisible(textLevel,0)
SetTextString(textLevel,"Level "+str(Level) )
SetTextVisible(textLevel,1):iAlpha=255
SetTextColorAlpha(textLevel, iAlpha )
//the messages that are used in game
if messagesFlag=1
CreateText(helpMessage,"")
CreateText(helpMessage+1,"")
CreateText(helpMessage+2,"")
SetTextSize(helpMessage,50)
SetTextSize(helpMessage+1,50)
SetTextSize(helpMessage+2,50)
SetTextPosition(helpMessage,(screenWidth*.5)-220,100)
SetTextPosition(helpMessage+1,(screenWidth*.5)-220,150)
SetTextPosition(helpMessage+2,(screenWidth*.5)-220,200)
endif
//set camera rotation to where the arena is location
SetCameraRotation(1,camangle_x#,GetObjectWorldAngleY(playerObj),GetObjectWorldAngleZ(playerObj) )
SetCameraPosition(1,GetObjectWorldX(playerObj),GetObjectWorldY(playerObj)+camOff_y#,GetObjectWorldZ(playerObj))
sync():time#=timer():messageTime#=timer():global lives=5:global kills=0:global level=1:Global enemySpeed#=.5:global iAlpha:alpha=255:flag=1
global spawnTime#=spawnStartTime:global ranSpeed#:ranSpeed#=((log(level))+0.50):global fruit=0 //calculate an exponential speed increase for the enemy
repeat
updatePlayerMovement(50)
updateEnemy()
for num=1 to enemyCount
//check if any ebenmy has collided with the player
collID=checkCollision(myEnemy[num].ID)
if collID=playerObj
DeleteObject(myEnemy[num].ID)
DeleteSprite(myEnemy[num].sprID)
myEnemy.remove(num)
dec enemyCount
dec lives
exit
endif
next num
if GetRawKeyPressed(KEY_T) then playBonusLevel()
//There is no limit to bullets but a timer of bulletlife for how long they live
for num=1 to bulletCount
if (myBullet[num].time)+bulletLife<timer()
DeleteObject(myBullet[num].ID)
myBullet.remove(num)
dec bulletCount
endif
next num
//spawn a new enemy every spawntime
if timer()>(time#+spawnTime#)
spawnEnemy(random(portal,portal+3))
time#=timer()
endif
if messagesFlag=1
if alpha>1
dec alpha
SetTextColorAlpha(helpMessage,alpha)
SetTextColorAlpha(helpMessage+1,alpha)
SetTextColorAlpha(helpMessage+2,alpha)
elseif flag=1 and timer()>messageTime#+5
SetTextString(helpMessage,"I already want to go")
SetTextString(helpMessage+1,"home there is nothing")
SetTextString(helpMessage+2,"here.")
alpha=255:flag=2:messageTime#=timer()
elseif flag=2 and timer()>messageTime#+6
SetTextString(helpMessage,"There seems to be")
SetTextString(helpMessage+1,"4 Portals which")
SetTextString(helpMessage+2,"one is the way home")
alpha=255:flag=3:messageTime#=timer()
elseif flag=3 and timer()>messageTime#+4
SetTextString(helpMessage,"What are these box")
SetTextString(helpMessage+1,"things coming from")
SetTextString(helpMessage+2,"the Portals")
alpha=255:flag=4:messageTime#=timer()
elseif flag=4 and timer()>messageTime#+5
SetTextString(helpMessage,"This is some kind of")
SetTextString(helpMessage+1,"robot battle arena.")
SetTextString(helpMessage+2,"Get me out of here")
alpha=255:flag=5:messageTime#=timer()
elseif flag=5 and timer()>messageTime#+6
SetTextString(helpMessage,"There has to be some ")
SetTextString(helpMessage+1,"end to the ammount of")
SetTextString(helpMessage+2,"Robots coming")
alpha=255:flag=6:messageTime#=timer()
elseif flag=6 and timer()>messageTime#+6
SetTextString(helpMessage,"That dam scientist ")
SetTextString(helpMessage+1,"tricked me. When I ")
SetTextString(helpMessage+2,"I find him %&&^%%.")
alpha=255:flag=7:messageTime#=timer()
elseif flag=7 and timer()>messageTime#+6
SetTextString(helpMessage,"These portals seem ")
SetTextString(helpMessage+1,"to be one way only. ")
SetTextString(helpMessage+2,"There must be way out.")
alpha=255:flag=8:messageTime#=timer()
elseif flag=8 and timer()>messageTime#+10
SetTextString(helpMessage,"Im getting tired and ")
SetTextString(helpMessage+1,"still no way out.")
SetTextString(helpMessage+2,"")
alpha=255:flag=9:messageTime#=timer()
endif
endif
if iAlpha>2 then iAlpha=iAlpha-2
SetTextColorAlpha(textLevel, iAlpha )
//set camera and its offsets in relation to the players position
SetCameraRotation(1,camangle_x#,GetObjectWorldAngleY(playerObj),GetObjectWorldAngleZ(playerObj) )
SetCameraPosition(1,GetObjectWorldX(playerObj),GetObjectWorldY(playerObj)+camOff_y#,GetObjectWorldZ(playerObj))
SetShaderConstantByName( Shader,"iGlobalTime",Timer()*.5,0,0,0 ) `tell the shader what time it is - so it can update its animations
print(ScreenFPS())
print("Level="+str(level))
print("Lives="+str(lives))
print("Kills="+str(kills))
sync()
until GetRawKeyState(KEY_ESCAPE) or lives <=1
DeleteSprite(radarSpr):
DeleteText(textLevel):DeleteText(helpMessage):DeleteText(helpMessage+1):DeleteText(helpMessage+2)
//set camera back to the locations where book is visible
SetCameraRotation(1,0,0,0)
SetCameraPosition(1,0,0,-20)
teleport(1):gameOver():messagesFlag=0
SetRawMouseVisible(1) //the mouse is now visible this makes more sence when clicking playgame
endfunction
function updateEnemy()
//update all enemy locations and check for collisions with player bullets
for num=1 to enemyCount
//gets the angle between you and the enemy
ang# = GetAngle(getObjectX(myEnemy[num].ID),getObjectZ(myEnemy[num].ID),getObjectX(playerObj),getObjectZ(playerObj))
//points the enemy toward you which is the difference between your location and the above angle
SetObjectRotation(myEnemy[num].ID,0,0,0)
RotateObjectGlobalY(myEnemy[num].ID,difference(ang#,GetObjectWorldAngleY(myEnemy[num].ID)) )
MoveObjectLocalZ( myEnemy[num].ID, -enemySpeed# )
if GetObject3DPhysicsFirstContact(myEnemy[num].ID) //check if the enemy has had contact
while GetObject3DPhysicsNextContact()
contactObjB = GetObject3DPhysicsContactObjectB()
for num2=1 to bulletCount
if contactObjB=myBullet[num2].ID //enemy has been shot destroy them and bullet
partID=Create3DParticles( getObjectX(myBullet[num2].ID),getObjectY(myBullet[num2].ID),getObjectZ(myBullet[num2].ID) )
Set3DParticlesDirection( partID, 0,2, 0, 0 )
Set3DParticlesDirectionRange( partID,275,45 )
Set3DParticlesImage(partID,texture3)
Set3DParticlesSize(partID,6)
Set3DParticlesLife(partID,5.5)
Set3DParticlesVelocityRange(partID,1,10)
Set3DParticlesMax(partID,50)
DeleteObject(myBullet[num2].ID)
myBullet.remove(num2)
dec bulletCount
DeleteObject(myEnemy[num].ID)
DeleteSprite(myEnemy[num].sprID)
myEnemy.remove(num)
dec enemyCount
inc kills
Update3DParticles( partID,0 )
if mod(kills,killsToLevel) =0
inc level
if mod(level,5)=0 then playBonusLevel()
ranSpeed#=((log(level))+0.50) //calculate an exponential speed increase for the enemy
if ranSpeed#>2.5 then ranSpeed#=2.5
SetTextString(textLevel,"Level "+str(Level) )
SetTextVisible(textLevel,1):iAlpha=255
SetTextColorAlpha(textLevel, iAlpha )
for num3=1 to enemyCount
DeleteObject(myEnemy[num3].ID)
DeleteSprite(myEnemy[num3].sprID)
myEnemy.remove(num3)
dec enemyCount
next num3
spawnTime#=SpawnTime#-.5
if spawnTime#<spawnMinTime then spawnTime#=spawnMinTime
endif
exitfunction
endif
next num2
endwhile
endif
//position the enemy sprite on radar
x#=GetObjectX(myEnemy[num].ID)+250:x#=(x#/500)*100:x#=100-x#:x#=screenWidth-x#
y#=(GetObjectZ(myEnemy[num].ID)-50):y#=(y#/500)*100:y#=100-y#:
SetSpritePosition(myEnemy[num].sprID,x#,y#)
next num
endfunction
function checkCollision(object)
//this checks for colliion between an object with any other object and returns its id
width#=50
height#=20
depth#=50
x#=getObjectWorldX(object)
y#=GetObjectWorldY(object)
z#=getObjectWorldZ(object)
// calculate the start of the ray cast
start_x# = x#-width#
start_y# = y#+height#
start_z# = z#-depth#
// calculate the end of the ray cast
end_x# = x#+width#
end_y# = y#-height#
end_z# = z#+depth#
// determine which object has been hit
object_hit = ObjectRayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
endfunction object_hit
//used to calculate a direction angle to point objects to an object
function getAngle(x1#, y1#, x2#, y2#)
//result# = ATanFull(x1# - x2#, y1# - y2#)
result# = ATan2(x1# - x2#,y1# - y2#)
endfunction result#
function updatePlayerMovement(velocity as float)
//update the player movement in the direction of the following keys
local old as integer
camAngle_x#=GetPointerY()
camAngle_y#=GetPointerX()
//rotate the player object in relation to pointer x if pointerx <10 then add 360 if pointerx too far right yake 360
if camAngle_y#>=10 and camAngle_y#<=(screenWidth-10)
Rotate3DPhysicsCharacterController(playerObj,camAngle_y#)
elseif camAngle_y#<10
camAngle_y#=camAngle_y#+360
SetRawMousePosition(camAngle_y#,camAngle_x#)
Rotate3DPhysicsCharacterController(playerObj,camAngle_y#)
elseif camAngle_y#>(screenWidth-10)
camAngle_y#=camAngle_y#-360
SetRawMousePosition(camAngle_y#,camAngle_x#)
Rotate3DPhysicsCharacterController(playerObj,camAngle_y#)
endif
if GetRawKeyState(KEY_LEFT) //strafe left
Move3DPhysicsCharacterController(playerObj,3,velocity)
old=3
endif
if GetRawKeyState(KEY_RIGHT) //strafe right
Move3DPhysicsCharacterController(playerObj,4,velocity)
old=4
endif
if GetRawKeyState(KEY_UP) //move forward
Move3DPhysicsCharacterController(playerObj,1,velocity)
old=1
endif
if GetRawKeyState(KEY_DOWN) //move backwards
Move3DPhysicsCharacterController(playerObj,2,velocity)
old=2
endif
if GetrawkeyPressed(KEY_SPACE) or GetRawMouseRightPressed() //jump
Jump3DPhysicsCharacterController(playerObj)
endif
if GetrawkeyPressed(KEY_ENTER) or GetPointerPressed() //shoot
ThrowBall( 1000.0, 10.0)
endif
Step3DPhysicsWorld() //needs to be called prior to below and any camera adjustments
select old //the following is used to reset the movement back to zero if player moved this turn otherwise it continuely moves
case 1
Move3DPhysicsCharacterController(playerObj,1,0)
endcase
case 2
Move3DPhysicsCharacterController(playerObj,2,0)
endcase
case 3
Move3DPhysicsCharacterController(playerObj,3,0)
endcase
case 4
Move3DPhysicsCharacterController(playerObj,4,0)
endcase
endselect
x#=GetObjectX(playerObj)+250:x#=(x#/500)*100:x#=100-x#:x#=screenWidth-x#
y#=(GetObjectZ(playerObj)-50):y#=(y#/500)*100:y#=100-y#
SetSpriteAngle(playerSpr,GetObjectAngleY(playerObj))
SetSpritePosition(playerSpr,x#,y#)
endfunction
function difference(x as float ,y as float)
diff as float
diff = (x-y)
endfunction diff
function CreateCharacterController(z as integer)
//create the character controller of the player its invisible but needed for physics
DeleteObject(playerObj)
CreateObjectBox(playerObj,20,20,20)
SetObjectPosition(playerObj,0,-10,z)
SetObjectVisible(playerObj,0)
characterOffsetVec = CreateVector3( 0.0, 2.5, 0.0 )
objectOrientationVec = CreateVector3( 0.0, 0.0, 0.0 )
Delete3DPhysicsCharacterController(playerObj)
Create3DPhysicsCharacterController(playerObj, 1, characterOffsetVec, objectOrientationVec, .90 )
DeleteVector3( characterOffsetVec )
DeleteVector3( objectOrientationVec )
CreateObjectBox(playerGunObj,20,20,20)
SetObjectPosition(playerGunObj,GetObjectWorldX(playerObj),GetObjectWorldY(playerObj)+camOff_y#,GetObjectWorldZ(playerObj))
SetObjectVisible(playerGunObj,0)
endfunction
function createArena()
//create the game world arena
CreateObjectBox(leftWall,2,502,502 )
SetObjectImage(leftWall,texture2,0)
SetObjectPosition(leftWall,-250,232,300)
Create3DPhysicsStaticBody(leftWall)
CreateObjectBox(rightWall,2,502, 502 )
SetObjectImage(rightWall,texture2,0)
SetObjectPosition(rightWall,250,232,300)
Create3DPhysicsStaticBody(rightWall)
CreateObjectBox(ground,502,1, 502 )
SetObjectImage(ground,texture1,0)
SetObjectPosition(ground,0,-18,300)
Create3DPhysicsStaticBody(ground)
CreateObjectBox(backWall,502, 502,2 )
SetObjectImage(backWall,texture2,0)
SetObjectPosition(backWall,0,232,550)
Create3DPhysicsStaticBody(backWall)
CreateObjectBox(frontWall,502, 502,2 )
SetObjectImage(frontWall,texture2,0)
SetObjectPosition(frontWall,0,232,50)
Create3DPhysicsStaticBody(frontWall)
CreateObjectBox(bonusLeftWall,2,502,1500 )
SetObjectImage(bonusLeftWall,texture2,0)
SetObjectPosition(bonusLeftWall,-50,232,1300)
Create3DPhysicsStaticBody(bonusLeftWall)
CreateObjectBox(bonusRightWall,2,502,1500 )
SetObjectImage(bonusRightWall,texture2,0)
SetObjectPosition(bonusRightWall,50,232,1300)
Create3DPhysicsStaticBody(bonusRightWall)
CreateObjectBox(bonusGround,502,1, 1500 )
SetObjectImage(bonusGround,texture1,0)
SetObjectPosition(bonusGround,0,-18,1300)
Create3DPhysicsStaticBody(bonusGround)
CreateObjectBox(bonusPortal,100,100,2 )
SetObjectImage(bonusPortal,texture1,0)
SetObjectPosition(bonusPortal,0,32,2000)
SetObjectImage(bonusPortal,texture4,1)
SetObjectImage(bonusPortal,texture5,2)
Create3DPhysicsStaticBody(bonusPortal)
CreateObjectPlane(portal,100,100)
SetObjectImage(portal,texture1,0)
SetObjectImage(portal,texture4,1) //the second texture used for masking out bits
SetObjectImage(portal,texture5,2)
//SetObjectTransparency(portal,1) //used so as the transparent bits with the above part dont show
SetObjectRotation(portal,0,-90,0)
SetObjectPosition(portal,-248,50,300)
SetObjectCollisionMode(portal,0)
InstanceObject(portal+1,portal)
SetObjectImage(portal+1,texture1,0)
SetObjectImage(portal+1,texture4,1) //the second texture used for masking out bits
SetObjectImage(portal+1,texture5,2)
//SetObjectTransparency(portal+1,1) //used so as the transparent bits with the above part dont show
SetObjectRotation(portal+1,0,-90,0)
SetObjectPosition(portal+1,248,50,300)
SetObjectCollisionMode(portal+1,0)
InstanceObject(portal+2,portal)
SetObjectImage(portal+2,texture1,0)
SetObjectImage(portal+2,texture4,1) //the second texture used for masking out bits
SetObjectImage(portal+2,texture5,2)
//SetObjectTransparency(portal,1) //used so as the transparent bits with the above part dont show
SetObjectRotation(portal+2,0,0,0)
SetObjectPosition(portal+2,0,50,548)
SetObjectCollisionMode(portal+2,0)
InstanceObject(portal+3,portal)
SetObjectImage(portal+3,texture1,0)
SetObjectImage(portal+3,texture4,1) //the second texture used for masking out bits
SetObjectImage(portal+3,texture5,2)
//SetObjectTransparency(portal+3,1) //used so as the transparent bits with the above part dont show
SetObjectRotation(portal+3,0,0,0)
SetObjectPosition(portal+3,0,50,52)
SetObjectCollisionMode(portal+3,0)
endfunction
function createShrub(objectNum as integer, xSize as float,ySize as float)
ClearScreen()
Render()
fern(256,668,7,90,7,50,150)
fern(255,668,7,90,7,50,150)
fern(257,668,7,90,7,50,150)
fern(254,668,7,90,7,50,150)
fern(258,668,7,90,7,50,150)
DrawLine(256,668,256,768,MakeColor(55,255,55),MakeColor(55,255,55))
DrawBox (254,668,258,768,MakeColor(55,255,55),MakeColor(55,255,55),MakeColor(55,255,55),MakeColor(55,255,55),1)
Swap()
img = getimage(0,320,512,768)
//a Shrub is made up of 4 planeobjects
CreateObjectPlane(objectNum,xSize,ySize)
InstanceObject(objectNum+1,objectNum)
InstanceObject(objectNum+2,objectNum)
InstanceObject(objectNum+3,objectNum)
SetObjectPosition(objectNum,0,0,0)
SetObjectPosition(objectNum+1,0,0,0)
SetObjectPosition(objectNum+2,0,0,0)
SetObjectPosition(objectNum+3,0,0,0)
SetObjectRotation(objectNum,0,0,0)
SetObjectRotation(objectNum+1,0,45,0)
SetObjectRotation(objectNum+2,0,90,0)
SetObjectRotation(objectNum+3,0,135,0)
SetObjectImage(objectNum,img,0)
SetObjectImage(objectNum+1,img,0)
SetObjectImage(objectNum+2,img,0)
SetObjectImage(objectNum+3,img,0)
SetObjectTransparency(objectNum,1)
SetObjectTransparency(objectNum+1,1)
SetObjectTransparency(objectNum+2,1)
SetObjectTransparency(objectNum+3,1)
FixObjectToObject(objectNum+1,objectNum)
FixObjectToObject(objectNum+2,objectNum)
FixObjectToObject(objectNum+3,objectNum)
endfunction
REM ====== FERN FRACTAL =======
REM X,Y - starting position for fern, root of first stem
REM passes - number of iterations
REM startAngle - angle to start drawing on this pass
REM bendAngle - overall bending angle of the whole leaf
REM branchAngle - angle to branch off each stem at
REM height - starting height
function fern(x as float, y as float, passes as integer, startAngle as float, bendAngle as float, branchAngle as float, height as float)
rootAngle# = wrapvalue(startAngle - bendAngle)
x2 = x + cos(rootAngle#)*height
y2 = y - sin(rootAngle#)*height
DrawLine(x,y,x2,y2,MakeColor(255,255,5),MakeColor(255,255,5))
height = height*0.5
x3 = x + cos(wrapvalue(rootAngle#+branchAngle))*height
y3 = y - sin(wrapvalue(rootAngle#+branchAngle))*height
DrawLine(x,y,x3,y3,MakeColor(55,255,55),MakeColor(55,255,55))
x4 = x + cos(wrapvalue(rootAngle#-branchAngle))*height
y4 = y - sin(wrapvalue(rootAngle#-branchAngle))*height
DrawLine(x,y,x4,y4,MakeColor(55,255,55),MakeColor(55,255,55))
if passes > 1
fern(x2,y2,passes-1, rootAngle#, bendAngle, branchAngle, height)
fern(x3,y3,passes-1, wrapvalue(rootAngle#+branchAngle), bendAngle, branchAngle, height)
fern(x4,y4,passes-1, wrapvalue(rootAngle#-branchAngle), bendAngle, branchAngle, height)
endif
endfunction
function createTree(objectNum as integer, xSize as float,ySize as float)
ClearScreen()
Render()
cantor2(512,768,250,40,270) //draws a tree
Swap()
img = getimage(0,0,1024,768)
// a tree is made up of four planeobjects
CreateObjectPlane(objectNum,xSize,ySize)
InstanceObject(objectNum+1,objectNum)
InstanceObject(objectNum+2,objectNum)
InstanceObject(objectNum+3,objectNum)
SetObjectPosition(objectNum,0,0,0)
SetObjectPosition(objectNum+1,0,0,0)
SetObjectPosition(objectNum+2,0,0,0)
SetObjectPosition(objectNum+3,0,0,0)
SetObjectRotation(objectNum,0,0,0)
SetObjectRotation(objectNum+1,0,45,0)
SetObjectRotation(objectNum+2,0,90,0)
SetObjectRotation(objectNum+3,0,135,0)
SetObjectImage(objectNum,img,0)
SetObjectImage(objectNum+1,img,0)
SetObjectImage(objectNum+2,img,0)
SetObjectImage(objectNum+3,img,0)
SetObjectTransparency(objectNum,1)
SetObjectTransparency(objectNum+1,1)
SetObjectTransparency(objectNum+2,1)
SetObjectTransparency(objectNum+3,1)
FixObjectToObject(objectNum+1,objectNum)
FixObjectToObject(objectNum+2,objectNum)
FixObjectToObject(objectNum+3,objectNum)
endfunction
//the cantor function used for creating a tree texture
function cantor2(x as float,y as float,length as float,thickness as float,ang as integer)
local x2 as float
local y2 as float
if length>1
x2= length * cos(ang) + x //calculate endx point given length and angle
y2= length * sin(ang) + y //calculate endy point given length and angle
for thick=-thickness/2 to thickness/2 step 1
DrawLine(x+thick,y,x2+thick,y2,MakeColor(71,25,0),MakeColor(71,35,0))
next thick
cantor2(x2,y2,length/1.5,thickness/1.5,ang+random(20,45))
cantor2(x2,y2,length/1.5,thickness/1.5,ang-random(20,45))
endif
endfunction
//wraps the value passed into a 360 degree range and returns thye new value
function wrapvalue(num as float)
while num>360
num=num-360
endwhile
endfunction num
//used to create grass texture
function createtexture(imgID as integer,sizex# as float, sizey# as float, color, density 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, a-strength)
next
deleteimage (img)
CreateImageFromMemblock(imgID,memblockid)
DeleteMemblock(memblockid)
endfunction
//creates the border around the radar
function radar()
SetClearColor(0,0,0)
ClearScreen()
Render()
DrawBox(0,0,100,100,MakeColor(255,255,255),MakeColor(255,255,255),MakeColor(255,255,255),MakeColor(255,255,255),0)
Swap()
img = getimage(0,0,102,102)
sync()
endfunction img
function createEllipse(img as integer)
rem create an ellipse that can be used as a sprite
SetClearColor(0,0,0)
ClearScreen()
Render()
//DrawBox(0,0,100,100,MakeColor(255,255,255),MakeColor(255,255,255),MakeColor(255,255,255),MakeColor(255,255,255),1)
DrawEllipse(75,75,25,25,MakeColor(55,55,55),MakeColor(55,55,55),1)
Swap()
getimage(img,0,0,100,100)
sync()
endfunction
function createEllipseForPortals(img as integer)
SetClearColor(0,0,0)
ClearScreen()
Render()
DrawBox(0,0,512,512,MakeColor(0,0,0),MakeColor(0,0,0),MakeColor(0,0,0),MakeColor(0,0,0),1)
DrawEllipse(256,256,248,248,MakeColor(255,255,255),MakeColor(255,255,255),1)
//DrawEllipse(256,256,64,64,MakeColor(0,0,0),MakeColor(0,0,0),1)
Swap()
getimage(img,0,0,512,512)
SetImageTransparentColor(img,0,0,0)
sync()
endfunction
function CreateWindow(img as integer)
SetClearColor(0,0,0)
ClearScreen()
Render()
DrawBox(0,0,512,512,MakeColor(102,178,255),MakeColor(102,178,255),MakeColor(102,178,255),MakeColor(102,178,255),1)
DrawBox(0,0,512,6,MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),1)
DrawBox(0,0,6,512,MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),1)
DrawBox(0,496,512,512,MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),1)
DrawBox(496,0,512,512,MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),1)
DrawBox(0,124,512,130,MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),1)
DrawBox(0,252,512,258,MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),1)
DrawBox(0,380,512,387,MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),1)
DrawBox(124,0,131,512,MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),1)
DrawBox(252,0,258,512,MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),1)
DrawBox(380,0,387,512,MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),MakeColor(102,51,0),1)
Swap()
getimage(img,0,0,512,512)
//SetImageTransparentColor(img,0,0,0)
sync()
endfunction
function createPlayerSprImage()
rem draw a triangle image used for the player sprite on radar
SetClearColor(0,0,0)
ClearScreen()
Render()
//DrawBox(0,0,10,10,MakeColor(0,0,0),MakeColor(0,0,0),MakeColor(0,0,0),MakeColor(0,0,0),1)
DrawLine(5,0,9,9,makeColor(255,255,255),makeColor(255,255,255))
DrawLine(0,9,9,9,makeColor(255,255,255),makeColor(255,255,255))
DrawLine(0,9,5,0,makeColor(255,255,255),makeColor(255,255,255))
swap()
img = getimage(0,0,10,10)
SetImageTransparentColor(img,0,0,0)
endfunction img
function createCrossHair()
rem draw an ellipse that can be used as a sprite and returns the value of the image
SetClearColor(0,0,0)
ClearScreen()
Render()
DrawEllipse(50,50,25,25,MakeColor(200,0,0),MakeColor(200,0,0),0)
DrawLine(25,50,75,50,200,0,0)
DrawLine(50,25,50,75,200,0,0)
Swap()
img = getimage(0,0,100,100)
endfunction img
//creates wall texture
function createWallTexture(img as integer)
ClearScreen()
Render()
DrawBox(0,0,512,512,MakeColor(155,155,155),MakeColor(155,155,155),MakeColor(155,155,155),MakeColor(155,155,155),1)
x=-5:y=0:oldX=0
repeat
repeat
DrawBox(x,y,x+5,y+1,MakeColor(155,5,5),MakeColor(155,5,5),MakeColor(155,5,5),MakeColor(155,5,5),1)
x=x+6
until x>512+5
if oldx=-5
x=-2:oldx=-2
else
x=-5:oldx=-5
endif
y=y+3
until y>512+2
Swap()
getimage(img,0,0,512,512)
sync()
endfunction
function spawnEnemy(spawnLoc as integer) //the spawn location is at the portal location
//offset Locations depending on which spawn location
local xOff as integer
local yOff as integer
local zOff as integer
select spawnLoc
case portal :
xOff=0:yOff=-60:zOff=40
endcase
case (portal+1) :
xOff=-40:yOff=-60:zOff=0
endcase
case (portal+2) :
xOff=0:yOff=-60:zOff=-40
endcase
case (portal+3) :
xOff=40:yOff=-60:zOff=0
endcase
endSelect
enemy = CreateObjectBox(16,20,16)
enemySpr=CreateSprite(0):SetSpriteSize(enemySpr,2,2):SetSpriteColor(enemySpr,255,0,0,255)
setobjectrotation(enemy,0,0,0)
SetObjectPosition( enemy, GetObjectX(spawnLoc)+xOff,GetObjectY(spawnLoc)+yOff,GetObjectZ(spawnLoc)+zOff )
SetObjectColor(enemy,random(50,255),random(50,255),random(50,255),255)
//SetObjectShader(enemy,Shader)
SetObjectCollisionMode(enemy,1)
//3D Physics code
Create3DPhysicsDynamicBody( enemy )
SetObjectShapeBox( enemy )
myItem as enemy
myItem.ID = enemy //the object id of the enemy
myItem.sprID=enemySpr
myEnemy.insert(myItem) //update bullet arrow as there is unlimeted bullets
inc enemyCount //used for a enemy counter to check if theyve timed out or not
endfunction
function ThrowBall( initialSpeed as float, mass as float)
//To move dynamic physics bodies we need to apply velocity to the physics body.
gunPositionVec= CreateVector3(GetObjectWorldX(playerObj),GetObjectWorldY(playerObj)+camOff_y#,GetObjectWorldZ(playerObj)) //im using the camera position as the gun position
//Create a tempory projectile block to calculate movement vectors of bullets
projectileDirBox as integer
projectileDirBox = CreateObjectBox( 1.0, 1.0, 1.0 )
SetObjectPosition( projectileDirBox, GetVector3X( gunPositionVec ), GetVector3Y( gunPositionVec ), GetVector3Z( gunPositionVec ) )
setobjectrotation(projectiledirbox,camangle_x#,GetObjectWorldAngleY(playerObj),GetObjectWorldAngleZ(playerObj))
MoveObjectLocalZ( projectileDirBox, 1.0 )
projectileDirVec = CreateVector3( GetobjectWorldX( projectileDirBox )-GetVector3X( gunPositionVec ), GetobjectWorldY( projectileDirBox )-GetVector3Y( gunPositionVec ), GetobjectWorldZ( projectileDirBox )-GetVector3Z( gunPositionVec ) )
DeleteObject( projectileDirBox )
throwBall as integer
throwBall = CreateObjectSphere( 10, 16, 32 )
SetObjectColor( throwBall, 255, 0,0,255 )
SetObjectPosition( throwBall, GetVector3X( gunPositionVec ), GetVector3Y( gunPositionVec ), GetVector3Z( gunPositionVec ) )
//3D Physics code
Create3DPhysicsDynamicBody( throwBall )
SetObjectShapeSphere( throwBall )
SetObject3DPhysicsMass( throwBall, mass )
SetObject3DPhysicsLinearVelocity( throwBall, projectileDirVec, initialSpeed )
//SetObject3DPhysicsFriction( throwBall, 0.8 )
//SetObject3DPhysicsRollingFriction( throwBall, 0.7 )
//SetObject3DPhysicsCanSleep(throwBall,0)
myItem as bullet
myItem.ID = throwBall //the object id of the bullet
myItem.time = timer() //timer is used to set there life time as bullets will die off after so long
myBullet.insert(myItem) //update bullet arrow as there is unlimeted bullets
inc bulletCount //used for a bullet counter to check if theyve timed out or not
deletevector3(projectileDirVec)
deletevector3(gunPositionVec)
endfunction
function startStory()
local flag:flag=1
//begin the story book by creating the cover and pages
CreateObjectBox(bookFront,10, 20, 0.1 )
createBookCover(bookCoverImg)
SetObjectImage(bookFront,bookCoverImg,0)
SetObjectPosition(bookFront,-5,10.0,.05)
FixObjectPivot(bookFront)
SetObjectPosition(bookFront,-5.0,-10.0,0)
SetObjectRotation(bookFront,0,180,0)
SetObjectCollisionMode(bookFront,0)
CreateObjectBox(bookPages1,10, 20,0.1 )
createBookPages1(bookPages1Img)
SetObjectImage(bookPages1,bookPages1Img,0)
SetObjectPosition(bookPages1,-5.0,10.0,.05)
FixObjectPivot(bookPages1)
SetObjectPosition(bookPages1,-5.0,-10.0,0)
SetObjectRotation(bookPages1,0,180,0)
SetObjectCollisionMode(bookPages1,0)
CreateObjectBox(bookPages2,10, 20,0.1 )
createBookPages2(bookPages2Img)
SetObjectImage(bookPages2,bookPages2Img,0)
SetObjectPosition(bookPages2,-5.0,10.0,.05)
FixObjectPivot(bookPages2)
SetObjectPosition(bookPages2,-5.0,-10.0,0.0)
SetObjectRotation(bookPages2,0,180,0)
SetObjectCollisionMode(bookPages2,0)
CreateObjectBox(bookPages3, 10, 20,0.1 )
createBookPages3(bookPages3Img)
SetObjectImage(bookPages3,bookPages3Img,0)
SetObjectPosition(bookPages3,-5.0,10.0,.05)
FixObjectPivot(bookPages3)
SetObjectPosition(bookPages3,-5.0,-10.0,0.0)
SetObjectRotation(bookPages3,0,180,0)
SetObjectCollisionMode(bookPages3,0)
CreateObjectBox(bookPages4, 10, 20,0.1 )
createBookPages4(bookPages4Img)
SetObjectImage(bookPages4,bookPages4Img,0)
SetObjectPosition(bookPages4,-5.0,10.0,.05)
FixObjectPivot(bookPages4)
SetObjectPosition(bookPages4,-5.0,-10.0,0.0)
SetObjectRotation(bookPages4,0,180,0)
SetObjectCollisionMode(bookPages4,0)
SetObJectVisible(bookPages4,0)
CreateObjectBox(bookBack,10, 20,0.1 )
createBookBack(bookBackImg)
SetObjectImage(bookBack,bookBackImg,0)
SetObjectPosition(bookBack,-5.0,10.0,.05)
FixObjectPivot(bookBack)
SetObjectPosition(bookBack,-5.0,-10.0,0.0)
SetObjectRotation(bookBack,0,180,0)
SetObjectCollisionMode(bookBack,0)
while GetObjectAngleY(bookFront)<360 and flag=1
RotateObjectLocalY( bookFront, .25 )
if GetPointerPressed() then flag=0
sync()
endwhile
SetObjectRotation(bookFront,0,360,0):flag=1
while GetObjectAngleY(bookPages1)<360 and flag=1
if GetObjectAngleY(bookPages1)>300 then SetObjectVisible(bookFront,0)
RotateObjectLocalY( bookPages1, .25 )
if GetPointerPressed() then flag=0
sync()
endwhile
SetObjectVisible(bookFront,0)
SetObjectRotation(bookPages1,0,360,0):flag=1
while GetObjectAngleY(bookPages2)<360 and flag=1
if GetObjectAngleY(bookPages2)>300 then SetObjectVisible(bookPages1,0)
RotateObjectLocalY( bookPages2, .25 )
if GetPointerPressed() then flag=0
sync()
endwhile
SetObjectVisible(bookPages1,0)
SetObjectRotation(bookPages2,0,360,0):flag=1
//DeleteObject(bookFront):DeleteImage(bookcoverImg)
//DeleteObject(bookPages1):DeleteImage(bookPages1Img)
//DeleteObject(bookPages2):DeleteImage(bookPages2Img)
//DeleteObject(bookPages3):DeleteImage(bookPages3Img)
endfunction
function teleport(direction as integer)
blankImage=createBlankImage()
teleport=CreateObjectCylinder(1,1,100)
SetObjectRotation(teleport,90,0,0)
SetObjectImage(teleport,blankImage,0)
SetObjectShader(teleport,Shader)
SetShaderConstantByName(teleport,"iResolution",100,100,0,0 )
blackCyl=CreateObjectCylinder(1,1,100)
SetObjectRotation(blackCyl,90,0,0)
SetObjectPosition(blackCyl,0,0,-1)
SetObjectColor(BlackCyl,0,0,0,255)
SetObjectVisible(blackCyl,0)
Local x#:local z#:local x2#:local y2#:local time#:local flag
x#=.25:z#=.25:x2#=2:z2#=2:flag=1:time#=timer()
repeat
if x#<140.0
inc x#:inc z#
endif
SetObjectScale(teleport,x#,.25,z#)
RotateObjectLocalY(teleport,direction)
SetShaderConstantByName( Shader,"iGlobalTime",Timer(),0,0,0 ) `tell the shader what time it is - so it can update its animations
if timer()>time#+2.0
SetObjectVisible(blackCyl,1)
SetObjectScale(blackCyl,x2#,.25,z2#)
inc x2#:inc z2#
endif
if GetPointerPressed() then flag=0
sync()
until timer()>time#+4.0 or flag=0
DeleteObject(teleport)
DeleteObject(blackCyl)
DeleteImage(blankImage)
endfunction
function createBlankImage()
rem create an ellipse that can be used as a sprite and returns the value of the image
SetClearColor(0,0,0)
ClearScreen()
Render()
DrawBox(0,0,100,100,MakeColor(255,255,255),MakeColor(255,255,255),MakeColor(255,255,255),MakeColor(255,255,255),1)
Swap()
img = getimage(0,0,100,100)
SetImageTransparentColor( img, 0, 0, 0 )
endfunction img
function createBookCover(img as integer)
SetClearColor(10,0,0)
ClearScreen()
DrawBox(0,0,256,256,makeColor(87,65,47),makeColor(87,65,47),makeColor(87,65,47),makeColor(87,65,47),1)
print(" ")
print(" The")
print(" Splendid")
print(" Book")
print(" of")
print(" Portals")
Render()
getimage(img,0,0,256,256)
Swap()
endfuncTion
function createBookBack(img as integer)
SetClearColor(10,0,0)
ClearScreen()
DrawBox(0,0,256,256,makeColor(87,65,47),makeColor(87,65,47),makeColor(87,65,47),makeColor(87,65,47),1)
print(" ")
print(" ")
print(" The")
print(" End")
Render()
getimage(img,0,0,256,256)
Swap()
endfuncTion
function createBookPages1(img as integer)
SetClearColor(10,0,0)
ClearScreen()
DrawBox(0,0,512,512,makeColor(255,255,255),makeColor(255,255,255),makeColor(255,255,255),makeColor(255,255,255),1)
SetPrintColor(1,1,1)
SetPrintSize(20)
print("")
print(" The Splendid Book of Portals ")
SetPrintSize(16)
print("")
print("")
print(" A fictional game programmed and published by")
print(" fubarpk. All media has been created with code")
print(" and all code has been produced by fubarpk, with")
print(" the exception some examples have been found on ")
print(" the TGC forums and modified to suit this Game.")
print("")
print("")
print(" Credits")
print(" The Game Creators for making it possible.")
print(" And a special thanks to lots of wonderful people")
print(" on the forums that make it easy to learn AGK.")
print("")
print("")
print("")
print(" The game is dedicated basicFanatics keyword game")
print(" jam July 9th - 16th 2018 with my key words being")
print(" book splendid and tunnel.")
Render()
getimage(img,0,0,512,512)
Swap()
SetPrintSize(30)
endfuncTion
function createBookPages2(img as integer)
SetClearColor(10,0,0)
ClearScreen()
DrawBox(0,0,512,512,makeColor(255,255,255),makeColor(255,255,255),makeColor(255,255,255),makeColor(255,255,255),1)
SetPrintColor(1,1,1)
SetPrintSize(20)
print("")
print(" The Splendid Book of Portals ")
SetPrintSize(16)
print("")
print("")
print(" The date is 2040 and your planets sun is on a ")
print(" collision course with the largest asteroid man")
print(" has ever known. It will surely destroy the sun")
print(" and its orbiting planets will float off into ")
print(" the galaxy somewhere.")
print("")
print("")
print(" A scientist has created a portal to another")
print(" universe but it is unknown what is on the ")
print(" other side")
print("")
print("")
print(" Armed with your trusty gun you begin your")
print(" journey by entering the portal with the warning")
print(" that the portal back will close after 1 hour and")
print(" after that there will be no way back.")
Render()
getimage(img,0,0,512,512)
Swap()
SetPrintSize(30)
endfuncTion
function createBookPages3(img)
SetClearColor(10,0,0)
ClearScreen()
DrawBox(0,0,512,512,makeColor(255,255,255),makeColor(255,255,255),makeColor(255,255,255),makeColor(255,255,255),1)
SetPrintColor(1,1,1)
SetPrintSize(20)
print("")
print(" The Splendid Book of Portals ")
SetPrintSize(16)
print("")
print("")
print(" Controls")
print(" Left mouse button to shoot.")
print(" Right mouse button to jump.")
print(" Use the mouse curser to aim.")
print(" Up arrow to move forward.")
print(" Down Arrow to move back.")
print(" Left Arrow strafe left.")
print(" Right Arrow strafe right.")
print(" Esc Exits")
print("")
print("")
print(" Click screen to take Portal")
print(" ")
print(" PS:Clicking advances pages and teleports")
print(" ")
Render()
getimage(img,0,0,512,512)
Swap()
SetPrintSize(30)
endfunction img
function createBookPages4(img)
SetClearColor(10,0,0)
ClearScreen()
DrawBox(0,0,512,512,makeColor(255,255,255),makeColor(255,255,255),makeColor(255,255,255),makeColor(255,255,255),1)
SetPrintColor(1,1,1)
SetPrintSize(20)
print("")
print(" The Splendid Book of Portals ")
SetPrintSize(16)
print("")
print("")
print(" Stumbling through another portal you find")
print(" yourself in a tunnel with moving walls and")
print(" fruit scattered on the ground.")
print(" ")
print(" Looking for a way back to finding that")
print(" Scientist responsible for you being here.")
print(" ")
print(" ")
Render()
getimage(img,0,0,512,512)
Swap()
SetPrintSize(30)
endfunction img
function gameOver()
If GetSpriteExists(radarSpr) then SetSpriteVisible(radarSpr,0)
If GetSpriteExists(playerSpr) then SetSpriteVisible(playerSpr,0)
local y#:local flag
SetObjectVisible(bookBack,1)
y#=180:flag=1
while y#<360 and flag=1
y#=y#+.25
if GetObjectAngleY(bookPages3)>300 then SetObjectVisible(bookPages2,0)
SetObjectRotation( bookPages3,0,y#,0 )
if getpointerpressed() then flag=0
if GetRawKeyState(KEY_ESCAPE) then end
sync()
endwhile
SetObjectRotation( bookPages3,0,360,0 ):SetObjectVisible(bookPages2,1) //incase the user clicked the screen
y#=360
while y#>180 and flag=1
y#=y#-.25
if y#<200 then SetObjectVisible(bookBack,0)
SetObjectRotation(bookPages3,0,y#,0)
if getpointerpressed() then flag=0
if GetRawKeyState(KEY_ESCAPE) then end
sync()
endwhile
SetObjectRotation(bookPages3,0,180,0) //incase the user clicked the screen
endfunction
function bonusLevel()
local flag:flag=1
SetObjectVisible(bookPages4,1)
If GetSpriteExists(radarSpr) then SetSpriteVisible(radarSpr,0)
If GetSpriteExists(playerSpr) then SetSpriteVisible(playerSpr,0)
while GetObjectAngleY(bookPages3)<360 and flag=1
if GetObjectAngleY(bookPages3)>300 then SetObjectVisible(bookPages2,0)
RotateObjectLocalY( bookPages3,.25 )
if getpointerpressed() then flag=0
if GetRawKeyState(KEY_ESCAPE) then end
sync()
endwhile
SetObjectRotation(bookPages3,0,360,0) //incase the user clicked the screen
teleport(-1)
CreateCharacterController(600):
SetObjectVisible(bookPages4,0)
SetObjectVisible(bookPages2,1)
SetObjectRotation(bookPages3,0,180,0)
endfunction
function playBonusLevel()
local obstacleCount:local alpha:local flag:local messageTime#:local z
obstacleCount=0:alpha=255:flag=1:messageTime#=timer()
for num=1 to bulletCount
DeleteObject(myBullet[num].ID)
myBullet.remove(num)
dec bulletCount
next num
for num=1 to enemyCount
DeleteObject(myEnemy[num].ID)
DeleteSprite(myEnemy[num].sprID)
myEnemy.remove(num)
dec enemyCount
next num
SetTextColorAlpha(helpMessage,0)
SetTextColorAlpha(helpMessage+1,0)
SetTextColorAlpha(helpMessage+2,0)
SetCameraRotation(1,0,0,0):SetCameraPosition(1,0,0,-20)
teleport(1):bonusLevel()
SetCameraRotation(1,camangle_x#,GetObjectWorldAngleY(playerObj),GetObjectWorldAngleZ(playerObj) )
SetCameraPosition(1,GetObjectWorldX(playerObj),GetObjectWorldY(playerObj)+camOff_y#,GetObjectWorldZ(playerObj))
SetRawMousePosition(screenWidth*.5,screenheight*.5)
z=650
for num = fruitStart to (24*2)+fruitStart step 2
DeleteObject(num)
createFruit(num)
SetObjectColor(num,random(1,255),random(1,255),random(1,255),255)
SetObjectPosition(num,0,-14,z)
SetObjectRotation(num,0,random(1,360),0)
SetObjectCollisionMode(num,1)
SetObjectCollisionMode(num+1,0)
z=z+50
next num
z=700
for num =1 to 10
ID=CreateObjectBox(100,100,2 )
//SetObjectImage(ID,texture2,0)
SetObjectColor(ID,random(1,255),random(1,255),random(1,255),255)
direction=random(1,4)
if direction=1 or direction =2
SetObjectPosition(ID,0,random(75,150),z)
elseif direction =3
SetObjectPosition(ID,150,32,z)
elseif direction =4
SetObjectPosition(ID,-150,32,z)
endif
Delete3DPhysicsBody(ID)
Create3DPhysicsStaticBody(ID)
SetObjectShapeBox(ID)
myItem as obstacle
myItem.ID = ID //the object id of the obstacle
myItem.direction=direction
myObstacles.insert(myItem) //update myObstacles
inc obstacleCount //used for a obstacle counter
z=z+100
next num
repeat
updatePlayerMovement(50)
for num=fruitStart to (26*2)+fruitStart step 2
collID=checkCollision(num)
if collID=playerObj
Delete3DPhysicsBody(num):DeleteObject(num):DeleteObject(num+1):inc fruit
endif
next num
//move the obstacles
for num =1 to obstacleCount
if myObstacles[num].direction=1
if getObjectY(myObstacles[num].ID)<150
SetObjectPosition(myObstacles[num].ID,getObjectX(myObstacles[num].ID),getObjectY(myObstacles[num].ID)+1,getObjectZ(myObstacles[num].ID))
else
myObstacles[num].direction=2
endif
elseif myObstacles[num].direction=2
if getObjectY(myObstacles[num].ID)>32
SetObjectPosition(myObstacles[num].ID,getObjectX(myObstacles[num].ID),getObjectY(myObstacles[num].ID)-1,getObjectZ(myObstacles[num].ID))
else
myObstacles[num].direction=1
endif
endif
if myObstacles[num].direction=3
if getObjectX(myObstacles[num].ID)<150
SetObjectPosition(myObstacles[num].ID,getObjectX(myObstacles[num].ID)+1,getObjectY(myObstacles[num].ID),getObjectZ(myObstacles[num].ID))
else
myObstacles[num].direction=4
endif
elseif myObstacles[num].direction=4
if getObjectX(myObstacles[num].ID)>-150
SetObjectPosition(myObstacles[num].ID,getObjectX(myObstacles[num].ID)-1,getObjectY(myObstacles[num].ID),getObjectZ(myObstacles[num].ID))
else
myObstacles[num].direction=3
endif
endif
SetObjectRotation(myObstacles[num].ID,0,0,0)
next num
if messagesFlag=1
if alpha>1
dec alpha
SetTextColorAlpha(helpMessage,alpha)
SetTextColorAlpha(helpMessage+1,alpha)
SetTextColorAlpha(helpMessage+2,alpha)
elseif flag=1 and timer()>messageTime#+5
SetTextString(helpMessage,"That portal just")
SetTextString(helpMessage+1,"led me to some")
SetTextString(helpMessage+2,"kind of tunnel.")
alpha=255:flag=2:messageTime#=timer()
elseif flag=2 and timer()>messageTime#+6
SetTextString(helpMessage,"The moving walls")
SetTextString(helpMessage+1,"look dangerous")
SetTextString(helpMessage+2,"I better take care")
alpha=255:flag=3:messageTime#=timer()
elseif flag=3 and timer()>messageTime#+4
SetTextString(helpMessage,"This place reminds ")
SetTextString(helpMessage+1,"me of something I")
SetTextString(helpMessage+2,"saw at the Movies.")
alpha=255:flag=4:messageTime#=timer()
elseif flag=4 and timer()>messageTime#+5
SetTextString(helpMessage,"I wonder if i can eat")
SetTextString(helpMessage+1,"this fruit. Some of")
SetTextString(helpMessage+2,"it looks tasty.")
alpha=255:flag=5:messageTime#=timer()
elseif flag=5 and timer()>messageTime#+4
SetTextString(helpMessage,"I see a portal at the ")
SetTextString(helpMessage+1,"other end. I am best ")
SetTextString(helpMessage+2,"to take it. ")
alpha=255:flag=6:messageTime#=timer()
elseif flag=6 and timer()>messageTime#+4
SetTextString(helpMessage,"How do these portals ")
SetTextString(helpMessage+1,"work. Perhaps by ")
SetTextString(helpMessage+2,"walking through it.")
alpha=255:flag=7:messageTime#=timer()
endif
endif
print("Level="+str(level))
print("Lives="+str(lives))
print("Fruit="+str(fruit))
//set camera and its offsets in relation to the players position
SetCameraRotation(1,camangle_x#,GetObjectWorldAngleY(playerObj),GetObjectWorldAngleZ(playerObj) )
SetCameraPosition(1,GetObjectWorldX(playerObj),GetObjectWorldY(playerObj)+camOff_y#,GetObjectWorldZ(playerObj))
SetShaderConstantByName( Shader,"iGlobalTime",Timer()*.5,0,0,0 ) `tell the shader what time it is - so it can update its animations
sync()
until getObjectZ(playerObj)> 1975 or GetRawKeyState(KEY_ESCAPE)
//do housekeeping remove any fired bullets
for num=1 to bulletCount
DeleteObject(myBullet[num].ID)
myBullet.remove(num)
dec bulletCount
next num
//remove all obstacles we no longer need them
for num =obstacleCount to 1 step -1
DeleteObject(myObstacles[num].ID)
myObstacles.remove(num)
next num
obstacleCount=0
SetCameraRotation(1,0,0,0):SetCameraPosition(1,0,0,-20)
If GetSpriteExists(radarSpr) then SetSpriteVisible(radarSpr,1)
If GetSpriteExists(playerSpr) then SetSpriteVisible(playerSpr,1)
teleport(-1):CreateCharacterController(200):
SetCameraRotation(1,camangle_x#,GetObjectWorldAngleY(playerObj),GetObjectWorldAngleZ(playerObj) )
SetCameraPosition(1,GetObjectWorldX(playerObj),GetObjectWorldY(playerObj)+camOff_y#,GetObjectWorldZ(playerObj))
SetRawMousePosition(screenWidth*.5,screenheight*.5)
endfunction
function createFruit(fruitID as integer)
CreateObjectSphere(fruitID,5,10,10)
SetObjectPosition(fruitID,25,0,0)
numMeshes=GetObjectNumMeshes(fruitID)
myObject as object
myObject.objMem=CreateMemblockFromObjectMesh(fruitID,1)
myObject.maxVertex=GetMemblockInt(myObject.objMem,0)-1
for index = 0 to 21//myObject.maxVertex
if index <=9
SetMeshMemblockVertexPosition(myObject.objMem,index,GetMeshMemblockVertexX(myObject.objMem,index),GetMeshMemblockVertexY(myObject.objMem,index)-2,GetMeshMemblockVertexZ(myObject.objMem,index))
else
SetMeshMemblockVertexPosition(myObject.objMem,index,GetMeshMemblockVertexX(myObject.objMem,index),GetMeshMemblockVertexY(myObject.objMem,index)-1,GetMeshMemblockVertexZ(myObject.objMem,index))
endif
next index
SetObjectMeshFromMemblock(fruitID,1,myObject.objMem)
DeleteMemblock(myObject.objMem)
SetObjectColor(fruitID,200,0,0,255)
Create3DPhysicsStaticBody(fruitID)
SetObjectShapeSphere(fruitID )
CreateObjectBox(fruitID+1,.5,2,.5)
vertex as integer[7] = [17,15,7,13, 1,19,3,5]
numMeshes=GetObjectNumMeshes(fruitID+1)
myObject.objMem=CreateMemblockFromObjectMesh(fruitID+1,1)
myObject.maxVertex=GetMemblockInt(myObject.objMem,0)-1
for i = 0 to 7
SetMeshMemblockVertexPosition(myObject.objMem,vertex[i],GetMeshMemblockVertexX(myObject.objMem,vertex[i])+1,GetMeshMemblockVertexY(myObject.objMem,vertex[i]),GetMeshMemblockVertexZ(myObject.objMem,vertex[i]))
next i
SetObjectMeshFromMemblock(fruitID+1,1,myObject.objMem)
DeleteMemblock(myObject.objMem)
SetObjectColor(fruitID+1,160,80,45,255)
SetObjectPosition(fruitID+1,-1,2,0)
FixObjectToObject(fruitID+1,fruitID)
endfunction
function createShader()
//create the shader used for the port holes
//Texture0 is where the kaleidosope is drawn
//Texture1 is a masking layer, anything on this layer that isn't transparent is used for drawing the Kali in texture0
//Texture2 is the texture you want to replace the transparent parts in texture1
//If no textures are set to an object the whole object will be a kaleidoscope
//if texture1 and setobjecttransparency is used then the transparent parts in texture1 will be transparent
//If texture2 is used with or without setobjecttransparency the parts visible on this texture will be drawn on the invisible bits in texture1
if GetFileExists("Kaliset.vs") then DeleteFile("Kaliset.vs")
file = OpenToWrite("Kaliset.vs")
WriteLine(file,"attribute highp vec3 position;")
WriteLine(file,"attribute mediump vec3 normal;")
WriteLine(file,"attribute mediump vec2 uv;")
WriteLine(file,"varying highp vec3 posVarying;")
WriteLine(file,"varying mediump vec3 normalVarying;")
WriteLine(file,"varying mediump vec2 uv0Varying;")
WriteLine(file,"varying mediump vec2 uv1Varying;")
WriteLine(file,"varying mediump vec2 uv2Varying;")
WriteLine(file,"varying mediump vec3 lightVarying;")
WriteLine(file,"uniform vec3 iResolution; // viewport resolution (in pixels)")
WriteLine(file,"uniform float iGlobalTime; // shader playback time (in seconds)")
WriteLine(file,"uniform float iChannelTime[10]; // channel playback time (in seconds)")
WriteLine(file,"uniform vec3 iChannelResolution[10]; // channel resolution (in pixels)")
WriteLine(file,"//uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down)")
WriteLine(file,"uniform sampler2D texture0; // input channel")
WriteLine(file,"uniform vec4 iDate; // (year, month, day, time in seconds)")
WriteLine(file,"uniform highp mat3 agk_WorldNormal;")
WriteLine(file,"uniform highp mat4 agk_World;")
WriteLine(file,"uniform highp mat4 agk_ViewProj;")
WriteLine(file,"uniform mediump vec4 uvBounds0;")
WriteLine(file,"uniform mediump vec4 uvBounds1;")
WriteLine(file,"uniform mediump vec4 uvBounds2;")
WriteLine(file,"mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file," uv0Varying = uv * uvBounds0.xy + uvBounds0.zw;")
WriteLine(file," uv1Varying = uv * uvBounds1.xy + uvBounds1.zw;")
WriteLine(file," uv2Varying = uv * uvBounds2.xy + uvBounds2.zw;")
WriteLine(file," highp vec4 pos = agk_World * vec4(position,1.0);")
WriteLine(file," gl_Position = agk_ViewProj * pos;")
WriteLine(file," mediump vec3 norm = normalize(agk_WorldNormal * normal);")
WriteLine(file," posVarying = pos.xyz;")
WriteLine(file," normalVarying = norm;")
WriteLine(file," lightVarying = GetVSLighting( norm, posVarying );")
WriteLine(file,"}")
CloseFile(file)
if GetFileExists("Kaliset.ps") then DeleteFile("Kaliset.ps")
file = OpenToWrite("Kaliset.ps")
WriteLine(file,"uniform vec3 iResolution; // viewport resolution (in pixels)")
WriteLine(file,"uniform float iGlobalTime; // shader playback time (in seconds)")
WriteLine(file,"uniform float iChannelTime[10]; // channel playback time (in seconds)")
WriteLine(file,"")
WriteLine(file,"//uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down)")
WriteLine(file,"uniform sampler2D texture0; // input channel ")
WriteLine(file,"uniform sampler2D texture1; // input channel ")
WriteLine(file,"uniform sampler2D texture2; // input channel ")
WriteLine(file,"uniform vec4 iDate; // (year, month, day, time in seconds)")
WriteLine(file,"varying mediump vec2 uv0Varying;")
WriteLine(file,"varying mediump vec2 uv1Varying;")
WriteLine(file,"varying mediump vec2 uv2Varying;")
WriteLine(file,"const int iterations=12;")
WriteLine(file,"void main(void)")
WriteLine(file,"{")
WriteLine(file,"//this takes the pixel we are working with to determine where it is on the screen")
//WriteLine(file,"vec2 z = gl_FragCoord.xy/iResolution.xy;")
WriteLine(file,"vec2 z = uv0Varying;")
WriteLine(file,"//fixes aspect ratio in favor of symmety. comment it and see what it looks like")
WriteLine(file,"//z.y*=iResolution.y/iResolution.x;")
WriteLine(file,"//gloobywavez")
WriteLine(file,"z.x += sin(z.y*2.0+iGlobalTime * .2)/10.0;")
WriteLine(file,"//zooom")
WriteLine(file,"//z*= 1.2 + sin(iGlobalTime*.15);")
WriteLine(file,"//pan")
WriteLine(file,"//z+=vec2(sin(iGlobalTime*.2),cos(iGlobalTime*.01));")
WriteLine(file,"//rotate")
WriteLine(file,"//z=vec2(z.x*cos(iGlobalTime*.2)- z.y*sin(iGlobalTime*.2),z.y*cos(iGlobalTime*.2));")
WriteLine(file,"vec2 c=vec2(0.5, 1.1);")
WriteLine(file,"")
WriteLine(file,"float average=0.;")
WriteLine(file,"float l=length(z);")
WriteLine(file,"float prevl;")
WriteLine(file,"for (int i=0; i<iterations; i++)")
WriteLine(file,"{")
WriteLine(file,"//kaliset base form")
WriteLine(file,"z=abs(z)/dot(z,z) -c;")
WriteLine(file,"//this is another function that can be iterated to produce some different fractals")
WriteLine(file,"//comment out the previous kaliset and experiment with values with this one!!")
WriteLine(file,"//z = abs(z)/(z.x*z.y)-c;")
WriteLine(file,"prevl=l;")
WriteLine(file,"l=length(z);")
WriteLine(file,"average+=abs(l-prevl);")
WriteLine(file,"}")
WriteLine(file,"//get the average length based upon the amount of iterations elapsed. multiply it to adjust definition")
WriteLine(file,"average/=float(iterations) * 15.;")
WriteLine(file,"//color fluctuation")
WriteLine(file,"average+=iGlobalTime*0.08;")
WriteLine(file,"vec3 myColor=vec3(0.2,0.21,.62);")
WriteLine(file,"vec3 finalColor;")
WriteLine(file,"//set the colors!")
WriteLine(file,"finalColor.r = (fract(float(average)/myColor.r));")
WriteLine(file,"finalColor.g = (fract(float(average)/myColor.g));")
WriteLine(file,"finalColor.b = (fract(float(average)/myColor.b));")
WriteLine(file,"vec4 colorResult1 = texture2D(texture1, uv1Varying);")
WriteLine(file,"vec4 colorResult2 = mix(colorResult1,vec4(finalColor,1.0), colorResult1.a);")
//WriteLine(file,"vec4 colorResult3 = texture2D(texture2, uv2Varying);")
WriteLine(file,"vec4 colorResult3 = mix(texture2D(texture2,uv2Varying),colorResult2,colorResult1.a);")
//WriteLine(file,"gl_FragColor = mix(colorResult3,colorResult1,colorResult2);")
WriteLine(file,"gl_FragColor = colorResult3;")
WriteLine(file,"}")
CloseFile(file)
endfunction
PS For those that tried the last there is some nice improvements that you can click
the mouse to advance pages as that animation got really annoying with all the testing
Shader now has the option of using a masking layer for texture1 if so chose this stops
it drawing anything on transparent parts. I did play with that effect a bit but thought
donuts are best for eating and not for games
fubar