r/learnpython • u/AutoModerator • Oct 12 '26
Ask Anything Monday - Weekly Thread
Welcome to another /r/learnPython weekly "Ask Anything* Monday" thread
Here you can ask all the questions that you wanted to ask but didn't feel like making a new thread.
* It's primarily intended for simple questions but as long as it's about python it's allowed.
If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.
Rules:
- Don't downvote stuff - instead explain what's wrong with the comment, if it's against the rules "report" it and it will be dealt with.
- Don't post stuff that doesn't have absolutely anything to do with python.
- Don't make fun of someone for not knowing something, insult anyone etc - this will result in an immediate ban.
That's it.
1
Upvotes
View all comments
1
u/Remote-Dimension3884 Oct 16 '26
Waar kan ik deze code runnen, zonder programma en zonder dat ik ergens in moet loggen, dus eigenlijk online.
#Stap 1 import
import turtle
import math
import random
#Stap 2 scherm instellen
win = turtle.Screen()
win.title("RUIMTE AVONTUUR(zonder Pygame)")
win.bgcolor("black")
win.setup(width=900, height=800)
win.tracer(0)
# Stap 2.1 variabele
score = 0
lives = 5
level = 1
enemy_speed = 0.05
game_started = False
game_over = False
#2.2 define
def draw_score():
pen.clear()
pen.goto(0, 340)
pen.write(f"Score:{score} Levens: {lives} Level {level}", align="center",font=("verdana",20, "bold"))
def start_game():
global game_started
if not game_started:
game_started = True
draw_score()
def reset_game():
global score, lives, level, enemy_speed, bullet_state, game_over, game_started
score = 0
lives = 5
level = 1
enemy_speed = 0.05
bullet_state = "ready"
game_over = False
game_started = True
player.goto(0, -300)
bullet.goto(0, -600)
for enemy in enemies:
x = random.randint(-350, 350)
y = random.randint(200, 380)
enemy.goto(x, y)
pen.clear()
draw_score()
#Stap 3 Speler/Ruimteschip
player = turtle.Turtle()
player.color("cyan")
player.shape("triangle")
player.shapesize(stretch_wid=2, stretch_len=2.5,)
player.penup()
player.goto(0, -300)
player.setheading(90)
player.speed = 30
#Stap 4 Vijand
enemies = []
number_of_enemies = 3
for i in range(number_of_enemies):
enemy = turtle.Turtle()
enemy.color("red")
enemy.shape("square")
enemy.shapesize(stretch_wid=2.5, stretch_len=2.5)
enemy.penup()
enemy.speed(0)
x = random.randint(-350, 300)
y = random.randint(200, 380)
enemy.goto(x, y)
enemies.append(enemy)
enemy_speed = 0.05
#Stap 5 laser/kogel
bullet = turtle.Turtle()
bullet.color("pink")
bullet.shape("triangle")
bullet.penup()
bullet.speed(0)
bullet.setheading(90)
bullet.shapesize(stretch_wid=0.5, stretch_len=1)
bullet.goto(0, -600)
bullet_state = "ready"
bullet_speed = 2
#Stap 6 scorebord
pen = turtle.Turtle()
pen.speed(0)
pen.color("white")
pen.penup()
pen.hideturtle()
#Stap 7 Besturingfuncties
def move_left():
if game_started and not game_over:
x = player.xcor()
x -= player.speed
if x< -380:
x = -380
player.setx(x)
def move_right():
if game_started and not game_over:
x = player.xcor()
x += player.speed
if x> 380:
x = 380
player.setx(x)
def fire_bullet():
global bullet_state
if game_started and not game_over:
if bullet_state == "ready":
bullet_state = "fire"
x = player.xcor()
y = player.ycor() + 50
bullet.goto(x,y)
#Stap 8 Botsingsdetctie
def is_collision(t1,t2):
distance = math.sqrt(math.pow(t1.xcor() - t2.xcor(),2) + math.pow(t1.ycor() - t2.ycor(),2))
return distance < 40
#Stap 9 Toetsenbord koppelen
win.listen()
win.onkeypress(move_left, "Left")
win.onkeypress(move_right, "Right")
win.onkeypress(fire_bullet, "space")
win.onkeypress(reset_game, "r")
win.onkeypress(start_game, "s")
#stap / Startscherm tonen
pen.goto(0,50)
pen.write("RUIMTE AVONTUUR", align="center", font=("verdana", 30, "bold"))
pen.goto(0,-20)
pen.write("Druk op 's' om te starten", align="center", font=("verdana", 20, "normal"))
#Stap 10 Gameloop
while True:
win.update()
if game_started and not game_over:
#Stap 10.1 Kogel bewegen
if bullet_state == "fire":
y = bullet.ycor()
y += bullet_speed
bullet.sety(y)
#Stap 10.2 Kogel verlaat het scherm
if bullet.ycor() > 400:
bullet.goto(0, -600)
bullet_state = "ready"
#Stap 10.3 Vijand bewegen
for enemy in enemies:
y = enemy.ycor()
y -= enemy_speed
enemy.sety(y)
#Stap 10.4 Vijand berijkt de onderkant (GAME OVER/RESET)
if enemy.ycor()<-380:
enemy.goto(random.randint(-350,350), random.randint(300, 380))
score -= 5
if score <0:
score = 0
draw_score()
#Stap 10.5 Botssing tussen Kogel en Vijand
if is_collision(bullet, enemy):
bullet.goto(0, -600)
bullet_state = "ready"
enemy.goto(random.randint(-350,350),random.randint(300, 380))
score +=50
if score >= 500 and level == 1:
level = 2
enemy_speed += 0.1
draw_score()
#Stap 10.6 Botsing tussen Vijand en Speler
if is_collision(player, enemy):
lives -= 1
enemy.goto(random.randint(-350,350),random.randint(300, 380))
draw_score()
if lives <= 0:
game_over = True
pen.goto(0, 0)
pen.write("GAME OVER\nDruk op 'r' om te herstarten", align="center",font=("verdana",30, "bold"))
win.mainloop()
#break
Ik kan de code nu niet runnen in een dergelijke website als online python, deze doet het niet want deze ondersteunt geen Turtle. ik heb dit juist gebruikt omdat dit standaard in Python zit en je hier dus geen pip install hoeft te gebruiken.
Als dit geen mogelijkheid is moet er een programma komen die simpel is, om de code te kunnen runnen.