Created
August 27, 2018 15:56
-
-
Save richardbwest/9b0b750610beb7674166ed112ab80a4d to your computer and use it in GitHub Desktop.
Simple Flappybird style game in Minecraft coded using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mcpi.minecraft as minecraft | |
import mcpi.block as block | |
import random, time | |
mc = minecraft.Minecraft.create() | |
def drawPillar(x): | |
mc.setBlocks(x,0,-10,x,100,10,block.STONE) | |
ypos = random.randint(20,60) | |
mc.setBlocks(x,ypos-5,-10,x,ypos+5,10,block.AIR) | |
def main(): | |
mc.postToChat("Welcome to flappy bird Minecraft!") | |
mc.player.setTilePos(-10,1,0) | |
mc.setBlocks(-10,0,-10,-5,-0,10,block.STONE) | |
mc.setBlock(-7,0,0,block.WOOL.id,3) | |
while True: | |
playerPos = tuple(mc.player.getTilePos()) | |
blockEvents = mc.events.pollBlockHits() | |
if playerPos == (-7,1,0) and len(blockEvents) > 0: | |
mc.postToChat("get ready...") | |
time.sleep(5) | |
runGame() | |
def runGame(): | |
posx = 0 | |
posy = 70 | |
posz = 0.0 | |
while True: | |
blockEvents = mc.events.pollBlockHits() | |
if len(blockEvents) > 0: | |
posy+= 6 | |
else: | |
posy-= 0.2 | |
mc.player.setPos(posx,posy,posz) | |
posx += 0.1 | |
time.sleep(0.01) | |
mc.player.setDirection(0,0,0) | |
mc.player.setRotation(270) | |
mc.player.setPitch(0) | |
if not mc.getBlock(posx,posy,posz) == 0: | |
mc.postToChat("Game Over") | |
time.sleep(3) | |
mc.player.setTilePos(-15,1,0) | |
mc.postToChat("You scored " + str(int(posx))) | |
break | |
return | |
for x in range(50,1000,30): | |
drawPillar(x) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment