Advertisement
mralasic

obstacle

May 7th, 2022
772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.73 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.    
  22.     #clearing the horizontal block line to protect player from loading the level multiple times
  23.     blocks.fill(BEDROCK, world(x-10,y-1,z-5),world(x+10,y-1,z+5))
  24.     #adding a barrier behind the player
  25.     blocks.fill(BEDROCK, world(x-10,y,z-3),world(x+10,y+10,z-1))
  26.    
  27.     #the line loading the next level
  28.     blocks.fill(GOLD_BLOCK, world(x-9,y-1,z+25),world(x+9,y-1,z+27))
  29.     #obstacles of the first stage
  30.     blocks.fill(IRON_BARS, world(x-9,y-1,z+3),world(x+9,y-1,z+20))
  31.     blocks.fill(LAVA, world(x-9,y-2,z+3),world(x+9,y-2,z+20))
  32.     while True:
  33.         if blocks.test_for_block(IRON_BARS, pos(0, -1, 0)):
  34.            
  35.             mobs.give(mobs.target(NEAREST_PLAYER), DIAMOND_AXE, 1)
  36.             for i in range(6):
  37.                
  38.                 mobs.spawn(CREEPER, randpos(world(x-8,y+1,z+3), world(x+8,y+1,z+20)))
  39.             #break finishes the loop that contains it.
  40.             #the program moves to the statement right after the loop
  41.  
  42.             break
  43.  
  44. def stage2(z):
  45.     player.say("STAGE 2")
  46.     #adding the next course segment
  47.  
  48.     blocks.fill(BEDROCK, world(x-10,y-1,z-2),world(x+10,y+10,z+30),FillOperation.HOLLOW)
  49.     blocks.fill(BEDROCK, world(x-10,y-1,z-5),world(x+10,y-1,z+5))
  50.     blocks.fill(BEDROCK, world(x-10,y,z-3),world(x+10,y+10,z-1))
  51.    
  52.     blocks.fill(GLASS, world(x-9,y-1,z+25),world(x+9,y-1,z+27))
  53.    
  54.    
  55.     for i in range(11):
  56.        
  57.         mobs.spawn(ZOMBIE, randpos(world(x-8,y+3,z+3), world(x+8,y+3,z+20)))
  58.  
  59. def stage3(z):
  60.     player.say("STAGE 3")
  61.     #adding another segment
  62.     blocks.fill(BEDROCK, world(x-10,y-1,z-2),world(x+10,y+10,z+30),FillOperation.HOLLOW)
  63.    
  64.     #clearing the horizontal line  
  65.     blocks.fill(BEDROCK, world(x-10,y-1,z-5),world(x+10,y-1,z+5))
  66.     #adding a barrier behind the player
  67.     blocks.fill(BEDROCK, world(x-10,y,z-3),world(x+10,y+10,z-1))
  68.     #adding the line that will load the next stage
  69.     blocks.fill(COBBLESTONE, world(x-9,y-1,z+25),world(x+9,y-1,z+27))
  70.     #stage 3 obstacles  
  71.     blocks.fill(DIAMOND_BLOCK, world(x-9,y-1,z+3),world(x+9,y-1,z+20))
  72.     while True:
  73.         if blocks.test_for_block(DIAMOND_BLOCK, pos(0, -1, 0)):
  74.             for i in range(11):
  75.                
  76.                 mobs.spawn(PRIMED_TNT, randpos(world(x-8,y+3,z+3), world(x+8,y+3,z+20)))
  77.             break
  78.  
  79. def stage4(z):
  80.     player.say("STAGE 4")
  81.     blocks.fill(BEDROCK, world(x-10,y-1,z-2),world(x+10,y+10,z+30),FillOperation.HOLLOW)
  82.  
  83.  
  84.     blocks.fill(BEDROCK, world(x-10,y-1,z-5),world(x+10,y-1,z+5))
  85.     blocks.fill(BEDROCK, world(x-10,y,z-3),world(x+10,y+10,z-1))
  86.    
  87.     blocks.fill(GRANITE, world(x-9,y-1,z+25),world(x+9,y-1,z+27))
  88.    
  89.     for i in range(11):
  90.        
  91.         blocks.place(LAVA, randpos(world(x-9,y+1,z+5), world(x+9,y+1,z+20)))
  92.  
  93. def stage5(z):
  94.    
  95.     player.say("STAGE 5")
  96.     blocks.fill(BEDROCK, world(x-10,y-1,z-2),world(x+10,y+10,z+30),FillOperation.HOLLOW)
  97.     blocks.fill(BEDROCK, world(x-10,y-1,z-5),world(x+10,y-1,z+5))
  98.     blocks.fill(BEDROCK, world(x-10,y,z-3),world(x+10,y+10,z-1))
  99.    
  100.     blocks.fill(REDSTONE_BLOCK, world(x-9,y-1,z+25),world(x+9,y-1,z+27))        
  101.    
  102.     blocks.fill(AIR, world(x-9,y,z+3),world(x+9,y-4,z+20))        
  103.    
  104.     blocks.fill(LAPIS_LAZULI_BLOCK, world(x-9,y-1,z+2),world(x+9,y-1,z+2))
  105.    
  106.     blocks.fill(LAPIS_LAZULI_BLOCK, world(x-9,y-1,z+7),world(x+9,y-1,z+7))
  107.    
  108.     blocks.fill(LAPIS_LAZULI_BLOCK, world(x-9,y-1,z+15),world(x+9,y-1,z+15))
  109.     #adding a glowstone block at the end, when the player destroys it they will be moved to a safe spot
  110.     blocks.place(GLOWSTONE, world(x, y, z+28))
  111.    
  112.     while blocks.test_for_block(REDSTONE_BLOCK, pos(0, -1, 0))==False:
  113.         if blocks.test_for_block(LAPIS_LAZULI_BLOCK, pos(0, -1, 0)):
  114.            
  115.             mobs.apply_effect(LEVITATION, mobs.target(NEAREST_PLAYER), 2, 1)
  116.  
  117. def afterDestroying():
  118.    
  119.     player.teleport(pos(0, 0, 10))
  120.    
  121. blocks.on_block_broken(GLOWSTONE, afterDestroying)
  122.  
  123. #the code responsible to loading next levels
  124. while True:
  125.     #Checking the block under the player
  126.     if blocks.test_for_block(SEA_LANTERN, pos(0, -1, 0)):
  127.         #getting the current position and passing it to the function
  128.         position=player.position()
  129.         z=position.get_value(Axis.Z)
  130.         stage1(z)
  131.         loops.pause(3000)
  132.     elif blocks.test_for_block(GOLD_BLOCK, pos(0, -1, 0)):
  133.         position=player.position()
  134.         z=position.get_value(Axis.Z)
  135.         stage2(z)
  136.         loops.pause(3000)
  137.     elif blocks.test_for_block(GLASS, pos(0, -1, 0)):
  138.         position=player.position()
  139.         z=position.get_value(Axis.Z)
  140.         stage3(z)
  141.         loops.pause(3000)
  142.     elif blocks.test_for_block(COBBLESTONE, pos(0, -1, 0)):
  143.         position=player.position()
  144.         z=position.get_value(Axis.Z)
  145.         stage4(z)
  146.         loops.pause(3000)
  147.     elif blocks.test_for_block(GRANITE, pos(0, -1, 0)):
  148.         position=player.position()
  149.         z=position.get_value(Axis.Z)
  150.         stage5(z)
  151.         loops.pause(3000)
  152.  
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement