Topic: Customizable Game Script (In_Progress)

Hello. I am working on a customizeable game script. It's sort of like my BaseMesh 3D models, in that it is a template you can use to make your own games easier. I will post what I have so far:


--CLASSES--
-------------------------------[[PERSON]]-----------------------
--New Person Class
[[CLASS]]    function newPerson(name,age)
            local object = {}
            
            object.name = name
            object.age = age
            
            function object:sayName()
                print (object.name)
            end    
                
            return object
        end

--Create Joe
local joe = newPerson("Joe",24)

--Create Bill
local bill = newPerson("Bill",25)

--Print Joe's name
print (joe.name)

--Make Bill say his name
bill:sayName()
-------------------------------[[ANIMATION]]-----------------------
-------------------------------[[CUTSCENE]]-----------------------
-------------------------------[[CHARACTER]]-----------------------
-------------------------------[[PROP]]-----------------------
-------------------------------[[MENU]]-----------------------
-------------------------------[[LEVEL]]-----------------------
-------------------------------[[CLOTH]]-----------------------


--FUNCTIONS--
-------------------------------[[MOVEMENT]]-----------------------

function Move()

end
------------------------------------------------------------------------
function Jump()

end
------------------------------------------------------------------------
function Spin()

end
------------------------------------------------------------------------
function Physics()

end
------------------------------------------------------------------------

-------------------------------[[SENSES]]---------------------------

function See()


end
------------------------------------------------------------------------
function Hear()


end
------------------------------------------------------------------------
function Touch()


end
------------------------------------------------------------------------
function Taste()


end
------------------------------------------------------------------------
function Smell()


end
------------------------------------------------------------------------


--VARIABLES--
-------------------------------[[JUMP]]---------------------------
jump_height =
jump_speed =
jump_button =
Jump_animation =
-------------------------------[[MOVE]]---------------------------
move_direction =
move_speed =
move_button = 
move_animation =
-------------------------------[[SPIN]]---------------------------
spin_direction =
spin_speed =
spin_button =
spin_animation =
-------------------------------[[PHYSICAL]]---------------------------
gravity =
friction =
damping =
-------------------------------[[SEE]]---------------------------
see_object =
see_FOV =
see_distance = 
see_animation =
-------------------------------[[SMELL]]---------------------------
smell_particle_system =
smell_animation =
-------------------------------[[HEAR]]---------------------------
hear_sound =
hear_proximity =
hear_pitch =
hear_animation = 
-------------------------------[[TOUCH]]---------------------------
touch_object = getObject("finish_line")
touch_action =
touch_animation = 

-------------------------------[[TASTE]]---------------------------
taste_object =
taste_proximity =

--SAMPLE GAME USAGE:--

menu = newMenu() --Creates a new menu
menu.Start() --Starts the menu
menu.Stop() --Stops the menu

cut_scene = newCutScene() --Creates a new cut-scene
cut_scene.Play() --Plays the new cut-scene
cut_scene.Stop() --Stops the new cut-secene

cut_scene_2 = newCutScene() --Creates a new cut-scene
cut_scene_2.Play() --Plays the new cut-scene
cut_scene_2.Stop() --Stops the new cut-secene

level1 = newLevel() --Creates a new level
level1.Start() --Starts the new level
level1.Stop() --Stops the new level

prop1 = newProp() --Creates a new prop
prop1.Create(room) --Creates the mesh for the new prop

man1 = newPerson()
man1.Create(man) --Creates the mesh for the new man (can be woman also)
man1.Move(forward,5 --[[mph]],"UP",walk) --Makes the man able to move
man1.Jump() --Makes the man able to jump
man1.Spin() --Makes the man able to move spin
man1.Physical() --Makes the man physical

man1.See() --Makes the man able to see
man1.Hear() --Makes the man able to hear
man1.Touch() --Makes the man able to touch
man1.Taste() --Makes the man able to taste
man1.Smell() --Makes the man able to smell

--SAMPLE GAME:--COMING SOON!!!

Last edited by Tutorial Doctor (2013-10-03 00:53:18)

Re: Customizable Game Script (In_Progress)

Okay. This is PHASE TWO: "Digging through the API":




--CLASSES--
-------------------------------[[PERSON]]----------------------------------------

--Create()        --Creates the mesh for the new man (can be woman also)
--Move        --Makes the man able to move
--Jump()         --Makes the man able to jump
--Spin()         --Makes the man able to move spin
--Physical()        --Makes the man physical

--See()         --Makes the man able to see
--Hear()         --Makes the man able to hear
--Touch()         --Makes the man able to touch
--Taste()         --Makes the man able to taste
--Smell()
--------------------------------------
--New Person Class
[[CLASS]]    function Person(name,age)
            local object = {}
            
            object.name = name
            object.age = age
            
            function object:sayName()
                print (object.name)
            end    
                
            return object
        end

--Create Joe
local joe = Person("Joe",24)

--Create Bill
local bill = Person("Bill",25)

--Print Joe's name
print (joe.name)

--Make Bill say his name
bill:sayName()
------------------------------------------------------------------------------

-------------------------------[[ANIMATION]]-----------------------
--Methods
--changeAnimation(object, animationId)

end
-------------------------------[[CUTSCENE]]-----------------------
--Methods:
--changeScene(scene)
--object:Play()
--object:Stop()
--object:Pause()

function Play(scene)
    changeScene(scene)
end


--Class Variables:
--object.length
-------------------------------[[CHARACTER]]-----------------------
--Methods
--object:Generate()

--Class Variables:
--object.name
--object.height

-------------------------------[[PROP]]-----------------------
--Methods
--object:Create()
--object:Destroy()
function Create(object)
    activate(object)
