• Предмет: Информатика
  • Автор: vladsid311010
  • Вопрос задан 3 месяца назад

Створи гру з декількома варіантами розвитку ігрового сюжету.

Створити гру використовуючи раніше отримані знання в таких темах як: 'змінні', 'умовні оператори', 'цикли'.має буди 70-130 строк поможіть плиз!!!! на пайтон

даю 40 балів

Ответы

Ответ дал: nullptr53
0

Ответ:

Анимация есть, а игрок должен уворачивается от призраков подпрыгивая

import pygame

import requests

from io import BytesIO

import time

pygame.init()

width, height = 640, 480

screen = pygame.display.set_mode((width, height))

clock = pygame.time.Clock()

player_x, player_y = 150, 250

player_speed = 10

is_jump = False

jump_count = 9

# Load walk animation

walk_right = [

pygame.image.load(BytesIO(requests.get('https://i.ibb.co/FKDQQYf/1670754087.png').content)).convert(),

pygame.image.load(BytesIO(requests.get("https://i.ibb.co/PCgTVGL/1670754094.png").content)).convert(),

pygame.image.load(BytesIO(requests.get("https://i.ibb.co/FKDQQYf/1670754087.png").content)).convert(),

pygame.image.load(BytesIO(requests.get('https://i.ibb.co/YRMq20J/1670754090.png').content)).convert()

]

grass = pygame.image.load(BytesIO(requests.get('https://opengameart.org/sites/default/files/grass_47.png').content)).convert()

ghost_list_in_game = []

ghost_timer = pygame.USEREVENT + 1

pygame.time.set_timer(ghost_timer, 3000)

ghost = pygame.image.load(BytesIO(requests.get('https://i.ibb.co/qsvY22x/imgonline-com-ua-Resize-f-Il-YYp-ACbf.png').content)).convert()

ghost.set_colorkey('black')

class Block(pygame.sprite.Sprite):#Класс Спрайта

def __init__(self):

pygame.sprite.Sprite.__init__(self)#Инициализация Sprite

self.image = pygame.Surface((50, 50))#Создаем спрайт 50 на 50

self.image = grass#Устанавливаем изображение

self.rect = self.image.get_rect()#Получаем поверхность спрайта

self.rect.center = (width / 2, height / 2)#Определяем центр спрайта

def update(self):

self.rect.x += 5 #Перемещаем спрайт вправо

if self.rect.left > width: #Если достигается граница

self.rect.right = 0#Возвращаем к началу

for image in walk_right:

image.set_colorkey((255, 255, 255)) # Set white color as transparent

Blocks = pygame.sprite.Group()

block = Block()

Blocks.add(block)

game_running = True

# Define button coordinates and sizes

button_x = 200

button_y = 600

button_width = 100

button_height = 50

# Define font

font = pygame.font.Font(None, 36)

while game_running:

screen.fill((255, 255, 255)) # Fill the screen with white

left_button = pygame.draw.rect(screen, (255, 0, 0), (button_x, button_y, button_width, button_height))

right_button = pygame.draw.rect(screen, (0, 0, 0), (button_x+200, button_y, button_width, button_height))

jump_button = pygame.draw.rect(screen, (0, 0, 0), (button_x+100, button_y-100, button_width, button_height))

for event in pygame.event.get():

if event.type == ghost_timer:

ghost_list_in_game.append(ghost.get_rect(topleft=(620, 250)))

if event.type == pygame.QUIT:

game_running = False

if event.type == pygame.MOUSEBUTTONDOWN:

if left_button.collidepoint(event.pos):

player_x -= player_speed

if right_button.collidepoint(event.pos):

player_x += player_speed

if jump_button.collidepoint(event.pos):

is_jump = True

if is_jump:

if jump_count >= -9:

if jump_count > 0:

player_y -= (jump_count ** 2) / 2

else:

player_y += (jump_count ** 2) / 2

jump_count -= 1

else:

is_jump = False

jump_count = 9

# Add walk animation for the player

player_anim_count = (pygame.time.get_ticks() // 100) % len(walk_right)

screen.blit(walk_right[player_anim_count], (player_x, player_y))

# Create a button with text

button_color = (255, 0, 0)

button_text = font.render("Назад", True, (255, 255, 255))

text_rect = button_text.get_rect(center=(button_x + button_width // 2, button_y + button_height // 2))

screen.blit(button_text, text_rect)

button_text = font.render("Вперед", True, (255, 255, 255))

text_rect = button_text.get_rect(center=(button_x+200 + button_width // 2, button_y + button_height // 2))

screen.blit(button_text, text_rect)

button_text = font.render("Прыжок", True, (85, 85, 255))

text_rect = button_text.get_rect(center=(button_x+100 + button_width // 2, button_y-100 + button_height // 2))

screen.blit(button_text, text_rect)

player_rect = walk_right[0].get_rect(topleft=(player_x-15, player_y))

#ghost_rect = ghost.get_rect(topleft=(ghost_x, 250))

if ghost_list_in_game:

for el in ghost_list_in_game:

screen.blit(ghost, el)

el.x -= 10

if player_rect.colliderect(el):

print("You lose!")

time.sleep(5)

ghost_list_in_game = []

Blocks.update()

Blocks.draw(screen)

#for o in objects:

# o.draw(screen)

screen.blit(grass, (100, 50))

pygame.display.update()

clock.tick(10) # Adjust animation speed as needed

pygame.quit()

Приложения:

vladsid311010: щоб тіпа всюди там де нева іf,else,while,elif іх підставити
nullptr53: на русском скажите в чем проблема
nullptr53: код рабочий
nullptr53: нужно только установить библиотеки requests
nullptr53: pygame
nullptr53: requests позволяет брать текстуры для игрв без интернета что позволяет избежать многих проблем
nullptr53: точнее из интернета
nullptr53: игра работает для андроид и для пк
nullptr53: я тестировал
vladsid311010: спс
Вас заинтересует