Commit 1357f88c by BellCodeEditor

save project

parent e273e0b5
i=1
a=2
b=3
c=4
print("i"+")
\ No newline at end of file
import pygame
from pygame import locals
# 初始化pygame,为使用pygame做准备
pygame.init()
background=pygame.image.load('c:/Users/pc/Desktop/test、/bg.png')
right=pygame.image.load('c:/Users/pc/Desktop/test、/right.png')
apple=pygame.image.load('c:/Users/pc/Desktop/test、/apple.png')
body=pygame.image.load('c:/Users/pc/Desktop/test、/body.png')
left=pygame.image.load('c:/Users/pc/Desktop/test、/left.png')
up=pygame.image.load('c:/Users/pc/Desktop/test、/up.png')
down=pygame.image.load('c:/Users/pc/Desktop/test、/down.png')
# 创建一个窗口
screen=pygame.display.set_mode((660,480))
FPSCLOCK=pygame.time.Clock()
x,y=240,120
position=[(180,90),(180,120),(210,120),(200,100),(320,123),(222,111),(x,y)]
setheading="right"
snake_head=right
while True:
for event in pygame.event.get():
if event.type==locals.QUIT:
#接收到退出事件后退出程序
exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
setheading = 'right'
snake_head=right
elif event.key == pygame.K_LEFT:
setheading = 'left'
snake_head=left
elif event.key == pygame.K_UP:
setheading = 'up'
snake_head=up
elif event.key == pygame.K_DOWN:
setheading = 'down'
snake_head=down
if setheading=="right":
x+=30
elif setheading=="left":
x-=30
elif setheading=="up":
y-=30
else:
y+=30
position.append((x,y))
position.pop(0)
screen.blit(background,(0,0))
screen.blit(up,(x,y))
for i in range(len(position)-1):
screen.blit(apple,position[i])
# screen.blit(body,(210,120))
# screen.blit(body,(180,120))
# screen.blit(body,(180,90))
screen.blit(apple,(360,360))
pygame.display.update()
FPSCLOCK.tick(10)
apple.png

2.05 KB

bg.png

22.5 KB

body.png

1.4 KB

down.png

2.01 KB

left.png

2.07 KB

File added
right.png

2.05 KB

import pygame
from pygame import locals
import random
import time
# 初始化pygame,为使用pygame做准备
pygame.init()
# 创建一个窗口
a = 660
b = 480
screen = pygame.display.set_mode((a,b))
pygame.display.set_caption('炸药蛇')
bg = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
body = pygame.image.load('body.png')
apple = pygame.image.load('apple.png')
x,y = 240,180
position= [(240,90),(240,120),(240,150),(x,y)]
clock = pygame.time.Clock()
FPS = 3
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
x += 30
position.append((x,y))
position.pop(0)
screen.blit(bg,(0,0))
screen.blit(right,position[-1])
screen.blit(apple,(300,400))
for i in range(len(position)-1):
screen.blit(body,position[i])
clock.tick(FPS)
pygame.display.update()
\ No newline at end of file
up.png

2.05 KB

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment