- 帖子
- 10
- 精华
- 0
- 积分
- 41
- 阅读权限
- 10
- 注册时间
- 2017-1-25
- 最后登录
- 2017-2-13
|
#先说下,我想先弄好多家敌机出来,下面是代码
# -*- coding: UTF-8 -*-
import pygame
from sys import exit
import random
class DJ:
def _init_(self):
self.x = 200
self.y = -50
self.image = pygame.image.load('dj.png').convert_alpha()
def move(self):
if self.y < 800:
self.y += 1#每帧移动两个像素
else:
self.y = -50
def restart(self):
self.x = random.randint(50, 400)
self.y = random.randint(-200, -50)
self.speed = random.random() + 1
pygame.init()
screen = pygame.display.set_mode((630,630),0,24)#创建窗口和你准备的图片大小一样
pygame.display.set_caption("雅玛碟")#设置标题用的
background = pygame.image.load('123.jpg').convert()#加载并转换图像
diji=DJ()
diji._init_()
djs=[]
for i in range(5):
djs.append(DJ())
while True:
screen.blit(background,(0,0))#将背景图片挂上去
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
for diji in djs:
diji._init_()
diji.move()
diji.restart()
screen.blit(diji.image,(diji.x,diji.y))#敌机的图片搞到屏幕上
pygame.display.update()
为啥敌机不出来呢?
|
|