[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Pygame module crashing on run
Hello,
Please forgive how lame this question probably sounds, as I'm clearly very
new compared to most of the programmers here.
I'm trying to program a simple checkers game. I've only just started and
only have the background right now. However, when I test it, the game
crashes after drawing the board, without producing an error. I'm using code
very similar to games I have made in the past, so I'm not sure why it's such
a problem.
I've included the code below.
import pygame
from defs import cursorSprite
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.
class cursorSprite(pygame.sprite.Sprite):
def __init__(self, image):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(image).convert()
self.image.set_colorkey((255,255,255))
self.rect = self.image.get_rect()
Any help would be greatly appreciated, since I'm pretty stumped.
--
View this message in context: http://pygame-users.25799.x6.nabble.com/Pygame-module-crashing-on-run-tp1076.html
Sent from the pygame-users mailing list archive at Nabble.com.