require "lua/entity.lua" require "lua/utilities.lua" --print("bramble init") myTime = 0 deleteTimer = math.huge myPosition = { position() } originalScale = 1 scaleY = 1 hitCount = 0 rx,ry,rz = rotation( _ , _ , math.random(-180,180) ) --sx,sy,sz = scale( _, _, 1 + ( math.random(0,50) * 0.01 ) ) myLeaves = spawn( "Bramble_Verticality" , myPosition[1], myPosition[2], myPosition[3]+2 ) -- * sz) ) myLeaves.rotation( rx,ry,rz ) --myLeaves.scale( scale() ) lootTypes = {"coin_a","coinhole_a","crystal"} while tick() do myTime = myTime + dt _, pd = getNearestPlayer(myPosition) if trigger.received(1,"gotHurt") and hitCount <= 3 then --r,g,b = object("LuaDebug").position() r = 5 --r - 100 g = -5 --g - 100 b = -5 --b - 100 hitCount = hitCount + 1 print("gotHurt" , hitCount ) trigger.send(1,"playSoundHit") --TODO spawn birds? if hitCount >= 3 then setColor( r , g , b ) myLeaves.setColor( r , g , b ) deleteTimer = myTime + 0.21 setAlphaSmooth(1,0,0.2) myLeaves.setAlphaSmooth(1,0,0.2) else setColorSmooth( r , g , b , 1 , 1 , 1 , 0.2 ) myLeaves.setColorSmooth( r , g , b , 1 , 1 , 1 , 0.2 ) end if math.random(0,1) == 1 then randomToggle = 1 else randomToggle = -1 end myLeaves.rotation( rx + (math.random(1,5) * randomToggle ) , ry + (math.random(1,5) * randomToggle ) , rz + (math.random(1,5) * randomToggle ) ) myLeaves.rotateSmooth( rx , ry , rz , 0.4 , 1 , 1 ) if hitCount == 1 then scaleSmooth(originalScale*0.95, originalScale*0.95, 0.75 , 0.250 , 0 , 0 ) myLeaves.translateSmooth( myPosition[1], myPosition[2], myPosition[3]+(2*0.75), 0.250, 0 , 0) myLeaves.scaleSmooth(0.95, 0.95 , 0.95 , 0.250 , 0 , 0 ) elseif hitCount == 2 then scaleSmooth(originalScale*0.90, originalScale*0.90, 0.40 , 0.250 , 0 , 0 ) myLeaves.translateSmooth( myPosition[1], myPosition[2], myPosition[3]+(2*0.40), 0.250, 0 , 0) myLeaves.scaleSmooth(0.90, 0.90 , 0.90 , 0.250 , 0 , 0 ) elseif hitCount >= 3 then collision.enable(false) local lx,ly,lz = math.displaceRelative( {position()} , ft2m(10) , 0 , 75 ) local theLootType = lootTypes[math.random(1,#lootTypes)] spawnThrownLoot( theLootType , {lx,ly,lz} , 1 , 0 , 1 ) end end if deleteTimer <= myTime then print("bramble deleting") delete() myLeaves.delete() end end if myLeaves then myLeaves.delete() end