For mine

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import sys import random import pygame from dust import Dust def check_keydown_events(event, robot): if event.key == pygame.K_RIGHT: # move right robot.moving_right = True elif event.key == pygame.K_LEFT: # move left robot.moving_left = True def check_keyup_events(event, robot): if event.key == pygame.K_RIGHT: robot.moving_right = False elif event.key == pygame.K_LEFT: robot.moving_left = False def check_events(robot): # respond to keyboard and mouse item # supervise keyboard and mouse item for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: check_keydown_events(event, robot) elif event.type == pygame.KEYUP: check_keyup_events(event, robot) def update_screen(ai_settings, screen, dusts, robot,detector): # fill color 填充颜色 screen.fill(ai_settings.bg_color) # check robot and dust collisions check_robot_dust_collisions(robot, dusts) # draw the dusts dusts.draw(screen) # draw the robot robot.blitme() # draw the detector detector.blitme() # visualiaze the window pygame.display.flip() def create_dust(ai_settings, screen, dusts): """Create dust, and place it in the room.""" dust = Dust(ai_settings, screen) dust.rect.x = random.randint(50, ai_settings.screen_width - 50) dust.rect.y = random.randint(50, ai_settings.screen_height - 50) dusts.add(dust) def create_room(ai_settings, screen, dusts): """Create a full room of dusts.""" for mine_number in range(ai_settings.dust_number): create_dust(ai_settings, screen, dusts) def check_robot_dust_collisions(robot, dusts): """Respond to robot-dust collisions.""" # Remove any robot and dusts that have collided. pygame.sprite.spritecollide(robot, dusts, True, None)
最新发布
07-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值