背景和飞机同时向下移动
#coding:utf-8
import pygame,sys,easygui
from pygame.locals import *
#初始化pygame环境
pygame.init()
#创建一个长宽分别为480/650窗口
canvas = pygame.display.set_mode((480, 650))
canvas.fill((255,255,255))
#设置窗口标题
pygame.display.set_caption("飞机大战")
#加载图片
enemy=pygame.image.load("images/enemy1.png")
bg=pygame.image.load("images/bg1.png")
def handleEvent():
for event in pygame.event.get():
if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
pygame.quit()
sys.exit()
x = 100
y = 0
x1 = 0
y1 = 0
while True:
canvas.blit(bg, (x1, y1))
y1 += 1
canvas.blit(enemy, (x1, y1))
y1 += 2
#延时15毫秒
pygame.time.delay(15)
# 更新屏幕内容
pygame.display.update()
#监听有没有按下退出按钮
handleEvent()
两张背景向下移动
#coding:utf-8
import pygame,sys,easygui
from pygame.locals import *
#初始化pygame环境
pygame.init()
#创建一个长宽分别为480/650窗口
canvas = pygame.display.set_mode((480, 650))
canvas.fill((255,255,255))
#设置窗口标题
pygame.display.set_caption("飞机大战")
#加载图片
enemy=pygame.image.load("images/enemy1.png")
bg=pygame.image.load("images/bg1.png")
def handleEvent():
for event in pygame.event.get():
if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
pygame.quit()
sys.exit()
height = 852
x = 100
y = 0
x1 = 0
y1 = 0
x2 = 0
y2 = -height
while True:
canvas.blit(bg, (x1, y1))
y1 += 1
canvas.blit(bg, (x2, y2))
y2 += 1
canvas.blit(enemy, (x, y))
y += 2
#延时15毫秒
pygame.time.delay(15)
# 更新屏幕内容
pygame.display.update()
#监听有没有按下退出按钮
handleEvent()
背景连续移动
#coding:utf-8
import pygame,sys,easygui
from pygame.locals import *
#初始化pygame环境
pygame.init()
#创建一个长宽分别为480/650窗口
canvas = pygame.display.set_mode((480, 650))
canvas.fill((255,255,255))
#设置窗口标题
pygame.display.set_caption("飞机大战")
#加载图片
enemy=pygame.image.load("images/enemy1.png")
bg=pygame.image.load("images/bg1.png")
def handleEvent():
for event in pygame.event.get():
if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
pygame.quit()
sys.exit()
height = 852
x = 100
y = 0
x1 = 0
y1 = 0
x2 = 0
y2 = -height
while True:
canvas.blit(bg, (x1, y1))
y1 += 1
canvas.blit(bg, (x2, y2))
y2 += 1
canvas.blit(enemy, (x, y))
y += 2
if y1 > 852:
y1 = -height
if y2 > height:
y2 = -height
#延时15毫秒
pygame.time.delay(15)
# 更新屏幕内容
pygame.display.update()
#监听有没有按下退出按钮
handleEvent()
飞机循环飞行
#coding:utf-8
import pygame,sys,easygui
from pygame.locals import *
#初始化pygame环境
pygame.init()
#创建一个长宽分别为480/650窗口
canvas = pygame.display.set_mode((480, 650))
canvas.fill((255,255,255))
#设置窗口标题
pygame.display.set_caption("飞机大战")
#加载图片
enemy=pygame.image.load("images/enemy1.png")
bg=pygame.image.load("images/bg1.png")
def handleEvent():
for event in pygame.event.get():
if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
pygame.quit()
sys.exit()
height = 852
x = 100
y = 0
x1 = 0
y1 = 0
x2 = 0
y2 = -height
while True:
canvas.blit(bg, (x1, y1))
y1 += 1
canvas.blit(bg, (x2, y2))
y2 += 1
canvas.blit(enemy, (x, y))
y += 2
if y1 > height:
y1 = -height
if y2 > height:
y2 = -height
if y > 650:
y = 0
#延时15毫秒
pygame.time.delay(15)
# 更新屏幕内容
pygame.display.update()
#监听有没有按下退出按钮
handleEvent()
飞机超过y坐标300,向右移动
#coding:utf-8
import pygame,sys,easygui
from pygame.locals import *
#初始化pygame环境
pygame.init()
#创建一个长宽分别为480/650窗口
canvas = pygame.display.set_mode((480, 650))
canvas.fill((255,255,255))
#设置窗口标题
pygame.display.set_caption("飞机大战")
#加载图片
enemy=pygame.image.load("images/enemy1.png")
bg=pygame.image.load("images/bg1.png")
def handleEvent():
for event in pygame.event.get():
if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
pygame.quit()
sys.exit()
height = 852
x = 100
y = 0
x1 = 0
y1 = 0
x2 = 0
y2 = -height
while True:
canvas.blit(bg, (x1, y1))
y1 += 1
canvas.blit(bg, (x2, y2))
y2 += 1
canvas.blit(enemy, (x, y))
if y <= 300:
y += 2
if y1 > height:
y1 = -height
if y2 > height:
y2 = -height
if y > 300:
x += 1
#延时15毫秒
pygame.time.delay(15)
# 更新屏幕内容
pygame.display.update()
#监听有没有按下退出按钮
handleEvent()