猫史档案馆


********

********

Lv.1

MC玩家,Python6b。

获赞:12收藏:2浏览:57作品收藏:0

签名:描述一下你正在沙雕

回复帖子评论
上一页1 页 / 共 1下一页

【社区星推荐】第六期·小企鹅飞 中回复

你的图像是Scratch里的对吧,因为我也是大佬,只是因为我没素材才没有名气,有素材的给我说。

2020-04-13T15:20:32 点赞:0

【社区星推荐】第六期·小企鹅飞 中回复

# Unit PYG04: Pygame Wall Ball Game version 8  鼠标型
import pygame
import sys

pygame.init()
size = width, height = 600, 400
speed = [1, 1]
BLACK = 0, 0, 0
screen = pygame.display.set_mode(size, pygame.RESIZABLE)  # 窗口大小可调

icon = pygame.image.load("PYG03-flower.png")
pygame.display.set_icon(icon)
pygame.display.set_caption("Pygame壁球")
ball = pygame.image.load("PYG02-ball.gif")
ballrect = ball.get_rect()
fps = 300
fclock = pygame.time.Clock()
still = False

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:
                speed[0] = speed[0] if speed[0] == 0 else (
                    abs(speed[0]) - 1)*int(speed[0]/abs(speed[0]))
            elif event.key == pygame.K_RIGHT:
                speed[0] = speed[0] + 1 if speed[0] > 0 else speed[0] - 1
            elif event.key == pygame.K_UP:
                speed[1] = speed[1] + 1 if speed[1] > 0 else speed[1] - 1
            elif event.key == pygame.K_DOWN:
                speed[1] = speed[1] if speed[1] == 0 else (
                    abs(speed[1]) - 1)*int(speed[1]/abs(speed[1]))
            elif event.key == pygame.K_ESCAPE:
                sys.exit()
        elif event.type == pygame.VIDEORESIZE:
            size = width, height = event.size[0], event.size[1]
            screen = pygame.display.set_mode(size, pygame.RESIZABLE)
        elif event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:
                still = True
        elif event.type == pygame.MOUSEBUTTONUP:
            still = False
            if event.button == 1:
                ballrect = ballrect.move(event.pos[0] - ballrect.left, event.pos[1] - ballrect.top)
        elif event.type == pygame.MOUSEMOTION:
            if event.buttons[0] == 1:
                ballrect = ballrect.move(event.pos[0] - ballrect.left, event.pos[1] - ballrect.top)
    if pygame.display.get_active() and not still:
        ballrect = ballrect.move(speed)
    if ballrect.left < 0 or ballrect.right > width:
        speed[0] = - speed[0]
        if ballrect.right > width and ballrect.right + speed[0] > ballrect.right:
            speed[0] = - speed[0]
    if ballrect.top < 0 or ballrect.bottom > height:
        speed[1] = - speed[1]
        if ballrect.right > height and ballrect.bottom + speed[1] > ballrect.right:
            speed[1] = - speed[1]

    screen.fill(BLACK)
    screen.blit(ball, ballrect)
    pygame.display.update()
    fclock.tick(fps)

请先下载pygame,sys再运行。

2020-04-13T15:47:43 点赞:0

【Wood源码图鉴】助力python学习! 中回复

两年前的贴,来挖坟。

2020-04-13T19:48:50 点赞:0

【Wood源码图鉴】助力python学习! 中回复

小短腿编程猫

 

2020-04-13T19:52:09 点赞:0

【有奖活动】一起来用方言来为Kitten打CALL!! 中回复

泽各铁字拐郝砍!

2020-05-19T11:41:45 点赞:0