设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: crossin先生
打印 上一主题 下一主题

【Pygame 第5课】 游戏中的运动

[复制链接]

0

主题

0

好友

26

积分

新手上路

Rank: 1

楼主
发表于 2016-12-7 21:38:51 |显示全部楼层
鼠标操控模式,但是这跟线太难看了……不知道有没方法弄得好看点

#-*-coding:utf-8-*-
import pygame
from sys import exit

pygame.init()
screen=pygame.display.set_mode((450,800),0,32)
pygame.display.set_caption("Plane")
background=pygame.image.load(r"C:\pythonexam\game\image\background.jpg").convert()
plane=pygame.image.load(r"C:\pythonexam\game\image\plane.png").convert_alpha()
bullet=pygame.image.load(r"C:\pythonexam\game\image\bullet.png").convert_alpha()

while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
            exit()
    screen.blit(background,(0,0))

    x,y=pygame.mouse.get_pos()
    x_plane=x-plane.get_width()/2
    y_plane=y-plane.get_height()/2
    y_value=y
    x_bullet=x-bullet.get_width()/2
    y_bullet=y-plane.get_height()/2
    screen.blit(plane,(x_plane,y_plane))
    if event.type==pygame.MOUSEBUTTONDOWN:
        for i in range(y_value):
            if y_bullet<0:
                y_bullet=y-bullet.get_width()/2
            if y_bullet>0:
                y_bullet-=1
            screen.blit(bullet,(x_bullet,y_bullet))
            pygame.display.update()
    pygame.display.update()





回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-5-4 19:27 , Processed in 0.016869 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部