Free friday assigment

Hello so i work on cyberpatriot

i got 23 points

what i did was there was some questions to answer you can see it down here .

another one

and i also try to make a game but i didn’t had time but i did some

from this video

i will do the rest tommrow

import pygame

# initializing the pygame engine
pygame.init()

# constants
WIDTH, HEIGHT = 800, 400
GROUND_HEIGHT = 100
FPS = 60

# colors
WHITE = (255, 255, 255)

# CREATE THE GAME WINDOW
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("subway surfers")

# Load the game assets (character and obstacles)
player_img = pygame.image.load('player.png')
obstacle_img = pygame.image.load('obstacle.png')

# Player variables
player_x = WIDTH // 2
player_y = HEIGHT - GROUND_HEIGHT - player_img.get_height()
player_speed = 5
player_jump = False
jump_height = 20

# obstacles variables
obstacle_x = WIDTH
obstacle_y = HEIGHT - GROUND_HEIGHT - obstacle_img.get_height()
obstacle_speed = 3

# score
score = 0

# game loop
running = True
clock = pygame.time.Clock()

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

        # handle player input
        keys = pygame.key.get_pressed()
        if keys[pygame.K_LEFT]:
            player_x -= player_speed
        if keys[pygame.K_RIGHT]:
            player_x += player_speed
        if keys[pygame.K_SPACE] and not player_jump:
            player_jump = True

        # player jumping and falling
        if player_jump:
            player_y -= jump_height
            jump_height -= 1
            if jump_height < -15:
                player_jump = False
                jump_height = 15
        else:
            if player_y < HEIGHT - GROUND_HEIGHT - player_img.get_height():
                player_y += jump_height
                jump_height += 1
            else:
                player_y = HEIGHT - GROUND_HEIGHT - player_img.get_height()
                jump_height = 15

# move the obstacle
obstacle_x -= obstacle_speed

# check for collision
player_rect = pygame.Rect(player_x, player_y, player_img.get_width(), player_img.get_height())
obstacle_rect = pygame.Rect(obstacle_x, obstacle_y, obstacle_img.get_width(), obstacle_img.get_height())

if player_rect.colliderect(obstacle_rect):
    running = False

# update the score
score += 1

# draw everthing
screen.fill(WHITE)
screen.blit(player_img, (player_x, player_y))
screen.blit(obstacle_img , (obstacle_x, obstacle_y))

# display score
font = pygame.font.Font(None, 36)
score_text = font.render(f"Score: {score}", True, (0,0,0))
screen.blit(score_text, (10,10))
pygame.display.flip()

# check if obstacle is off the screen

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top