pygame最小开发框架:

import pygame, sys

pygame.init()
screen = pygame.display.set_mode((600, 480))
pygame.display.set_caption("Pygame游戏之旅") while True:
for event in pygame.event.get():
if event == pygame.QUIT:
sys.exit()
pygame.display.update()

pygame壁球小游戏(不可控制版):

import pygame, sys

pygame.init()
size = width, height = 600, 400
speed = [1, 1]
BLACK = 0, 0, 0
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Pygame壁球")
ball = pygame.image.load("PYG02-ball.jpg")
ballrect = ball.get_rect()
fps = 300
fclock = pygame.time.Clock() while True:
for event in pygame.event.get():
if event == pygame.QUIT:
sys.exit()
ballrect = ballrect.move(speed[0], speed[1])
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1] screen.fill(BLACK)
screen.blit(ball, ballrect)
fclock.tick(fps)
pygame.display.update()

pygame壁球小游戏(键盘控制速度版):

import pygame, sys

pygame.init()
size = width, height = 600, 400
speed = [1, 1]
BLACK = 0, 0, 0
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Pygame壁球")
ball = pygame.image.load("PYG02-ball.jpg")
ballrect = ball.get_rect()
fps = 100
fclock = pygame.time.Clock() while True:
for event in pygame.event.get():
if event == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
speed[0] -= 1
elif event.key == pygame.K_RIGHT:
speed[0] += 1
elif event.key == pygame.K_DOWN:
speed[1] += 1
elif event.key == pygame.K_UP:
speed[1] -= 1 ballrect = ballrect.move(speed[0], speed[1])
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1] screen.fill(BLACK)
screen.blit(ball, ballrect)
fclock.tick(fps)
pygame.display.update()

游戏屏幕的设置:

pygame.display.set_mode(r = (0, 0), flags = 0)
r是游戏屏幕的分辨率,采用(width, height)方式输入
flags用来控制显示类型,可用|组合使用,常用显示标签如下:
pygame.RESIZABLE 窗口大小可调
pygame.NOFRAME 窗口没有边界显示
pygame.FULLSCREEN 窗口全屏显示

pygame壁球游戏(可调整窗口大小版):

import pygame, sys

pygame.init()
vInfo = pygame.display.Info()
size = width, height = 600, 400
speed = [1, 1]
BLACK = 0, 0, 0
screen = pygame.display.set_mode(size, pygame.RESIZABLE)
pygame.display.set_caption("Pygame壁球")
ball = pygame.image.load("PYG02-ball.jpg")
ballrect = ball.get_rect()
fps = 100
fclock = pygame.time.Clock() while True:
for event in pygame.event.get():
if event == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
speed[0] -= 1
elif event.key == pygame.K_RIGHT:
speed[0] += 1
elif event.key == pygame.K_DOWN:
speed[1] += 1
elif event.key == pygame.K_UP:
speed[1] -= 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)
ballrect = ballrect.move(speed[0], speed[1])
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1] screen.fill(BLACK)
screen.blit(ball, ballrect)
fclock.tick(fps)
pygame.display.update()

pygame壁纸游戏(全屏版):

import pygame, sys

pygame.init()
vInfo = pygame.display.Info()
size = width, height = vInfo.current_w, vInfo.current_h
speed = [1, 1]
BLACK = 0, 0, 0
screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
pygame.display.set_caption("Pygame壁球")
ball = pygame.image.load("PYG02-ball.jpg")
ballrect = ball.get_rect()
fps = 100
fclock = pygame.time.Clock() while True:
for event in pygame.event.get():
if event == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
speed[0] -= 1
elif event.key == pygame.K_RIGHT:
speed[0] += 1
elif event.key == pygame.K_DOWN:
speed[1] += 1
elif event.key == pygame.K_UP:
speed[1] -= 1
elif event.key == pygame.K_ESCAPE:
sys.exit()
ballrect = ballrect.move(speed[0], speed[1])
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1] screen.fill(BLACK)
screen.blit(ball, ballrect)
fclock.tick(fps)
pygame.display.update()

pygame壁球游戏(最小化可暂停版):

import pygame, sys

pygame.init()
vInfo = pygame.display.Info()
size = width, height = 600, 400
speed = [1, 1]
BLACK = 0, 0, 0
screen = pygame.display.set_mode(size, pygame.RESIZABLE)
pygame.display.set_caption("Pygame壁球")
ball = pygame.image.load("PYG02-ball.jpg")
ballrect = ball.get_rect()
fps = 100
fclock = pygame.time.Clock() while True:
for event in pygame.event.get():
if event == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
speed[0] -= 1
elif event.key == pygame.K_RIGHT:
speed[0] += 1
elif event.key == pygame.K_DOWN:
speed[1] += 1
elif event.key == pygame.K_UP:
speed[1] -= 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)
if pygame.display.get_active():
ballrect = ballrect.move(speed[0], speed[1])
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1] screen.fill(BLACK)
screen.blit(ball, ballrect)
fclock.tick(fps)
pygame.display.update()

