鱼C论坛

 找回密码
 立即注册
查看: 1806|回复: 3

[新人报道] 贪吃蛇

[复制链接]
发表于 2020-5-22 14:36:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import pygame
import sys
from pygame.locals import *
import random

pygame.init()
white=(255,255,255)
bg=(255,255,255)
black=(0,0,0)

left=50
top=50
speed = [-2, 1]

size = width,height = 640,640
screen = pygame.display.set_mode(size)
pygame.display.set_caption('贪吃蛇')

clock=pygame.time.Clock()
rectangle=pygame.draw.rect(screen,black,(left,top,50,50),1)


while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit(0)

        if event.type == KEYDOWN:
            if event.key == K_LEFT:
                speed = [-5, 0]

            if event.key == K_RIGHT:
                speed = [5, 0]

            if event.key == K_UP:
                speed = [0, -5]

            if event.key == K_DOWN:
                speed = [0, 5]

    if left < 0 or left > 590:
        # 翻转图像
        
        # 反方向移动
        speed[0] = -speed[0]
        speed[1] = -speed[1]

    if top < 0 or top > 590:
        speed[0] = -speed[0]
        speed[1] = -speed[1]

    '''screen.fill(white)
    
    pygame.draw.rect(screen,black,(left,top,50,50),1)'''
    left=left+speed[0]
    top=top+speed[1]

    screen.fill(bg)
    # 更新图像
    pygame.draw.rect(screen,black,(left,top,50,50),1)
    # 更新界面
    pygame.display.flip()
    # 延迟10毫秒
    pygame.time.delay(30)
貌似忽然间发现了贪吃蛇的雏形

评分

参与人数 1鱼币 +1 收起 理由
aaron.yang + 1 无条件支持楼主!

查看全部评分

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-5-22 14:55:58 | 显示全部楼层
你是原创??
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-5-22 14:58:37 | 显示全部楼层

呃,哥们,这还不是成型的游戏,只是贪吃蛇的一个小部分的功能模块,原创也不失我,是小甲鱼。哈哈哈哈
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-6-17 20:55:17 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-7-6 16:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表