kjgthjghj.py

Created by wperez274

Created on September 24, 2023

4.12 KB


from math import *
from random import *
from random import randint as RAND 
from kandinsky import *
from kandinsky import fill_rect as F
from ion import keydown as KP
from kandinsky import draw_string as STR 
from ion import *
from time import *

# screen width and height
SW, SH = 320, 220
GAME_OVER = False

red = (255, 0, 0)
green = (0, 255, 0)
blue = "blue"
yellow = "yellow"
brown = "brown"
cyan = "cyan"
pink = "pink"
orange = "orange"
purple = "purple"
black = "black"
white = "white"

direc = ["left", "right", "up", "down"]
DIR = direc[1]

bg = (110, 18, 23)

x, y, w, h, c = 220, 200, 12, 20, (0, 0, 100)

# ******************
# starting point: area = 1
area = 1
# ******************
level_1=[
#area=1
[[0, 208, 78, 14, (176, 157, 217)], [0, 199, 14, 8, (144, 46, 229)], [126, 200, 32, 22, (51, 18, 23)], [177, 209, 10, 12, (39, 41, 41)]],
#area=2
[[0, 64, 148, 170, black], [105, 127, 114, 136, black], [162, 181, 28, 40, black], [30, 43, 28, 28, black], [51, 25, 54, 64, black], [37, 184, 42, 40, (189, 25, 51)], [13, 100, 24, 28, (45, 138, 186)]],
#area=3
[[75, 178, 154, 44, 'black'], [99, 145, 110, 44, 'black'], [114, 145, 86, 64, 'red'], [236, 85, 86, 64, 'red'], [50, 16, 22, 32, (153, 126, 88)]],
#area=3
[[40, 176, 50, 46, black], [168, 134, 154, 88, black], [202, 86, 120, 88, black], [246, 44, 76, 88, black], [90, 206, 76, 16, red]]
]
# Define bullets and critters
bullets = []
critters = []

# Add critters to the level
def add_critters_to_level(area):
    # Depending on the area, add critters with different properties
    if area == 1:
        critters.append([50, 200, 8, 8, green, 1])  # x, y, w, h, color, speed
    elif area == 2:
        critters.append([100, 180, 8, 8, green, 1])
        critters.append([200, 160, 8, 8, green, 1])
    elif area == 3:
        critters.append([50, 200, 8, 8, green, 1])
        critters.append([250, 180, 8, 8, green, 1])

add_critters_to_level(area)

# Add bullets to the player's ammunition
ammo = 5

def refresh_level():
    F(0, 0, SW, SH, bg)
    for i in level_1[area]:
        F(*i)

F(0, 0, SW, SH, bg)

for i in level_1[area]:
    F(*i)

while not GAME_OVER:
    F(x, y, w, h, c)
    F(x + 3, y + 3, 4, 3, white)
    F(x + 9, y + 3, 4, 3, white)

    # Display the number of bullets left
    STR("Ammo: " + str(ammo), 5, 5, white, bg)

    # Display the number of critters in the area
    STR("Critters: " + str(len(critters)), 200, 5, green, bg)

    for critter in critters:
        F(critter[0], critter[1], critter[2], critter[3], critter[4])
        critter[0] += critter[5]  # Move the critter

    # Handle bullet shooting
    if KP(KEY_OK) and ammo > 0:
        bullet_x = x + w // 2
        bullet_y = y
        bullets.append([bullet_x, bullet_y, 2, 5, white])
        ammo -= 1

    # Display the number of bullets on the screen
    STR("Ammo: " + str(ammo), 5, 5, white, bg)

    for bullet in bullets:
        F(bullet[0], bullet[1], bullet[2], bullet[3], bullet[4])
        bullet[1] -= 5  # Move the bullet upwards

    # Remove bullets that go off the screen
    bullets = [bullet for bullet in bullets if bullet[1] > 0]

    # Check for collisions between bullets and critters
    for critter in critters:
        for bullet in bullets:
            if (bullet[0] + bullet[2] > critter[0] and bullet[0] < critter[0] + critter[2] and
                bullet[1] + bullet[3] > critter[1] and bullet[1] < critter[1] + critter[3]):
                critters.remove(critter)  # Remove the critter
                bullets.remove(bullet)  # Remove the bullet

    if len(critters) == 0:
        add_critters_to_level(area)  # Add new critters when all are defeated

    if KP(KEY_LEFT):
        x -= 1
        F(x + w + 1, y, 1, h, bg)

    if KP(KEY_RIGHT):
        x += 1
        F(x - 1, y, 1, h, bg)

    if x > 320:
        sleep(0.2)
        x = 0
        area += 1
        refresh_level()
        add_critters_to_level(area)  # Add critters to the new area
        ammo = 5  # Reset ammo

    if x < 0 and area == 1:
        x = 0

    if x < 0 and area > 1:
        x = 321
        area -= 1
        refresh_level()
        add_critters_to_level(area)  # Add critters to the new area
        ammo = 5  # Reset ammo

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.