end

function Destroy(object)
    deactivate(object)
end

--Class Variables:
--object.length
-------------------------------[[MENU]]-----------------------
--Methods
--object:Start()
--object:End()

function Start()

end

function End()

end

--Class Variables:
--object.length
-------------------------------[[LEVEL]]-----------------------
--Methods
--object:Begin()
--object:Finish()

function Begin(level)
    loadLevel(level)
end

function Finish(level)
    loadLevel(level)
end
--Class Variables:

-------------------------------[[CLOTH]-----------------------
--Methods
--object:Simulate()

--Class Variables:

-------------------------------[[LIGHT]-----------------------
--Methods
--object:TurnOff()
--object:TurnOn()
--object:ChangeColor()
function TurnOn(light)
    activate(light)
end

function TurnOff(light)
    deactivate(light)
end

function ChangeColor(light,color)
    setLightColor(light,color)
end
--Class Variables:
--object.color
--object.state
--object.brightness
--------------------------------------------------------------------

--VARIABLES--
-------------------------------[[JUMP]]---------------------------
--translate(object,direction,"local")
jump_height =         3
jump_speed =         1
jump_btn =         "SPACE"
Jump_animation =    changeAnimation(object, animationId)
-------------------------------[[MOVE]]---------------------------
--translate(object,direction,"local")

move_forward =        vec3(x, y, move_speed) --[1]
move_backward =    vec3(x, y, -move_speed) --[2]
move_left =        vec3(-move_speed, y, z) --[3]
move_right =        vec3(move_speed, y, z) --[4]
move_down=        vec3(x, -move_speed, z) --[5]
move_up=            vec3(x, move_speed, z) --[6]
move_direction =        {move_forward,move_backward,move_left,move_right,move_down,move_up}
move_speed =        1
move_btn =        "UP" 
move_animation =    changeAnimation(object, animationId)
-------------------------------[[SPIN]]---------------------------
--rotate(object,direction,angle,"local")
spin_direction =        vec = vec3(x, y, z)
spin_left =             vec = vec3(-spin_speed, y, z)
spin_right =        vec = vec3(spin_speed, y, z)
spin_speed =        1
spin_btn =        "RIGHT"
spin_animation =        changeAnimation(object, animationId)
-------------------------------[[PHYSICAL]]---------------------------
gravity =             setGravity({x, y, z})
linear_damping =         setLinearDamping(object, damping)
angular_damping =     setAngularDamping(object, damping)
linear factor =         setLinearFactor(object, {x, y, z})
angular_factor =         setAngularFactor(object, factor)
mass =             setMass(object, mass)
friction =             setFriction(object, friction)
restitution =         setRestitution(object, restitution)
-------------------------------[[SEE]]---------------------------
--isCollisionTest(object)
--isCollisionBetween(object1, object2)
--getNumCollisions(object)
--setScale(object, {x, y, z})
--changeAnimation(object, animationId)
--setAnimationSpeed(object, speed)

seen =             isCollisionTest(object)--true or false
see_object =        getObject(« objectName »)        
see_FOV =            0            
see_distance =        0
see_animation =        changeAnimation(object, animationId)        
-------------------------------[[SMELL]]---------------------------
smelled =             isCollisionTest(object)--true or false
smell_particle_system =
smell_animation =        changeAnimation(object, animationId)
-------------------------------[[HEAR]]---------------------------
--playSound(object)
--pauseSound(object)
--stopSound(object)
--getSoundGain(object)
--setSoundGain(object, gain)
heard =             false
hear_sound =        getSoundGain(object)
hear_proximity =        0
hear_pitch =        0
hear_animation =        changeAnimation(object, animationId) 
-------------------------------[[TOUCH]]---------------------------
touched =             isCollisionTest(object)
touch_object =         getObject("finish_line")
touch_animation =     changeAnimation(object, animationId)

-------------------------------[[TASTE]]---------------------------
tasted =             isCollisionTest(object)
taste_object =        getObject(« objectName »)
taste_proximity =        0

--------------------------------------------------------------------------------------------

--FUNCTIONS--

--------[[MOVEMENT]]------
--translate(object,direction,"local")
--clearForces(object)
--addCentralForce(object, {x, y, z}, "local")
--addTorque(object, {x, y, z}, "local")

function Move(move_direction,move_speed,move_btn,move_animation)
    if isKeyPressed(move_btn) then
        changeAnimation(object,move_animation)
        translate(object,move_direction,"local")
    end    
end

--local forward = move_forward
--local backward=move_backward
--local left=move_left
--local right=move_right
--local up=move_up
--local down=move_down
------------------------------------------------------------------------
function Jump(jump_direction,jump_height,jump_speed,jump_btn,jump_animation)
    if isKeyPressed(jump_btn) then
        changeAnimation(object,0)
        addCentralForce(object, {x, jump_height, z}, "local")
    end
end
------------------------------------------------------------------------
function Spin(spin_direction,spin_speed,spin_btn,spin_animation)
    if isKeyPressed(key) then
        changeAnimation(object,0)
        rotate(object,spin_direction,angle,"local")
    end
end
------------------------------------------------------------------------
function Physics()
    
    
end
------------------------------------------------------------------------

----[[SENSES]]-----

function See()
    if seen then
        changeAnimation(object,0)
    end

end
------------------------------------------------------------------------
function Hear()
    if heard then
        changeAnimation(object,0)
    end
end
------------------------------------------------------------------------
function Touch()
    if touched then
        changeAnimation(object,0)
    end
end
------------------------------------------------------------------------
function Taste()
    if tasted then
        changeAnimation(object,0)
        tasted=true
    end
end
------------------------------------------------------------------------
function Smell()
    if smelled then
        changeAnimation(object,0)
        smelled=true
    end
end
------------------------------------------------------------------------

--------------------------------------------------------------------------------

--SAMPLE GAME:--

--setText(object , "text")
--getText(object)
--getTextColor(object)
--setTextColor(object, {r, g, b, a})
--getScene("sceneName")
--changeScene(scene)
--getCurrentSceneId()
--getScenesNumber()
--loadLevel("levels/myLevel.level")


menu = Menu() --Creates a new menu
menu.Start() --Starts the menu
menu.End() --Stops the menu
--------------------------------------------------------------------------------------------
--changeCurrentCamera(object)
--getCurrentCamera()
--getCameraClearColor(object)
--getCameraFov(object)
--getCameraNear(object)
--getCameraFar(object)
--getCameraFogDistance(object)
--isCameraOrtho(object)
--isCameraFogEnabled(object)
--setCameraClearColor(object, {r, g, b})
--setCameraFov(object, fov)
--setCameraNear(object, near)
--setCameraFar(object, far)
--setCameraFogDistance(object, fogDistance)
--enableCameraOrtho(object, ortho)
--enableCameraFog(object, fog)
--enableCameraLayer(object, scene)
--disableCameraLayer(object)
--enableRenderToTexture(object, "textureName", renderWith, renderHeight)
--disableRenderToTexture(object)
--***getProjectedPoint(object, point)
--***getUnProjectedPoint(object, point)

--getScene("sceneName")
--getScenesNumber()

cut_scene = newCutScene() --Creates a new cut-scene
cut_scene.Play()         --Plays the new cut-scene
cut_scene.Stop() --Stops the new cut-secene

--getScene("sceneName")
--getScenesNumber()

cut_scene_2 = newCutScene() --Creates a new cut-scene
cut_scene_2.Play()    changeScene(scene) --Plays the new cut-scene
cut_scene_2.Stop() --Stops the new cut-secene
-------------------------------------------------------------------------------------
--loadLevel("levels/myLevel.level")

level1 = Level() --Creates a new level
level1.Begin() =         loadLevel("levelName") --Starts the new level
level1.Finish() --Stops the new level
-------------------------------------------------------------------------------------
--getObject(« objectName »)
--activate(object)
--deactivate(object)
--isVisible(object)
--isActive(object)

prop1 = Prop()=    --Creates a new prop
prop1.Create(room) --Creates the mesh for the new prop
prop1.Destroy()
-------------------------------------------------------------------------------------
man1 = Person()--Creates a new person called man1
man1.Create(man)    activate(object) --Creates the mesh for the new man (can be woman also)
man1.Move    (move_direction,move_speed,move_button,move_animation) --Move() forward at 5mph using the UP button and playing the WALK animation
man1.Jump(jump_height,jump_speed,jump_animation) --Makes the man able to jump
man1.Spin(spin_direction,spin_speed,spin_btn) --Makes the man able to move spin
man1.Physical() --Makes the man physical
-------------------------------------------------------------------------------------
man1.See() --Makes the man able to see
man1.Hear() --Makes the man able to hear
man1.Touch() --Makes the man able to touch
man1.Taste() --Makes the man able to taste
man1.Smell() --Makes the man able to smell
-------------------------------------------------------------------------------------


--OTHER--
--[[dofile("lights/lightsfx.lua") 
   light = getObject("Light") 
   function onSceneUpdate()
       flickerLightEffects(light)
   end]]
   
   --function QuitGame()
--if isKeyPressed("Q") then
    --quit()
--end
--end

Last edited by Tutorial Doctor (2013-10-03 00:54:53)

Re: Customizable Game Script (In_Progress)

Testing out my new MOVEMENT abilities:

monkey = getObject("monkey")
box = getObject("cube")

--translate(object,direction,"local")
move_object =         monkey
move_speed =        .2
move_forward =        vec3(x, -move_speed, z) --[1]
move_backward =    vec3(x, move_speed, z) --[2]
move_left =        vec3(move_speed, y, z) --[3]
move_right =        vec3(-move_speed, y, z) --[4]
move_down=        vec3(x, y,-move_speed) --[5]
move_up=            vec3(x, y, move_speed) --[6]
move_direction =        {move_forward,move_backward,move_left,move_right,move_down,move_up}
move_btn =         {move_btn_U,move_btn_D,move_btn_L,move_btn,R}
move_btn_U =        "UP"
move_btn_D =        "DOWN"
move_btn_L =        "LEFT"
move_btn_R =        "RIGHT" 
move_animation =    changeAnimation(object, animationId)


function Move(move_object,move_direction,move_btn)
    if isKeyPressed(move_btn) then
        --changeAnimation(move_object,move_animation)
        translate(move_object,move_direction,"local")
    end    
end

function onSceneUpdate()

    Move(monkey,move_forward,move_btn_U)
    Move(monkey,move_backward,move_btn_D)
    Move(monkey,move_left,move_btn_L)
    Move(monkey,move_right,move_btn_R)
    
    
    Move(box,move_direction[1],move_btn_U)
    Move(box,move_direction[2],move_btn_D)
    Move(box,move_direction[3],move_btn_L)
    Move(box,move_direction[4],move_btn_R)
    

end

Last edited by Tutorial Doctor (2013-10-06 17:04:45)

Re: Customizable Game Script (In_Progress)

Now we can JUMP!:

box=getObject("cube")

--translate(object,direction,"local")
jump_object =         box
jump_height =         3
jump_speed =         1
jump_btn =         "SPACE"
jump_animation =    changeAnimation(object, animationId)
jump_direction =         {jump_up,jump_down,jump,left,jump_right}
jump_up =            vec3(x, y, jump_speed*jump_height) 
jump_down =        vec3(x, y, jump_speed*jump_height) 
jump_left =            vec3(-jump_speed*jump_height, y, z) 
jump_right =        vec3(jump_speed*jump_height, y, z) 



function Jump(jump_object,jump_direction,jump_btn--[[,jump_animation]])
    if isKeyPressed(jump_btn) then
        --changeAnimation(jump_object,jump_animation)
        addCentralForce(jump_object, jump_direction, "local")
    end
end


function onSceneUpdate()

    Jump(box,jump_up,jump_btn)

end

Last edited by Tutorial Doctor (2013-10-06 17:05:03)

Re: Customizable Game Script (In_Progress)

Now You can MOVE JUMP and SPIN:

box=getObject("cube")

monkey = getObject("monkey")

-------------------------------[[MOVE]]---------------------------
--translate(object,direction,"local")
move_object =         box
move_speed =        .2
move_forward =        vec3(x, -move_speed, z) --[1]
move_backward =    vec3(x, move_speed, z) --[2]
move_left =        vec3(move_speed, y, z) --[3]
move_right =        vec3(-move_speed, y, z) --[4]
move_down=        vec3(x, y,-move_speed) --[5]
move_up=            vec3(x, y, move_speed) --[6]
move_direction =        {move_forward,move_backward,move_left,move_right,move_down,move_up}
move_btn =         {move_btn_U,move_btn_D,move_btn_L,move_btn,R}
move_btn_U =        "W"
move_btn_D =        "S"
move_btn_L =        "LEFT"
move_btn_R =        "RIGHT" 
move_animation =    changeAnimation(object, animationId)


function Move(move_object,move_direction,move_btn)
    if isKeyPressed(move_btn) then
        --changeAnimation(move_object,move_animation)
        translate(move_object,move_direction,"local")
    end    
end

-------------------------------[[JUMP]]---------------------------
--translate(object,direction,"local")
jump_object =         box
jump_height =         3
jump_speed =         1
jump_btn =         "SPACE"
jump_animation =    changeAnimation(object, animationId)
jump_direction =         {jump_up,jump_down,jump,left,jump_right}
jump_up =            vec3(x, y, jump_speed*jump_height) 
jump_down =        vec3(x, y, jump_speed*jump_height) 
jump_left =            vec3(-jump_speed*jump_height, y, z) 
jump_right =        vec3(jump_speed*jump_height, y, z) 

collisions = getNumCollisions(box)

function Jump(jump_object,jump_direction,jump_btn--[[,jump_animation]])
    if isKeyPressed(jump_btn) then
        --changeAnimation(jump_object,jump_animation)
        addCentralForce(jump_object, jump_direction, "local")
    end
end

-------------------------------[[SPIN]]-------
--rotate(object,direction,angle,"local")
spin_speed =        7
spin_object =         box
spin_direction =        {spin_left,spin_right}
spin_left =             vec3(x, y, spin_speed)
spin_right =        vec3(x, y, -spin_speed)
spin_btn =            {spin_btn_L,spin_btn_R}
spin_btn_L =        "A"
spin_btn_R    =        "D"
spin_animation =        changeAnimation(object, animationId)



function Spin(spin_object,spin_direction,spin_btn)
    if isKeyPressed(spin_btn) then
        --changeAnimation(spin_object,spin_animation)
        rotate(spin_object,spin_direction,spin_speed,"local")
    end    
end

function onSceneUpdate()

    Jump(box,jump_up,jump_btn)
    
    Move(box,move_direction[1],move_btn_U)
    Move(box,move_direction[2],move_btn_D)
    Move(box,move_direction[3],move_btn_L)
    Move(box,move_direction[4],move_btn_R)
    
    Spin(box,spin_left,spin_btn_L)
    Spin(box,spin_right,spin_btn_R)

end
--------------------------

Last edited by Tutorial Doctor (2013-10-06 17:05:27)

Re: Customizable Game Script (In_Progress)

Now we can MOVE,JUMP,SPIN,ANIMATE, and MAKE SOUND!

box=getObject("cube")
man=getObject("man")
monkey = getObject("monkey")
cone = getObject("cone")
person = getObject("person")
steps = getObject("steps")
-------------------------------[[MOVE]]---------------------------
--translate(object,direction,"local")
--onKeyDown(key)
--onKeyUp(key)
--setAnimationSpeed(object, speed)
--playSound(object)
--pauseSound(object)
--stopSound(object)
--getSoundGain(object)
--setSoundGain(object, gain)


move_object =         box
move_speed =        .1
move_forward =        vec3(x, -move_speed, z) --[1]
move_backward =    vec3(x, move_speed, z) --[2]
move_left =        vec3(move_speed, y, z) --[3]
move_right =        vec3(-move_speed, y, z) --[4]
move_down=        vec3(x, y,-move_speed) --[5]
move_up=            vec3(x, y, move_speed) --[6]
move_direction =        {move_forward,move_backward,move_left,move_right,move_down,move_up}
move_btn =         {move_btn_U,move_btn_D,move_btn_L,move_btn,R}
move_btn_U =        "W"
move_btn_D =        "S"
move_btn_L =        "LEFT"
move_btn_R =        "RIGHT" 
move_animation =    1
idle_animation =         0
move_animation_speed =  2
idle_animation_speed = .5
move_sound = steps

function Move(move_object,move_direction,move_btn,move_animation,idle_animation)
    if isKeyPressed(move_btn) then
        changeAnimation(move_object,move_animation)
        translate(move_object,move_direction,"local")
        setAnimationSpeed(move_object, move_animation_speed)
    end    
    
    if onKeyDown(move_btn_U) then
        playSound(move_sound)
    end
    
    if onKeyUp(move_btn) then
        changeAnimation(move_object,idle_animation)
        setAnimationSpeed(move_object, idle_animation_speed)
        stopSound(move_sound)
    end
    
end

-------------------------------[[JUMP]]---------------------------
--translate(object,direction,"local")
col = getNumCollisions(jump_object)
jump_object =         box
jump_height =         3
jump_speed =         1
jump_btn =         "SPACE"
jump_animation =    changeAnimation(object, animationId)
jump_direction =         {jump_up,jump_down,jump,left,jump_right}
jump_up =            vec3(x, y, jump_speed*jump_height) 
jump_down =        vec3(x, y, jump_speed*jump_height) 
jump_left =            vec3(-jump_speed*jump_height, y, z) 
jump_right =        vec3(jump_speed*jump_height, y, z) 

collisions = getNumCollisions(box)

function Jump(jump_object,jump_direction,jump_btn--[[,jump_animation]])
    if isKeyPressed(jump_btn) then
        --changeAnimation(jump_object,jump_animation)
        addCentralForce(jump_object, jump_direction, "local")
    end
end

-------------------------------[[SPIN]]-------
--rotate(object,direction,angle,"local")
spin_speed =        7
spin_object =         box
spin_direction =        {spin_left,spin_right}
spin_left =             vec3(x, y, spin_speed)
spin_right =        vec3(x, y, -spin_speed)
spin_btn =            {spin_btn_L,spin_btn_R}
spin_btn_L =        "A"
spin_btn_R    =        "D"
spin_animation =        changeAnimation(object, animationId)



function Spin(spin_object,spin_direction,spin_btn)
    if isKeyPressed(spin_btn) then
        --changeAnimation(spin_object,spin_animation)
        rotate(spin_object,spin_direction,spin_speed,"local")
    end    
end


changeAnimation(person,0)
stopSound(steps)

------GAME---
function onSceneUpdate()
--Jumping Box
    Jump(box,jump_up,jump_btn)
    
    
    Move(box,move_direction[1],move_btn_U)
    Move(box,move_direction[2],move_btn_D)
    Move(box,move_direction[3],move_btn_L)
    Move(box,move_direction[4],move_btn_R)
    
    Spin(box,spin_left,spin_btn_L)
    Spin(box,spin_right,spin_btn_R)
----------------------------------------------------------------
--Jumping Person
    Jump(person,jump_up,jump_btn)
    
    
    Move(person,move_direction[1],move_btn_U,move_animation,idle_animation)
    Move(person,move_direction[2],move_btn_D,move_animation,idle_animation)
    Move(person,move_direction[3],move_btn_L,move_animation,idle_animation)
    Move(person,move_direction[4],move_btn_R,move_animation,idle_animation)
    
    Spin(person,spin_left,spin_btn_L)
    Spin(person,spin_right,spin_btn_R)    
    --See(cone,monkey)

end
--------------------------

Last edited by Tutorial Doctor (2013-10-06 17:05:46)

Re: Customizable Game Script (In_Progress)

Okay, I made the code a little neater:

----CUSTOMIZABLE GAME SCRIPT----

----OBJECTS
box=getObject("cube")
man=getObject("man")
monkey = getObject("monkey")
cone = getObject("cone")
person = getObject("person")
steps = getObject("steps")
Player = getObject("Player")
Set = getObject("Set")
Feet = getObject("Feet")
apple = getObject("apple")
snd_collect = getObject("collect")
apple_clone = getClone(apple)
----END OBJECTS

----MOTION
--MOVE VARIABLES
--[[translate(object,direction,"local")
onKeyDown(key)
onKeyUp(key)
setAnimationSpeed(object, speed)
playSound(object)
pauseSound(object)
stopSound(object)
getSoundGain(object)
setSoundGain(object, gain)]]

move_object =         box
move_speed =        .1
move_forward =        vec3(x, -move_speed, z) --[1]
move_backward =    vec3(x, move_speed, z) --[2]
move_left =        vec3(move_speed, y, z) --[3]
move_right =        vec3(-move_speed, y, z) --[4]
move_down=        vec3(x, y,-move_speed) --[5]
move_up=            vec3(x, y, move_speed) --[6]
move_direction =        {move_forward,move_backward,move_left,move_right,move_down,move_up}
move_btn =         {move_btn_U,move_btn_D,move_btn_L,move_btn,R}
move_btn_U =        "W"
move_btn_D =        "S"
move_btn_L =        "LEFT"
move_btn_R =        "RIGHT" 
move_animation =    1
idle_animation =         0
move_animation_speed =  2
idle_animation_speed = .5
move_sound = steps

--JUMP VARIABLES
--[[translate(object,direction,"local") ]]

col = getNumCollisions(jump_object)
jump_object =         box
jump_height =         3
jump_speed =         1
jump_btn =         "SPACE"
jump_animation =        changeAnimation(object, animationId)
jump_direction =         {jump_up,jump_down,jump,left,jump_right}
jump_up =            vec3(x, y, jump_speed*jump_height) 
jump_down =        vec3(x, y, jump_speed*jump_height) 
jump_left =            vec3(-jump_speed*jump_height, y, z) 
jump_right =        vec3(jump_speed*jump_height, y, z) 
collisions =             getNumCollisions(box)

--SPIN VARIABLES
--[[rotate(object,direction,angle,"local")]]

spin_speed =        7
spin_object =         box
spin_direction =        {spin_left,spin_right}
spin_left =             vec3(x, y, spin_speed)
spin_right =        vec3(x, y, -spin_speed)
spin_btn =            {spin_btn_L,spin_btn_R}
spin_btn_L =        "A"
spin_btn_R    =        "D"
spin_animation =        changeAnimation(object, animationId)

--MOVE FUNCTION
function Move(move_object,move_direction,move_btn,move_animation,idle_animation)
    if isKeyPressed(move_btn) then
        changeAnimation(move_object,move_animation)
        translate(move_object,move_direction,"local")
        playSound(move_sound)
        setAnimationSpeed(move_object, move_animation_speed)
        
    end    
    
    if onKeyDown(move_btn) then
        playSound(move_sound)
    end
    
    if onKeyUp(move_btn) then
        changeAnimation(move_object,idle_animation)
        setAnimationSpeed(move_object, idle_animation_speed)
        stopSound(move_sound)
    end
    
end

--JUMP FUNCTION
function Jump(jump_object,jump_direction,jump_btn--[[,jump_animation]])
    if isKeyPressed(jump_btn) then
        --changeAnimation(jump_object,jump_animation)
        addCentralForce(jump_object, jump_direction, "local")
    end
end


--SPIN FUNCTION
function Spin(spin_object,spin_direction,spin_btn)
    if isKeyPressed(spin_btn) then
        --changeAnimation(spin_object,spin_animation)
        rotate(spin_object,spin_direction,spin_speed,"local")
    end    
end
----END MOTION

----ARTIFICIAL INTELLIGENCE 
--SEE VARIABLES
--[[isCollisionTest(object)
isCollisionBetween(object1, object2)
getNumCollisions(object)
setScale(object, {x, y, z})
changeAnimation(object, animationId)
setAnimationSpeed(object, speed)]]

seen_object =        monkey    
seeing_object =         cone
seen =             isCollisionBetween(seeing_object,seen_object)--true or false
see_FOV =            0            
see_distance =        0
see_animation =        0--animatinoID

--SMELL VARIABLES
smelled =             isCollisionTest(object)--true or false
smell_particle_system =
smell_animation =        0--animatinoID

--HEAR VARIABLES
--[[playSound(object)
--pauseSound(object)
--stopSound(object)
--getSoundGain(object)
--setSoundGain(object, gain)]]

heard =             false
hear_sound =        getSoundGain(object)
hear_proximity =        0
hear_pitch =        0
hear_animation =        0--animationID
hear_limit =         3 --limit at which sound can be heard

--TOUCH VARIABLES
touched =             isCollisionTest(object)
touch_object =         getObject("finish_line")
touch_animation =     0--animationID

--TASTE VARIABLES
tasted =             isCollisionTest(object)
taste_object =        getObject(« objectName »)
taste_proximity =        0
taste_animation =    0


--SEE FUNCTION
function See(seeing_object,seen_object)
    if isCollisionBetween(seeing_object,seen_object) then 
        quit()
    end
end

--HEAR FUNCTION
--the object in parenthesis is the object being heard (a sound object)
function Hear()
    if heard and hear_sound > hear_limit then
        changeAnimation(object,hear_animation)
    end
end

--TOUCH FUNCTION
function Touch()
    if touched then
        changeAnimation(object,touch_animation)
    end
end

--TASTE FUNCTION
function Taste()
    if tasted then
        changeAnimation(object,taste_animation)
        tasted=true
    end
end

--SMELL FUNCTION
function Smell()
    if smelled then
        changeAnimation(object,smell_animation)
        smelled=true
    end
end
----END ARTIFICIAL INTELLIGENCE

----DEFAULTS
changeAnimation(person,0)
stopSound(steps)
----END DEFAULTS

----ADDITIONAL FUNCTIONS
function GetText()
    --Apples
    --apples = {apple_clone,apple_clone,apple_clone,apple_clone}
    --apples_collected = 0
    --scale = vec3(2,2,2)

    GuiScene = getScene("Scene_name")
    Camera = getObject("Camera_name")
    enableCameraLayer(Camera, GuiScene)
    text = getObject(GuiScene,"Text_object")
    show_apples_collected = "Apples = " .. apples_collected
    setText(text,show_apples_collected)
    --Collect(apple)
    --Collect(apple_clone)
    
    --coll = getNumCollisions(Feet)
end


--[[COLLECTION FUNCTION
function Collect(object)
    if isCollisionBetween(Player,object) then
        deactivate(object)
        playSound(snd_collect)
        --Scale()
        apples_collected = apples_collected + 1
    end
end
]]
----END OF ADDITIONAL FUNCTIONS

----GAME
function onSceneUpdate()

    --Move Box
    Move(box,move_direction[1],move_btn_U)
    Move(box,move_direction[2],move_btn_D)
    Move(box,move_direction[3],move_btn_L)
    Move(box,move_direction[4],move_btn_R)
    
    --Jump Box
    Jump(box,jump_up,jump_btn)
    
    --Spin Box
    Spin(box,spin_left,spin_btn_L)
    Spin(box,spin_right,spin_btn_R)
----------------------------------------------------------------
    --Move Person
    Move(person,move_direction[1],move_btn_U,move_animation,idle_animation)
    Move(person,move_direction[2],move_btn_D,move_animation,idle_animation)
    Move(person,move_direction[3],move_btn_L,move_animation,idle_animation)
    Move(person,move_direction[4],move_btn_R,move_animation,idle_animation)
    
    --Jump Person
    Jump(person,jump_up,jump_btn)

    
    --Spin Person
    Spin(person,spin_left,spin_btn_L)
    Spin(person,spin_right,spin_btn_R)
    
    

end
----END GAME

 

Re: Customizable Game Script (In_Progress)

If you understand how to do "Object-Oriented Programming" in Lua then your totally ready for C++

Re: Customizable Game Script (In_Progress)

zester wrote:

If you understand how to do "Object-Oriented Programming" in Lua then your totally ready for C++

I think Lua can only fake it, but I have not implemented that yet (Script is not big enough yet). I actually do understand C++(just like any other coding language), but the syntax is just annoying. I need to finish this tutorial I began to watch a while ago.

Last edited by Tutorial Doctor (2013-11-17 00:44:07)

Re: Customizable Game Script (In_Progress)

Heavily Commented it to show how the code works.

----CUSTOMIZABLE GAME SCRIPT----

----OBJECTS
--This is where you create all of the objects in your game
box=getObject("cube")
man=getObject("man")
monkey = getObject("monkey")
cone = getObject("cone")
person = getObject("person")
steps = getObject("steps")
Player = getObject("Player")
Set = getObject("Set")
Feet = getObject("Feet")
apple = getObject("apple")
snd_collect = getObject("collect")
apple_clone = getClone(apple)
----END OBJECTS

----MOTION (Self-Explanatory)
--MOVE VARIABLES
--Below, I commented out some of the Maratis functions I might want to use in my motion functions 
--[[translate(object,direction,"local")
onKeyDown(key)
onKeyUp(key)
setAnimationSpeed(object, speed)
playSound(object)
pauseSound(object)
stopSound(object)
getSoundGain(object)
setSoundGain(object, gain)]]

--These are all of the motion variables
move_object =         box
move_speed =        .1

--These are the various DIRECTIONS in which you can move. They are Vector3 variables. 
--A vector3(vec3) is just a spot in 3D space. 
--I used a variable inside of the vector3 so that I can change it outside of the vec3 function.
--[[
The reason that I made one negative and positive inside of the vec3 function is so that when
I change it outside of the function I don't have to make it negative (I can just use positive values)
]]
move_forward =        vec3(x, -move_speed, z) --[1]
move_backward =    vec3(x, move_speed, z) --[2]
move_left =        vec3(move_speed, y, z) --[3]
move_right =        vec3(-move_speed, y, z) --[4]
move_down=        vec3(x, y,-move_speed) --[5]
move_up=            vec3(x, y, move_speed) --[6]

--This table/array holds all of the directions so that I don't have to keep type out every direction. Instead of:
--[[
move_forward
move_backward
move_right
move_down
move_up
]]
--I can type:
--[[
move_direction[1]
move_direction[2]
etc
]]
move_direction =        {move_forward,move_backward,move_left,move_right,move_down,move_up}

--This is another table for choosing which buttons are used to move something
--I can quickly change what button moves an object up by switching out the "W" to "UP"
move_btn =         {move_btn_U,move_btn_D,move_btn_L,move_btn,R}
move_btn_U =        "W"
move_btn_D =        "S"
move_btn_L =        "LEFT"
move_btn_R =        "RIGHT" 

--These variables deterine animations that are played, as well as the speed at which they are played. 
-- I don't have to dig through functions to simply adjust the speed at whcih the animation plays
move_animation =    1
idle_animation =         0
move_animation_speed =  2
idle_animation_speed = .5
--The sound made when moving
move_sound = steps

--JUMP VARIABLES
--[[translate(object,direction,"local") ]]

--The Jump area works just like the Move area. 
col = getNumCollisions(jump_object)
jump_object =         box
jump_height =         3
jump_speed =         1
jump_btn =         "SPACE"
jump_animation =        changeAnimation(object, animationId)
jump_direction =         {jump_up,jump_down,jump,left,jump_right}
jump_up =            vec3(x, y, jump_speed*jump_height) 
jump_down =        vec3(x, y, jump_speed*jump_height) 
jump_left =            vec3(-jump_speed*jump_height, y, z) 
jump_right =        vec3(jump_speed*jump_height, y, z) 
collisions =             getNumCollisions(box)

--SPIN VARIABLES
--[[rotate(object,direction,angle,"local")]]

--Same as the Move area
spin_speed =        7
spin_object =         box
spin_direction =        {spin_left,spin_right}
spin_left =             vec3(x, y, spin_speed)
spin_right =        vec3(x, y, -spin_speed)
spin_btn =            {spin_btn_L,spin_btn_R}
spin_btn_L =        "A"
spin_btn_R    =        "D"
spin_animation =        changeAnimation(object, animationId)

--MOVE FUNCTION
--All of the variables above are substituted into their respective functions.
--The goals is to have NO VALUES inside of the function itself as it simply controls variables.
--This way we can adjust variables outside of the function and have easy access to them.
--Also, complete and descriptive naming conventions are a MUST for clarity
function Move(move_object,move_direction,move_btn,move_animation,idle_animation)
    if isKeyPressed(move_btn) then
        changeAnimation(move_object,move_animation)
        translate(move_object,move_direction,"local")
        playSound(move_sound)
        setAnimationSpeed(move_object, move_animation_speed)
        
    end    
    
    if onKeyDown(move_btn) then
        playSound(move_sound)
    end
    
    if onKeyUp(move_btn) then
        changeAnimation(move_object,idle_animation)
        setAnimationSpeed(move_object, idle_animation_speed)
        stopSound(move_sound)
    end
    
end

--JUMP FUNCTION
function Jump(jump_object,jump_direction,jump_btn--[[,jump_animation]])
    if isKeyPressed(jump_btn) then
        --changeAnimation(jump_object,jump_animation)
        addCentralForce(jump_object, jump_direction, "local")
    end
end


--SPIN FUNCTION
function Spin(spin_object,spin_direction,spin_btn)
    if isKeyPressed(spin_btn) then
        --changeAnimation(spin_object,spin_animation)
        rotate(spin_object,spin_direction,spin_speed,"local")
    end    
end
----END MOTION

----ARTIFICIAL INTELLIGENCE 
--This section works like the Motion section also.

--[[
So far I am trying to simulate the 5 senses. All of the senses are physics base and use basic collision to determine if something
is either SEEN or HEARD etc. 
]]

--SEE VARIABLES
--[[isCollisionTest(object)
isCollisionBetween(object1, object2)
getNumCollisions(object)
setScale(object, {x, y, z})
changeAnimation(object, animationId)
setAnimationSpeed(object, speed)]]

--The SEEING section is a COLLISION TEST. A cone is representive of the eyes. 

--object that can be seen
seen_object =        monkey

--object that is seeing     
seeing_object =         cone

--A boolean to see if something is seen (if there was a collision between the seen and seeing object)
seen =             isCollisionBetween(seeing_object,seen_object)--true or false

--Field of view. Basically the width of the cone
see_FOV =            0

--Length of the cone            
see_distance =        0

--Animation to be played when SEEN is TRUE
see_animation =        0--animatinoID

--SMELL VARIABLES

--The smelling section is also COLLISION BASED. However, it detects collisions with a particle system
smelled =             isCollisionTest(object)--true or false
smell_particle_system =
smell_animation =        0--animatinoID

--HEAR VARIABLES
--[[playSound(object)
--pauseSound(object)
--stopSound(object)
--getSoundGain(object)
--setSoundGain(object, gain)]]

--The hearing section is not physics based. It detects whether or not the volume of a sound is above a certain number. If it is, it is HEARD. 

heard =             false
hear_sound =        getSoundGain(object)
hear_proximity =        0
hear_pitch =        0
hear_animation =        0--animationID
hear_limit =         3 --limit at which sound can be heard

--TOUCH VARIABLES
--Phsycs based. 
touched =             isCollisionTest(object)
touch_object =         getObject("finish_line")
touch_animation =     0--animationID

--TASTE VARIABLES
--Physics based
tasted =             isCollisionTest(object)
taste_object =        getObject(« objectName »)
taste_proximity =        0
taste_animation =    0


--SEE FUNCTION
function See(seeing_object,seen_object)
    if isCollisionBetween(seeing_object,seen_object) then 
        quit()
    end
end

--HEAR FUNCTION
--the object in parenthesis is the object being heard (a sound object)
function Hear()
    if heard and hear_sound > hear_limit then
        changeAnimation(object,hear_animation)
    end
end

--TOUCH FUNCTION
function Touch()
    if touched then
        changeAnimation(object,touch_animation)
    end
end

--TASTE FUNCTION
function Taste()
    if tasted then
        changeAnimation(object,taste_animation)
        tasted=true
    end
end

--SMELL FUNCTION
function Smell()
    if smelled then
        changeAnimation(object,smell_animation)
        smelled=true
    end
end
----END ARTIFICIAL INTELLIGENCE

----DEFAULTS
changeAnimation(person,0)
stopSound(steps)
----END DEFAULTS

----ADDITIONAL FUNCTIONS
function GetText()
    --Apples
    --apples = {apple_clone,apple_clone,apple_clone,apple_clone}
    --apples_collected = 0
    --scale = vec3(2,2,2)

    GuiScene = getScene("Scene_name")
    Camera = getObject("Camera_name")
    enableCameraLayer(Camera, GuiScene)
    text = getObject(GuiScene,"Text_object")
    show_apples_collected = "Apples = " .. apples_collected
    setText(text,show_apples_collected)
    --Collect(apple)
    --Collect(apple_clone)
    
    --coll = getNumCollisions(Feet)
end


--[[COLLECTION FUNCTION
function Collect(object)
    if isCollisionBetween(Player,object) then
        deactivate(object)
        playSound(snd_collect)
        --Scale()
        apples_collected = apples_collected + 1
    end
end
]]
----END OF ADDITIONAL FUNCTIONS

----GAME
function onSceneUpdate()

    --Move Box
    Move(box,move_direction[1],move_btn_U)
    Move(box,move_direction[2],move_btn_D)
    Move(box,move_direction[3],move_btn_L)
    Move(box,move_direction[4],move_btn_R)
    
    --Jump Box
    Jump(box,jump_up,jump_btn)
    
    --Spin Box
    Spin(box,spin_left,spin_btn_L)
    Spin(box,spin_right,spin_btn_R)
----------------------------------------------------------------
    --Move Person
    Move(person,move_direction[1],move_btn_U,move_animation,idle_animation)
    Move(person,move_direction[2],move_btn_D,move_animation,idle_animation)
    Move(person,move_direction[3],move_btn_L,move_animation,idle_animation)
    Move(person,move_direction[4],move_btn_R,move_animation,idle_animation)
    
    --Jump Person
    Jump(person,jump_up,jump_btn)

    
    --Spin Person
    Spin(person,spin_left,spin_btn_L)
    Spin(person,spin_right,spin_btn_R)
    
    

end
----END GAME

The difference between the SEEING OBJECT and the TASTING OBJECT and the FEELING OBJECT is simply the SHAPE of the representative geometry. Seeing object is a cone. Tasting object can be a cube if you want. Feeling Object can be a cylinder etc. Whatever geometry best portrays the sense. Cone is best for sight.

These objects can also be parented to different objects and in various locations on the object so that the object itself will only be able to, for example, TOUCH something that has collided with it's RIGHT SHOE. hehe

Last edited by Tutorial Doctor (2013-10-06 17:04:17)

Re: Customizable Game Script (In_Progress)

I am working on making this an OOP library so that you can import it using dofile() so that your code won't be cluttered.