[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Pygame module crashing on run



On dim, 2014-02-16 at 23:57 -0800, Mole-chan wrote:
> However, when I test it, the game
> crashes after drawing the board, without producing an error.

I find it hard to believe it would crash with no output at all.

It's running fine on my machine, after moving the class to the top, and
replacing the reference to an image I don't have. So, without any
output, I couldn't tell you what's wrong on your end.

I attached the barely modified version, if you want to check it.
import pygame
#from defs import cursorSprite

class cursorSprite(pygame.sprite.Sprite):
    def __init__(self, image):
        pygame.sprite.Sprite.__init__(self)

        
        self.image = pygame.Surface((50,50))
        self.image.fill((255,0,0))
        #self.image.set_colorkey((255,255,255))

        self.rect = self.image.get_rect()

class Square(pygame.sprite.Sprite):
    def __init__(self, x, y):
        pygame.sprite.Sprite.__init__(self)

        
        self.image = pygame.Surface([60, 60])
        self.image.fill(pygame.Color(82,41,8))

        self.rect = self.image.get_rect()
        self.rect.y = y
        self.rect.x = x
        self.occupied = False
    def changeOccupied(_occupied):
        self.occupied = _occupied

class Piece(pygame.sprite.Sprite):
    def __init__(self, x, y, color):
        pygame.sprite.Sprite.__init__(self)

        
        if color == "black":
            self.image = pygame.image.load("black_piece.png").convert()
        else:
            self.image = pygame.image.load("white_piece.png").convert()
            
        self.image.set_colorkey(white)

        self.rect = self.image.get_rect()
        self.rect.y = y
        self.rect.x = x
    

pygame.init()

screen = pygame.display.set_mode([800, 600])
pygame.display.set_caption('Escape from Puzzlegate')
screen.fill(pygame.Color(0,0,0))
squareList = pygame.sprite.Group()
whitePieceList = pygame.sprite.Group()
blackPieceList = pygame.sprite.Group()
boardBG = pygame.Surface([600,600])
boardBG.fill(pygame.Color(242,162,97))

board =[
"oxoxoxoxox",
"xoxoxoxoxo",
"oxoxoxoxox",
"xoxoxoxoxo",
"oxoxoxoxox",
"xoxoxoxoxo",
"oxoxoxoxox",
"xoxoxoxoxo",
"oxoxoxoxox",
"xoxoxoxoxo",
]
x = 100
y = 0
for row in board:
    for col in row:
        if col == "x":
            square = Square(x, y)
            squareList.add(square)
        x += 60

    y += 60
    x = 100

cursor_img = "mouse.png"
cursor = cursorSprite(cursor_img)
cursorGroup = pygame.sprite.Group()
cursorGroup.add(cursor)

clock = pygame.time.Clock()
done = False

while not done:
    
    screen.blit(boardBG, (100,0))
    squareList.draw(screen)
    pos = pygame.mouse.get_pos()
    cursor.rect.x = pos[0]
    cursor.rect.y = pos[1]
    cursorGroup.draw(screen)  

    pygame.display.flip()

    

    clock.tick(40)
pygame.quit()


def switchTurn(_turn):
    if whosTurn == "enemy":
        whosTurn = "player"
    else:
        whosTurn = "enemy"
        return whosTurn


#The "cursorSprite" it imports refers to this class.

Attachment: signature.asc
Description: This is a digitally signed message part