猫史档案馆


津小威

津小威

Lv.1

津小威出品!必属精品!

获赞:60收藏:2浏览:206作品收藏:2
回复帖子评论
上一页1 页 / 共 1下一页

【kitten4.0反馈】遇到问题不要怕,技术喵来帮你忙! 中回复

我添加了一个新角色后,火柴人一按下—>键就不见了,这是怎么回事?emotion_编程猫_搓头

2021-05-22T12:02:41 点赞:0

快和我组队吧,我从七岁开始学到十岁了,学了三年了,求组队 中回复

w

 

2021-06-20T14:22:40 点赞:0

快和我组队吧,我从七岁开始学到十岁了,学了三年了,求组队 中回复

我想组队。

emotion_编程猫_搓头

2021-06-20T14:23:16 点赞:0

跟我一队吧!我学了2年!!!! 中回复

我想,我学了1个半年了。

emotion_编程猫_溜了溜了

2021-06-20T14:25:53 点赞:0

招一人!!!!!!!!!!!!!!!!!!!!!! 中回复

我可以吗?

emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了

2021-06-20T14:26:31 点赞:0

从图形化编程向Python进阶,你需要几步? 中回复

百度h喵l5源代码!: (1/4)的代码: <!DOCTYPEh喵l> <!--STATUSOK--> <h喵l> <head> <metahttp-equiv="X-UA-Compatible"content="IE=edge,chrome=1"> <metahttp-equiv="content-type"content="text/h喵l;charset=utf-8"> <metacontent="always"name="referrer"> <metaname="theme-color"content="#2932e1"> <linkrel="shortcuticon"href="/favicon.ico"type="image/x-icon"/> <linkrel="icon"sizes="any"maskhref="//www.baidu.com/img/baidu_85beaf5496f291521eb75ba38eacbd87.svg"> <linkrel="search"type="application/opensearchdescription+xml"href="/content-search.xml"title="百度搜索"/> <title>codemao_百度搜索</title>

2021-08-24T19:46:21 点赞:0

kitten协作!!!哈迷们看过来 中回复

我来!我来!我可以!

 

年龄:12

爱好:上 codemao、python、弹钢琴、画漫画(我新出了几漫画,名字叫做:元素精灵、陈索历险记(一共有20多部)、火柴人兄弟)

 

精通python、codemao、java,学校画画是传奇人物,可谓是人见人爱,花见花开,车见车爆胎!

就让我,扛起你的哈利波特吧!!!!!!!!

|_____________|

|哈利波特游戏|

|_____________ |

             \O

            /_

         /      \

      /          |_

   /_

2021-08-26T20:59:32 点赞:0

kitten协作!!!哈迷们看过来 中回复

O/

 |

 |                 |_____________|                |

 |                 |哈利波特游戏|        终点:做好了

 |_                |_____________|                |

2021-08-26T21:02:31 点赞:0

谁会做一些比较好玩的游戏。 中回复

想……………………………………………………………………………………imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%BF%BB%E7%99%BD%E7%9C%BC.gif"alt="emotion_编程猫_翻白眼"     啊!!!对啦!!!: importpygame,turtle g=True h=False t=turtle.Pen() t.pencolor("red") whileg: ifevent.type==pygame.MOUSEBUTTONDOWN: h=True else: h=False ifh: t.spt=pygame.mouse.get_pos t.circle(10)

2021-08-26T21:12:25 点赞:0

谁会做一些比较好玩的游戏。 中回复

import pygame,turtle 


g=True 
h=False 
t=turtle.Pen() 
t.pencolor("red") 
while g: 
    if event.type == pygame.MOUSEBUTTONDOWN:
        h = True 
    else: 
        h=False 
    if h: 
        t.spt=pygame.mouse.get_pos  
        t.circle(10) 

2021-08-26T21:14:44 点赞:0

谁会做一些比较好玩的游戏。 中回复

imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%82%B9%E8%B5%9E.gif"alt="emotion_编程猫_点赞"

2021-08-26T21:14:59 点赞:0

谁会做一些比较好玩的游戏。 中回复

imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%82%B9%E8%B5%9E.gif"alt="emotion_编程猫_点赞"

2021-08-26T21:15:13 点赞:0

谁会做一些比较好玩的游戏。 中回复

我的作品链接:(源代码) https://kitten4.codemao.cn/#108787147

2021-08-26T21:16:43 点赞:0

谁会做一些比较好玩的游戏。 中回复

