当前位置: 首页 > news >正文

用Python Pygame做的一些好玩的小游戏

有些游戏的代码比较长就不公布了

1.简简单单

1.疯狂的鸡哥

 你要准备的图片:

命名为:ji.png 

 代码:

import pygame
import random as r
pygame.init()
pygame.display.set_caption('aaa')
pm = pygame.display.set_mode((800,600))class Ls(pygame.sprite.Sprite):def __init__(self,pos):#pos 鼠标点击的位置super().__init__()self.image = pygame.image.load('ji.png')self.dx = r.randint(20,50)self.dx2 = r.randint(20, 50)self.image = pygame.transform.scale(self.image,(self.dx,self.dx2))self.rect = self.image.get_rect()self.rect.top = pos[0]self.rect.left =pos[1]self.vx = r.randint(-3,11)self.vy = r.randint(-2,12)# update方法def update(self):self.rect.left += self.vxself.rect.top += self.vyif self.rect.left <= 0 or self.rect.left >= 750:self.vx = -self.vxself.image = pygame.transform.scale(self.image,(self.dx,self.dx2))if self.rect.top <= 0 or self.rect.top >= 550:self.vy = -self.vy
group = pygame.sprite.Group()
while True:pm.fill((120,205,255))zt = pygame.mouse.get_pressed()zy = pygame.font.Font('叶根友刀锋黑草.ttf',50).render('左键增加滚轮碰到哪个哪个删除 ',True,(0,0,0))pm.blit(zy,(0,0))if zt[0]:group.add(Ls([100,200]))if zt[1]:wz = pygame.mouse.get_pos()for i in group:if i.rect.collidepoint(wz):     #给定点是否在给定矩形范围中,前面的是给定矩形,括号中的是点.i.kill()group.draw(pm)group.update()for event in pygame.event.get():if event.type == pygame.QUIT:exit()pygame.display.update()pygame.time.Clock().tick(20)

 2.智慧的随机分数系统

 

while True:import pygamepygame.init()pygame.display.set_caption('aaa')screen = pygame.display.set_mode((800,600))jts = pygame.image.load('照片\jts.png')jtx = pygame.image.load('照片\jtx.png')qd = pygame.image.load('照片\qd.png')a = 100mm = 1while mm == 1:screen.fill((255,255,255))ju = pygame.font.Font('字体\叶根友刀锋黑草.ttf', 100)s = ju.render(str(a), True, (1, 2, 200))ju2 = pygame.font.Font('字体\叶根友刀锋黑草.ttf', 100)s2 = ju2.render('满分:', True, (1, 2, 200))for event in pygame.event.get():if event.type == pygame.QUIT:exit()screen.blit(s,(300,300))screen.blit(qd, (620, 10))screen.blit(s2,(100,100))screen.blit(jts,(500,200))screen.blit(jtx,(500,400))x, y = pygame.mouse.get_pos()for i in range(111):for ii in range(101):if x == 500+i and y == 200 + ii and pygame.mouse.get_pressed()[0] == True:a = a+1for i in range(97):for ii in range(117):if x == 500+i and y == 400 + ii and pygame.mouse.get_pressed()[0] == True:a = a-1for i in range(154):for ii in range(79):if x == 620+i and y == 10 + ii and pygame.mouse.get_pressed()[0] == True:mm = 1333pygame.display.update()pygame.time.Clock().tick(20)import pygameimport random as rpygame.init()pygame.display.set_caption('aaa')screen = pygame.display.set_mode((800,600))qd = pygame.image.load('照片\qd.png')b = str(r.randint(0,a)) + '分'mm = 1while mm == 1:screen.fill((255,255,255))ju = pygame.font.Font('字体\叶根友刀锋黑草.ttf', 50)s = ju.render(b, True, (1, 2, 200))ju2 = pygame.font.Font('字体\叶根友刀锋黑草.ttf', 50)s2 = ju2.render('我预测你这次考试会考:', True, (1, 2, 200))for event in pygame.event.get():if event.type == pygame.QUIT:exit()screen.blit(s,(100,200))screen.blit(qd, (620, 500))screen.blit(s2,(100,100))x, y = pygame.mouse.get_pos()for i in range(154):for ii in range(79):if x == 620+i and y == 500 + ii and pygame.mouse.get_pressed()[0] == True:print(1)mm = 1333pygame.display.update()pygame.time.Clock().tick(20)

要准备的图片:

jts.png  #向上的箭头
jtx.png   #向下的箭头
qd.png  #确定

2.平平淡淡也挺好玩

1.极速赛车

准备一个汽车图片叫做:

qc.png

代码:

