Anyone doing simple scripting?

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
monchito
Posts: 59
Joined: Thu Mar 08, 2007 9:38 pm

Anyone doing simple scripting?

Post by monchito »

Hi
I'm experimenting with a simple text scripting using the irrlicht 1.5
Don't know much about it but i'm learning.
I want to read a text file and do some basic stuff like movement, rotation, and simple material handling. So far so good, but very slow. I did a simple
text file reader, parser and elemental interpreter. It's more a practice than a real work in progress. Does anyone already done this?
Any hint is wellcome. Thanks.
The following text file load and works ok at 120 fps while looking at the fire or transparent tree. Too many token readings :(

Code: Select all

'irrlicht HelloWorld.txt script file
Var int count = 0     ' global variables
Var int life = 0         
Var string level = "E:/my_map.irr"
Var string sky =  "E:/media/skyblue.jpg"  ' _up, _dn, _fr, _bk...

Function main()
  
  'directx, software, opengl, fps cmarera as default
  Initialize ( directx, 640, 480 )
  
  'standard camera is a child node, xyz Offsets are from parent
  SetCamera ( standard )            'standard, fps
  Camera.tilt = 90
  Camera.yOffset = 50
  Camera.zOffset = -50

  TraceMode = USE_BOUNDING_BOX          ' or USE_POLYGON
  CollisionMode = USE_BOUNDING_BOX      ' or USE_RADII
  SceneBgColor = ( 255, 100, 100, 140 ) ' background color alpha,r,g,b
  
  LoadImage ("logo", "E:/Media/irrlichtlogo.jpg", 0, 0, false )
  logo.x = 20
  logo.y = 50

  InsertParticles ( "fire", 0, 0, 0,"E:/media/fire.bmp", 5, 5, true )
  fire.x = -200       ' set fire position
  fire.y = 0
  fire.z = -200
  
  ShowCursor(False)

  Call LoadModels()

  Do

    If ( Kbhit( KEY_Q ))  ' exit program
      Exit
    Endif

    Call CamKbd()         'camera movement
    
    Call PlayerKbd()      'player movement

    Call LifeItems( health1 ) 'life model movement
    Call LifeItems( health2 ) 

    Render()              ' do the render phase

  Loop

EndFunc

Function CamKbd()

    If ( Kbhit( KEY_W ))          ' go front
      Camera.z = Camera.z + 1 
    Endif

    If ( Kbhit( KEY_S ))          ' go back
      Camera.z = Camera.z - 1
    Endif

    If ( Kbhit( KEY_A ))          ' go right
      Camera.x = Camera.x + 1
    Endif

    If ( Kbhit( KEY_D ))          ' go left
      Camera.x = Camera.x - 1
    Endif

    If ( Kbhit( KEY_Z ))          ' rotate right 
      Camera.pan = Camera.pan + 1 
    Endif
    If ( Kbhit( KEY_X ))          ' rotate left
      Camera.pan = Camera.pan - 1 
    Endif
    If ( Kbhit( KEY_C ))          ' go up
      Camera.y = Camera.y + 1
    Endif
    If ( Kbhit( KEY_V ))          ' go down
      Camera.y = Camera.y - 1
    Endif
EndFunc

Function PlayerKbd()       ' move player

    If ( Kbhit( KEY_I ))
      Move( "sydney", 3 )
    Endif

    If ( Kbhit( KEY_K ))
      Move( "sydney", -3 )      
    Endif

    If ( Kbhit( KEY_J ))
      Strafe( "sydney", 3 )      
    Endif
  
    If ( Kbhit( KEY_L ))
      Strafe( "sydney", -3 )      
    Endif

EndFunc

Function LoadModels()
  'load model and use the name for any change.
  LoadModelByName("sydney","E:/Media/sydney.md2","E:/Media/sydney.bmp")
  sydney.x = 120
  sydney.y = 20
  sydney.pan = 35
  sydney.scalex = 1.5        'set entity size
  sydney.scaley = 1.5
  sydney.scalez = 1.5
  sydney.setAnimLoop = 1
  sydney.mtlType = EMT_SOLID
  sydney.collision = true    ' can collide with others

  LoadModelByName("crate","E:/Media/crate.ms3d",NULL)
  crate.x = 100
  crate.y = 10
  crate.pan = 0
  crate.scalex = 1.5
  crate.scaley = 1.5
  crate.scalez = 1.5
  crate.rotx = 0
  crate.roty = 1
  crate.rotz = 1
  crate.speedx = 0.25
  crate.speedz = 0.25
 
  LoadModelByName( "tree","E:/Media/palmtree.ms3d" )
  tree.x = 0
  tree.y = 10
  tree.pan = 35
  tree.scalex = 25
  tree.scaley = 25
  tree.scalez = 25
  tree.mtlType = EMT_TRANSPARENT_ADD_COLOR

  LoadModelByName( "health1","E:/Media/healthpack.ms3d" )
  health1.x = random( -200, 200 )
  health1.y = random( -200, 200 )
  health1.pan = random( 1, 360 )

  LoadModelByName( "health2","E:/Media/healthpack.ms3d" )
  health1.x = random( -200, 200 )
  health1.y = random( -200, 200 )
  health1.pan = random( 1, 360 )

  'make a ground plane with sand texture, tile size xy, tiles in x and y
  InsertPlane ( "e:/media/detail_sand.bmp", 100, 8 )
  
  CreateMaterial ("mat")     ' create a material for later assign
  mat.texture = "E:/Media/te.bmp"
  mat.mtlFlag = ( EMF_LIGHTING, false )
  mat.mtlFlag = ( EMF_ZBUFFER, true )
  mat.mtlType = EMT_SOLID;
  mat.ambientColor = color(255, 125,125,125); 'alpha,r,g,b
  mat.diffuseColor = color(0, 0, 0, 0);
  mat.specularColor = color(0, 0, 0, 0);
  
EndFunc

Function LifeItems( Entity Health )

  If ( Health )
    Health.pan = Health.pan + 1 * delta_time;
    If ( VecDist ( Health, sydney ) < 50 )
      Health.remove()
      sydney.skill2 = 100
    EndIf
  EndIf  
  
EndFunc
aanderse
Posts: 155
Joined: Sun Aug 10, 2008 2:02 pm
Location: Canada

Post by aanderse »

you'd be better off to just use a real scripting language like lua, squirrel, freebasic, etc... i believe all mentioned already have irrlicht bindings.

if your goal is to actually learn how to write a scripting language, though... well that really hasn't anything to do with irrlicht.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

What's strange is why this is in 2d/3d graphics, I guess this has become similar to an Offtopic forum in some ways. :P
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Post Reply