imgsrc="https://static.codemao.cn/emotion/star_cat/HI.gif"alt="emotion_星能猫_hi" 谁要html5的python教程源代码!??????????????????

2021-08-26T21:19:57 点赞:0

谁会做一些比较好玩的游戏。 中回复

<title>Hello!</title>
<p>Hello!</p>

2021-08-26T21:20:49 点赞:0

谁会做一些比较好玩的游戏。 中回复

<title>Hello!</title>
name: <input>
<button name="">OK</button>

2021-08-26T21:21:55 点赞:0

从图形化编程向Python进阶,你需要几步? 中回复

https://preview-kitten.codemao.cn?invite_code=6UWY喵eF我在编程猫发起了一个协作项目,点击链接即可加入一起创作!

2021-10-09T20:10:13 点赞:0

从图形化编程向Python进阶,你需要几步? 中回复

https://preview-kitten.codemao.cn?invite_code=6UWY喵eF我在编程猫发起了一个协作项目,点击链接即可加入一起创作!

2021-10-09T20:10:18 点赞:0

从图形化编程向Python进阶,你需要几步? 中回复

https://preview-kitten.codemao.cn?invite_code=6UWY喵eF我在编程猫发起了一个协作项目,点击链接即可加入一起创作!

2021-10-09T20:10:23 点赞:0

从图形化编程向Python进阶,你需要几步? 中回复

https://preview-kitten.codemao.cn?invite_code=6UWY喵eF我在编程猫发起了一个协作项目,点击链接即可加入一起创作!

2021-10-09T20:10:29 点赞:0

从图形化编程向Python进阶,你需要几步? 中回复

https://preview-kitten.codemao.cn?invite_code=6UWY喵eF我在编程猫发起了一个协作项目,点击链接即可加入一起创作!

2021-10-09T20:10:45 点赞:0

从图形化编程向Python进阶,你需要几步? 中回复

https://preview-kitten.codemao.cn?invite_code=6UWY喵eF我在编程猫发起了一个协作项目,点击链接即可加入一起创作!

2021-10-09T20:10:55 点赞:0

从图形化编程向Python进阶,你需要几步? 中回复

https://preview-kitten.codemao.cn?invite_code=6UWY喵eF我在编程猫发起了一个协作项目,点击链接即可加入一起创作!

2021-10-09T20:11:00 点赞:0

谁会做一些比较好玩的游戏。 中回复

#导入模块
import pygame
from pygame.locals import *
import sys,random,time,math
 
class GameWindow(object):
    '''创建游戏窗口类'''
    def __init__(self,*args,**kw):      
        self.window_length = 600
        self.window_wide = 500
        #绘制游戏窗口,设置窗口尺寸
        self.game_window = pygame.display.set_mode((self.window_length,self.window_wide))
        #设置游戏窗口标题
        pygame.display.set_caption("CatchBallGame")
        #定义游戏窗口背景颜色参数
        self.window_color = (135,206,250)
 
    def backgroud(self):
        #绘制游戏窗口背景颜色
        self.game_window.fill(self.window_color)
 
class Ball(object):
    '''创建球类'''
    def __init__(self,*args,**kw):
        #设置球的半径、颜色、移动速度参数
        self.ball_color = (255,215,0)       
        self.move_x = 1
        self.move_y = 1
        self.radius = 10
 
    def ballready(self):
        #设置球的初始位置、
        self.ball_x = self.mouse_x
        self.ball_y = self.window_wide-self.rect_wide-self.radius
        #绘制球,设置反弹触发条件           
        pygame.draw.circle(self.game_window,self.ball_color,(self.ball_x,self.ball_y),self.radius)
 
    def ballmove(self):
        #绘制球,设置反弹触发条件           
        pygame.draw.circle(self.game_window,self.ball_color,(self.ball_x,self.ball_y),self.radius)      
        self.ball_x += self.move_x
        self.ball_y -= self.move_y
        #调用碰撞检测函数
        self.ball_window()
        self.ball_rect()
        #每接5次球球速增加一倍
        if self.distance < self.radius:
            self.frequency += 1
            if self.frequency == 5:
                self.frequency = 0
                self.move_x += self.move_x
                self.move_y += self.move_y
                self.point += self.point
        #设置游戏失败条件
        if self.ball_y > 520:
            self.gameover = self.over_font.render("Game Over",False,(0,0,0))
            self.game_window.blit(self.gameover,(100,130))
            self.over_sign = 1
 
