python 键盘输入立刻反应

编程入门 行业动态 更新时间:2024-10-27 14:26:00

python <a href=https://www.elefans.com/category/jswz/34/1761706.html style=键盘输入立刻反应"/>

python 键盘输入立刻反应

跟着那个12岁的少年学pygame的时候,遇到点问题,原文地址:青少年如何使用Python开发游戏

做完第三步之后,怎么按键盘都反应,也没有报错,win32,pygame1.9.1,python2.7

#1 - Import library

import pygame

from pygame.locals import *

#2 - Initialize the game

pygame.init()

width, height = 640, 480

screen = pygame.display.set_mode((width, height))

keys = [False, False, False, False]

playerpos = [100, 100]

#3 - Load images

player = pygame.image.load('resources/images/dude.png')

grass = pygame.image.load('resources/images/grass.png')

castle = pygame.image.load('resources/images/castle.png')

#4 - keep looping through

while 1:

#5 - clear the screen before drawing it again

screen.fill(0)

#6 - draw the screen elements

for x in range(width/grass.get_width()+1):

for y in range(height/gra

更多推荐

python 键盘输入立刻反应

本文发布于:2024-02-17 04:16:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1692596.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:键盘输入   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!