Last active
April 15, 2024 18:47
-
-
Save CoolGuyBraydan/994ab8c328443c371dd3dd176c21f2bb to your computer and use it in GitHub Desktop.
Most recent version of the zombie game
This file contains hidden or 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 turtle | |
import time | |
import random | |
import math | |
tick=0 | |
print('"Join the Undead" made by Braydan Smith') | |
print() | |
print("WARNING: There are flashing lights/colors in this game.") | |
print() | |
print("Would you like a tutorial? Type y/n and press 'enter'.") | |
awnser=input(":") | |
awnser=awnser.lower() | |
if "y" in awnser: | |
print() | |
print("At any point in the tutorial, press 'Enter' to continue.") | |
print() | |
print("You are playing as the blue square, trying to avoid the green square (the zombie).") | |
a=input() | |
print("Use w-a-s-d to move or unpause, and the arrow keys to shoot in different directions.") | |
a=input() | |
print("Press any other key to pause.") | |
a=input() | |
print("You cannot shoot again until the bullet is off screen.") | |
a=input() | |
print("When you shoot the zombie, you gain 10 points and the game speeds up slightly.") | |
a=input() | |
print("You can travel off screen to teleport to the opposite side (like the tunnel in Pac-Man).") | |
a=input() | |
print("If the zombie touches you, you die.") | |
a=input() | |
print("The game will start in 5 seconds (A new window should appear).") | |
print() | |
print("5...") | |
time.sleep(1) | |
print() | |
print("4...") | |
time.sleep(1) | |
print() | |
print("3...") | |
time.sleep(1) | |
print() | |
print("2...") | |
time.sleep(1) | |
print() | |
print("1...") | |
time.sleep(1) | |
elif "y" not in awnser: | |
print("The game will start in 3 seconds (A new window should appear).") | |
time.sleep(3) | |
score=0 | |
delay = 0.05 | |
high_score = 0 | |
gamemode="play" | |
wn = turtle.Screen() | |
wn.title("Join the Undead") | |
wn.setup(width=600, height=600) | |
wn.tracer(0) | |
pen = turtle.Turtle() | |
pen.speed(0) | |
player = turtle.Turtle() | |
player.shape("square") | |
player.penup() | |
player.goto(0,0) | |
player.direction = "Stop" | |
blood=turtle.Turtle() | |
blood.shape("circle") | |
blood.ht() | |
blood.color("maroon") | |
zombie = turtle.Turtle() | |
zombie.width(20) | |
x = random.randint(-300, 300) | |
y = random.randint(-300,300) | |
zombie.setposition(x,y) | |
zombiesize=26 | |
bullet = turtle.Turtle() | |
bullet.penup() | |
bullet.shape("circle") | |
bullet.shapesize(0.5) | |
bullet.hideturtle() | |
bulletspeed = 15 | |
bulletstate = "ready" | |
def fbu(): | |
global bulletstate | |
global score | |
if bulletstate == "ready" and player.direction!="Stop": | |
bulletstate = "fu" | |
x = player.xcor() | |
y = player.ycor()+1 | |
if score == 800: | |
bulletstate = "fd" | |
y = player.ycor()-1 | |
bullet.setposition(x,y) | |
bullet.showturtle() | |
def fbd(): | |
global bulletstate | |
global score | |
if bulletstate == "ready" and player.direction!="Stop": | |
bulletstate = "fd" | |
x = player.xcor() | |
y = player.ycor()-1 | |
if score == 800: | |
bulletstate = "fu" | |
y = player.ycor()+1 | |
bullet.setposition(x,y) | |
bullet.showturtle() | |
def fbl(): | |
global bulletstate | |
global score | |
if bulletstate == "ready" and player.direction!="Stop": | |
bulletstate = "fl" | |
x = player.xcor()-1 | |
y = player.ycor() | |
if score == 800: | |
bulletstate = "fr" | |
x = player.xcor()+1 | |
bullet.setposition(x,y) | |
bullet.showturtle() | |
def fbr(): | |
global bulletstate | |
global score | |
if bulletstate == "ready" and player.direction!="Stop": | |
bulletstate = "fr" | |
x = player.xcor()+1 | |
y = player.ycor() | |
if score == 800: | |
bulletstate = "fl" | |
x = player.xcor()-1 | |
bullet.setposition(x,y) | |
bullet.showturtle() | |
def isCollision(bullet, zombie): | |
distance = math.sqrt(math.pow(bullet.xcor()-zombie.xcor(),2)+math.pow(bullet.ycor()-zombie.ycor(),2)) | |
if distance < zombiesize: | |
return True | |
else: | |
return False | |
def goup(): | |
player.direction = "up" | |
def godown(): | |
player.direction = "down" | |
def goleft(): | |
player.direction = "left" | |
def goright(): | |
player.direction = "right" | |
def move(): | |
global score | |
if player.direction == "up": | |
y = player.ycor() | |
if score!=666: | |
player.sety(y+7) | |
if score==666: | |
player.sety(y+3) | |
if score==800: | |
player.sety(y-7) | |
if player.direction == "down": | |
y = player.ycor() | |
player.sety(y-7) | |
if score==800: | |
player.sety(y+7) | |
if player.direction == "left": | |
x = player.xcor() | |
player.setx(x-7) | |
if score==800: | |
player.setx(x+7) | |
if player.direction == "right": | |
x = player.xcor() | |
player.setx(x+7) | |
if score==800: | |
player.setx(x-7) | |
def movezombie(): | |
global tv | |
if player.direction != "Stop": | |
if player.ycor()>zombie.ycor(): | |
y = zombie.ycor() | |
zombie.sety(y+3.5) | |
if player.ycor()<zombie.ycor(): | |
y = zombie.ycor() | |
zombie.sety(y-3.5) | |
if player.xcor()<zombie.xcor(): | |
x = zombie.xcor() | |
zombie.setx(x-3.5) | |
if player.xcor()>zombie.xcor(): | |
x = zombie.xcor() | |
zombie.setx(x+3.5) | |
t=random.choice(['l','r','d','u']) | |
if t=='l': | |
x = zombie.xcor() | |
zombie.setx(x-tv) | |
if t=='r': | |
x = zombie.xcor() | |
zombie.setx(x+tv) | |
if t=='d': | |
y = zombie.ycor() | |
zombie.sety(y-tv) | |
if t=='u': | |
y = zombie.ycor() | |
zombie.sety(y+tv) | |
def pause(): | |
player.direction="Stop" | |
def draw_screen(): | |
global score | |
global high_score | |
if score == 600 or score == 666: | |
score = 666 | |
pen.color("red") | |
blood.goto(0,0) | |
blood.pendown() | |
blood.width(1) | |
blood.color("red") | |
blood.write("COME DOWN", align="center",font=("Chiller", 80)) | |
blood.color("maroon") | |
wn.bgcolor("maroon") | |
if player.direction == "Stop": | |
player.sety(player.ycor()+5) | |
player.sety(player.ycor()-5) | |
zombie.color("red") | |
player.color("red") | |
if score == 676: | |
score = 610 | |
pen.clear() | |
pen.penup() | |
pen.setposition(-300,-300) | |
pen.pendown() | |
pen.pensize(3) | |
if score != 666: | |
pen.color("white") | |
for side in range(4): | |
pen.fd(600) | |
pen.lt(90) | |
pen.penup() | |
pen.hideturtle() | |
pen.goto(0,250) | |
pen.pendown() | |
pen.write("Score: {} High Score: {}".format( | |
score, high_score), align = "center", font=("candara", 24, "bold")) | |
draw_screen() | |
def respawn_zombie(): | |
global x3 | |
global y3 | |
die=random.choice(["a","b","c","d"]) | |
x1=player.xcor()-100 | |
x2=player.xcor()+100 | |
y1=player.ycor()-100 | |
y2=player.ycor()+100 | |
zombie.ht() | |
zombie.penup() | |
if die=="a": | |
if player.xcor()>-200 and player.ycor()<200: | |
x3=random.randint(-300, x1) | |
y3=random.randint(y2, 300) | |
if player.xcor()<-199 or player.ycor()>199: | |
respawn_zombie() | |
if die=="b": | |
if player.xcor()<200 and player.ycor()<200: | |
x3=random.randint(x2, 300) | |
y3=random.randint(y2, 300) | |
if player.xcor()>199 or player.ycor()>199: | |
respawn_zombie() | |
if die=="c": | |
if player.xcor()>-200 and player.ycor()>-200: | |
x3=random.randint(-300, x1) | |
y3=random.randint(-300,y1) | |
if player.xcor()<-199 or player.ycor()<-199: | |
respawn_zombie() | |
if die=="d": | |
if player.xcor()<200 and player.ycor()>-200: | |
x3=random.randint(x2, 300) | |
y3=random.randint(-300,y1) | |
if player.xcor()>199 or player.ycor()<-299: | |
respawn_zombie() | |
zombie.setposition(x3,y3) | |
wn.listen() | |
wn.onkeypress(goup,"w") | |
wn.onkeypress(godown, "s") | |
wn.onkeypress(goleft, "a") | |
wn.onkeypress(goright, "d") | |
wn.onkeypress(fbu, "Up") | |
wn.onkeypress(fbd, "Down") | |
wn.onkeypress(fbl, "Left") | |
wn.onkeypress(fbr, "Right") | |
wn.onkeypress(pause, " ") | |
while True: | |
wn.update() | |
move() | |
movezombie() | |
time.sleep(delay) | |
if player.direction != "Stop" and score > 690: | |
tick += 1 | |
if tick == 30: | |
tick = 0 | |
if score!=200 and score != 500: | |
blood.penup() | |
if score==200 or score==500: | |
blood.pendown() | |
if high_score == 676: | |
high_score == 610 | |
if player.direction=="Stop" and (score!=0 or player.xcor()!=0 or player.ycor()!=0): | |
pen.penup() | |
pen.ht() | |
pen.goto(0,0) | |
pen.pendown() | |
pen.write("press w, a, s, or d to unpause", align="center", font=("candara", 12, "bold")) | |
if isCollision(bullet,zombie): | |
if bulletstate != "ready": | |
bullet.ht() | |
bulletstate = "ready" | |
bullet.setposition(0,-400) | |
if score > 890: | |
delay += 0.01 | |
score += 20 | |
tv += 1 | |
if score == 890: | |
delay += 0.01 | |
score += 10 | |
tv += 1 | |
if score < 890: | |
respawn_zombie() | |
delay -= 0.0004 | |
score += 10 | |
zombie.st() | |
if score == 300: | |
zombie.ht() | |
zombie.setposition(0,340) | |
zombie.ht() | |
zombie.pendown() | |
tv=0 | |
if score > high_score: | |
high_score = score | |
draw_screen() | |
if isCollision(zombie,player) or (player.ycor()<-300 and score == 666): | |
bullet.ht() | |
bulletstate = "ready" | |
bullet.setposition(0,-400) | |
pen.color("white") | |
player.ht() | |
zombie.ht() | |
player.goto(0,0) | |
player.direction = "Stop" | |
x = random.randint(-200, 200) | |
y = random.randint(100,250) | |
zombie.setposition(x,y) | |
player.st() | |
zombie.st() | |
score = 0 | |
delay = 0.05 | |
draw_screen() | |
blood.clear() | |
if player.direction!="Stop": | |
if bulletstate == "fu": | |
y = bullet.ycor() | |
y += bulletspeed | |
bullet.sety(y) | |
if bulletstate == "fd": | |
y = bullet.ycor() | |
y -= bulletspeed | |
bullet.sety(y) | |
if bulletstate == "fl": | |
x = bullet.xcor() | |
x -= bulletspeed | |
bullet.setx(x) | |
if bulletstate == "fr": | |
x = bullet.xcor() | |
x += bulletspeed | |
bullet.setx(x) | |
if bullet.ycor()>300 or bullet.ycor()<-300 or bullet.xcor()<-300 or bullet.xcor()>300: | |
bullet.hideturtle() | |
bulletstate = "ready" | |
draw_screen() | |
if player.ycor()>300: | |
blood.penup() | |
x = player.xcor() | |
y = player.ycor()-600 | |
player.hideturtle() | |
player.goto(x,y) | |
blood.goto(x,y) | |
player.showturtle() | |
blood.pendown() | |
if player.ycor()<-300 and score != 666: | |
blood.penup() | |
x = player.xcor() | |
y = player.ycor()+600 | |
player.hideturtle() | |
player.goto(x,y) | |
blood.goto(x,y) | |
player.showturtle() | |
blood.pendown() | |
if player.xcor()<-300: | |
blood.penup() | |
x = player.xcor()+600 | |
y = player.ycor() | |
player.hideturtle() | |
player.goto(x,y) | |
blood.goto(x,y) | |
player.showturtle() | |
blood.pendown() | |
if player.xcor()>300: | |
blood.penup() | |
x = player.xcor()-600 | |
y = player.ycor() | |
player.hideturtle() | |
player.goto(x,y) | |
player.showturtle() | |
blood.goto(x,y) | |
blood.pendown() | |
if score < 900 and score!=666: | |
zombiesize=26 | |
zombie.shapesize(1,1) | |
if score!=400: | |
zombie.color("lime") | |
if score == 100: | |
blood.goto(0,0) | |
blood.width(1) | |
blood.pendown() | |
blood.ht() | |
blood.color("maroon") | |
blood.write("join the undead", align="center",font=("Chiller", 24)) | |
blood.color("black") | |
blood.penup() | |
blood.goto(0,-400) | |
if score == 200: | |
blood.goto(zombie.xcor(),zombie.ycor()) | |
blood.color("maroon") | |
blood.pendown() | |
tv=7 | |
if score == 400 and player.direction != "Stop": | |
shapes=["circle","square","triangle","turtle",] | |
colors=['red','orange','yellow','green','blue','purple','pink','brown','black','white'] | |
zombie.shape(random.choice(shapes)) | |
zombie.color(random.choice(colors)) | |
wn.bgcolor(random.choice(colors)) | |
if score == 500 and player.direction != "Stop": | |
blood.width(15) | |
blood.color("maroon") | |
t=random.choice(['l','r','d','u']) | |
if t=='l': | |
x = player.xcor() | |
player.setx(x-5) | |
if t=='r': | |
x = player.xcor() | |
player.setx(x+5) | |
if t=='d': | |
y = player.ycor() | |
player.sety(y-5) | |
if t=='u': | |
y = player.ycor() | |
player.sety(y+5) | |
tv=0 | |
blood.goto(player.xcor(),player.ycor()) | |
blood.pendown() | |
if score == 1000: | |
zombie.color("lime") | |
zombie.shapesize(1,1) | |
zombiesize=26 | |
bullet.ht() | |
wn.update() | |
time.sleep(2) | |
for i in range(3): | |
zombie.ht() | |
wn.update() | |
time.sleep(0.5) | |
zombie.st() | |
wn.update() | |
time.sleep(0.5) | |
for i in range(700): | |
time.sleep(0.01) | |
zombie.sety(zombie.ycor()-1) | |
wn.update() | |
pen.penup() | |
pen.ht() | |
pen.goto(0,0) | |
pen.pendown() | |
pen.write("The End", align="center", font=("chiller", 24, "bold")) | |
pen.penup() | |
pen.goto(0,-40) | |
pen.write("Thank you for playing :)", align="center", font=("candara", 6)) | |
wn.update() | |
time.sleep(5) | |
score = 0 | |
zombie.ht() | |
zombie.goto(player.xcor(),player.ycor()) | |
zombie.st() | |
wn.update() | |
if score==210 or score==110 or score==310 or score==410 or score==510 or score==610 or score==0 or score==980 or score==710: | |
blood.clear() | |
blood.penup() | |
blood.width(20) | |
tv=3 | |
zombie.clear() | |
zombie.penup() | |
zombie.st() | |
zombie.shape("square") | |
zombie.shapesize(1,1) | |
zombiesize=26 | |
zombie.color("lime") | |
wn.bgcolor("black") | |
pen.color("white") | |
player.color("navy blue") | |
bullet.color("red") | |
if score == 666 and player.direction != "Stop": | |
player.sety(player.ycor()-4) | |
zombie.color("red") | |
if score > 890 and score < 960: | |
zombie.color("dark green") | |
zombie.shapesize(3,3) | |
zombiesize=45 | |
if score == 980: | |
zombie.color("green") | |
zombie.shapesize(2,2) | |
zombiesize=45 | |
if score == 700: | |
if tick > 14: | |
zombie.color("black") | |
player.color("black") | |
bullet.color("black") | |
if tick < 15: | |
zombie.color("lime") | |
player.color("navy blue") | |
bullet.color("red") | |
wn.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment