xsncriw
im pygame
import sys
from pygame.locals import *
pygame.init()
size = width,hight = 600,400
speed = [-2,1]
by = (255,255,255)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("移動皮卡丘")
#這個將路徑,改為自己想要的物體的路徑
pp = pygame.image.load("e:\python\python練習\imgs\pp.jpg")
position = pp.get_rect(xsncriw)
l_head = pp
r_head = pygame.transform.flip(pp,true,false)
while true:
for event in pygame.event.get():
if event.type == pygame.quit:
sys.exit()
if event.type == keydown:
if event.key == k_left:
speed = [-1,0]
if event.key == k_right:
speed = [1,0]
if event.key == k_up:
speed = [0,-1]
if event.key == k_down:
speed = [0,1]
position = position.move(speed)
if position.left < 0 or position.right > width:
pp = pygame.transform.flip(pp,true,false)
speed[0] = -speed[0]
if position.top < 0 or position.bottom > hight :
speed[1] = -speed[1]
screen.fill(by)
screen.blit(pp,position)
pygame.displa程式設計客棧y.flip()
pygame.time.delay(10)
本文標題: pythonpygame實現控制物體移動
本文位址: /jiaoben/python/450027.html
python pygame實現簡單的網遊
此示例為簡單的實現遊戲伺服器端和客戶端的訊息同步,使用自定定義協議,引入了twisted網路框架,還有諸多不足 其實就是半成品 截圖 伺服器端 coding utf8 game server import threading from random import randint as rint im...
Python pygame如何安裝?
linux 下安裝 python2 下執行 sudo pip2 install pygame驗證是否安裝成功 python2 m pygame.examples.alienspython3 下執行 sudo pip3 install pygame驗證是否安裝成功 python3 m pygame.e...
python pygame 事件學習
coding utf 8 import pygame import sys from pygame.locals import 初始化pygame pygame.init size width,height 600,400 speed 2,1 bg 255,255,255 rgb 建立指定大小的視窗...