Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions game/intro.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import random

import pgzrun
import pygame

from pgzero.actor import Actor
from pgzero.animation import animate, decelerate
from pgzero.animation import animate
from pgzero.clock import clock
from pgzero.loaders import sounds, images
from pgzero.loaders import sounds
from pgzero.rect import Rect

from game.star import Star

JUMP_HIGHT = 80

WIDTH = 1280 # ось X
Expand All @@ -26,12 +27,10 @@
DARK_RED_COLOUR = 139, 0, 0
ground = Rect((0, HEIGHT - 100), (WIDTH, 100))


stars = []
for i in range(30):
stars.append(
Actor('star', topleft=(random.randint(0, 200) * i, random.randint(0, 400)))
)
stars.append(Star('star.png', (random.randint(0, 200) * i, random.randint(0, 400))))

clouds = []
for i in range(40):
clouds.append(
Expand All @@ -45,7 +44,6 @@
)



def draw():
screen.clear()
sky_color = (sky_color_red, sky_color_green, sky_color_blue)
Expand All @@ -54,7 +52,8 @@ def draw():
screen.draw.rect(ground, DARK_RED_COLOUR)

for star in stars:
star.draw()
screen.blit(star.image, star.position)

for cloud in clouds:
cloud.draw()

Expand Down Expand Up @@ -90,8 +89,7 @@ def update():
cloud.x -= 2

for star in stars:
star.angle += 1

star.change_transparency(from_dark_to_light)

# player
step = 3
Expand Down Expand Up @@ -127,8 +125,6 @@ def jump():

def set_alien_hurt():
player.image = 'player_red'
# circle.angle += 180
# circle.y -= 20
sounds.eep.play()
clock.schedule_unique(set_alien_normal, 0.2)

Expand Down
26 changes: 26 additions & 0 deletions game/star.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import Tuple

import pygame
from pygame.surface import Surface


class Star:
image: Surface
position: Tuple[int, int]
transparent_step = 2
angle = 0

def __init__(self, image, position):
self.image = pygame.image.load(f"images/{image}").convert_alpha()
self.position = position

def change_transparency(self, is_fading):
step = -self.transparent_step if is_fading else self.transparent_step
self.image.set_alpha(self.image.get_alpha() + step)

def rotate(self, angle):
self.angle += angle
self.image = pygame.transform.rotate(self.image, self.angle % 360)

# self.position = self.image.get_rect(self.position).center
# print(f"pos= {self.position}")