大家好,我是涵子码农,今天我要分享一个游戏:iwanna——python版本。

链接: https://pan.baidu.com/s/1V2Ajw6j1YBhqr8HRiR87jQ?pwd=xx4j 提取码: xx4j

百度网盘文件提取

CSDN文库文件提取

坑爹的游戏,打了好几遍都赢不了,一开始就有一个坑爹陷阱

文件放法:py文件在最外面,里面要有一个文件images,里面都是图片

iwanna开始!

下面是源代码,百度网盘里面也有。

一、iwanna.py

# -*- coding: utf-8 -*-
import pygame
goodBoard=[]
brokeBoard=[]
board=[]
state=1
pygame.init()
canvas=pygame.display.set_mode((1750,750))
font_name = pygame.font.match_font('KaiTi')
bigFont = pygame.font.Font(font_name, 250)
font = pygame.font.Font(font_name, 20)
pygame.display.set_caption("iwanna")
def loadPng(name):return pygame.image.load('images/'+name+'.png')
air=loadPng('air')
water=loadPng('water')
fire=loadPng('bad')
ground=loadPng('ground')
floor=loadPng('floor')
grass=loadPng('grass')
man=loadPng('man')
manLeft1=loadPng('manLeft1')
manLeft2=loadPng('manLeft2')
manRight1=loadPng('manRight1')
manRight2=loadPng('manRight2')
finisher=loadPng('finish')
jumpp=loadPng('jump')
jump=1
class Person():def __init__(self):self.x=500self.y=50self.fall=0self.faller=1self.jump=2self.stand=1def paint(self):canvas.blit(man,(self.x,self.y))def up(self):if self.jump>0:self.fall=-3self.jump-=1self.y-=3self.stand=0def left(self):#if self.fall==0:self.x-=2def right(self):#if self.fall==0:self.x+=2def check(self):global stateif self.y>=(750-20) or self.y<=0 or self.x>=(1750-13) or self.x<=0:state=2a=0for i in floors:if i.x<=self.x+13 and i.x>=self.x-20 and i.y<=self.y+20 and i.y>=self.y-2 and i.y>=self.y-1 and self.stand:a=1self.y=i.y-20if a:self.faller=0self.fall=0self.jump=2else:self.faller=1def move(self):if self.faller:self.fall+=0.1self.stand=1self.y+=self.falldef shut(self):pass
class Floor:def __init__(self,x,y):self.x=xself.y=ydef paint(self):canvas.blit(floor,(self.x,self.y))
class Jump:def __init__(self,x,y):self.x=xself.y=ydef paint(self):canvas.blit(jumpp,(self.x,self.y))
class Fire:def __init__(self,x,y):self.x=xself.y=ydef paint(self):canvas.blit(fire,(self.x,self.y))def check(self):global stateif self.x<=person.x+13 and self.x>=person.x-20 and self.y<=person.y+20 and self.y>=person.y-20:state=2
class Finish():def __init__(self,x,y):self.x=xself.y=ydef paint(self):canvas.blit(finisher,(self.x,self.y))def check(self):global stateif self.x<=person.x+13 and self.x>=person.x-20 and self.y<=person.y+20 and self.y>=person.y-20:state=4
person=Person()
canvas.fill((255,255,255))
fires=[]
def createFire(x,y):fires.append(Fire(x,y))
floors=[]
def createFloor(x,y):floors.append(Floor(x,y))
jumps=[]
def createJump(x,y):floors.append(Jump(x,y))
a=0
b=0
c=0
d=0
e=0
f=0
g=0
h=0
j=0
k=0
l=0
m=0
n=0
o=0
p=0
q=0
r=0
s=0
t=0
u=0
v=0
w=0
x=0
y=0
z=0
A=0
B=0
C=0
D=0
E=0
F=0
G=0
H=0
I=0
J=0
K=0
L=0
M=0
N=0
O=0
P=0
Q=0
R=0
S=0
T=0
U=0
V=0
W=0
X=0
Y=0
Z=0
timer=0
time=0
finish=0
def setup():global a,b,c,d,e,f,g,h,finish,j,k,l,m,n,o,p,q,timer,time,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,ZcreateFloor(500,100)createFloor(540,100)createFloor(560,100)createFloor(580,100)createFloor(600,100)createFloor(620,100)createFire(950,100)createFire(950,120)createFire(950,140)createFire(950,160)createFire(950,180)finish=Finish(1260,220)a=1b=1c=1d=1e=1f=1g=1h=1j=1k=1l=1m=1n=1o=1p=1q=1timer=0time=1r=1s=1t=1u=1v=1w=1x=1y=1z=1A=1B=1C=1D=1E=1F=1G=1H=1I=1J=1K=1L=1M=1N=1O=1P=1Q=1R=1S=1T=1U=1V=1W=1X=1Y=1Z=1
setup()
while 1:pygame.time.Clock().tick(100)event = pygame.event.poll()if event.type == pygame.QUIT:pygame.quit()exit()if state==1:finish.check()person.check()if person.x>=500-13 and person.x<=540 and person.y>=90-20 and person.y<=95-20 and a==1:createFire(500,100)a=0if person.x>=600-13 and person.x<=620 and person.y>=90-20 and person.y<=100 and b==1:createFire(620,80)createFloor(640,120)b=0if person.x>=640-13 and person.x<=660 and person.y>=100-20 and person.y<=120 and c==1 and b==0:createFloor(700,120)createFloor(740,120)createFloor(760,120)createFloor(820,120)createFloor(880,120)createFire(850,100)c=0if person.x>=730-13 and person.x<=750 and d==1 and c==0:floors.pop(7)floors.pop(7)d=0if person.x>=790-13 and person.x<=810 and e==1 and d==0:createFire(790,120)createFire(790,100)createFire(790,80)e=0if person.x>=880-13 and person.x<=900 and person.y>=100-20 and person.y<=120 and f==1 and e==0:for i in range(800,1300,20):if i==860 or i==840:continuecreateFloor(i,240)f=0if person.x>=800-13 and person.x<=820 and person.y>=160-20 and person.y<=260 and g==1 and f==0:createFire(800,180)createFloor(780,240)createFloor(760,230)createFloor(740,220)createFloor(720,220)createFloor(700,220)for i in range(240,500,20):createFloor(780,i)createFloor(720,i)g=0if person.x>=1100-13 and person.x<=1160 and person.y>=160-20 and person.y<=260 and h==1 and f==0:for i in range(0,240,20):createFire(1200,i)createFire(1000,i)h=0if person.x>=740-13 and person.x<=760 and person.y>=220-20 and person.y<=240 and j==1 and g==0:for i in floors:if i.x==740 and i.y==220:floors.remove(i)breakcreateFire(740,480)for i in floors:if i.x==760 and i.y==230:floors.remove(i)breakcreateFire(760,480)j=0if person.x>=700-13 and person.x<=705 and person.y>=220-20 and person.y<=240 and k==1 and g==0:for i in floors:if i.x==700 and i.y==220:floors.remove(i)breakcreateFire(660,180)for i in range(100,680,20):createFloor(i,200)k=0if person.x>=620-13 and person.x<=640 and l==1 and k==0:for i in fires:if i.x==620 and i.y==80:fires.remove(i)breakcreateFire(600,180)l=0if person.x>=500-13 and person.x<=520 and m==1 and k==0:createFire(500,120)createFire(450,180)m=0if person.x>=340-13 and person.x<=380 and n==1 and k==0:for i in floors:if i.x==340:floors.remove(i)breakfor i in floors:if i.x==360:floors.remove(i)breakn=0while 1:pygame.time.Clock().tick(100)timer+=1if timer//100%3==0 and time:for i in range(100,500):if i==320 or i==340 or i==360 or i==380:continuecreateFire(i,340)time=0elif timer//100%3!=0 and not time:for i in range(100,600):if i==320 or i==340 or i==360 or i==380:continuecreateFloor(i,340)try:if i<500:fires.pop()except:passtime=1if person.x>=550 or state!=1:breakcanvas.fill((255,255,255))person.paint()finish.check()event = pygame.event.poll()if event.type == pygame.QUIT:pygame.quit()exit()keys=pygame.key.get_pressed()if keys[pygame.K_w] or keys[pygame.K_UP] or keys[pygame.K_SPACE]:if jump:person.up()jump=0else:jump=1if keys[pygame.K_a] or keys[pygame.K_LEFT]:person.left()if keys[pygame.K_d] or keys[pygame.K_RIGHT]:person.right()if keys[pygame.K_s] or keys[pygame.K_DOWN]:person.shut()if keys[pygame.K_r]:state=3person.move()person.check()for i in floors:i.paint()for i in fires:i.paint()i.check()finish.paint()pygame.display.update()if person.x<=200 and o==1 and n==0:for i in range(0,300,20):for z in range(0,1000,20):createFire(i,z)o=0if person.x<=540 and p==1 and k==0:createFire(600,320)for i in range(0,500):createFire(660,i)p=0if person.x>=540 and q==1 and n==0:for i in range(400,640):createFloor(i,440)q=0if person.x<=600 and r==1 and q==0:createFire(570,420)createFire(500,420)r=0if person.x<=500 and s==1 and q==0:createFire(450,420)s=0if person.x<=400 and t==1 and q==0:for i in range(0,1750,20):createFloor(i,580)createFloor(i,740)t=0if person.x>=1370 and u==1 and t==0:for i in range(0,1750):createFire(i,570)u=0if person.y>=420 and v==1 and x==0:for i in range(0,800,20):for z in range(0,2000,20):createFire(z,i)v=0if person.x<=1120 and w==1 and y==0 and h==0:for i in floors:if i.x==1020 and i.y==240:floors.remove(i)breakfor i in floors:if i.x==1040 and i.y==240:floors.remove(i)breakfor i in floors:if i.x==1060 and i.y==240:floors.remove(i)breakcreateFire(1010,240)createFire(1070,240)w=0if person.x<=1300 and x==1 and y==0:finish=Finish(1200,400)x=0if person.x>=1325 and person.y<=775 and y==1 and t==0:for i in range(220,750,60):createJump(1350,i)y=0if person.y>=250 and A==1 and w==0:for i in range(1000,1200,20):createFloor(i,300)A=0if person.y>=375 and B==1 and A==0:createFire(1160,370)createFire(1180,370)createFire(1200,370)createFire(1220,370)createFire(1240,370)B=0if person.y>=320 and person.x<=990 and C==1 and A==0 and B==1:for i in range(900,1200,20):createFloor(i,350)C=0if person.y>=350 and person.x<=990 and D==1 and C==0:for i in range(800,2000,20):createFloor(i,435)D=0if person.x>=760 and E==1 and t==0:for i in floors:if i.x==740 and i.y==580:floors.remove(i)breakfor i in floors:if i.x==760 and i.y==580:floors.remove(i)breakfor i in floors:if i.x==780 and i.y==580:floors.remove(i)breakfor i in floors:if i.x==800 and i.y==580:floors.remove(i)breakE=0if person.x>=830 and F==1 and t==0:for i in range(400,520,20):createFire(820,i)F=0if person.x>=885 and G==1 and t==0:createFire(890,580)G=0if person.x>=950 and H==1 and t==0:for i in range(400,520,20):createFire(908,i)H=0if person.x>=1000 and I==1 and t==0:for i in range(400,580,20):createFire(978,i)I=0if person.x>=1300 and J==1 and t==0:for i in range(0,1280,20):createFire(i,580)createFire(i,560)createFire(i,540)createFire(i,520)createFire(i,500)J=0if person.x>=1320 and M==1 and t==0:for i in floors:if i.x==1240 and i.y==580:floors.remove(i)breakfor i in floors:if i.x==1260 and i.y==580:floors.remove(i)breakfor i in floors:if i.x==1280 and i.y==580:floors.remove(i)breakfor i in floors:if i.x==1300 and i.y==580:floors.remove(i)breakfor i in floors:if i.x==1320 and i.y==580:floors.remove(i)breakM=0canvas.fill((255,255,255))person.paint()keys=pygame.key.get_pressed()if keys[pygame.K_w] or keys[pygame.K_UP] or keys[pygame.K_SPACE]:if jump:person.up()jump=0else:jump=1if keys[pygame.K_a] or keys[pygame.K_LEFT]:person.left()if keys[pygame.K_d] or keys[pygame.K_RIGHT]:person.right()if keys[pygame.K_s] or keys[pygame.K_DOWN]:person.shut()if keys[pygame.K_r]:state=3person.move()for i in floors:i.paint()for i in fires:i.paint()i.check()finish.paint()pygame.display.update()elif state==2:font_surface = bigFont.render('Game over', True, 'red')canvas.blit(font_surface, (250, 30))font_surface = font.render('\'c\' for exit', True, 'red')canvas.blit(font_surface, (800, 450))font_surface = font.render('\'r\' for again', True, 'red')canvas.blit(font_surface, (800, 550))pygame.display.update()event = pygame.event.poll()if event.type == pygame.QUIT:pygame.quit()exit()keys=pygame.key.get_pressed()if keys[pygame.K_r]:state=3if keys[pygame.K_c]:pygame.quit()exit()elif state==3:person=0person=Person()floors=[]fires=[]setup()state=1elif state==4:font_surface = bigFont.render('You win!', True, 'red')canvas.blit(font_surface, (300, 150))pygame.display.update()break