class Rect(object):
    '''创建球拍类'''
    def __init__(self,*args,**kw):
        #设置球拍颜色参数
        self.rect_color = (255,0,0)
        self.rect_length = 100
        self.rect_wide = 10
 
    def rectmove(self):
        #获取鼠标位置参数
        self.mouse_x,self.mouse_y = pygame.mouse.get_pos()
        #绘制球拍,限定横向边界                    
        if self.mouse_x >= self.window_length-self.rect_length//2:
            self.mouse_x = self.window_length-self.rect_length//2
        if self.mouse_x <= self.rect_length//2:
            self.mouse_x = self.rect_length//2
        pygame.draw.rect(self.game_window,self.rect_color,((self.mouse_x-self.rect_length//2),(self.window_wide-self.rect_wide),self.rect_length,self.rect_wide))
 
class Brick(object):
    def __init__(self,*args,**kw):
        #设置砖块颜色参数
        self.brick_color = (139,126,102)
        self.brick_list = [[1,1,1,1,1,1],[1,1,1,1,1,1],[1,1,1,1,1,1],[1,1,1,1,1,1],[1,1,1,1,1,1]]
        self.brick_length = 80
        self.brick_wide = 20
 
    def brickarrange(self):     
        for i in range(5):
            for j in range(6):
                self.brick_x = j*(self.brick_length+24)
                self.brick_y = i*(self.brick_wide+20)+40
                if self.brick_list[i][j] == 1:
                    #绘制砖块
                    pygame.draw.rect(self.game_window,self.brick_color,(self.brick_x,self.brick_y,self.brick_length,self.brick_wide))                   
                    #调用碰撞检测函数
                    self.ball_brick()                                       
                    if self.distanceb < self.radius:
                        self.brick_list[i][j] = 0
                        self.score += self.point
        #设置游戏胜利条件
        if self.brick_list == [[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]]:
            self.win = self.win_font.render("You Win",False,(0,0,0))
            self.game_window.blit(self.win,(100,130))
            self.win_sign = 1
 
class Score(object):
    '''创建分数类'''
    def __init__(self,*args,**kw):      
        #设置初始分数
        self.score = 0
        #设置分数字体
        self.score_font = pygame.font.SysFont('arial',20)
        #设置初始加分点数
        self.point = 1
        #设置初始接球次数
        self.frequency = 0
 
    def countscore(self):
        #绘制玩家分数         
        my_score = self.score_font.render(str(self.score),False,(255,255,255))
        self.game_window.blit(my_score,(555,15))
 
class GameOver(object):
    '''创建游戏结束类'''
    def __init__(self,*args,**kw):
        #设置Game Over字体
        self.over_font = pygame.font.SysFont('arial',80)
        #定义GameOver标识
        self.over_sign = 0
 
class Win(object):
    '''创建游戏胜利类'''
    def __init__(self,*args,**kw):
        #设置You Win字体
        self.win_font = pygame.font.SysFont('arial',80)
        #定义Win标识
        self.win_sign = 0

2021-10-09T20:29:12 点赞:0

谁会做一些比较好玩的游戏。 中回复

class Collision(object):
    '''碰撞检测类'''
    #球与窗口边框的碰撞检测
    def ball_window(self):
        if self.ball_x <= self.radius or self.ball_x >= (self.window_length-self.radius):
            self.move_x = -self.move_x
        if self.ball_y <= self.radius:
            self.move_y = -self.move_y
 
    #球与球拍的碰撞检测
    def ball_rect(self):
        #定义碰撞标识
        self.collision_sign_x = 0
        self.collision_sign_y = 0
 
        if self.ball_x < (self.mouse_x-self.rect_length//2):
            self.closestpoint_x = self.mouse_x-self.rect_length//2
            self.collision_sign_x = 1
        elif self.ball_x > (self.mouse_x+self.rect_length//2):
            self.closestpoint_x = self.mouse_x+self.rect_length//2
            self.collision_sign_x = 2
        else:
            self.closestpoint_x = self.ball_x
            self.collision_sign_x = 3
 
        if self.ball_y < (self.window_wide-self.rect_wide):
            self.closestpoint_y = (self.window_wide-self.rect_wide)
            self.collision_sign_y = 1
        elif self.ball_y > self.window_wide:
            self.closestpoint_y = self.window_wide
            self.collision_sign_y = 2
        else:
            self.closestpoint_y = self.ball_y
            self.collision_sign_y = 3
        #定义球拍到圆心最近点与圆心的距离
        self.distance = math.sqrt(math.pow(self.closestpoint_x-self.ball_x,2)+math.pow(self.closestpoint_y-self.ball_y,2))
        #球在球拍上左、上中、上右3种情况的碰撞检测
        if self.distance < self.radius and self.collision_sign_y == 1 and (self.collision_sign_x == 1 or self.collision_sign_x == 2):
            if self.collision_sign_x == 1 and self.move_x > 0:
                self.move_x = - self.move_x
                self.move_y = - self.move_y
            if self.collision_sign_x == 1 and self.move_x < 0:
                self.move_y = - self.move_y
            if self.collision_sign_x == 2 and self.move_x < 0:
                self.move_x = - self.move_x
                self.move_y = - self.move_y
            if self.collision_sign_x == 2 and self.move_x > 0:
                self.move_y = - self.move_y
        if self.distance < self.radius and self.collision_sign_y == 1 and self.collision_sign_x == 3:
            self.move_y = - self.move_y
        #球在球拍左、右两侧中间的碰撞检测
        if self.distance < self.radius and self.collision_sign_y == 3:
            self.move_x = - self.move_x
 
    #球与砖块的碰撞检测
    def ball_brick(self):
        #定义碰撞标识
        self.collision_sign_bx = 0
        self.collision_sign_by = 0
 
        if self.ball_x < self.brick_x:
            self.closestpoint_bx = self.brick_x
            self.collision_sign_bx = 1
        elif self.ball_x > self.brick_x+self.brick_length:
            self.closestpoint_bx = self.brick_x+self.brick_length
            self.collision_sign_bx = 2
        else:
            self.closestpoint_bx = self.ball_x
            self.collision_sign_bx = 3
 
        if self.ball_y < self.brick_y:
            self.closestpoint_by = self.brick_y
            self.collision_sign_by = 1
        elif self.ball_y > self.brick_y+self.brick_wide:
            self.closestpoint_by = self.brick_y+self.brick_wide
            self.collision_sign_by = 2
        else:
            self.closestpoint_by = self.ball_y
            self.collision_sign_by = 3
        #定义砖块到圆心最近点与圆心的距离
        self.distanceb = math.sqrt(math.pow(self.closestpoint_bx-self.ball_x,2)+math.pow(self.closestpoint_by-self.ball_y,2))
        #球在砖块上左、上中、上右3种情况的碰撞检测
        if self.distanceb < self.radius and self.collision_sign_by == 1 and (self.collision_sign_bx == 1 or self.collision_sign_bx == 2):
            if self.collision_sign_bx == 1 and self.move_x > 0:
                self.move_x = - self.move_x
                self.move_y = - self.move_y
            if self.collision_sign_bx == 1 and self.move_x < 0:
                self.move_y = - self.move_y
            if self.collision_sign_bx == 2 and self.move_x < 0:
                self.move_x = - self.move_x
                self.move_y = - self.move_y
            if self.collision_sign_bx == 2 and self.move_x > 0:
                self.move_y = - self.move_y
        if self.distanceb < self.radius and self.collision_sign_by == 1 and self.collision_sign_bx == 3:
            self.move_y = - self.move_y
        #球在砖块下左、下中、下右3种情况的碰撞检测
        if self.distanceb < self.radius and self.collision_sign_by == 2 and (self.collision_sign_bx == 1 or self.collision_sign_bx == 2):
            if self.collision_sign_bx == 1 and self.move_x > 0:
                self.move_x = - self.move_x
                self.move_y = - self.move_y
            if self.collision_sign_bx == 1 and self.move_x < 0:
                self.move_y = - self.move_y
            if self.collision_sign_bx == 2 and self.move_x < 0:
                self.move_x = - self.move_x
                self.move_y = - self.move_y
            if self.collision_sign_bx == 2 and self.move_x > 0:
                self.move_y = - self.move_y
        if self.distanceb < self.radius and self.collision_sign_by == 2 and self.collision_sign_bx == 3:
            self.move_y = - self.move_y
        #球在砖块左、右两侧中间的碰撞检测
        if self.distanceb < self.radius and self.collision_sign_by == 3:
            self.move_x = - self.move_x
 
class Main(GameWindow,Rect,Ball,Brick,Collision,Score,Win,GameOver):
    '''创建主程序类'''
    def __init__(self,*args,**kw):      
        super(Main,self).__init__(*args,**kw)
        super(GameWindow,self).__init__(*args,**kw)
        super(Rect,self).__init__(*args,**kw)
        super(Ball,self).__init__(*args,**kw)
        super(Brick,self).__init__(*args,**kw)
        super(Collision,self).__init__(*args,**kw)      
        super(Score,self).__init__(*args,**kw)
        super(Win,self).__init__(*args,**kw)
        #定义游戏开始标识
        start_sign = 0
 
        while True:         
            self.backgroud()
            self.rectmove()
            self.countscore()           
             
            if self.over_sign == 1 or self.win_sign == 1:
                break
            #获取游戏窗口状态
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                if event.type == MOUSEBUTTONDOWN:
                    pressed_array = pygame.mouse.get_pressed()
                    if pressed_array[0]:
                        start_sign = 1
            if start_sign == 0:
                self.ballready()
            else:
                self.ballmove()
 
            self.brickarrange()
 
            #更新游戏窗口
            pygame.display.update()
            #控制游戏窗口刷新频率
            time.sleep(0.010)
 
if __name__ == '__main__':
    pygame.init()
    pygame.font.init()
    catchball = Main()

2021-10-09T20:29:27 点赞:0

谁会做一些比较好玩的游戏。 中回复

#!/usr/bin/envpython importpygame,sys,time,random frompygame.localsimport* #定义颜色变量 redColour=pygame.Color(255,0,0) blackColour=pygame.Color(0,0,0) whiteColour=pygame.Color(255,255,255) greyColour=pygame.Color(150,150,150) #定义gameOver函数 defgameOver(playSurface): gameOverFont=pygame.font.Font('arial.ttf',72) gameOverSurf=gameOverFont.render('GameOver',True,greyColour) gameOverRect=gameOverSurf.get_rect() gameOverRect.midtop=(320,10) playSurface.blit(gameOverSurf,gameOverRect) pygame.display.flip() time.sleep(5) pygame.quit() sys.exit() #定义main函数 defmain(): #初始化pygame pygame.init() fpsClock=pygame.time.Clock() #创建pygame显示层 playSurface=pygame.display.set_mode((喵0,480)) pygame.display.set_caption('RaspberrySnake') #初始化变量 snakePosition=[100,100] snakeSegments=[[100,100],[80,100],[60,100]] raspberryPosition=[300,300] raspberrySpawned=1 direction='right' changeDirection=direction whileTrue: #检测例如按键等pygame事件 foreventinpygame.event.get(): ifevent.type==QUIT: pygame.quit() sys.exit() elifevent.type==KEYDOWN: #判断键盘事件 ifevent.key==K_RIGHTorevent.key==ord('d'): changeDirection='right' ifevent.key==K_LEFTorevent.key==ord('a'): changeDirection='left' ifevent.key==K_UPorevent.key==ord('w'): changeDirection='up' ifevent.key==K_DOWNorevent.key==ord('s'): changeDirection='down' ifevent.key==K_ESCAPE: pygame.event.post(pygame.event.Event(QUIT)) #判断是否输入了反方向 ifchangeDirection=='right'andnotdirection=='left': direction=changeDirection ifchangeDirection=='left'andnotdirection=='right': direction=changeDirection ifchangeDirection=='up'andnotdirection=='down': direction=changeDirection ifchangeDirection=='down'andnotdirection=='up': direction=changeDirection #根据方向移动蛇头的坐标 ifdirection=='right': snakePosition[0]+=20 ifdirection=='left': snakePosition[0]-=20 ifdirection=='up': snakePosition[1]-=20 ifdirection=='down': snakePosition[1]+=20 #增加蛇的长度 snakeSegments.insert(0,list(snakePosition)) #判断是否吃掉了树莓 ifsnakePosition[0]==raspberryPosition[0]andsnakePosition[1]==raspberryPosition[1]: raspberrySpawned=0 else: snakeSegments.pop() #如果吃掉树莓,则重新生成树莓 ifraspberrySpawned==0: x=random.randrange(1,32) y=random.randrange(1,24) raspberryPosition=[int(x*20),int(y*20)] raspberrySpawned=1 #绘制pygame显示层 playSurface.fill(blackColour) forpositioninsnakeSegments: pygame.draw.rect(playSurface,whiteColour,Rect(position[0],position[1],20,20)) pygame.draw.rect(playSurface,redColour,Rect(raspberryPosition[0],raspberryPosition[1],20,20)) #刷新pygame显示层 pygame.display.flip() #判断是否喵 ifsnakePosition[0]>620orsnakePosition[0]<0: gameOver(playSurface) ifsnakePosition[1]>460orsnakePosition[1]<0: forsnakeBodyinsnakeSegments[1:]: ifsnakePosition[0]==snakeBody[0]andsnakePosition[1]==snakeBody[1]: gameOver(playSurface) #控制游戏速度 fpsClock.ti

2021-10-09T20:31:41 点赞:0

谁会做一些比较好玩的游戏。 中回复

#!/usr/bin/envpython importpygame,sys,time,random frompygame.localsimport* #定义颜色变量 redColour=pygame.Color(255,0,0) blackColour=pygame.Color(0,0,0) whiteColour=pygame.Color(255,255,255) greyColour=pygame.Color(150,150,150) #定义gameOver函数 defgameOver(playSurface): gameOverFont=pygame.font.Font('arial.ttf',72) gameOverSurf=gameOverFont.render('GameOver',True,greyColour) gameOverRect=gameOverSurf.get_rect() gameOverRect.midtop=(320,10) playSurface.blit(gameOverSurf,gameOverRect) pygame.display.flip() time.sleep(5) pygame.quit() sys.exit() #定义main函数 defmain(): #初始化pygame pygame.init() fpsClock=pygame.time.Clock() #创建pygame显示层 playSurface=pygame.display.set_mode((喵0,480)) pygame.display.set_caption('RaspberrySnake') #初始化变量 snakePosition=[100,100] snakeSegments=[[100,100],[80,100],[60,100]] raspberryPosition=[300,300] raspberrySpawned=1 direction='right' changeDirection=direction whileTrue: #检测例如按键等pygame事件 foreventinpygame.event.get(): ifevent.type==QUIT: pygame.quit() sys.exit() elifevent.type==KEYDOWN: #判断键盘事件 ifevent.key==K_RIGHTorevent.key==ord('d'): changeDirection='right' ifevent.key==K_LEFTorevent.key==ord('a'): changeDirection='left' ifevent.key==K_UPorevent.key==ord('w'): changeDirection='up' ifevent.key==K_DOWNorevent.key==ord('s'): changeDirection='down' ifevent.key==K_ESCAPE: pygame.event.post(pygame.event.Event(QUIT)) #判断是否输入了反方向 ifchangeDirection=='right'andnotdirection=='left': direction=changeDirection ifchangeDirection=='left'andnotdirection=='right': direction=changeDirection ifchangeDirection=='up'andnotdirection=='down': direction=changeDirection ifchangeDirection=='down'andnotdirection=='up': direction=changeDirection #根据方向移动蛇头的坐标 ifdirection=='right': snakePosition[0]+=20 ifdirection=='left': snakePosition[0]-=20 ifdirection=='up': snakePosition[1]-=20 ifdirection=='down': snakePosition[1]+=20 #增加蛇的长度 snakeSegments.insert(0,list(snakePosition)) #判断是否吃掉了树莓 ifsnakePosition[0]==raspberryPosition[0]andsnakePosition[1]==raspberryPosition[1]: raspberrySpawned=0 else: snakeSegments.pop() #如果吃掉树莓,则重新生成树莓 ifraspberrySpawned==0: x=random.randrange(1,32) y=random.randrange(1,24) raspberryPosition=[int(x*20),int(y*20)] raspberrySpawned=1 #绘制pygame显示层 playSurface.fill(blackColour) forpositioninsnakeSegments: pygame.draw.rect(playSurface,whiteColour,Rect(position[0],position[1],20,20)) pygame.draw.rect(playSurface,redColour,Rect(raspberryPosition[0],raspberryPosition[1],20,20)) #刷新pygame显示层 pygame.display.flip() #判断是否喵 ifsnakePosition[0]>620orsnakePosition[0]<0: gameOver(playSurface) ifsnakePosition[1]>460orsnakePosition[1]<0: forsnakeBodyinsnakeSegments[1:]: ifsnakePosition[0]==snakeBody[0]andsnakePosition[1]==snakeBody[1]: gameOver(playSurface) #控制游戏速度 fpsClock.ti

2021-10-09T20:32:22 点赞:0

快和我组队吧,我从七岁开始学到十岁了,学了三年了,求组队 中回复

我,我差不多4年前就开始玩codemao了。

2021-10-09T20:34:43 点赞:0