home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Stoning.lua < prev    next >
Encoding:
Text File  |  2010-09-27  |  3.8 KB  |  122 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Stoning + Projectile Stone
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, September 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.stoning={}
  10. cc.stoning.stone={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.stoning.gfx_icon=loadgfx("weapons/stoning.png")                -- Weapon Icon
  14. setmidhandle(cc.stoning.gfx_icon)
  15. cc.stoning.gfx_pro=loadgfx("weapons/stone.bmp")                    -- Projectile Image
  16. setmidhandle(cc.stoning.gfx_pro)
  17. cc.stoning.sfx_hit=loadsfx("stoneimpact.ogg")
  18.  
  19. --------------------------------------------------------------------------------
  20. -- Weapon: Stoning
  21. --------------------------------------------------------------------------------
  22.  
  23. cc.stoning.id=addweapon("cc.stoning","Stoning",cc.stoning.gfx_icon,0,3)    -- Add Weapon (0 uses, first in round 3)
  24.  
  25. function cc.stoning.draw()                                            -- Draw
  26.     -- HUD Positioning
  27.     if weapon_shots==0 then
  28.         hudpositioning(pos_invisible)
  29.     end
  30. end
  31.  
  32. function cc.stoning.attack(attack)                                    -- Attack
  33.     if (weapon_shots<=0) and (weapon_position==1) then
  34.         -- No more weapon switching!
  35.         useweapon(0)
  36.         weapon_shots=weapon_shots+1
  37.         weapon_position=0
  38.         -- Random Seed
  39.         randomseed(getframe()*911+getround()*77)
  40.         -- Spawn stones
  41.         for i=1,10,1 do
  42.             pid=createprojectile(cc.stoning.stone.id)
  43.             projectiles[pid]={}
  44.             projectiles[pid].x=weapon_x+random(-100,100)
  45.             projectiles[pid].y=-random(200,350)
  46.             projectiles[pid].sy=random(150,200)*0.1
  47.             projectiles[pid].timer=i*random(15,20)
  48.         end
  49.         -- End Turn
  50.         endturn()
  51.     end
  52. end
  53.  
  54. --------------------------------------------------------------------------------
  55. -- Projectile: Stone
  56. --------------------------------------------------------------------------------
  57.  
  58. cc.stoning.stone.id=addprojectile("cc.stoning.stone")        -- Add Projectile
  59.  
  60. function cc.stoning.stone.draw(id)                            -- Draw
  61.     if projectiles[id].timer<=0 then
  62.         -- Stone
  63.         setcolor(255,255,255)
  64.         setblend(blend_alpha)
  65.         setalpha(1)
  66.         setrotation(0)
  67.         drawimage(cc.stoning.gfx_pro,projectiles[id].x,projectiles[id].y)
  68.     end
  69. end
  70.  
  71. function cc.stoning.stone.update(id)                        -- Update
  72.     -- Timer
  73.     if projectiles[id].timer>0 then
  74.         -- Count Down before stone appears
  75.         projectiles[id].timer=projectiles[id].timer-1
  76.     else
  77.         -- Stone appears
  78.         -- Particle Tail
  79.         particle(p_smoke,projectiles[id].x+math.random(-6,6),projectiles[id].y-7)
  80.         particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
  81.         particlefadealpha(0.05)
  82.         -- Move (in substep loop for optimal collision precision)
  83.         msubt=math.abs((projectiles[id].sy)/5)
  84.         msuby=projectiles[id].sy/msubt
  85.         for i=1,msubt,1 do
  86.             projectiles[id].y=projectiles[id].y+msuby
  87.             -- Collision
  88.             if collision(cc.stoning.gfx_pro,projectiles[id].x,projectiles[id].y)==1 then
  89.                 -- Player Damage
  90.                 if playercollision()~=0 then
  91.                     playerdamage(playercollision(),10000)
  92.                 else
  93.                     -- Object Damage
  94.                     if objectcollision()>0 then
  95.                         objectdamage(objectcollision(),10000)
  96.                     end
  97.                     -- Impact
  98.                     playsound(cc.stoning.sfx_hit)
  99.                     terrainimage(cc.stoning.gfx_pro,projectiles[id].x,projectiles[id].y)
  100.                     for angle=0,340,20 do
  101.                         particle(p_smoke,projectiles[id].x,projectiles[id].y)
  102.                         particlespeed(math.sin(math.rad(angle))*2,-math.cos(math.rad(angle))*2)
  103.                         particlecolor(150,150,150)
  104.                     end
  105.                     -- Free projectile
  106.                     freeprojectile(id)
  107.                     break
  108.                 end
  109.             end
  110.             -- Water
  111.             if (projectiles[id].y)>getwatery()+5 then
  112.                 -- Effects
  113.                 particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  114.                 particlesize(1.5,2.0)
  115.                 playsound(sfx_hitwater4)
  116.                 -- Free projectile
  117.                 freeprojectile(id)
  118.                 break
  119.             end
  120.         end
  121.     end
  122. end