二、文件

因为文件过多,所以大家最好到百度网盘下载。链接在上方。

三、推荐文章

python也能开发minecraft启动器

python-minecraft启动器要在网址里面的链接下载。


github链接

gitee链接


python-pygame小游戏之球球大作战

球球大作战源码(可以去网址复制,也可以在这里复制,也可以用csdn文库):

csdn文库-这个文件是关于我最火热的文章:球球大作战的py文件

# import pygame, random and math
import pygame as pg
import random as rd
import math# init program
pg.init()
# set screen
screen = pg.display.set_mode((1000, 500))
screen.fill((255, 255, 255))
# set title
pg.display.set_caption("BallFight_Avaritia", "4.0")
# Chinese:pg.display.set_caption("球球大作战_无尽贪婪", "4.0")# def circle
def circle(color, point, r, size):pg.draw.circle(screen, color, point, r, size)# class ball
class Ball():def __init__(self):self.color = (rd.randint(0, 255), rd.randint(0, 255), rd.randint(0, 255))self.x =rd.randint(0, 1000)self.y = rd.randint(0, 500)self.r = rd.randint(5, 15)self.size = rd.randint(5, 15)# make a balllist
balllist = []
for i in range(600):balllist.append(Ball())# creat myball
myball = Ball()
myball.color = (0, 0, 0)
myball.x = 500
myball.y = 250
myball.size = 5
myball.speed = 10# def check touch
# use the pythagorean theorem
def touch(myX, myY, fX, fY, myR, fR):distance = math.sqrt((myX - fX) ** 2 + (myY - fY) ** 2)if distance <= myR + fR:# just return Truereturn Trueelse:# return Falsereturn False# def foodDelivery
def foodDelivery():time = pg.time.get_ticks()# every 10 seconds put 30 foodsif time % 10000 >= 9000 and time % 10000 <= 9020:for i in range(30):balllist.append(Ball())# def draw
# use "Ball" and for range to append in the balllist
def draw():for ball in balllist:if touch(myball.x, myball.y, ball.x, ball.y, myball.size, ball.size):balllist.remove(ball)myball.size += 0.1# make the speed to be smaller than the last one# use the multiplier scale decreases and inverse proportional functionmyball.speed *= 0.992else:circle(ball.color, (ball.x, ball.y), ball.size, 0)circle(myball.color, (myball.x, myball.y), myball.size, 0)# check fps, do not quit program
fps = pg.time.Clock()
# check quit and play program
while True:# do not make the fps so high# if the fps is high, the computer will ~"bomb!"fps.tick(60)event = pg.event.poll()if event.type == pg.QUIT:pg.quit()exit()keys = pg.key.get_pressed()# make the ball to move# I use the "wasd"# also can use up down right leftif keys[pg.K_w]:myball.y -= myball.speedif keys[pg.K_a]:myball.x -= myball.speedif keys[pg.K_s]:myball.y += myball.speedif keys[pg.K_d]:myball.x += myball.speedif keys[pg.K_UP]:myball.y -= myball.speedif keys[pg.K_DOWN]:myball.y += myball.speedif keys[pg.K_LEFT]:myball.x -= myball.speedif keys[pg.K_RIGHT]:myball.x += myball.speed# the e is to update ball's xyelif keys[pg.K_e]:myball.x, myball.y = 500, 250# draw and checkdraw()foodDelivery()# display programpg.display.update()screen.fill((255, 255, 255))

