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

  1. property pPatroling, pPointX1, pPointX2, pPointY1, pPointY2, pTowardsPoint1, pDirection, pMovementSpeed, pFrameNumber, pAnimationSpeed, pEnemyAlert, pPositionX, pPositionY, pEnemyChannel, pDestDirection, pAlertTime, pInalertTime, pYDelta, pXDelta, pDefaultSpeed, pMaxFrameNumer, pCharacterName, pDoDeath, pEnemySearch
  2. global gMapChannel, gCurrentLevel
  3.  
  4. on new me, enemyDirection, enemySpeed, animationSpeed, posX, posY, spriteName, enemyChannel
  5.   pTowardsPoint1 = 1
  6.   pEnemySearch = 1
  7.   pDoDeath = 0
  8.   pPatroling = 0
  9.   pCharacterName = spriteName
  10.   pMaxFrameNumer = 4
  11.   pYDelta = 0
  12.   pXDelta = 0
  13.   pAlertTime = 0
  14.   pInalertTime = 0
  15.   pDirection = enemyDirection
  16.   pMovementSpeed = enemySpeed
  17.   pAnimationSpeed = animationSpeed
  18.   pEnemyChannel = enemyChannel
  19.   pEnemyAlert = 0
  20.   pPositionX = posX
  21.   pPositionY = posY
  22.   pFrameNumber = 1
  23.   sprite(pEnemyChannel).puppet = 1
  24.   case pDirection of
  25.     1:
  26.       sprite(pEnemyChannel).member = pCharacterName & "_up_1"
  27.     2:
  28.       sprite(pEnemyChannel).member = pCharacterName & "_right_1"
  29.     3:
  30.       sprite(pEnemyChannel).member = pCharacterName & "_down_1"
  31.     4:
  32.       sprite(pEnemyChannel).member = pCharacterName & "_left_1"
  33.   end case
  34.   sprite(pEnemyChannel).locH = pPositionX
  35.   sprite(pEnemyChannel).locV = pPositionY
  36.   sprite(pEnemyChannel).backColor = 6
  37.   sprite(pEnemyChannel).ink = 36
  38.   return me
  39. end
  40.  
  41. on setIntelligence enemySearch
  42.   pEnemySearch = enemySearch
  43. end
  44.  
  45. on getEnemyChannel me
  46.   return pEnemyChannel
  47. end
  48.  
  49. on moveEnemy me
  50.   case pDirection of
  51.     1:
  52.       pPositionY = pPositionY - pMovementSpeed
  53.       pYDelta = pYDelta + pMovementSpeed
  54.     2:
  55.       pPositionX = pPositionX + pMovementSpeed
  56.       pXDelta = pXDelta + pMovementSpeed
  57.     3:
  58.       pPositionY = pPositionY + pMovementSpeed
  59.       pYDelta = pYDelta + pMovementSpeed
  60.     4:
  61.       pPositionX = pPositionX - pMovementSpeed
  62.       pXDelta = pXDelta + pMovementSpeed
  63.   end case
  64.   sprite(pEnemyChannel).loc = point(pPositionX, pPositionY)
  65.   updateStage()
  66.   stringLength = length(string(member(sprite(pEnemyChannel).member).name))
  67.   currFrame = chars(string(member(sprite(pEnemyChannel).member).name), stringLength, stringLength)
  68.   currFrame = integer(currFrame) + 1
  69.   if currFrame > pMaxFrameNumer then
  70.     currFrame = 1
  71.   end if
  72.   sprite(pEnemyChannel).member = chars(string(member(sprite(pEnemyChannel).member).name), 1, stringLength - 1) & string(currFrame)
  73.   if pPositionY > 410 then
  74.     pPositionY = -20
  75.   end if
  76.   if pPositionY < -20 then
  77.     pPositionY = 410
  78.   end if
  79.   if pPositionX > 590 then
  80.     pPositionX = -20
  81.   end if
  82.   if pPositionX < -20 then
  83.     pPositionX = 590
  84.   end if
  85.   if sprite(pEnemyChannel).intersects(7) = 1 then
  86.     case pDirection of
  87.       1:
  88.         pPositionY = pPositionY + pMovementSpeed
  89.         pYDelta = pYDelta - pMovementSpeed
  90.       2:
  91.         pPositionX = pPositionX - pMovementSpeed
  92.         pXDelta = pXDelta - pMovementSpeed
  93.       3:
  94.         pPositionY = pPositionY - pMovementSpeed
  95.         pYDelta = pXDelta - pMovementSpeed
  96.       4:
  97.         pPositionX = pPositionX + pMovementSpeed
  98.         pXDelta = pXDelta - pMovementSpeed
  99.     end case
  100.     sprite(pEnemyChannel).loc = point(pPositionX, pPositionY)
  101.   end if
  102.   if sprite(pEnemyChannel).intersects(7) = 1 then
  103.     switchDirection()
  104.   end if
  105.   if (pXDelta > 40) or (pYDelta > 40) then
  106.     pXDelta = 0
  107.     pYDelta = 0
  108.     if (pEnemyAlert = 0) and (pInalertTime > 100) and (pEnemySearch = 1) then
  109.       seekAnt()
  110.       if pEnemyAlert = 1 then
  111.         pInalertTime = 0
  112.       end if
  113.     end if
  114.   end if
  115.   if pEnemyAlert = 1 then
  116.     pPatroling = 0
  117.     chaseAnt(me, sprite(8).locH, sprite(8).locV)
  118.   end if
  119.   if pPatroling = 1 then
  120.     doPatroleStuff()
  121.   end if
  122.   if pEnemyAlert = 1 then
  123.     pAlertTime = pAlertTime + 1
  124.   end if
  125.   if pEnemyAlert = 0 then
  126.     pInalertTime = pInalertTime + 1
  127.   end if
  128.   if pAlertTime > 500 then
  129.     pEnemyAlert = 0
  130.     pAlertTime = 0
  131.   end if
  132. end
  133.  
  134. on setEnemyPosition me, posX, posY
  135.   pPositionX = posX
  136.   pPositionY = posY
  137.   sprite(pEnemyChannel).locH = pPositionX
  138.   sprite(pEnemyChannel).locV = pPositionY
  139. end
  140.  
  141. on getEnemyPositionX me
  142.   return pPositionX
  143. end
  144.  
  145. on getEnemyPositionY me
  146.   return pPositionY
  147. end
  148.  
  149. on setEnemyDirection me, enemyDirection
  150.   if pDirection = enemyDirection then
  151.     exit
  152.   end if
  153.   pDirection = enemyDirection
  154.   case pDirection of
  155.     1:
  156.       sprite(pEnemyChannel).member = pCharacterName & "_up_1"
  157.     2:
  158.       sprite(pEnemyChannel).member = pCharacterName & "_right_1"
  159.     3:
  160.       sprite(pEnemyChannel).member = pCharacterName & "_down_1"
  161.     4:
  162.       sprite(pEnemyChannel).member = pCharacterName & "_left_1"
  163.   end case
  164. end
  165.  
  166. on getEnemyDirection me
  167.   return pDirection
  168. end
  169.  
  170. on switchDirection me
  171.   sprite(12).loc = sprite(pEnemyChannel).loc
  172.   case pDirection of
  173.     1:
  174.       if random(2) = 1 then
  175.         sprite(12).locH = sprite(12).locH + 10
  176.         updateStage()
  177.         if sprite(12).intersects(7) = 1 then
  178.           sprite(12).loc = sprite(pEnemyChannel).loc
  179.           sprite(12).locH = sprite(12).locH - 10
  180.           updateStage()
  181.           if sprite(12).intersects(7) = 1 then
  182.             directionNum = 3
  183.           else
  184.             directionNum = 4
  185.           end if
  186.         else
  187.           directionNum = 2
  188.         end if
  189.       else
  190.         sprite(12).locH = sprite(12).locH - 10
  191.         updateStage()
  192.         if sprite(12).intersects(7) = 1 then
  193.           sprite(12).loc = sprite(pEnemyChannel).loc
  194.           sprite(12).locH = sprite(12).locH + 10
  195.           updateStage()
  196.           if sprite(12).intersects(7) = 1 then
  197.             directionNum = 3
  198.           else
  199.             directionNum = 2
  200.           end if
  201.         else
  202.           directionNum = 4
  203.         end if
  204.       end if
  205.     2:
  206.       if random(2) = 1 then
  207.         sprite(12).locV = sprite(12).locV + 10
  208.         updateStage()
  209.         if sprite(12).intersects(7) = 1 then
  210.           sprite(12).loc = sprite(pEnemyChannel).loc
  211.           sprite(12).locV = sprite(12).locV - 10
  212.           updateStage()
  213.           if sprite(12).intersects(7) = 1 then
  214.             directionNum = 4
  215.           else
  216.             directionNum = 1
  217.           end if
  218.         else
  219.           directionNum = 3
  220.         end if
  221.       else
  222.         sprite(12).locV = sprite(12).locV - 10
  223.         updateStage()
  224.         if sprite(12).intersects(7) = 1 then
  225.           sprite(12).loc = sprite(pEnemyChannel).loc
  226.           sprite(12).locV = sprite(12).locV + 10
  227.           updateStage()
  228.           if sprite(12).intersects(7) = 1 then
  229.             directionNum = 4
  230.           else
  231.             directionNum = 3
  232.           end if
  233.         else
  234.           directionNum = 1
  235.         end if
  236.       end if
  237.     3:
  238.       if random(2) = 1 then
  239.         sprite(12).locH = sprite(12).locH + 10
  240.         updateStage()
  241.         if sprite(12).intersects(7) = 1 then
  242.           sprite(12).loc = sprite(pEnemyChannel).loc
  243.           sprite(12).locH = sprite(12).locH - 10
  244.           updateStage()
  245.           if sprite(12).intersects(7) = 1 then
  246.             directionNum = 1
  247.           else
  248.             directionNum = 4
  249.           end if
  250.         else
  251.           directionNum = 2
  252.         end if
  253.       else
  254.         sprite(12).locH = sprite(12).locH - 10
  255.         updateStage()
  256.         if sprite(12).intersects(7) = 1 then
  257.           sprite(12).loc = sprite(pEnemyChannel).loc
  258.           sprite(12).locH = sprite(12).locH + 10
  259.           updateStage()
  260.           if sprite(12).intersects(7) = 1 then
  261.             directionNum = 1
  262.           else
  263.             directionNum = 2
  264.           end if
  265.         else
  266.           directionNum = 4
  267.         end if
  268.       end if
  269.     4:
  270.       if random(2) = 1 then
  271.         sprite(12).locV = sprite(12).locV + 10
  272.         updateStage()
  273.         if sprite(12).intersects(7) = 1 then
  274.           sprite(12).loc = sprite(pEnemyChannel).loc
  275.           sprite(12).locV = sprite(12).locV - 10
  276.           updateStage()
  277.           if sprite(12).intersects(7) = 1 then
  278.             directionNum = 2
  279.           else
  280.             directionNum = 1
  281.           end if
  282.         else
  283.           directionNum = 3
  284.         end if
  285.       else
  286.         sprite(12).locV = sprite(12).locV - 10
  287.         updateStage()
  288.         if sprite(12).intersects(7) = 1 then
  289.           sprite(12).loc = sprite(pEnemyChannel).loc
  290.           sprite(12).locV = sprite(12).locV + 10
  291.           updateStage()
  292.           if sprite(12).intersects(7) = 1 then
  293.             directionNum = 2
  294.           else
  295.             directionNum = 3
  296.           end if
  297.         else
  298.           directionNum = 1
  299.         end if
  300.       end if
  301.   end case
  302.   setEnemyDirection(me, directionNum)
  303. end
  304.  
  305. on seekAnt me
  306.   antX = sprite(8).locH
  307.   antY = sprite(8).locV
  308.   sprite(10).loc = sprite(pEnemyChannel).loc
  309.   sprite(11).loc = sprite(pEnemyChannel).loc
  310.   bool = 0
  311.   if (pPositionX < (antX + 20)) and (pPositionX > (antX - 20)) then
  312.     if pPositionY > antY then
  313.       repeat while bool = 0
  314.         sprite(10).locV = sprite(10).locV - 20
  315.         updateStage()
  316.         if sprite(10).intersects(7) = 1 then
  317.           bool = 1
  318.           next repeat
  319.         end if
  320.         if sprite(10).intersects(8) = 1 then
  321.           pEnemyAlert = 1
  322.           bool = 1
  323.         end if
  324.       end repeat
  325.     else
  326.       repeat while bool = 0
  327.         sprite(10).locV = sprite(10).locV + 20
  328.         updateStage()
  329.         if sprite(10).intersects(7) = 1 then
  330.           bool = 1
  331.           next repeat
  332.         end if
  333.         if sprite(10).intersects(8) = 1 then
  334.           pEnemyAlert = 1
  335.           bool = 1
  336.         end if
  337.       end repeat
  338.     end if
  339.   end if
  340.   sprite(10).loc = sprite(pEnemyChannel).loc
  341.   sprite(11).loc = sprite(pEnemyChannel).loc
  342.   bool = 0
  343.   if (pPositionY < (antY + 20)) and (pPositionY > (antY - 20)) then
  344.     if pPositionX > antX then
  345.       repeat while bool = 0
  346.         sprite(11).locH = sprite(11).locH - 20
  347.         updateStage()
  348.         if sprite(11).intersects(7) = 1 then
  349.           bool = 1
  350.           next repeat
  351.         end if
  352.         if sprite(11).intersects(8) = 1 then
  353.           pEnemyAlert = 1
  354.           bool = 1
  355.         end if
  356.       end repeat
  357.     else
  358.       repeat while bool = 0
  359.         sprite(11).locH = sprite(11).locH + 20
  360.         updateStage()
  361.         if sprite(11).intersects(7) = 1 then
  362.           bool = 1
  363.           next repeat
  364.         end if
  365.         if sprite(11).intersects(8) = 1 then
  366.           pEnemyAlert = 1
  367.           bool = 1
  368.         end if
  369.       end repeat
  370.     end if
  371.   end if
  372.   if pEnemyAlert = 1 then
  373.     pMovementSpeed = pDefaultSpeed + 1
  374.   end if
  375. end
  376.  
  377. on chaseAnt me, antX, antY
  378.   if (pEnemyAlert = 1) or (pPatroling = 1) then
  379.     if (pDirection = 1) or (pDirection = 3) then
  380.       if pPositionX > antX then
  381.         pDestDirection = 4
  382.       else
  383.         pDestDirection = 2
  384.       end if
  385.       if (pPositionX > (antX - 10)) and (pPositionX < (antX + 10)) then
  386.         if pPositionY > antY then
  387.           pDestDirection = 1
  388.         else
  389.           pDestDirection = 3
  390.         end if
  391.       end if
  392.     else
  393.       if pPositionY > antY then
  394.         pDestDirection = 1
  395.       else
  396.         pDestDirection = 3
  397.       end if
  398.       if (pPositionY > (antY - 10)) and (pPositionY < (antY + 10)) then
  399.         if pPositionX > antX then
  400.           pDestDirection = 4
  401.         else
  402.           pDestDirection = 2
  403.         end if
  404.       end if
  405.     end if
  406.     sprite(12).loc = sprite(pEnemyChannel).loc
  407.     case pDestDirection of
  408.       1:
  409.         sprite(12).locV = sprite(12).locV - 30
  410.         updateStage()
  411.         if sprite(12).intersects(7) = 0 then
  412.           setEnemyDirection(me, 1)
  413.         end if
  414.       2:
  415.         sprite(12).locH = sprite(12).locH + 30
  416.         updateStage()
  417.         if sprite(12).intersects(7) = 0 then
  418.           setEnemyDirection(me, 2)
  419.         end if
  420.       3:
  421.         sprite(12).locV = sprite(12).locV + 30
  422.         updateStage()
  423.         if sprite(12).intersects(7) = 0 then
  424.           setEnemyDirection(me, 3)
  425.         end if
  426.       4:
  427.         sprite(12).locH = sprite(12).locH - 30
  428.         updateStage()
  429.         if sprite(12).intersects(7) = 0 then
  430.           setEnemyDirection(me, 4)
  431.         end if
  432.     end case
  433.   end if
  434. end
  435.  
  436. on setEnemyInalert me
  437.   pEnemyAlert = 0
  438.   pMovementSpeed = pDefaultSpeed
  439. end
  440.  
  441. on doDeathAnimation me
  442.   if sprite(pEnemyChannel).blend < 5 then
  443.     if gCurrentLevel >= 4 then
  444.       go(24)
  445.     else
  446.       go(44)
  447.       exit
  448.     end if
  449.   end if
  450.   sprite(pEnemyChannel).blend = sprite(pEnemyChannel).blend - 2
  451. end
  452.  
  453. on setPatrolePoints me, x1, y1, x2, y2
  454.   pPatroling = 1
  455.   pPointX1 = x1
  456.   pPointX2 = x2
  457.   pPointY1 = y1
  458.   pPointY2 = y2
  459. end
  460.  
  461. on disablePatrole me
  462.   pPatroling = 0
  463. end
  464.  
  465. on doPatroleStuff me
  466.   if pPatroling = 0 then
  467.     exit
  468.   end if
  469.   if pTowardsPoint1 = 1 then
  470.     chaseAnt(me, pPointX1, pPointY1)
  471.     if (sprite(pEnemyChannel).locH < (pPointX1 + 25)) and (sprite(pEnemyChannel).locH > (pPointX1 - 25)) and (sprite(pEnemyChannel).locV < (pPointY1 + 25)) and (sprite(pEnemyChannel).locV > (pPointY1 - 25)) then
  472.       pTowardsPoint1 = 0
  473.     end if
  474.   else
  475.     chaseAnt(me, pPointX2, pPointY2)
  476.     if (sprite(pEnemyChannel).locH < (pPointX2 + 25)) and (sprite(pEnemyChannel).locH > (pPointX2 - 25)) and (sprite(pEnemyChannel).locV < (pPointY2 + 25)) and (sprite(pEnemyChannel).locV > (pPointY2 - 25)) then
  477.       pTowardsPoint1 = 1
  478.     end if
  479.   end if
  480. end
  481.