lklijlk.py

Created by wperez274

Created on September 22, 2023

1.35 KB


from time import *
from Kandinsky import *
from Kandinsky import fill_rect as FILL
from ion import keypad


player_x, player_y, player_w, player_h = 20, 100, 10, 13
enemy_x, enemy_y, enemy_w, enemy_h = 300, 100, 15, 15
missiles = []
bullets = []
enemy_hit = False

while True:
    FILL(player_x, player_y, player_w, player_h, (0, 0, 255))
    FILL(enemy_x, enemy_y, enemy_w, enemy_h, (0, 0, 0))

    keys = keypad.is_pressed()
    if keys & keypad.KEY_OK:
        missiles.append([player_x + player_w, player_y + player_h // 2])
    if keys & keypad.KEY_BACKSPACE:
        bullets.append([player_x + player_w, player_y + player_h // 2])

    new_missiles = []
    for mx, my in missiles:
        FILL(mx, my, 2, 2, (255, 0, 0))
        if enemy_x <= mx <= (enemy_x + enemy_w) and enemy_y <= my <= (enemy_y + enemy_h):
            enemy_hit = True
        else:
            new_missiles.append([mx + 5, my])
    missiles = new_missiles

    new_bullets = []
    for bx, by in bullets:
        FILL(bx, by, 2, 2, (0, 0, 0))
        if enemy_x <= bx <= (enemy_x + enemy_w) and enemy_y <= by <= (enemy_y + enemy_h):
            enemy_hit = True
        else:
            new_bullets.append([bx + 2, by])
    bullets = new_bullets

    if enemy_hit:
        FILL(enemy_x, enemy_y, enemy_w, enemy_h, (0, 255, 0))
        sleep(1)
        enemy_hit = False

    sleep(0.01)

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.