这几天闲着无聊,想着自己编个小游戏来玩玩,看网上的大牛可是1,2天就可以搞一个出来,小弟不才,估计的要一个星期,废话不多说,先贴上我的代码和截图。
下面是截图:
[img]http://dl.iteye.com/upload/attachment/200457/2f0a3586-fd2e-39e4-9e3f-be73c987f7e5.jpg[/img]
[/img]
如果想要知道更详细的内容,请自行查看附件的文档吧。
原来做2D游戏也可以这么好玩,争取这几周弄一个出来玩一玩。
import pygame
from pygame.locals import *
from random import *
SIZE = (width,height) = (640,480)
#初始化系统,一切交给pygame来完成
pygame.init()
#建立一个窗口
screen = pygame.display.set_mode(SIZE)
#设置标题
pygame.display.set_caption('This is test')
points = []
while True:
# 等待事件
for event in pygame.event.get():
if event.type == QUIT:
exit(0)
if event.type == MOUSEBUTTONDOWN:
points.append(event.pos)
random_color = (randint(0,255),randint(0,255),randint(0,255))
if len(points) >= 3:
#在窗口里画多边形,第一个参数一定要是SURFACE对象哟
pygame.draw.polygon(screen,random_color,points)
for p in points:
#画个圆
pygame.draw.circle(screen,random_color,p,5)
#这句一定不要忘记了,否则你什么也看不到
pygame.display.flip()
下面是截图:
[img]http://dl.iteye.com/upload/attachment/200457/2f0a3586-fd2e-39e4-9e3f-be73c987f7e5.jpg[/img]
[/img]
如果想要知道更详细的内容,请自行查看附件的文档吧。
原来做2D游戏也可以这么好玩,争取这几周弄一个出来玩一玩。