Commit 2691eaf9 by BellCodeEditor

auto save

parent f3b99271
Showing with 46 additions and 0 deletions
002.png

26.4 KB

import sys
import pygame
pygame.init()
bg_color1=(0,120,120)
bg_color2=(60,60,60)
#主窗口
screen_image=pygame.display.set_mode((800,600))
screen_rect=screen_image.get_rect()
#标题栏
pygame.display.set_caption("飞机大战")
#飞机
ship=pygame.image.load("002.png")
ship_rect=ship.get_rect()
ship_rect.center=screen_rect.center
#子弹
bullet_rect=pygame.Rect(0,0,3,15)
bullet_rect.midbottom=ship_rect.midtop
#文字
txt_font=pygame.font.SysFont(None,48)
txt_image=txt_font.render("50",True,bg_color2,bg_color1)
txt_rect=txt_image.get_rect()
txt_rect.x=740
txt_rect.y=20
#死循环
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type==pygame.KEYDOWN:
if event.key==pygame.K_LEFT:
ship_rect.x-=10
if event.key==pygame.K_RIGHT:
ship_rect.x+=10
if event.key==pygame.K_UP:
ship_rect.y-=10
if event.key==pygame.K_DOWN:
ship_rect.y+=10
bullet_rect.y-=1
#绘制图像
screen_image.fill(bg_color1)
screen_image.blit(ship,ship_rect)
pygame.draw.rect(screen_image,bg_color2,bullet_rect)
screen_image.blit(txt_image,txt_rect)
pygame.display.flip()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment