夜光带你走进python开发 (进阶二)游戏开发

夜光序言:

 

 

 

 

希望有那么一个人,在路灯下或转角口安静的等候,用满心的温柔暖化寂冷的夜,让自己不再畏惧孤单。

 

 

 

 

 

正文:

 

 

#  夜光:矩形可移动的/

import pygame,sys
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((600, 500))
pygame.display.set_caption("Genius:Drawing Rectangles")

pos_x = 200
pos_y = 210
vel_x = 3
vel_y = 2

while True:
    for event in pygame.event.get():
        if event.type in (QUIT, KEYDOWN):
            pygame.quit()
            sys.exit()

    screen.fill((0, 200, 200))

    # 移动矩形
    pos_x += vel_x
    pos_y += vel_y

    # Genius:使矩形保持在窗口内
    if pos_x > 500 or pos_x < 0:
        vel_x = -vel_x
    if pos_y > 400 or pos_y < 0:
        vel_y = -vel_y

        # Genius:绘制矩形
    color = 200, 255, 0
    width = 0  # solid fill
    pos = pos_x, pos_y, 100, 100
    pygame.draw.rect(screen, color, pos, width)

    pygame.display.update()

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值