pygame学习的第一天的更多相关文章

  1. pygame学习笔记(3)——时间、事件、文字

    转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 1.运动速率    上节中,实现了一辆汽车在马路上由下到上行驶,并使用了pygame.time.delay(200 ...

  2. RabbitMQ学习总结 第一篇:理论篇

    目录 RabbitMQ学习总结 第一篇:理论篇 RabbitMQ学习总结 第二篇:快速入门HelloWorld RabbitMQ学习总结 第三篇:工作队列Work Queue RabbitMQ学习总结 ...

  3. 学习KnockOut第一篇之Hello World

    学习KnockOut第一篇之Hello World 笔者刚开始学习KnockOut.写的内容就相当于一个学习笔记.且在此处向官网致敬,比较喜欢他们家的Live Example版块,里面有jsFiddl ...

  4. ActionBarSherlock学习笔记 第一篇——部署

    ActionBarSherlock学习笔记 第一篇--部署          ActionBarSherlock是JakeWharton编写的一个开源框架,使用这个框架,可以实现在所有的Android ...

  5. Java学习记录第一章

    学习Java第一章的记录,这一章主要记录的是Java的最基础部分的了解知识,了解Java的特性和开发环境还有Java语言的优缺点. 计算机语言的发展大概过程:机器语言--->汇编语言---> ...

  6. oracle学习笔记第一天

    oracle学习笔记第一天 --oracle学习的第一天 --一.几个基础的关键字   1.select select (挑选) 挑选出显示的--列--(可以多列,用“,”隔开,*表示所有列),为一条 ...

  7. javascript的ES6学习总结(第一部分)

    ES6(ESNext学习总结——第一部分) ES6, 全称 ECMAScript 6.0 ,是 JavaScript 的下一个版本标准,2015.06 发版. ECMA每年6月份,发布一个版本 201 ...

  8. Web基础学习---HTML 第一天

    Web基础学习---HTML 第一天 1 HTML标签 2.CSS Web开发基础HTML好吧离开Python几天...如何学好前端?? 多去看别人的网站.多看.多写.多练,(知乎.36Kr.)多练就 ...

  9. QT学习之第一个程序

    QT学习之第一个程序 目录 手动创建主窗口 居中显示 添加窗口图标 显示提示文本 Message Box的应用 手动连接信号与槽 手动创建主窗口 窗口类型 QMainWindow: 可以包含菜单栏.工 ...

随机推荐

  1. centos7一步一步搭建docker tomcat 及重点讲解

    系统环境:centos7.7 (VMware中) image版本:tomcat:8-jdk8-openjdk (截止2020.01.10该系列版本) 安装步骤参考文章:https://www.jian ...

  2. Ubuntu 18 设置静态 IP

    在Ubuntu 18中使用 netplan 命令 首先 cd /etc/netplan/ 找到 *.yaml文件(每个人可能不一样),编辑它 root@waydeserver:/etc/netplan ...

  3. python学习HTML之CSS

    1.sytle属性设置 . <head> <meta charset="UTF-8"> <title>Title</title> & ...

  4. C:数值溢出问题

    当超过一个数据类型能够存放最大的范围时,数值会溢出. 有符号位最高位溢出的区别:符号位溢出会导致数的正负发生改变,但最高位的溢出会导致最高位丢失. #include <stdio.h> i ...

  5. springboot2.x整合redis

    pom文件 <!--springboot中的redis依赖--> <dependency> <groupId>org.springframework.boot< ...

  6. 高级T-SQL进阶系列 (一)【下篇】:使用 CROSS JOIN 介绍高级T-SQL

    [译注:此文为翻译,由于本人水平所限,疏漏在所难免,欢迎探讨指正] 原文链接:传送门. 性能考虑产生了笛卡尔积的这个CROSS JOIN操作符具有一些性能方面的问题需要考虑.因为SQL引擎需要将一个数 ...

  7. jemter-plugins-maven dependency -WIiki用法配置介绍

    1.先介绍下jmeter 的maven中央仓库地址,有兴趣自己看下 https://mvnrepository.com/artifact/org.apache.jmeter 2.Wiki github ...

  8. 国外电商网站snapdeal爬取流程

    首页爬取 1.首页获取各个目录的url 如所有优惠all_offers的其中urlhttps://www.snapdeal.com/products/men-apparel-shirts?sort=p ...

  9. Git - reset和checkout的区别

    参考 https://segmentfault.com/a/1190000006185954 1. Git的所有操作实际上是在操作这三个区域的状态(或内容) 2. 区别 checkout是会修改HEA ...

  10. pikachu-字符型注入(get) #手工注入

    1.检测注入类型 http://127.0.0.1/pikachu-master/vul/sqli/sqli_str.php?name=1&submit=%E6%9F%A5%E8%AF%A2 ...