【发布时间】:2014-12-02 05:31:57
【问题描述】:
我对 pygame 很陌生。我设法创建了一个绘制矩形的类。
我将使用这个类来制作多个形状,并尝试在单击时移动一个形状。但在我创建更多形状之前,我必须确保我可以移动它。 但我连移动一个形状都没有成功。
Example.py
import pygame, sys
from pygame.locals import *
# Global variables
whiteColor = (255, 255, 255)
darkColor = (51, 51, 51)
lightColor = (83, 83, 83)
blackColor = (0, 0, 0)
# Classes
class obj_disk(object):
def __init__(self):
self.rect = pygame.draw.rect(screen, blackColor, (0,0,234,32))
# Methods
def game_settings():
"""
Manage all the main settings for the game.
@Global screen: The main window
"""
global screen
pygame.init()
pygame.display.set_caption("Towers of Hanoi")
pygame.time.Clock().tick(60)
pygame.time.wait(10)
screen = pygame.display.set_mode([800,600])
screen.fill(darkColor)
create_objects()
pygame.display.update()
def create_objects():
"""
Creates all the objects that are required to play the game.
"""
# Create disks
disk_array = []
for i in range(0,1):
disk_array.append(obj_disk())
disk_array[0].rect.move(40,50)
def game_start():
"""
Starts the game and handles all the events.
"""
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if __name__ == '__main__':
game_settings()
game_start()
【问题讨论】:
-
有什么问题?什么都没发生?崩溃?
-
形状不动。没有崩溃。