home *** CD-ROM | disk | FTP | other *** search
/ 100 Plus Great Games 2 / 100PLUSV2.BIN / games / MachineWar.dxr / 00005_EnemyScript.ls < prev    next >
Encoding:
Text File  |  2002-01-25  |  11.8 KB  |  374 lines

  1. property pHoldingFlag, pAngle, pMovementSpeed, pPositionX, pPositionY, pSpriteName, pAntChannel, pCurrentPathReversed, pPointList, pDestPoint, pCurrentPath, pDestIDPoint, pObjectStopped, pDoWideTurn, pExpectedAngle, pEnemyShooting, pTarget, pEnergy, stundTime, pStund, pCannonAngle, pCannonChannel
  2. global gFlagSeised, gCurrentLevel, gPlayer3, gEnemy1, gEnemy2, gEnemy3, gBombList, gInfluence, gPathNetwork, gThePad
  3.  
  4. on new me, antDirection, antSpeed, animationSpeed, posX, posY, spriteName, antChannel
  5.   stundTime = 120
  6.   pState = 1
  7.   pEnergy = 120
  8.   pEnemyShooting = 0
  9.   pTarget = point(200, 200)
  10.   pDoWideTurn = 0
  11.   pObjectStopped = 0
  12.   pHoldingFlag = 0
  13.   pDirection = antDirection
  14.   pMovementSpeed = antSpeed
  15.   pPositionX = posX
  16.   pPositionY = posY
  17.   pSpriteName = spriteName
  18.   pAntChannel = antChannel
  19.   case pAntChannel of
  20.     54:
  21.       pDestIDPoint = 4
  22.       aPoint = 4
  23.       getNextPath(pDestIDPoint, aPoint)
  24.       pDestPoint = 1
  25.     55:
  26.       pDestIDPoint = 3
  27.       aPoint = 3
  28.       getNextPath(pDestIDPoint, aPoint)
  29.       pDestPoint = 1
  30.     56:
  31.       pDestIDPoint = 7
  32.       aPoint = 7
  33.       getNextPath(pDestIDPoint, aPoint)
  34.       pDestPoint = 1
  35.   end case
  36.   case pAntChannel of
  37.     54:
  38.       pCannonChannel = 59
  39.     55:
  40.       pCannonChannel = 60
  41.     56:
  42.       pCannonChannel = 61
  43.   end case
  44.   pDestPoint = 1
  45.   pAngle = getAngle(integer(pPositionX), integer(pPositionY), integer(pPointList[pDestPoint][1]), integer(pPointList[pDestPoint][2]))
  46.   sprite(pAntChannel).rotation = 360 - pAngle
  47.   pCannonAngle = pAngle
  48.   sprite(pCannonChannel).rotation = 360 - pCannonAngle
  49.   sprite(pAntChannel).loc = point(pPositionX, pPositionY)
  50.   return me
  51. end
  52.  
  53. on getAntChannel me
  54.   return pAntChannel
  55. end
  56.  
  57. on updateAnt me
  58.   if stundTime < 120 then
  59.     stundTime = stundTime + 1.5
  60.     if (stundTime > 100) and (stundTime < 110) then
  61.       case pAntChannel of
  62.         54:
  63.           sprite(69).loc = point(800, 800)
  64.         55:
  65.           sprite(70).loc = point(800, 800)
  66.         56:
  67.           sprite(71).loc = point(800, 800)
  68.       end case
  69.     end if
  70.     exit
  71.   end if
  72.   if pEnergy < 120 then
  73.     pEnergy = pEnergy + 3
  74.   end if
  75.   if pEnergy >= 120 then
  76.     if random(10) = 1 then
  77.       if (gFlagSeised = 1) and (pHoldingFlag = 0) then
  78.         if gPlayer3.pIsHoldingObject = 1 then
  79.           pTarget = 1
  80.         else
  81.           if gEnemy1.pHoldingFlag = 1 then
  82.             pTarget = 2
  83.           else
  84.             if gEnemy2.pHoldingFlag = 1 then
  85.               pTarget = 3
  86.             else
  87.               if gEnemy3.pHoldingFlag = 1 then
  88.                 pTarget = 4
  89.               end if
  90.             end if
  91.           end if
  92.         end if
  93.         doShooting()
  94.       else
  95.         shortestDistance = 100000
  96.         if (getDistance(gPlayer3.pPositionX, gPlayer3.pPositionY, pPositionX, pPositionY) < shortestDistance) and (gPlayer3.pState <> 6) then
  97.           shortestDistance = getDistance(gPlayer3.pPositionX, gPlayer3.pPositionY, pPositionX, pPositionY)
  98.           pTarget = 1
  99.         end if
  100.         if (getDistance(gEnemy1.pPositionX, gEnemy1.pPositionY, pPositionX, pPositionY) < shortestDistance) and (pAntChannel <> 54) and (gEnemy1.stundTime >= 120) then
  101.           shortestDistance = getDistance(gEnemy1.pPositionX, gEnemy1.pPositionY, pPositionX, pPositionY)
  102.           pTarget = 2
  103.         end if
  104.         if (getDistance(gEnemy2.pPositionX, gEnemy2.pPositionY, pPositionX, pPositionY) < shortestDistance) and (pAntChannel <> 55) and (gEnemy2.stundTime >= 120) then
  105.           shortestDistance = getDistance(gEnemy2.pPositionX, gEnemy2.pPositionY, pPositionX, pPositionY)
  106.           pTarget = 3
  107.         end if
  108.         if (getDistance(gEnemy3.pPositionX, gEnemy3.pPositionY, pPositionX, pPositionY) < shortestDistance) and (pAntChannel <> 56) and (gEnemy3.stundTime >= 120) then
  109.           shortestDistance = getDistance(gEnemy3.pPositionX, gEnemy3.pPositionY, pPositionX, pPositionY)
  110.           pTarget = 4
  111.         end if
  112.         if shortestDistance < 100000 then
  113.           doShooting()
  114.         end if
  115.       end if
  116.     end if
  117.   end if
  118.   if pEnemyShooting = 1 then
  119.     continueShooting()
  120.   end if
  121.   if pDoWideTurn = 1 then
  122.     doWideTurn()
  123.     exit
  124.   end if
  125.   howDeep = spriteColision(sprite(pAntChannel).rect, 1)
  126.   if howDeep = 2 then
  127.     pMovementSpeed = 1
  128.   else
  129.     if howDeep = 1 then
  130.       pMovementSpeed = 3
  131.     else
  132.       pMovementSpeed = 5
  133.     end if
  134.   end if
  135.   pPositionX = pPositionX - (float(sin(pAngle * 3.14000000000000012 / 180.0)) * pMovementSpeed)
  136.   pPositionY = pPositionY - (float(cos(pAngle * 3.14000000000000012 / 180.0)) * pMovementSpeed)
  137.   if pHoldingFlag = 1 then
  138.     sprite(20).loc = point(pPositionX, pPositionY)
  139.   end if
  140.   if (pPositionX > (pPointList[pDestPoint][1] - 3)) and (pPositionX < (pPointList[pDestPoint][1] + 3)) and (pPositionY > (pPointList[pDestPoint][2] - 3)) and (pPositionY < (pPointList[pDestPoint][2] + 3)) then
  141.     totalDestPoints = totalDestPoints + 1
  142.     pDestPoint = pDestPoint + 1
  143.     if pDestPoint > count(pPointList) then
  144.       pDestPoint = 1
  145.     end if
  146.     if (pDestPoint = 1) or (pDestPoint = count(pPointList)) then
  147.       if pCurrentPathReversed then
  148.         pDestIDPoint = gPathNetwork[pCurrentPath].pIDPoint1
  149.       else
  150.         pDestIDPoint = gPathNetwork[pCurrentPath].pIDPoint2
  151.       end if
  152.       doIntelligence()
  153.     end if
  154.     newAngle = getAngle(pPositionX, pPositionY, pPointList[pDestPoint][1], pPointList[pDestPoint][2])
  155.     difference = abs(pAngle - newAngle)
  156.     if difference > 180 then
  157.       difference = 360 - difference
  158.     end if
  159.     if difference > 50 then
  160.       pDoWideTurn = 1
  161.       pExpectedAngle = newAngle
  162.       doWideTurn()
  163.       exit
  164.     end if
  165.     pAngle = newAngle
  166.     sprite(pAntChannel).rotation = 360 - pAngle
  167.     if pDestPoint = count(pPointList) then
  168.     end if
  169.   end if
  170.   sprite(pAntChannel).loc = point(pPositionX, pPositionY)
  171.   case pAntChannel of
  172.     54:
  173.       sprite(59).loc = point(pPositionX + (float(sin(pAngle * 3.14000000000000012 / 180)) * 9), pPositionY + (float(cos(pAngle * 3.14000000000000012 / 180)) * 9))
  174.     55:
  175.       sprite(60).loc = point(pPositionX + (float(sin(pAngle * 3.14000000000000012 / 180)) * 9), pPositionY + (float(cos(pAngle * 3.14000000000000012 / 180)) * 9))
  176.     56:
  177.       sprite(61).loc = point(pPositionX + (float(sin(pAngle * 3.14000000000000012 / 180)) * 9), pPositionY + (float(cos(pAngle * 3.14000000000000012 / 180)) * 9))
  178.   end case
  179. end
  180.  
  181. on setAntPosition me, posX, posY
  182.   pPositionX = posX
  183.   pPositionY = posY
  184.   sprite(pAntChannel).locH = pPositionX
  185.   sprite(pAntChannel).locV = pPositionY
  186. end
  187.  
  188. on getNextPath currentIDPoint, finalDestination
  189.   possiblePaths = []
  190.   repeat with counter = 1 to count(gPathNetwork)
  191.     if (gPathNetwork[counter].pIDPoint1 = currentIDPoint) or (gPathNetwork[counter].pIDPoint2 = currentIDPoint) then
  192.       append(possiblePaths, counter)
  193.     end if
  194.   end repeat
  195.   shortestDistance = 100000
  196.   repeat with counter = 1 to count(possiblePaths)
  197.     if gPathNetwork[possiblePaths[counter]].pIDPoint1 = currentIDPoint then
  198.       destPoint = gPathNetwork[possiblePaths[counter]].pPoint2
  199.     else
  200.       destPoint = gPathNetwork[possiblePaths[counter]].pPoint1
  201.     end if
  202.     case finalDestination of
  203.       1:
  204.         finalDestPoint = point(264, 400)
  205.       2:
  206.         finalDestPoint = point(414, 331)
  207.       3:
  208.         finalDestPoint = point(517, 403)
  209.       4:
  210.         finalDestPoint = point(110, 404)
  211.       5:
  212.         finalDestPoint = point(33, 196)
  213.       6:
  214.         finalDestPoint = point(192, 77)
  215.       7:
  216.         finalDestPoint = point(493, 91)
  217.     end case
  218.     newDistance = getDistance(finalDestPoint[1], finalDestPoint[2], destPoint[1], destPoint[2])
  219.     if newDistance < shortestDistance then
  220.       shortestDistance = newDistance
  221.       thePath = possiblePaths[counter]
  222.     end if
  223.   end repeat
  224.   if gPathNetwork[thePath].pIDPoint1 = currentIDPoint then
  225.     pCurrentPathReversed = 0
  226.     pCurrentPath = thePath
  227.     pPointList = gPathNetwork[pCurrentPath].pNodeList
  228.   else
  229.     pCurrentPathReversed = 1
  230.     pCurrentPath = thePath
  231.     pPointList = gPathNetwork[pCurrentPath].pNodeList
  232.     tempPointList = duplicate(pPointList)
  233.     pPointList = reversePath(tempPointList)
  234.   end if
  235. end
  236.  
  237. on doIntelligence
  238.   if gFlagSeised = 0 then
  239.     aPoint = 6
  240.     getNextPath(pDestIDPoint, aPoint)
  241.     pDestPoint = 1
  242.   else
  243.     if pHoldingFlag = 1 then
  244.       case gThePad of
  245.         1:
  246.           aPoint = 7
  247.           getNextPath(pDestIDPoint, aPoint)
  248.           pDestPoint = 1
  249.         2:
  250.           aPoint = 3
  251.           getNextPath(pDestIDPoint, aPoint)
  252.           pDestPoint = 1
  253.         3:
  254.           aPoint = 1
  255.           getNextPath(pDestIDPoint, aPoint)
  256.           pDestPoint = 1
  257.         4:
  258.           aPoint = 5
  259.           getNextPath(pDestIDPoint, aPoint)
  260.           pDestPoint = 1
  261.       end case
  262.     else
  263.       aPoint = random(7)
  264.       getNextPath(pDestIDPoint, aPoint)
  265.       pDestPoint = 1
  266.     end if
  267.   end if
  268. end
  269.  
  270. on reversePath thePath
  271.   numElements = count(thePath)
  272.   revPath = [0]
  273.   revPath[1] = thePath[count(thePath)]
  274.   deleteAt(thePath, count(thePath))
  275.   repeat with counter = 2 to numElements
  276.     revPath[counter] = thePath[count(thePath)]
  277.     deleteAt(thePath, count(thePath))
  278.   end repeat
  279.   return duplicate(revPath)
  280. end
  281.  
  282. on doWideTurn
  283.   case pAntChannel of
  284.     54:
  285.       sprite(59).loc = point(pPositionX + (float(sin(pAngle * 3.14000000000000012 / 180)) * 9), pPositionY + (float(cos(pAngle * 3.14000000000000012 / 180)) * 9))
  286.     55:
  287.       sprite(60).loc = point(pPositionX + (float(sin(pAngle * 3.14000000000000012 / 180)) * 9), pPositionY + (float(cos(pAngle * 3.14000000000000012 / 180)) * 9))
  288.     56:
  289.       sprite(61).loc = point(pPositionX + (float(sin(pAngle * 3.14000000000000012 / 180)) * 9), pPositionY + (float(cos(pAngle * 3.14000000000000012 / 180)) * 9))
  290.   end case
  291.   if pAngle <= 180 then
  292.     if (pExpectedAngle > pAngle) and (pExpectedAngle < (pAngle + 180)) then
  293.       pAngle = pAngle + 7
  294.     else
  295.       pAngle = pAngle - 7
  296.     end if
  297.   else
  298.     if (pExpectedAngle < pAngle) and (pExpectedAngle > (pAngle - 180)) then
  299.       pAngle = pAngle - 7
  300.     else
  301.       pAngle = pAngle + 7
  302.     end if
  303.   end if
  304.   if pAngle < 0 then
  305.     pAngle = 359
  306.   end if
  307.   if pAngle >= 360 then
  308.     pAngle = 0
  309.   end if
  310.   if (pAngle > (pExpectedAngle - 7)) and (pAngle < (pExpectedAngle + 7)) then
  311.     pAngle = pExpectedAngle
  312.     pDoWideTurn = 0
  313.   end if
  314.   sprite(pAntChannel).rotation = 360 - pAngle
  315. end
  316.  
  317. on doShooting
  318.   pEnemyShooting = 1
  319. end
  320.  
  321. on continueShooting
  322.   case pTarget of
  323.     1:
  324.       pTarget = point(gPlayer3.pPositionX, gPlayer3.pPositionY)
  325.     2:
  326.       pTarget = point(gEnemy1.pPositionX, gEnemy1.pPositionY)
  327.     3:
  328.       pTarget = point(gEnemy2.pPositionX, gEnemy2.pPositionY)
  329.     4:
  330.       pTarget = point(gEnemy3.pPositionX, gEnemy3.pPositionY)
  331.   end case
  332.   theExpectedAngle = getAngle(pPositionX, pPositionY, pTarget[1], pTarget[2])
  333.   if pCannonAngle <= 180 then
  334.     if (theExpectedAngle > pCannonAngle) and (theExpectedAngle < (pCannonAngle + 180)) then
  335.       pCannonAngle = pCannonAngle + 7
  336.     else
  337.       pCannonAngle = pCannonAngle - 7
  338.     end if
  339.   else
  340.     if (theExpectedAngle < pCannonAngle) and (theExpectedAngle > (pCannonAngle - 180)) then
  341.       pCannonAngle = pCannonAngle - 7
  342.     else
  343.       pCannonAngle = pCannonAngle + 7
  344.     end if
  345.   end if
  346.   if pCannonAngle < 0 then
  347.     pCannonAngle = 359
  348.   end if
  349.   if pCannonAngle >= 360 then
  350.     pCannonAngle = 0
  351.   end if
  352.   sprite(pCannonChannel).rotation = 360 - pCannonAngle
  353.   if (pCannonAngle > (theExpectedAngle - 7)) and (pCannonAngle < (theExpectedAngle + 7)) then
  354.     pCannonAngle = theExpectedAngle
  355.     pEnergy = 0
  356.     aChannel = 150
  357.     found = 0
  358.     repeat while found = 0
  359.       if sprite(aChannel).puppet = 1 then
  360.         aChannel = aChannel + 1
  361.         next repeat
  362.       end if
  363.       found = 1
  364.     end repeat
  365.     append(gBombList, new(script("BombScript"), pPositionX, pPositionY, 600, 10, 1, aChannel, pAntChannel, pTarget[1], pTarget[2]))
  366.     repeat with counter = 1 to count(gBombList)
  367.       if gBombList[counter].pState = 3 then
  368.         deleteAt(gBombList, counter)
  369.       end if
  370.     end repeat
  371.     pEnemyShooting = 0
  372.   end if
  373. end
  374.