This game is really challenging, you spawn in and you have to kill the enemies, this is a never ending game. If you kill 1 enemy another one spawns. You have to dodge their shots which is impossible. The only way to “beat” the game is to get 50 kills which is really challenging.
In order to play the game, you must copy the code below and paste it into your python file. After that, run the code and enjoy!
Copy the code for FREE!:
import turtle
import random
import math
screen = turtle.Screen()
screen.title("Weapon Game")
screen.bgcolor("white")
screen.setup(width=800, height=600)
screen.tracer(0)
player = turtle.Turtle()
player.shape("turtle")
player.color("blue")
player.penup()
player_speed = 10
box = turtle.Turtle()
box.shape("square")
box.color("brown")
box.penup()
box.goto(0, 200)
enemies = []
enemy_count = 0
enemy_laser = turtle.Turtle()
enemy_laser.shape("triangle")
enemy_laser.color("red")
enemy_laser.penup()
enemy_laser.speed(0)
enemy_laser.goto(0, -200)
enemy_laser.hideturtle()
player_health = 100
health_display = turtle.Turtle()
health_display.hideturtle()
health_display.penup()
health_display.goto(-380, 270)
health_display.write("Health: {}".format(player_health), align="left", font=("Arial", 16, "normal"))
kill_count_display = turtle.Turtle()
kill_count_display.hideturtle()
kill_count_display.penup()
kill_count_display.goto(350, 270)
projectiles = []
enemy_lasers = []
enemies_to_remove = []
weapon_type = ""
weapon_level = 0
player_damage = 0
def check_collision():
global weapon_type, weapon_level, player_damage
distance = player.distance(box)
if distance < 30:
weapon_type = random.choice(["sword", "axe"])
weapon_level = random.randint(1, 10)
player_damage = weapon_level
box.clear()
box.goto(0, 200)
box.write("{} (Level {})".format(weapon_type.capitalize(), weapon_level),
align="center", font=("Arial", 16, "normal"))
def shoot(x, y):
projectile = turtle.Turtle()
projectile.shape("triangle")
if weapon_type == "sword":
projectile.color("red")
elif weapon_type == "axe":
projectile.color("black")
projectile.penup()
projectile.speed(0)
projectile.goto(player.position())
angle = math.atan2(y - player.ycor(), x - player.xcor())
projectile.setheading(math.degrees(angle))
projectiles.append(projectile)
def enemy_shoot():
enemy_laser.goto(random.randint(-380, 380), random.randint(-250, 250))
enemy_laser.showturtle()
enemy_lasers.append(enemy_laser.clone())
def move_enemy_lasers():
for laser in enemy_lasers:
laser.setheading(laser.towards(player.position()))
laser.forward(5)
def check_projectile_enemy_collision():
for projectile in projectiles:
for enemy in enemies:
if projectile.distance(enemy) < 30:
projectiles.remove(projectile)
projectile.hideturtle()
enemies_to_remove.append(enemy)
def check_enemy_laser_player_collision():
for laser in enemy_lasers:
if laser.distance(player) < 30:
player_health -= 10
health_display.clear()
health_display.write("Health: {}".format(player_health), align="left", font=("Arial", 16, "normal"))
laser.hideturtle()
enemy_lasers.remove(laser)
def move_forward():
player.setheading(90)
player.forward(player_speed)
def move_backward():
player.setheading(270)
player.forward(player_speed)
def move_left():
player.setheading(180)
player.forward(player_speed)
def move_right():
player.setheading(0)
player.forward(player_speed)
screen.onkeypress(move_forward, "w")
screen.onkeypress(move_backward, "s")
screen.onkeypress(move_left, "a")
screen.onkeypress(move_right, "d")
screen.onclick(shoot)
screen.listen()
def create_enemy():
enemy = turtle.Turtle()
enemy.shape("circle")
enemy.color("red")
enemy.penup()
enemy.goto(random.randint(-380, 380), random.randint(-250, 250))
enemies.append(enemy)
create_enemy()
enemy_shooting_frequency = 0.01
while True:
screen.update()
for projectile in projectiles:
projectile.forward(10)
move_enemy_lasers()
check_projectile_enemy_collision()
check_enemy_laser_player_collision()
for projectile in projectiles:
if abs(projectile.xcor()) > 400 or abs(projectile.ycor()) > 300:
projectiles.remove(projectile)
projectile.hideturtle()
for enemy in enemies_to_remove:
enemies.remove(enemy)
enemy.hideturtle()
create_enemy()
enemy_count += 1
kill_count_display.clear()
kill_count_display.write("Kills: {}".format(enemy_count), align="right", font=("Arial", 16, "normal"))
enemies_to_remove.clear()
for enemy in enemies:
if player.distance(enemy) < 30:
player_health -= 10
health_display.clear()
health_display.write("Health: {}".format(player_health), align="left", font=("Arial", 16, "normal"))
enemy.goto(random.randint(-380, 380), random.randint(-250, 250))
if player_health <= 0:
break
if random.random() < enemy_shooting_frequency:
enemy_shoot()
check_collision()
game_over.hideturtle()
game_over.penup()
game_over.goto(0, 0)
game_over.write("Game Over", align="center", font=("Arial", 24, "normal"))
screen.exitonclick()