space.py

Created by 4223

Created on August 28, 2025

1.17 KB

space


from kandinsky import *
from ion import *
from time import sleep

WIDTH, HEIGHT = 320, 222
WHITE = color(255,255,255)
BLACK = color(0,0,0)

player_x = WIDTH//2
bullet = None
aliens = [[x*30+20,20] for x in range(8)]
score = 0

while True:
    # Besturing
    if keydown(KEY_LEFT) and player_x>0:
        player_x -= 4
    if keydown(KEY_RIGHT) and player_x<WIDTH-20:
        player_x += 4
    if keydown(KEY_OK) and bullet is None:
        bullet = [player_x+8,HEIGHT-20]

    # Beweeg kogel
    if bullet:
        bullet[1]-=5
        if bullet[1]<0:
            bullet=None

    # Check botsing
    if bullet:
        for a in aliens:
            if a[0]<bullet[0]<a[0]+20 and a[1]<bullet[1]<a[1]+15:
                aliens.remove(a)
                bullet=None
                score+=1
                break

    # Teken
    fill_rect(0,0,WIDTH,HEIGHT,BLACK)
    fill_rect(player_x,HEIGHT-15,20,10,WHITE)
    if bullet:
        fill_rect(bullet[0],bullet[1],2,5,WHITE)
    for a in aliens:
        fill_rect(a[0],a[1],20,15,WHITE)
    draw_string("Score:"+str(score),5,5,WHITE,BLACK)

    if not aliens:
        draw_string("YOU WIN!",120,100,WHITE,BLACK)
        break

    sleep(0.05)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.