- 帖子
- 6
- 精华
- 0
- 积分
- 34
- 阅读权限
- 10
- 注册时间
- 2019-11-27
- 最后登录
- 2019-12-20
|
先生教我,
问题:子弹太长了。。。。求教,原因出在哪里
[img][/img]
代码:
# -*- coding: utf-8 -*-
import pygame
#导入pygame库
from sys import exit
import time
#向sys模块借一个exit函数用来退出程序
pygame.init()
#初始化pygame,为使用硬件做准备
screen = pygame.display.set_mode((600, 419), 0, 32)
#创建了一个窗口,窗口大小和背景图片大小一样
pygame.display.set_caption("Hello, hahaha!")
#设置窗口标题
pic_a='pygame_pic.png'
pic_b='pygame_pic2.png'
pic_c='pygame_pic3.jpg'
pic_all=[pic_a,pic_b,pic_c]
pic_num=3
background = pygame.image.load(pic_all[pic_num%3]).convert()
plane = pygame.image.load('plane.png').convert_alpha()
bullet=pygame.image.load('bullet.png').convert_alpha()
x_bullet = 0
y_bullet = -1
while True:
#游戏主循环
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
if event.type == pygame.MOUSEBUTTONDOWN:
pic_num+=1
background = pygame.image.load(pic_all[pic_num%3]).convert()
width=background.get_width()
height=background.get_height()
screen = pygame.display.set_mode((width, height), 0, 32)
screen.blit(background, (0, 0))
x, y = pygame.mouse.get_pos()
# 获取鼠标位置
# 计算飞机的左上角位置
if y_bullet < 0:
x_bullet = int(x - bullet.get_width()/2)
y_bullet = int(y - bullet.get_height()/2)
else:
y_bullet -= 0.2
screen.blit(bullet, (x_bullet, y_bullet)) # 把子弹画到屏幕上
x -= int(plane.get_width() / 2)
y -= int(plane.get_height() / 2)
screen.blit(plane, (x, y)) # 将背景图画上去
#加载并转换图像
pygame.display.update()#刷新一下画面 |
|