Задать вопрос
@UuuuuuuuuuuuuuuuNiX

Не работает код pigame?

Не работает функция jump и выстрел(arrow)

import pygame 
import random
import sqlite3

time = pygame.time.Clock()

# Запуск pygame для означение начала работы с кодом
pygame.init()

#pth = 'data/data/com.example.myapp.MineRunner/files/app'

screen = pygame.display.set_mode((626, 376)) # установка периметра окна
pygame.display.set_caption('MineRunner') 
icon = pygame.image.load('img/icon.png')# подгрузка иконки для иконки игры
pygame.display.set_icon(icon) # установка подгруженной иконки
ghost = pygame.image.load('img/ghost.png')
bg_sound = pygame.mixer.Sound('sounds/sounds.mp3')
s_jump = pygame.mixer.Sound('sounds/jump.mp3')
go = pygame.mixer.Sound('sounds/go.mp3')
mm_bg = pygame.image.load('img/mm.png')
point = pygame.image.load('img/point.png')
arrow = pygame.image.load('img/arrow.png')
bg = pygame.image.load('img/1.png') #подгрузка заднего фона
gameover = pygame.mixer.Sound('sounds/gameover.mp3')
s_coin =  pygame.mixer.Sound('sounds/coin.mp3')
m_bg_S =  pygame.mixer.Sound('sounds/bg.mp3')

mob_list = [

]

# w - право
wolk_w = [
    pygame.image.load('img/player/w1.png'),
    pygame.image.load('img/player/w2.png'),
    pygame.image.load('img/player/w3.png'),
    pygame.image.load('img/player/w4.png')
]
# r - лево

wolk_r = [
    pygame.image.load('img/player/r1.png'),
    pygame.image.load('img/player/r2.png'),
    pygame.image.load('img/player/r3.png'),
    pygame.image.load('img/player/r4.png')
]

ghost_skin = []
point_c = [
]

arrow_list = [
]

st = [25000, 21500, 22500, 23500, 24500, 25500, 26500,
27500, 28500, 29500, 35000]
rst = random.choice(st)

player = wolk_r[0] 

player_anim = 0

bg_x = 0
mm_bg_x = 0
ghost_timer = pygame.USEREVENT + 1
pygame.time.set_timer(ghost_timer, 6500)

point_timer = pygame.USEREVENT + 0
pygame.time.set_timer(point_timer, rst)

gameplay = False

player_speed = 4
player_x = 100
player_y = 250
jump = False
jump_count = 7

#arrow_x = player_x += 5

label = pygame.font.Font('fonts/font2.ttf', 45)
lose_label = label.render('Вы проиграли!', True, (193, 196, 199))
restart_label = label.render('Играть сново', True, (115, 132, 148))
restart_label_rec = restart_label.get_rect(topleft=(180, 200))

start = pygame.font.Font('fonts/font2.ttf', 45)
menu_start = start.render('Game Menu', True, (245, 21, 5))
start_start = start.render('Start', True, (245, 21, 5))
quit_start = start.render('Покинуть игру', True, (115, 132, 148))
start_start_rec = start_start.get_rect(topleft=(250, 150))
q_quit_start = quit_start.get_rect(topleft=(150, 50))

Bullets_left = 5

your_point = 0

# цикл для работы с экраном
running = True

gamestart = True
while running:
    screen.blit(bg, (bg_x, 0))
    screen.blit(bg, (bg_x +5, 0))

    if gameplay:
        m_bg_S.stop()
        player_rect = player.get_rect(topleft=(player_x, player_y))
        if point_c:
            for (i, el) in enumerate(point_c):
                screen.blit(point, el)
                el.x -= 5
     
                if player_rect.colliderect(el):
                    point_c.pop(i)
                    s_coin.play()
                    your_point += 1
                if el.x < -10:
                    point_c.pop(i)

        if mob_list:
            for (i, el) in enumerate(mob_list):
                screen.blit(ghost, el)
                el.x -= 10
     
                if player_rect.colliderect(el):
                    gameplay = False
                    gameover.play()
                if el.x < -10:
                    mob_list.pop(i)

        
        keys = pygame.key.get_pressed()

        if keys[pygame.K_a]:
            screen.blit(wolk_w[player_anim], (player_x, player_y))
            go.play()
        else:
            screen.blit(wolk_r[player_anim], (player_x, player_y)) 

        if keys[pygame.K_a] and player_x > 50:
            player_x -= player_speed
        elif keys[pygame.K_d] and player_x < 350:
            player_x += player_speed
            go.play()  

    
    if point_c:
        for (i, el) in enumerate(point_c):
            screen.blit(point, el)
            el.x -= 5
    
            if player_rect.colliderect(el):
                point_c.pop(i)
                s_coin.play()
                your_point += 1
            if el.x < -10:
                point_c.pop(i)
    
            if player_rect.colliderect(el):
                point_c.pop(i)
                s_coin.play()
                your_point += 1
    
        if not jump:
            if keys[pygame.K_s]:
                jump = True
                s_jump.play()
        else:
            if jump_count >= -7:
                neg = 1
                if jump_count < 0:
                    neg = -1
                player_y -= (jump_count ** 2) / 1.5 * neg
                neg -= 1
                jump_count -= 1
            else:
                jump = False
                jump_count = 7
    
        if player_anim == 3:
            player_anim = 0
        else:
            player_anim += 1
    
        bg_x -= 2
        if bg_x == -626:
            bg_x = 0 

        
        if arrow_list:
            for (i, element) in enumerate(arrow_list):
                screen.blit(arrow, (element.x, element.y))
                element.x += 4

                if element.x > 626:
                    arrow_list.pop(i)

                if mob_list:
                    for (index, ghostr) in enumerate(mob_list):
                        if element.colliderect(ghostr):
                            mob_list.pop(index)
                            arrow_list.pop(i)

    if gameplay == False:
        screen.fill((87, 88, 89))
        screen.blit(lose_label, (188, 100))
        screen.blit(restart_label, restart_label_rec)

        mouse = pygame.mouse.get_pos()
        if restart_label_rec.collidepoint(mouse) and pygame.mouse.get_pressed()[0]:
            gameplay = True
            player_x = 150
            mob_list.clear()
            point_c.clear()
            arrow_list.clear()
            Bullets_left = 5

    if gamestart:
        screen.fill((87, 88, 89))
        pygame.draw.rect(screen, (130, 125, 111), (250, 150, 100, 50))
        screen.blit(menu_start, (200, 50))
        screen.blit(start_start, start_start_rec)
        m_bg_S.play()

        mouse_pos = pygame.mouse.get_pos()
        if start_start_rec.collidepoint(mouse_pos) and pygame.mouse.get_pressed()[0]:
            gameplay = True
            mob_list.clear()
            player_x = 150
            gamestart = False
            point_c.clear()
            arrow_list.clear()     




    pygame.display.update()
        
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            pygame.quit()
        if event.type == ghost_timer:
            mob_list.append(ghost.get_rect(topleft=(620, 250)))
        if event.type == point_timer:
            point_c.append(ghost.get_rect(topleft=(620, 250)))
        if gameplay and event.type == pygame.KEYUP and event.key == pygame.K_w and Bullets_left > 0:
            arrow_list.append(arrow.get_rect(topleft=(player_x + 30, player_y + 10)))
            Bullets_left -= 1



    time.tick(10)
  • Вопрос задан
  • 52 просмотра
Подписаться 1 Простой 1 комментарий
Пригласить эксперта
Ответы на вопрос 1
phaggi
@phaggi
лужу, паяю, ЭВМы починяю
Не работает код pigame?
Нет, не работает.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы