initial commit

This commit is contained in:
hoffmeisterda104361 committed 2026-10-19 20:29:13 +02:00
commit 39f56a3b10
83 files changed
+3583

No files matched your search

+91
View File
@@ -0,0 +1,91 @@
import random
import pygame
from my_package.Particle_class import Particle
class Spark(Particle):
def __init__(self,x,y,color,fade_speed=4):
super().__init__(x,y,color,fade_speed)
self.y = y
self.rad = CIRCLE_RADIUS
self.image = pygame.Surface((self.rad * 2, self.rad * 2), pygame.SRCALPHA)
pygame.draw.circle(self.image, self.color, (self.rad, self.rad), self.rad)
def appear(self, screen):
if self.alpha > 0:
self.image.set_alpha(self.alpha)
screen.blit(self.image, (self.pos[0] - self.rad, self.pos[1] - self.rad))
particles = []
width = 600
height = 600
SIZE = (width, height)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
ORANGE = (255, 128, 0)
BLACK = (0, 0, 0)
CIRCLE_RADIUS = 3
f_x = [-0.1,0,0.1]
f_y = [-0.2,-0.1]
COLOR = (ORANGE, RED)
def main():
screen = init_game()
game_loop(screen)
exit_game()
def init_game():
global clock
clock = pygame.time.Clock()
pygame.init()
screen = pygame.display.set_mode(SIZE)
return screen
def game_loop(screen):
while True:
if not event_handling():
break
if not update_game():
break
draw_screen(screen)
def event_handling():
for event in pygame.event.get():
if event.type == pygame.QUIT:
return False
return True
def update_game():
for _ in range(2):
particles.append(Spark(300,300,random.choice(COLOR)))
for particle_object in particles:
particle_object.apply_force((random.choice(f_x), -0.1))
if particle_object.y <= 0 or particle_object.alpha <= 0:
print(particle_object)
particles.remove(particle_object)
particle_object.fade()
particle_object.update()
clock.tick(60)
return True
def draw_screen(screen):
screen.fill(BLACK)
for particle_object in particles:
particle_object.set_surface(screen)
particle_object.appear(screen)
pygame.display.flip()
def exit_game():
pygame.quit()
main()
+91
View File
@@ -0,0 +1,91 @@
import random
import pygame
from my_package.Particle_class import Particle
class Spark(Particle):
def __init__(self, x, y, color, fade_speed=4):
super().__init__(x, y, color, fade_speed)
self.x = x
self.y = y
self.rad = CIRCLE_RADIUS
self.image = pygame.Surface((self.rad * 2, self.rad * 2), pygame.SRCALPHA)
pygame.draw.circle(self.image, self.color, (self.rad, self.rad), self.rad)
def appear(self, screen):
if self.alpha > 0:
self.image.set_alpha(self.alpha)
screen.blit(self.image, (self.pos[0] - self.rad, self.pos[1] - self.rad))
particles = []
width = 600
height = 600
SIZE = (width, height)
BLACK = (0, 0, 0)
CIRCLE_RADIUS = 1
COLORS = [(255,0,0), (0,0,255), (255,0,255), (0,255,255), (255,0,255)]
FRICTION = -0.5
def main():
screen = init_game()
game_loop(screen)
exit_game()
def init_game():
global clock
clock = pygame.time.Clock()
pygame.init()
screen = pygame.display.set_mode(SIZE)
return screen
def game_loop(screen):
while True:
if not event_handling():
break
if not update_game():
break
draw_screen(screen)
def event_handling():
for event in pygame.event.get():
if event.type == pygame.QUIT:
return False
if event.type == pygame.MOUSEBUTTONDOWN:
x = pygame.mouse.get_pos()[0]
y = pygame.mouse.get_pos()[1]
for _ in range(3000):
particles.append(Spark(x, y, random.choice(COLORS)))
return True
def update_game():
for particle_object in particles:
particle_object.apply_force((random.randint(-2,2),random.randint(-2,2)))
if particle_object.y <= 0 or particle_object.x <= 0 or particle_object.y == height or particle_object.x == width or particle_object.alpha <= 0:
particle_object.set_surface(None)
print(particle_object)
particles.remove(particle_object)
particle_object.fade()
particle_object.update()
clock.tick(60)
return True
def draw_screen(screen):
screen.fill(BLACK)
for particle_object in particles:
particle_object.set_surface(screen)
particle_object.appear(screen)
pygame.display.flip()
def exit_game():
pygame.quit()
main()
+87
View File
@@ -0,0 +1,87 @@
import random
import pygame
from my_package.Particle_class import Particle
class Spark(Particle):
def __init__(self, x, y, color=(255,255,255), fade_speed=20):
super().__init__(x, y, color, fade_speed)
self.x = x
self.y = y
self.rad = CIRCLE_RADIUS
self.image = pygame.Surface((self.rad * 2, self.rad * 2), pygame.SRCALPHA)
pygame.draw.circle(self.image, self.color, (self.rad, self.rad), self.rad)
def appear(self, screen):
if self.alpha > 0:
self.image.set_alpha(self.alpha)
screen.blit(self.image, (self.pos[0] - self.rad, self.pos[1] - self.rad))
particles = []
width = 600
height = 600
SIZE = (width, height)
BLACK = (0, 0, 0)
CIRCLE_RADIUS = 2
f_x = [-0.1,0,0.1]
def main():
screen = init_game()
game_loop(screen)
exit_game()
def init_game():
global clock
clock = pygame.time.Clock()
pygame.init()
screen = pygame.display.set_mode(SIZE)
return screen
def game_loop(screen):
while True:
if not event_handling():
break
if not update_game():
break
draw_screen(screen)
def event_handling():
for event in pygame.event.get():
if event.type == pygame.QUIT:
return False
return True
def update_game():
x = pygame.mouse.get_pos()[0]
y = pygame.mouse.get_pos()[1]
for _ in range(10):
particles.append(Spark(x,y))
for particle_object in particles:
particle_object.apply_force((random.randint(-2,2),random.randint(-2,2)))
if particle_object.y <= 0 or particle_object.x <= 0 or particle_object.y == height or particle_object.x == width or particle_object.alpha <= 0:
particle_object.set_surface(None)
print(particle_object)
particles.remove(particle_object)
particle_object.fade()
particle_object.update()
clock.tick(60)
return True
def draw_screen(screen):
screen.fill(BLACK)
for particle_object in particles:
particle_object.set_surface(screen)
particle_object.appear(screen)
pygame.display.flip()
def exit_game():
pygame.quit()
main()
+73
View File
@@ -0,0 +1,73 @@
import random
import time
import pygame
class Star:
def __init__(self,visible,pos):
self.visible = visible
self.pos = pos
self.size = random.randint(1,3)
def set_visible(self):
self.visible = True
def star_appear(self,screen):
pygame.draw.circle(screen, WHITE, self.pos, self.size)
stars = []
width = 640
height = 600
SIZE = (width, height)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
def main():
screen = init_game()
game_loop(screen)
exit_game()
def init_game():
pygame.init()
screen = pygame.display.set_mode(SIZE)
return screen
def game_loop(screen):
while True:
if not event_handling():
break
if not update_game(screen):
break
event = event_handling()
update_game(screen)
draw_screen(screen)
time.sleep(0.5)
def event_handling():
for event in pygame.event.get():
if event.type == pygame.QUIT:
return False
return True
def update_game(screen):
for _ in range (2):
night_sky(screen)
random.choice(stars).set_visible()
return True
def draw_screen(screen):
screen.fill(BLACK)
x = 0
for _ in stars:
if stars[x].visible:
stars[x].star_appear(screen)
x+=1
pygame.display.flip()
def night_sky(screen):
pos = (random.randint(0, SIZE[0]), random.randint(0, SIZE[1]))
stars.append(Star(False, pos))
def exit_game():
pygame.quit()
main()