Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------
- -- Methods for Calculation.
- ----------
- function reset(p)
- p.unsetColor()
- p.unsetSpeed()
- p.setGravity(0,0,0)
- p.setDelay(0)
- p.setEnd(80)
- p.unsetDamage()
- p.setPosition(0,0,0)
- p.setAngle(0,0)
- p.stack()
- p.release()
- end
- function dist(x, y, z)
- return math.sqrt(x*x + y*y + z*z)
- end
- function rotateX(radius, yaw, pitch, rotation)
- local rad1 = math.rad(yaw+90);
- local rad2 = math.rad(pitch);
- local rad3 = math.rad(rotation);
- local newX = radius*math.cos(rad2)*math.sin(rad1);
- local newY = radius*(-math.cos(rad2)*math.cos(rad1)*math.sin(rad3) + math.sin(rad2)*math.cos(rad3));
- local newZ = radius*(math.cos(rad2)*math.cos(rad1)*math.cos(rad3) + math.sin(rad2)*math.sin(rad3));
- local newPitch = math.asin(newY/radius);
- --[[ if newX < 0 then
- newPitch = math.pi-newPitch
- end]]
- local newYaw = math.acos(newZ/(radius*math.cos(newPitch)));
- if newX < 0 then
- newYaw = 0 - newYaw
- end
- return math.deg(newYaw-math.pi/2), math.deg(newPitch), newX, newY, newZ
- end
- function rotateY(radius, yaw, pitch, rotation)
- local rad1 = math.rad(yaw+90);
- local rad2 = math.rad(pitch);
- local rad3 = math.rad(rotation);
- local newX = radius*
- (math.cos(rad2)*math.cos(rad1)*math.sin(rad3) + math.cos(rad2)*math.sin(rad1)*math.cos(rad3));
- local newY = radius*math.sin(rad2);
- local newZ = radius*
- (math.cos(rad2)*math.cos(rad1)*math.cos(rad3) - math.cos(rad2)*math.sin(rad1)*math.sin(rad3));
- local newPitch = math.asin(newY/radius);
- --[[ if newX < 0 then
- newPitch = math.pi-newPitch
- end]]
- local newYaw = math.acos(newZ/(radius*math.cos(newPitch)));
- if newX < 0 then
- newYaw = 0 - newYaw
- end
- return math.deg(newYaw-math.pi/2), math.deg(newPitch), newX, newY, newZ
- end
- function rotateZ(radius, yaw, pitch, rotation)
- local rad1 = math.rad(yaw+90);
- local rad2 = math.rad(pitch);
- local rad3 = math.rad(rotation);
- local newX = radius*(math.cos(rad2)*math.sin(rad1)*math.cos(rad3) - math.sin(rad2)*math.sin(rad3));
- local newY = radius*(math.cos(rad2)*math.sin(rad1)*math.sin(rad3) + math.sin(rad2)*math.cos(rad3));
- local newZ = radius*math.cos(rad2)*math.cos(rad1);
- local newPitch = math.asin(newY/radius);
- --[[ if newX < 0 then
- newPitch = math.pi-newPitch
- end]]
- local newYaw = math.acos(newZ/(radius*math.cos(newPitch)));
- if newX < 0 then
- newYaw = 0 - newYaw
- end
- return math.deg(newYaw-math.pi/2), math.deg(newPitch), newX, newY, newZ
- end
- function fromPolar(radius, yaw, pitch)
- local x = radius*math.cos(math.rad(pitch))*math.sin(math.rad(yaw+90))
- local y = radius*math.sin(math.rad(pitch))
- local z = radius*math.cos(math.rad(pitch))*math.cos(math.rad(yaw+90))
- return x, y, z
- end
- function toPolar(x, y, z)
- local radius = dist(x,y,z)
- local pitch = math.asin(y/radius)
- if x < 0 then
- pitch = math.pi-pitch
- end
- local yaw = math.acos(z/(radius*math.cos(pitch)))
- if x < 0 then
- yaw = 0 - yaw
- end
- return radius, -1*math.deg(yaw-math.pi/2), -1*math.deg(pitch)
- end
- ----------
- -- Method for Communicate.
- ----------
- function checkEnd()
- return rs.getInput("back")
- end
- function goNext(p, msg)
- p.remove(50)
- rednet.open("left")
- rednet.send(9, msg)
- os.pullEvent("rednet_message")
- rednet.close("left")
- end
- ----------
- -- Methods for Shooting.
- ----------
- function interval_1(p)
- reset(p)
- p.setSpeed(0.3, 0.3, 0)
- p.setColor(7)
- p.setPosition(2,0,0)
- turtle.select(1)
- while true do
- p.shoot()
- sleep(1)
- if checkEnd() then
- return
- end
- end
- end
- function spell_1(p)
- p.setGravity(0,0,0)
- for k=1, 1000 do
- local dist = 1.5;
- local yaw1 = 0
- local pitch1 = 35 * math.pow(-1, (k+1)%2)
- local x1, y1, z1 = fromPolar(dist, yaw1, pitch1)
- local yaw2, pitch2, x2, y2, z2 = rotateX(dist, yaw1, pitch1, 120)
- local yaw3, pitch3, x3, y3, z3 = rotateX(dist, yaw1, pitch1, -120)
- turtle.select(4)
- p.setSpeed(0,0,0)
- p.setEnd(200)
- p.setColor(4)
- for i=1, 10 do
- p.stack()
- p.setPosition(x1*i, y1*i, z1*i)
- p.shoot()
- p.setPosition(x2*i, y2*i, z2*i)
- p.shoot()
- p.setPosition(x3*i, y3*i, z3*i)
- p.shoot()
- p.release()
- end
- turtle.select(2)
- p.setSpeed(0.1,0.1,0)
- p.setEnd(160)
- p.setColor(4)
- local angle1 = {}
- local angle2 = {}
- for i=1, 10 do
- angle1[i] = math.random(12)
- angle2[i] = math.random(12)
- end
- for i=1, 10 do
- p.stack()
- for j=1, 10 do
- p.setPosition(x1*j, y1*j, z1*j)
- p.setAngle(angle1[j]*30, angle2[j]*30)
- p.shoot()
- p.setPosition(x2*j, y2*j, z2*j)
- p.setAngle(angle1[j]*30, angle2[j]*30)
- p.shoot()
- p.setPosition(x3*j, y3*j, z3*j)
- p.setAngle(angle1[j]*30, angle2[j]*30)
- p.shoot()
- end
- p.release()
- sleep(0.5)
- end
- if checkEnd() then
- return
- end
- end
- end
- function interval_2(p)
- reset(p)
- p.setColor(7)
- p.setPosition(2,0,0)
- turtle.select(1)
- while true do
- p.shootSphere(16)
- sleep(1)
- p.shootWide(6, 160)
- if checkEnd() then
- return
- end
- sleep(1)
- end
- end
- function spell_2(p)
- reset(p)
- while true do
- for i=1, 9 do
- turtle.select(3)
- p.stack()
- p.setSpeed(0.2,0.2,0)
- p.setColor(4)
- p.setAngle(i%2*90,0)
- p.setGravity(0,-0.005,0)
- p.setPosition(3,6,6)
- p.shootSphere(6, 100)
- p.setPosition(3,6,-6)
- p.shootSphere(6, 100)
- p.setPosition(18,6,6)
- p.shootSphere(12, 100)
- p.setPosition(18,6,-6)
- p.shootSphere(6, 100)
- p.setGravity(0,0.005,0)
- p.setPosition(3,-6,6)
- p.shootSphere(6, 100)
- p.setPosition(3,-6,-6)
- p.shootSphere(6, 100)
- p.setPosition(18,-6,6)
- p.shootSphere(6, 100)
- p.setPosition(18,-6,-6)
- p.shootSphere(6, 100)
- p.release()
- if i%3 == 0 then
- p.setColor(1)
- p.unsetSpeed()
- p.setGravity(0,0,0)
- p.setPosition(3,0,0)
- turtle.select(4)
- local flag, angle1, angle2 = p.setAngleToNearestPlayer()
- p.shootWide(6+i%2, 120)
- end
- if checkEnd() then
- return
- end
- sleep(0.5)
- end
- end
- end
- function interval_3(p)
- reset(p)
- p.setColor(7)
- p.setPosition(2,0,0)
- turtle.select(1)
- while true do
- p.shootCircle(18)
- sleep(1)
- p.shootRing(12, 30)
- sleep(1)
- p.shootRandomRing(6,30)
- if checkEnd() then
- return
- end
- sleep(1)
- end
- end
- function spell_3(p)
- reset(p)
- while true do
- local x, y, z = p.getPositionOfNearestPlayer()
- p.stack()
- p.setSpeed(0,0,0)
- p.setColor(1)
- turtle.select(3)
- p.stack()
- local flag = math.random(3)
- local angle = math.random(6)
- for i=1, 5 do
- for j=1, 12 do
- local yaw, pitch, addX, addY, addZ
- if flag == 1 then
- yaw, pitch, addX, addY, addZ = rotateX(4,(j-i*2+2)*30,-60+i*20,angle*30)
- elseif flag == 2 then
- yaw, pitch, addX, addY, addZ = rotateY(4,(j-i*2+2)*30,-60+i*20,angle*30)
- else
- yaw, pitch, addX, addY, addZ = rotateZ(4,(j-i*2+2)*30,-60+i*20,angle*30)
- end
- p.setPosition(x+addX+0.5,y+addY+0.5,z+addZ+0.5)
- p.shoot()
- end
- end
- p.release()
- p.setSpeed(0.3,0.3,0)
- p.stack()
- p.setPosition(2,8,8)
- turtle.select(3)
- p.setAngleToNearestPlayer()
- p.setColor(4)
- p.shootRing(12, 30)
- turtle.select(10)
- p.setColor(4)
- p.shootRandomRing(5,20)
- p.setPosition(2,8,-8)
- turtle.select(3)
- p.setAngleToNearestPlayer()
- p.setColor(4)
- p.shootRing(12, 30)
- turtle.select(10)
- p.setColor(4)
- p.shootRandomRing(5,20)
- p.setPosition(2,-8,8)
- turtle.select(3)
- p.setAngleToNearestPlayer()
- p.setColor(4)
- p.shootRing(12, 30)
- turtle.select(10)
- p.setColor(4)
- p.shootRandomRing(5,20)
- p.setPosition(2,-8,-8)
- turtle.select(3)
- p.setAngleToNearestPlayer()
- p.setColor(4)
- p.shootRing(12, 30)
- turtle.select(10)
- p.setColor(4)
- p.shootRandomRing(5,20)
- p.release()
- if checkEnd() then
- return
- end
- sleep(3)
- end
- end
- --Attainment of Eternal Truth.
- function spell_4(p)
- reset(p)
- for k=1, 1000 do
- p.setAngle(0,-90)
- p.setSpeed(0.1,0.1,0)
- p.setColor(1)
- p.setEnd(300)
- for i=1, 10 do
- turtle.select(6)
- p.setPosition(math.random(30), -15, math.random(12)*math.pow(-1, math.random(2)))
- p.shoot()
- turtle.select(11)
- p.setPosition(math.random(30), -15, math.random(12)*math.pow(-1, math.random(2)))
- p.shoot()
- end
- turtle.select(9)
- p.setColor(0)
- p.setPosition(2,0,0)
- local flag, yaw, pitch = p.setAngleToNearestPlayer()
- p.setSpeed(0,0.7,0.05)
- p.setEnd(80)
- for i=1, 20 do
- p.stack()
- p.setAngle(yaw, pitch)
- p.setPosition(2,0,0)
- p.shoot()
- p.setAngle(yaw, pitch-10)
- p.setGravity(0,0.005,0)
- p.setPosition(2,4*math.sin(math.pi*math.sqrt(i-1)/5),0)
- p.shoot()
- p.setAngle(yaw, pitch+10)
- p.setGravity(0,-0.005,0)
- p.setPosition(2,-4*math.sin(math.pi*math.sqrt(i-1)/5),0)
- p.shoot()
- p.setAngle(yaw+10, pitch)
- p.setGravity(0,0,-0.005)
- p.setPosition(2,0,4*math.sin(math.pi*math.sqrt(i-1)/5))
- p.shoot()
- p.setAngle(yaw-10, pitch)
- p.setGravity(0,0,0.005)
- p.setPosition(2,0,-4*math.sin(math.pi*math.sqrt(i-1)/5))
- p.shoot()
- p.setGravity(0,0,0)
- p.setPosition(-2,0,0)
- if i%3 == 0 then
- turtle.select(10)
- p.setSpeed(0,0.3,0.05)
- p.shootSphere(20)
- p.setSpeed(0,0.7,0.05)
- turtle.select(9)
- end
- p.release()
- end
- if checkEnd() then
- return
- end
- end
- end
- --Curse of Dreams and Reality
- function spell_5(p)
- reset(p)
- for l=1, 1000 do
- local x = {}
- local y = {}
- local z = {}
- for i=1, 4 do
- x[i] = 3
- y[i] = math.random(5)*math.pow(-1, math.ceil(i/2)) -2
- z[i] = math.random(8)*math.pow(-1, (i%2))
- end
- turtle.select(4)
- p.setColor(1)
- p.setPosition(2,0,0)
- p.setEnd(20)
- p.stack()
- for i=1, 4 do
- local a = -1*dist(x[i],y[i],z[i])*2/200
- local v = -1*a*13.5
- local radius, yaw, pitch = toPolar(x[i]-2,y[i],z[i])
- p.setSpeed(v,0,a)
- p.setPosition(2,0,0)
- p.setAngle(yaw, pitch)
- p.shoot()
- end
- p.release()
- sleep(1)
- local angle1 = math.random(6)*30
- local angle2 = math.random(6)*30
- p.setSpeed(0.15,0.15,0)
- turtle.select(2)
- p.setColor(2)
- p.setEnd(200)
- for i=1, 2 do
- p.stack()
- p.setPosition(x[(i-2)%4+1],y[(i-2)%4+1],z[(i-2)%4+1])
- local flag, playerYaw, playerPitch = p.setAngleToNearestPlayer()
- for k=1, 4 do
- local yaw, pitch, addX, addY, addZ = rotateY(1,k*90,0,playerYaw)
- yaw, pitch, addX, addY, addZ = rotateZ(1,yaw,pitch,-playerPitch)
- p.setPosition(x[(i-2)%4+1]+addX,y[(i-2)%4+1]+addY,z[(i-2)%4+1]+addZ)
- for j=0, 7 do
- yaw, pitch = rotateY(1,j*45,0,playerYaw)
- yaw, pitch = rotateZ(1,yaw,pitch,playerPitch)
- p.setAngle(yaw, pitch)
- p.shoot()
- end
- end
- p.release()
- end
- turtle.select(6)
- for i=1, 5 do
- for j=1, 2 do
- p.stack()
- p.setPosition(x[j+1],y[j+1],z[j+1])
- local flag, playerYaw, playerPitch = p.setAngleToNearestPlayer()
- p.shoot()
- for k=1, 4 do
- local yaw, pitch, addX, addY, addZ = rotateX(2,0,90,k*90)
- -- yaw, pitch, addX, addY, addZ = rotateY(1,yaw,pitch,playerYaw)
- -- yaw, pitch, addX, addY, addZ = rotateZ(1,yaw,pitch,-playerPitch)
- p.setPosition(x[j+1]+addX,y[j+1]+addY,z[j+1]+addZ)
- p.setAngleToNearestPlayer()
- p.shoot()
- end
- p.release()
- sleep(0.13)
- end
- end
- if checkEnd() then
- return
- end
- sleep(0.5)
- end
- end
- --Perfect Black-Dyed Cherry Blossom.
- function spell_6(p)
- reset(p)
- spell_6_sphere(p,0)
- while true do
- for i=1, 3 do
- spell_6_fly(p,4,3)
- spell_6_fly(p,1,4)
- if checkEnd() then
- return
- end
- end
- local flag, yaw, pitch = p.setAngleToNearestPlayer()
- spell_6_sphere(p,-yaw)
- end
- end
- function spell_6_sphere(p, angle)
- reset(p)
- turtle.select(4)
- p.setColor(1)
- for i=1, 5 do
- p.stack()
- for j=1, 6 do
- for k=1, 12-(j*2) do
- local yaw, pitch, addX, addY, addZ = rotateY(2,k*(360/(12-j*2)),j*15,angle)
- p.setPosition(addX, addY, addZ)
- p.setAngle(-yaw, -pitch)
- p.shoot()
- p.setPosition(addX, -addY, addZ)
- p.setAngle(-yaw, pitch)
- p.shoot()
- end
- end
- local yaw, pitch, addX, addY, addZ = rotateY(2,0,90,angle)
- p.setPosition(addX, addY, addZ)
- p.setAngle(-yaw, -pitch)
- p.shoot()
- for i=1, 12 do
- local yaw, pitch, addX, addY, addZ = rotateY(2,i*30,0,angle)
- p.setPosition(addX, addY, addZ)
- p.setAngle(-yaw, -pitch)
- p.shoot()
- end
- p.release()
- sleep(0.2)
- end
- end
- function spell_6_petal(p, num)
- reset(p)
- turtle.select(6)
- p.setSpeed(0.1,0.1,0)
- p.setColor(0)
- p.setEnd(300)
- p.setAngle(0,90)
- for i=1, num do
- p.setPosition(math.random(30), 15, math.random(12)*math.pow(-1, math.random(2)))
- p.shoot()
- end
- end
- function spell_6_fly(p, color, line)
- spell_6_petal(p,30)
- reset(p)
- turtle.select(3)
- p.setColor(color)
- p.setSpeed(0,0,0)
- p.setEnd(40)
- local yaw = {}
- local pitch = {}
- local x = {}
- local y = {}
- local z = {}
- for i=1, line do
- yaw[i], pitch[i], x[i], y[i], z[i] = rotateX(2,0,-50,30+(120/(line-1)*(i-1)))
- end
- p.stack()
- for i=1, 10 do
- for j=1, line*2 do
- p.setPosition(x[j%line+1]*i,y[j%line+1]*i,z[j%line+1]*math.pow(-1,math.ceil(j/line))*i)
- p.shoot()
- end
- end
- p.release()
- sleep(1)
- spell_6_petal(p,10)
- reset(p)
- turtle.select(3)
- p.setColor(color)
- p.setSpeed(0.2,0.2,0)
- p.setEnd(80)
- local flyYaw = {}
- local flyPitch = {}
- for i=1, line*2 do
- flyYaw[i] = {}
- flyPitch[i] = {}
- end
- local flag
- for i=1, 10 do
- if math.random(2) == 1 then
- for j=1, line*2 do
- p.setPosition(x[j%line+1]*i,y[j%line+1]*i,z[j%line+1]*math.pow(-1,math.ceil(j/line))*i)
- flag, flyYaw[j][i], flyPitch[j][i] = p.setAngleToNearestPlayer()
- end
- else
- for j=1, line*2 do
- local dir = 1
- if j < line+1 then
- dir = -1
- end
- flyYaw[j][i] = dir*math.random(6)*30
- flyPitch[j][i] = math.random(3)*math.pow(-1,math.random(2))
- end
- end
- end
- for k=1, 3 do
- p.stack()
- for i=1, 10 do
- for j=1, line*2 do
- p.setPosition(x[j%line+1]*i,y[j%line+1]*i,z[j%line+1]*math.pow(-1,math.ceil(j/line))*i)
- p.setAngle(flyYaw[j][i],flyPitch[j][i])
- p.shoot()
- end
- end
- p.release()
- sleep(0.2)
- end
- spell_6_petal(p,10)
- end
- ----------
- -- Main.
- ----------
- local p = peripheral.wrap("right")
- p.setGameMode(1)
- rednet.open("left")
- os.pullEvent()
- rednet.close("left")
- interval_1(p)
- goNext(p, "spell1")
- spell_1(p)
- goNext(p, "interval2")
- interval_2(p)
- goNext(p, "spell2")
- spell_2(p)
- goNext(p, "interval3")
- interval_3(p)
- goNext(p, "spell3")
- spell_3(p)
- goNext(p, "spell4")
- spell_4(p)
- goNext(p, "spell5")
- spell_5(p)
- goNext(p, "spell6")
- spell_6(p)
- goNext(p, "finish")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement