马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这个的文件在下方…………(有python+pygame就可以运行)
# -*- coding: utf-8 -*-
windows_size = (640,480)
#窗口的大小
background_image_file = 'sushiplate.jpg'
ball_image_file = 'ball.png'
grard_image_file = 'Guard.png'
#文件名称
grard_x = 0
grard_y = windows_size[1]-40
ball_x,ball_y = 1,1
right = 5
down = 5
mun = 0
#变量定义
import pygame
from pygame.locals import *
from sys import exit
from time import sleep
#导入模块
pygame.init()
pygame.mixer.init()
#初始化
screen = pygame.display.set_mode(windows_size,0,32)
my_font = pygame.font.Font(".\\arial.ttf", 40)
text_font = my_font.render("score:%d"%mun,True,(0,0,255))
#创建窗口,字体对象
background = pygame.image.load(background_image_file).convert_alpha()
ball = pygame.image.load(ball_image_file).convert()
grard = pygame.image.load(grard_image_file).convert()
pygame.mixer.music.load('.\\卡路里.mp3')
pygame.mixer.music.play(-1,250)
#加载图片,播放音乐
while True:
#游戏主循环
text_font = my_font.render(u"score: %d"%mun,True,(0,0,255))
#初始化字体
for event in pygame.event.get():
#处理事件
if event.type == QUIT:
#退出
exit()
elif event.type == KEYDOWN:
if event.key == K_LEFT:
#挡板向左移动10个像素
grard_x -= 20
elif event.key == K_RIGHT:
#挡板向右移动10个像素
grard_x += 20
screen.blit(background,(0,0))
screen.blit(ball,(ball_x,ball_y))
screen.blit(grard,(grard_x,grard_y))
screen.blit(text_font,(400,0))
#显示桌面、小球和挡板还有字体
if ball_x > screen.get_width()-20 or ball_x<0:
right = -right
if ball_y > screen.get_height()-20 or ball_y<0:
down = -down
#向量
ball_x = ball_x+right
ball_y = ball_y+down
#小球的x, y 变化
if ball_x >= grard_x and ball_x <= grard_x+grard.get_width()\
and ball_y >= grard_y and ball_y <= grard_y+grard.get_height():
#如果碰到挡板
down = -down
mun += 1
pygame.display.flip()
#更新界面
sleep(0.01)
#进程睡眠0.01
资源在下方(音乐自己找下…………)
|