Проблема с движением спрайтов в игре, похожей на PACMAN: может быть связана с обнаружением столкновений или нажатием клаPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Проблема с движением спрайтов в игре, похожей на PACMAN: может быть связана с обнаружением столкновений или нажатием кла

Сообщение Anonymous »

Я создаю pygame для проекта старшей школы, срок реализации которого составляет менее месяца, и использую специальное руководство для PACMAN и адаптирую его для создания своей собственной игры с аналогичной концепцией. Однако, поскольку я следую этому и немного меняю код в соответствии с моей игрой, мой персонаж «mouse.png» не двигается. Я не знаю, что привело к этому, является ли это частью определенной функции или неправильной логикой, и как я могу это исправить?
Вот руководство, которое я использую. следующее:
Следующий код — моя программа:

Код: Выделить всё

from board import board
import pygame
import math

pygame.init()

pygame.display.set_caption('The Big Cheese Heist')

WIDTH = 600
HEIGHT = 625

screen = pygame.display.set_mode([WIDTH, HEIGHT])
timer = pygame.time.Clock()
fps = 60
font = pygame.font.Font('freesansbold.ttf', 20)
level = boards
color = 'orange'
PI = math.pi

image = (pygame.transform.scale(pygame.image.load('mouse.png'), (60, 45)))

class MySprite(pygame.sprite.Sprite):
def __init__ (self, image):
super().__init__()
self.image = image
self.rect = self.image.get_rect()

my_sprite = MySprite(image)

print(my_sprite.rect.x, my_sprite.rect.y, my_sprite.rect.width, my_sprite.rect.height)

playerX = 150
playerY = 338
direction = 0
counter = 0
flicker = False
#L, R, D, U
turnsAllowed = [False, False, False, False]
directionCommand = 0
playerSpeed = 2

#drawing each tile type onto the board
def drawBoard():
num1 = ((HEIGHT - 50) // 32)
num2 = (WIDTH // 30)
for i in range (len(level)):
for j in range(len(level[i])):
if level [i][j] == 1:
pygame.draw.circle(screen, 'white', (j * num2 + (0.5 * num2), i * num1 + (0.5 * num1)), 4)
if level [i][j] == 2 and not flicker:
pygame.draw.circle(screen, 'white', (j * num2 + (0.5 * num2), i * num1 + (0.5 * num1)), 10)
if level [i][j] == 3:
pygame.draw.line(screen, color, (j * num2 + (0.5 * num2), i * num1),
(j * num2 + (0.5 * num2), i * num1 + num1), 3)
if level [i][j] == 4:
pygame.draw.line(screen, color, (j * num2, i * num1 + (0.5 * num1)),
(j * num2 + num2, i * num1 + (0.5 * num1)), 3)
if level [i][j] == 5:
pygame.draw.arc(screen, color, [(j * num2 - (num2 *0.4)) - 2, (i * num1 + (0.5 * num1)), num2, num1], 0, PI/2, 3)
if level [i][j] == 6:
pygame.draw.arc(screen, color, [(j * num2 + (num2 *0.5)), (i * num1 + (0.5 * num1)), num2, num1], PI/2, PI, 3)
if level [i][j] == 7:
pygame.draw.arc(screen, color, [(j * num2 + (num2 *0.5)), (i * num1 - (0.4 * num1)), num2, num1], PI, 3 *PI/2, 3)
if level [i][j] == 8:
pygame.draw.arc(screen, color, [(j * num2 - (num2 *0.4)) - 2, (i * num1 - (0.4 * num1)), num2, num1], 3 * PI/2, 2 * PI, 3)
if level [i][j] == 9:
pygame.draw.line(screen, 'white', (j * num2, i * num1 + (0.5 * num1)),
(j * num2 + num2, i * num1 + (0.5 * num1)), 3)

def drawPlayer():
#screen.blit(image,(0,0))
# 0 - RIGHT, 1 - LEFT, 2 - UP, 3 - DOWN
if direction == 0:
screen.blit(image, (playerX, playerY))
elif direction == 1:
screen.blit(pygame.transform.flip(image, True, False), (playerX, playerY))
elif direction == 2:
screen.blit(pygame.transform.rotate(image, (90)), (playerX, playerY))
elif direction == 3:
screen.blit(pygame.transform.rotate(image, (270)), (playerX, playerY))

def checkPosition(centerX, centerY):
turns = [False, False, False, False]
#checks if players center position is clear
num1 = (HEIGHT - 50 //32)
num2 = (WIDTH//30)
num3 = 15
# check collisions based on center x and center y of player +/0 fudge number
if centerX // 30 < 29:
#L, R, D, U !!!
#row, column
if direction == 1: #right
if level[centerY//num1][(centerX - num3)// num2] < 3: #empty square, small dot or big dot
turns[0] = True
if direction == 0: #left
if level[centerY//num1][(centerX + num3)// num2] < 3: #empty square, small dot or big dot
turns[1] = True
if direction == 3: #up
if level[(centerY+num3)//num1][centerX // num2] < 3: #empty square, small dot or big dot
turns[2] = True
if direction == 2: #down
if level[(centerY-num3)//num1][centerX// num2] <  3: #empty square, small dot or big dot
turns[3] = True

#L, R, D, U
# L = 0, R = 1, D = 2, U = 3
if direction == 2 or direction == 3:
if 12 

Подробнее здесь: [url]https://stackoverflow.com/questions/78509469/issue-with-sprite-movement-in-a-pacman-like-game-may-be-related-to-collision-de[/url]
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»