home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / AI / AI.lua
Encoding:
Text File  |  2010-03-19  |  1.3 KB  |  54 lines

  1. --------------------------------------------------------------------------------
  2. -- Carnage Contest AI (Artificial Intelligence) Script
  3. -- Script by DC, February 2010, www.UnrealSoftware.de
  4. --------------------------------------------------------------------------------
  5.  
  6. ai={}
  7.  
  8. -- Initialization Function (called once at each start of AI turn)
  9. function ai_init()
  10.     math.randomseed(os.time())
  11.     ai.movetimer=math.random(50,300)
  12.     ai.dir=math.random(0,1)
  13.     ai.aim=math.random(-100,100)
  14.     ai.power=math.random(50,200)
  15. end
  16.  
  17. -- Movement Function (called each frame, pre attack)
  18. function ai_move()
  19.     if ai.movetimer>0 then
  20.         if ai.dir==0 then
  21.             ai_left()
  22.         else
  23.             ai_right()
  24.         end
  25.         ai.movetimer=ai.movetimer-1
  26.     elseif ai.aim~=0 then
  27.         if ai.aim>0 then
  28.             ai_down()
  29.             ai.aim=ai.aim-1
  30.         else
  31.             ai_up()
  32.             ai.aim=ai.aim+1
  33.         end
  34.     elseif ai.power>0 then
  35.         ai_attack()
  36.         ai.power=ai.power-1
  37.     end
  38. end
  39.  
  40. -- Backing Function (called each frame, post attack)
  41. function ai_back()
  42.     if ai.dir==0 then
  43.         ai_right()
  44.     else
  45.         ai_left()
  46.     end
  47. end
  48.  
  49.  
  50. --------------------------------------------------------------------------------
  51. -- AI Helper Functions
  52. -- Attention: These functions are also used by orig. AI weapon Lua scripts
  53. -- !!! CHECK ALL DEPENDENCIES WHEN CHANGING !!!
  54. --------------------------------------------------------------------------------