import pygame,sys
from random import*
while True:js = ''class Block(pygame.sprite.Sprite):def __init__(self):super().__init__()self.kd = randint(90,180)self.image = pygame.Surface((self.kd,20))self.image.fill((255,255,255))self.rect = self.image.get_rect()self.rect.top = 0self.rect.left = 0def update(self,v):self.rect.top += vif self.rect.top >= 600:self.kill()class Block2(Block):def __init__(self):super().__init__()self.rect.left = 400-self.kdclass Car(pygame.sprite.Sprite):def __init__(self):super().__init__()self.image = pygame.image.load('qc.png')self.image = pygame.transform.scale(self.image, (20, 50))self.rect = self.image.get_rect()self.rect.top = 400self.rect.left = 150def update(self):k = pygame.key.get_pressed()if k[pygame.K_RIGHT]:self.rect.left += 5elif k[pygame.K_LEFT]:self.rect.left -= 5if self.rect.left >= 400:self.rect.left = 400if self.rect.left <= 0:self.rect.left = 0def zi(dx,x,y):xz = pygame.font.Font('叶根友刀锋黑草.ttf', 50).render(str(dx), True, (0, 0, 0))screen.blit(xz,(x,y))pygame.init()screen = pygame.display.set_mode((400,600))pygame.display.set_caption("qc")group = pygame.sprite.Group()group2 = pygame.sprite.Group()group3 = pygame.sprite.Group()group3.add(Car())i = 0v = 3while True:screen.fill((0,0,255))for event in pygame.event.get():if event.type == pygame.QUIT:sys.exit()t = pygame.time.get_ticks()if js == '':miao = str(t / 1000)miao2 = int(miao[0])zi('速度:' + str(int(v)), 0, 0)if miao2 == 1 and miao2 != 0:v += 0.001i += 1jg = randint(20,50)  #间隔if i % jg == 0:group.add(Block())group.draw(screen)group.update(v)jg2 = randint(20, 50)  # 间隔2if i % jg2 == 0:group2.add(Block2())group2.draw(screen)group2.update(v)group3.draw(screen)group3.update()else:zi('Game Over',0,100)zi('按滚轮回去',50,200)#碰撞a = pygame.sprite.groupcollide(group,group3,False,False)b = pygame.sprite.groupcollide(group2, group3, False, False)if a or b:js = '结束'i = 0v = 3if pygame.mouse.get_pressed()[1] and js == '结束':breakpygame.display.update()pygame.time.Clock().tick(60)

2.滑雪 

代码太长了:294行

 提供一个创意思路

3.制作困难的游戏

提供思路

1.风叶穿行

被我爆改成了火山穿行

网站链接(B站的灵感):风叶穿行 (bilibili.com)

 2.鱿鱼游戏系列

 

 

4.我还有很多有意思的pygame游戏 

 

http://www.lryc.cn/news/353548.html

相关文章:

  • 【吊打面试官系列】Java高并发篇 - ThreadLocal 是什么?有什么用?
  • Spring MVC的数据转换及数据格式化:java 转换器接口(将一种类型的对象转换为另一种类型及其子类对象)
  • 【开源】多语言大型语言模型的革新:百亿参数模型超越千亿参数性能
  • DDL—表—数据类型—日期时间类型相关语法
  • Ant Design pro 6.0.0 搭建使用以及相关配置
  • Vue生命周期钩子是如何实现的
  • 002 仿muduo库实现高性能服务器组件_整体框架
  • 车道线识别与预警系统LDWS(代码+教程)
  • Python基础学习笔记(七)——元组
  • 安卓开发:相机水印设置
  • Excel工作表单元格单击选中事件,VBA动态数值排序
  • 数据结构~~链式二叉树
  • 线程池,日志
  • vue的图片上传
  • 题解 P1150
  • 牛客NC324 下一个更大的数(三)【中等 双指针 Java/Go/PHP/C++】参考lintcode 52 · 下一个排列
  • Vue3解决“找不到模块“@/components/xxx.vue”或其相应的类型声明”
  • nginx的Connection refused
  • Haskell 的高阶函数(Higher-order functions)
  • Unity websocket客户端
  • 每日一题——博弈论(枚举与暴力)
  • pytorch笔记:torch.nn.Flatten()
  • 一个人应该怎么操作抖音小店呢?店铺操作流程给你讲解清楚!
  • “等保测评与安全运维的协同:保障企业网络安宁
  • python抽取pdf中的参考文献
  • Java进阶学习笔记21——泛型概念、泛型类、泛型接口
  • 深入理解计算机系统 家庭作业4.55
  • 第二天-⑦前后端需要注意的事项
  • Socket 函数详细讲解(Socket编程步骤、socket函数、TCP和UDP的区别)
  • 【限免】杂波环境下线性调频脉冲、巴克码、频率步进脉冲雷达MTI、脉冲压缩【附MATLAB代码】