四、总结和玩法

w,s,a,d,上下左右都可以移动。空格跳跃,可以两段跳。十分坑爹。r重新开始,c退出。

这个游戏代码很长,内容很多。里面涉及到了很多知识。大家可以边学边玩。希望大家玩得快乐,学得快乐。祝所有学生暑假快乐!

python大全-iwanna相关推荐

  1. 【涵子来信python大全】——第二季——opencv第三篇-numpy和颜色通道解释

    各位亲爱的读者,博主: 大家好,我是涵子.今天我们继续讲讲opencv,讲讲其中numpy的秘密.如果不清楚上一章的内容,请从链接或者主页回去先读一遍之前的文章,否则今天的内容很难理解. [涵子来信& ...

  2. python大全-那些有用的包

    更新提醒: python大全写的内容比较深,所以可能时间要久一点. 大家好,我又来了.今天我要为大家分享一下那些有用的包! 目录 一.怎么下载包 二.了解一下包 三.示例 四.总结 一.怎么下载包 首 ...

  3. 【涵子来信python大全】——第二季——opencv第二篇

    各位亲爱的读者,博主: 大家好,我是涵子.今天我们继续讲下去,如果不清楚上一章的内容,请从链接或者主页回去先读一遍之前的文章,否则今天的内容很难理解. (2条消息) [涵子来信&python大 ...

  4. 【涵子来信python大全】——第二季——opencv第四篇-用手势控制屏幕鼠标

    各位亲爱的读者,博主: 大家好,我是涵子.今天我们需要使用cv2,mediapipe和pyautogui用手势控制屏幕鼠标. 目录 一.准备 二.代码 可以先去看看之前的文章哦. 一.准备 首先pip ...

  5. 【涵子来信python大全】——第二季——opencv第一篇

    各位亲爱的读者,博主: 首先恭喜大家,涵子来信已经到达第二季--2023年篇.今天,我们要步入机器学习的初级内容:python opencv图片! 目录 一.提前准备 二.程序代码学习 2.1.如何读 ...

  6. python大全1015python大全_python 列表总结大全

    1定义 names=[] names=[1,2,1,1,1,] names=[1.'10'.[1,1]] 2添加元素 names.append() names.insert(0,10) names.e ...

  7. [资源]Python资源大全中文版

    Python资源大全中文版,内容包括:Web框架.网络爬虫.网络内容提取.模板引擎.数据库.数据可视化.图片处理.文本处理.自然语言处理.机器学习.日志.代码分析等 Python 资源大全中文版 我想 ...

  8. [转]Python 资源大全中文版

    摘自:https://github.com/jobbole/awesome-python-cn 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesom ...

  9. python你想知道的都在这里 python资源大全中文版

    Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesome-python 是 vinta 发起维护的 Python 资源列 ...

最新文章

  1. bookstrap 怎么用ajax,bootstrap里怎么用ajax请求数据到table里
  2. 【机器学习基础】Python机器学习的神器- Scikit-learn使用说明
  3. css实现鼠标覆盖显示大图
  4. 2019阿里云910会员节大促主会场全攻略
  5. 《老马的职业“鬼”话》 马华兴著
  6. x86构架之-Intel8042键盘控制器简介
  7. spark任务shell运行_Spark原理与实战(七)部署模式与运行机制
  8. 技术剖析 | Axonius为什么能获得 2019 RSAC创新大奖 1
  9. Kotlin入门(18)利用单例对象获取时间
  10. Compose Multiplatform 正式官宣,与 Flutter 必有一战?
  11. 无界面和应用图标的应用程序
  12. ORACLE表空间查看和扩展
  13. (一)密码学之数论基础
  14. fw325r没有虚拟服务器,FAST FW325R配置教程
  15. 遗传算法占用计算机空间,遗传算法
  16. 导出的excel添加水印
  17. STM32 学习十 Flash下载与调试
  18. sort(function(a,b){return a -b})函数排序问题
  19. 多维正态随机变量的条件概率密度函数推导
  20. 开源软件xxl-job的oracle版本

热门文章

  1. 5款优秀的在线表格生成工具
  2. 从个人网站到泛生活化平台 百货之家背后的故事
  3. win10锁屏后默认1分钟进入睡眠状态的解决办法
  4. 盘点40个最佳项目管理工具大全
  5. Word 恢复默认样式
  6. 社区版pycharm的django创建app失败问题解决
  7. 多维尺度分析MDS详解
  8. BZOJ 1127 [POI2008]KUP 最大子矩阵
  9. Cubase中文版教程分享:如何通过音频剪辑软件创建工程
  10. Pixelmator Pro Mac(图像编辑软件)