fireball_5.py

Created by wperez274

Created on September 20, 2023

3.66 KB


from math import *
from random import *
from random import randint as RAND
from kandinsky import *
from kandinsky import fill_rect as FILL
from kandinsky import draw_string as STR
from ion import *
from time import sleep

RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)
WHITE = (255,) * 3
CYAN = (0, 255, 255)
YELLOW = (255, 255, 0)

S_WIDTH = 320
S_HEIGHT = 222

rect_w = 20
rect_h = 20
rect_c = RED
center_x = S_WIDTH // 2
center_y = S_HEIGHT // 2
radius = 50
angle = 0
angular_speed = 0.02

gx = 0
gy = 170
gw = S_WIDTH
gh = 6
gc = WHITE

lavax = 0
lavay = RAND(200, 218)
lavaw = 322
lavah = 30
lavac = RED

fireball_radius1 = 10
fireball_radius2 = 5
fireball_color = RED

# Initial position and parameters of the smaller fireball
fireball2_radius = 10
fireball2_angle = 0
fireball2_speed = 0.01  # Adjust the speed as needed
fireball2_y = S_HEIGHT // 2  # Start in the middle of the screen

px = 40
pw = 12
ph = 22
py = gy - ph + 1
pc = BLUE
pskin = WHITE
pe = 45
game = True
bg = (RAND(0, 80), RAND(0, 80), RAND(0, 80))
FILL(0, 0, S_WIDTH, S_HEIGHT, bg)
FILL(gx, gy, gw, gh, gc)

while game:
    sleep(0.001)

    FILL(15, 5, int(pe), 8, (255, 0, 0))
    x = center_x + int(radius * cos(angle))
    y = center_y + int(radius * sin(angle))

    FILL(px, py, pw, ph, pc)

    FILL(px, py, 1, ph, pskin)
    FILL(px + pw - 1, py, 1, ph, pskin)
    FILL(px, py, pw, 1, pskin)
    FILL(px, py + ph - 1, pw, 1, pskin)

    FILL(x - rect_w // 2, y - rect_h // 2, rect_w, rect_h, rect_c)
    FILL((x - rect_w // 2) + 3, (y - rect_h // 2) + 3, rect_w - 6, rect_h - 6, (RAND(50, 255), 0, 0))

    if px < x + rect_w // 2 and px + pw > x - rect_w // 2 and py < y + rect_h // 2 and py + ph > y - rect_h // 2:
        pe -= 10
        px = 40

    angle += angular_speed

    if keydown(KEY_LEFT):
        FILL(px + pw + 1, py, 1, ph, bg)
        px -= 1
        if keydown(KEY_TOOLBOX):
            FILL(px + pw, py, 2, ph, bg)
            FILL(15 + int(pe), 5, 1, 8, bg)
            px -= 2
            pe -= 0.8

    if keydown(KEY_RIGHT):
        FILL(px - 1, py, 1, ph, bg)
        px += 1
        if keydown(KEY_TOOLBOX):
            FILL(px - 2, py, 3, ph, bg)
            FILL(15 + int(pe), 5, 1, 8, bg)
            px += 2
            pe -= 0.8

    if px + pw < 0:
        px = S_WIDTH
    if px > S_WIDTH:
        px = -pw

    if keydown(KEY_UP) or keydown(KEY_OK) and pe > 0:
        FILL(15 + int(pe), 5, 1, 8, bg)
        FILL(px, py + ph, pw, 1, bg)
        py -= 1
        pe -= 0.4
    else:
        py += 1

    if not keydown(KEY_UP) and not keydown(KEY_OK):
        FILL(px, py - 1, pw, 1, bg)

    if py + ph - 1 > gy:
        py = gy - ph + 1

    if keydown(KEY_DOWN) and py + ph >= gy:
        ph = 10
        FILL(px, py, pw, ph, bg)
        sleep(0.01)
        py = gy - ph
    else:
        ph = 22

    pe += 0.05

    if pe > 55:
        pe = 55

    if pe < 0:
        pe = 0
        game = False

    FILL(lavax, lavay, lavaw, lavah, lavac)
    FILL(lavax + 2, lavay + 5, lavaw - 4, lavah, (RAND(150, 255), 0, 0))

    # Draw the larger fireball
    FILL(x - fireball_radius1, y - fireball_radius1, 2 * fireball_radius1, 2 * fireball_radius1, fireball_color)

    # Calculate the position of the smaller fireball in a circular motion
    fireball2_x = center_x + int(radius * cos(fireball2_angle))
    fireball2_y = center_y + int(radius * sin(fireball2_angle))
    fireball2_angle += fireball2_speed

    # Draw the smaller fireball
    FILL(fireball2_x - fireball_radius2, fireball2_y - fireball_radius2, 2 * fireball_radius2, 2 * fireball_radius2, fireball_color)

STR("E", 2, 2, GREEN, bg)
bg = BLACK
FILL(0, 0, S_WIDTH, S_HEIGHT, bg)
STR("GAME OVER", 100, 100, RED, BLACK)

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.