Advertisement
mralasic

Obstacle Course - lesson

Apr 9th, 2022 (edited)
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.69 KB | None | 0 0
  1. # After starting the program get the player's coordinates which will be used in the entire project
  2. # We will only update the Z coordinate of the player to be able to correctly add stages
  3. position=player.position()
  4. x=position.get_value(Axis.X)
  5. y=position.get_value(Axis.Y)
  6. z=position.get_value(Axis.Z)
  7.  
  8. #function creating the first fragment of the course
  9. def course():
  10.    
  11.     #create the shape of the course from bedrock
  12.     blocks.fill(BEDROCK, world(x-10,y-1,z-2),world(x+10,y+10,z+35),FillOperation.HOLLOW)
  13.     #the line lauching stage 1
  14.     blocks.fill(SEA_LANTERN, world(x-9,y-1,z+3),world(x+9,y-1,z+5))
  15.     #gameplay.set_game_mode(SURVIVAL, mobs.target(NEAREST_PLAYER))
  16.    
  17. player.on_chat("start", course)
  18.  
  19. def stage1(z):
  20.     player.say("STAGE 1!!!!")
  21.     #clearing the horizontal block line to protect player from loading the level multiple times
  22.     blocks.fill(BEDROCK, world(x-10, y-1, z-5), world(x+10, y-1, z+5))
  23.     #adding a barrier behind the player
  24.     blocks.fill(BEDROCK, world(x-10, y, z-3), world(x+10, y+10, z-1))
  25.     #line for loading the next level
  26.     blocks.fill(GOLD_BLOCK, world(x-9,y-1,z+25),world(x+9,y-1,z+27))
  27.     #obstacles for stage 1
  28.     blocks.fill(IRON_BARS, world(x-9,y-1,z+3),world(x+9,y-1,z+20))
  29.     blocks.fill(LAVA, world(x-9,y-2,z+3),world(x+9,y-2,z+20))
  30.     while True:
  31.         if blocks.test_for_block(IRON_BARS, pos(0, -1, 0)):
  32.             mobs.give(mobs.target(NEAREST_PLAYER), DIAMOND_AXE, 1)
  33.             for i in range(8):
  34.                 mobs.spawn(CREEPER, randpos(world(x-8,y+1,z+3),world(x+8,y+1,z+20)))
  35.             break
  36.  
  37. #pocetak definicije stage-a
  38. def stage2(z):
  39.     player.say("STAGE 2!!!!")
  40.     #create an arena
  41.     blocks.fill(BEDROCK, world(x-10,y-1,z-2),world(x+10,y+10,z+30),FillOperation.HOLLOW)
  42.     #clearing the horizontal block line to protect player from loading the level multiple times
  43.     blocks.fill(BEDROCK, world(x-10, y-1, z-5), world(x+10, y-1, z+5))
  44.     #adding a barrier behind the player
  45.     blocks.fill(BEDROCK, world(x-10, y, z-3), world(x+10, y+10, z-1))
  46.     #line for loading the next level
  47.     blocks.fill(GLASS, world(x-9,y-1,z+25),world(x+9,y-1,z+27))
  48.     mobs.apply_effect(NIGHT_VISION, mobs.target(NEAREST_PLAYER))
  49.     #kraj definicije stage-a
  50.     for i in range(15):
  51.         mobs.spawn(ZOMBIE, randpos(world(x-8, y+3, z+3), world(x+10, y+3, z+20)))
  52.  
  53. #pocetak definicije stage-a
  54. def stage3(z):
  55.     player.say("STAGE 3!!!!")
  56.     #create an arena
  57.     blocks.fill(BEDROCK, world(x-10,y-1,z-2),world(x+10,y+10,z+30),FillOperation.HOLLOW)
  58.     #clearing the horizontal block line to protect player from loading the level multiple times
  59.     blocks.fill(BEDROCK, world(x-10, y-1, z-5), world(x+10, y-1, z+5))
  60.     #adding a barrier behind the player
  61.     blocks.fill(BEDROCK, world(x-10, y, z-3), world(x+10, y+10, z-1))
  62.     #line for loading the next level
  63.     blocks.fill(COBBLESTONE, world(x-9,y-1,z+25),world(x+9,y-1,z+27))
  64.     mobs.apply_effect(NIGHT_VISION, mobs.target(NEAREST_PLAYER))
  65.     #kraj definicije stage-a
  66.     blocks.fill(DIAMOND_BLOCK, world(x-9,y-1,z+3),world(x+9,y-1,z+20))
  67.     while True:
  68.         if blocks.test_for_block(DIAMOND_BLOCK, pos(0, -1, 0)):
  69.             for i in range(10):
  70.                 mobs.spawn(PRIMED_TNT, randpos(world(x-8,y+3,z+3),world(x+8,y+3,z+20)))
  71.             break
  72.  
  73.  
  74. #pocetak definicije stage-a
  75. def stage4(z):
  76.     player.say("STAGE 4!!!!")
  77.     #create an arena
  78.     blocks.fill(BEDROCK, world(x-10,y-1,z-2),world(x+10,y+10,z+30),FillOperation.HOLLOW)
  79.     #clearing the horizontal block line to protect player from loading the level multiple times
  80.     blocks.fill(BEDROCK, world(x-10, y-1, z-5), world(x+10, y-1, z+5))
  81.     #adding a barrier behind the player
  82.     blocks.fill(BEDROCK, world(x-10, y, z-3), world(x+10, y+10, z-1))
  83.     #line for loading the next level
  84.     blocks.fill(GRANITE, world(x-9,y-1,z+25),world(x+9,y-1,z+27))
  85.     mobs.apply_effect(NIGHT_VISION, mobs.target(NEAREST_PLAYER))
  86.     #kraj definicije stage-a
  87.     for i in range(11):
  88.         blocks.place(LAVA, randpos(world(x-9,y+1,z+5), world(x+9,y+1,z+20)))  
  89.  
  90. #pocetak definicije stage-a
  91. def stage5(z):
  92.     player.say("STAGE 5!!!!")
  93.     #create an arena
  94.     blocks.fill(BEDROCK, world(x-10,y-1,z-2),world(x+10,y+10,z+30),FillOperation.HOLLOW)
  95.     #clearing the horizontal block line to protect player from loading the level multiple times
  96.     blocks.fill(BEDROCK, world(x-10, y-1, z-5), world(x+10, y-1, z+5))
  97.     #adding a barrier behind the player
  98.     blocks.fill(BEDROCK, world(x-10, y, z-3), world(x+10, y+10, z-1))
  99.     #line for loading the next level
  100.     blocks.fill(REDSTONE_BLOCK, world(x-9,y-1,z+25),world(x+9,y-1,z+27))
  101.     mobs.apply_effect(NIGHT_VISION, mobs.target(NEAREST_PLAYER))
  102.     #kraj definicije stage-a
  103.     blocks.fill(AIR, world(x-9,y,z+3),world(x+9,y-4,z+20))
  104.  
  105.     blocks.fill(LAPIS_LAZULI_BLOCK, world(x-9,y-1,z+2),world(x+9,y-1,z+2))
  106.     blocks.fill(LAPIS_LAZULI_BLOCK, world(x-9,y-1,z+7),world(x+9,y-1,z+7))
  107.     blocks.fill(LAPIS_LAZULI_BLOCK, world(x-9,y-1,z+15),world(x+9,y-1,z+15))
  108.  
  109.     blocks.place(GLOWSTONE, world(x, y, z+28))
  110.  
  111.     while blocks.test_for_block(REDSTONE_BLOCK, pos(0, -1, 0))==False:
  112.         if blocks.test_for_block(LAPIS_LAZULI_BLOCK, pos(0, -1, 0)):
  113.             mobs.apply_effect(LEVITATION, mobs.target(NEAREST_PLAYER), 2, 1)
  114.  
  115. def afterDestroying():
  116.     player.teleport(pos(0, 0, 10))
  117.  
  118. #code responsible to loading levels
  119. while True:
  120.     #Checking the block under the player
  121.     if blocks.test_for_block(SEA_LANTERN, pos(0, -1, 0)):
  122.         #getting the current position and passing it to the function
  123.         position = player.position()
  124.         z = position.get_value(Axis.Z)
  125.         stage1(z)
  126.         loops.pause(3000)
  127.     elif blocks.test_for_block(GOLD_BLOCK, pos(0, -1, 0)):
  128.         #getting the current position and passing it to the function
  129.         position = player.position()
  130.         z = position.get_value(Axis.Z)
  131.         stage2(z)
  132.         loops.pause(3000)
  133.     elif blocks.test_for_block(GLASS, pos(0, -1, 0)):
  134.         #getting the current position and passing it to the function
  135.         position = player.position()
  136.         z = position.get_value(Axis.Z)
  137.         stage3(z)
  138.         loops.pause(3000)
  139.     elif blocks.test_for_block(COBBLESTONE, pos(0, -1, 0)):
  140.         #getting the current position and passing it to the function
  141.         position = player.position()
  142.         z = position.get_value(Axis.Z)
  143.         stage4(z)
  144.         loops.pause(3000)
  145.     elif blocks.test_for_block(GRANITE, pos(0, -1, 0)):
  146.         #getting the current position and passing it to the function
  147.         position = player.position()
  148.         z = position.get_value(Axis.Z)
  149.         stage5(z)
  150.         loops.pause(3000)
  151.  
  152. blocks.on_block_broken(GLOWSTONE, afterDestroying)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement