import random
import pygame
from objects import Tile, Player, SkullCircle, Particle, Message, BlinkingText, Button
pygame.init()
SCREEN = WIDTH, HEIGHT = 288, 512
CENTER = WIDTH //2, HEIGHT // 2
info = pygame.display.Info()
width = info.current_w
height = info.current_h
if width >= height:
win = pygame.display.set_mode(SCREEN, pygame.NOFRAME)
else:
win = pygame.display.set_mode(SCREEN, pygame.NOFRAME | pygame.SCALED | pygame.FULLSCREEN)
clock = pygame.time.Clock()
FPS = 60
# COLORS **********************************************************************
RED = (255,0,0)
GREEN = (0,177,64)
BLUE = (30, 144,255)
ORANGE = (252,76,2)
YELLOW = (254,221,0)
PURPLE = (155,38,182)
AQUA = (0,103,127)
WHITE = (255,255,255)
BLACK = (0,0,0)
GRAY = (32, 32, 32)
color_list = [RED, GREEN, BLUE, ORANGE, YELLOW, PURPLE]
color_index = 0
color = color_list[color_index]
death_color_list = [BLUE, ORANGE, YELLOW, PURPLE, RED, GREEN]
death_color_index = 0
death_color = death_color_list[color_index]
# FONTS ***********************************************************************
title_font = "Fonts/Aladin-Regular.ttf"
tap_to_play_font = "Fonts/BubblegumSans-Regular.ttf"
score_font = "Fonts/DalelandsUncialBold-82zA.ttf"
game_over_font = "Fonts/ghostclan.ttf"
HyperTile = Message(WIDTH//2, HEIGHT//2-20, 50, "HyperTiles", title_font, BLUE, win)
dash = Message(WIDTH//2+40, HEIGHT//2+40, 50, "Dash...", title_font, GREEN, win)
tap_to_play = BlinkingText(WIDTH//2, HEIGHT-50, 20, "Tap To Play", tap_to_play_font, WHITE, win)
score_msg = Message(WIDTH//2, HEIGHT//2, 50, "0", score_font, (100, 100, 100), win)
final_score = Message(WIDTH//3, HEIGHT//2 - 20, 90, "0", score_font, WHITE, win)
best_msg = Message(WIDTH//2 + 45, HEIGHT//2 - 40, 25, "BEST", None, WHITE, win)
high_score_msg = Message(WIDTH//2 + 35, HEIGHT//2 - 5, 35, "0", None, WHITE, win)
# SOUNDS **********************************************************************
target_tile_fx = pygame.mixer.Sound('Sounds/target.mp3')
empty_tile_fx = pygame.mixer.Sound('Sounds/empty.mp3')
deadly_tile_fx = pygame.mixer.Sound('Sounds/dead.mp3')
dash_fx = pygame.mixer.Sound('Sounds/dash.mp3')
score_page_fx = pygame.mixer.Sound('Sounds/score_page.mp3')
pygame.mixer.music.load('Sounds/cbpd.mp3')
pygame.mixer.music.play(loops=-1)
pygame.mixer.music.set_volume(0.5)
# Button images
home_img = pygame.image.load('Assets/homeBtn.png')
replay_img = pygame.image.load('Assets/replay.png')
sound_off_img = pygame.image.load("Assets/soundOffBtn.png")
sound_on_img = pygame.image.load("Assets/soundOnBtn.png")
# Buttons
home_btn = Button(home_img, (24, 24), WIDTH // 4 - 18, HEIGHT//2 + 50)
replay_btn = Button(replay_img, (36,36), WIDTH // 2 - 18, HEIGHT//2 + 45)
sound_btn = Button(sound_on_img, (24, 24), WIDTH - WIDTH // 4 - 18, HEIGHT//2 + 50)
# OBJECTS *********************************************************************
tile_group = pygame.sprite.Group()
for i in range(8):
tile = Tile(i, 1, win)
tile_group.add(tile)
tile = Tile(i, 2, win)
tile_group.add(tile)
particle_group = pygame.sprite.Group()
skull_group = pygame.sprite.Group()
p = Player(win, tile_group)
# FUNCTIONS *******************************************************************
deadly_tiles_list = []
def get_index():
if p.tile_type == 1:
indices = [2*index+1 for index in range(8)]
elif p.tile_type == 2:
indices = [2*index for index in range(8)]
index = random.choice(indices)
return index
def generate_target_tile(color):
for tile in tile_group:
if not tile.is_deadly_tile:
tile.color = WHITE
tile.is_target_tile = False
index = get_index()
tile = tile_group.sprites()[index]
if tile.is_deadly_tile:
generate_target_tile(color)
else:
tile.color = color
tile.is_target_tile = True
return tile
def generate_deadly_tile(color):
for tile in tile_group:
if tile.is_deadly_tile:
tile.color = color
index = get_index()
tile = tile_group.sprites()[index]
if tile.is_target_tile:
generate_deadly_tile(color)
else:
if tile.is_deadly_tile:
generate_deadly_tile(color)
else:
tile.color = color
tile.is_deadly_tile = True
deadly_tiles_list.append(tile)
clicked = False
num_clicks = 0
index = None
target_tile = None
auto_generate_deadly_tile = True
player_alive = True
score = 0
highscore = 0
sound_on = True
home_page = True
game_page = False
score_page = False
running = True
while running:
win.fill(GRAY)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE or \
event.key == pygame.K_q:
running = False
if event.type == pygame.MOUSEBUTTONDOWN and home_page:
home_page = False
game_page = True
score_page = False
player_alive = True
p.reset()
p.reset_path_variables()
for tile in tile_group:
tile.color = WHITE
if event.type == pygame.MOUSEBUTTONDOWN and game_page:
if not clicked:
if p.can_move:
dash_fx.play()
index = p.path_index
tile = p.path_target_tile
x = p.path_x
y = p.path_y
p.set_move(x, y, index)
num_clicks += 1
if num_clicks % 5 == 0:
color_index += 1
if color_index > len(color_list) - 1:
color_index = 0
color = color_list[color_index]
death_color_index += 1
if death_color_index > len(death_color_list) - 1:
death_color_index = 0
death_color = death_color_list[death_color_index]
for tile in deadly_tiles_list:
tile.color = death_color
if event.type == pygame.MOUSEBUTTONDOWN:
clicked = False
if home_page:
tile_group.update()
HyperTile.update()
dash.update()
tap_to_play.update()
if score_page:
tile_group.update()
final_score.update(score, color)
best_msg.update()
high_score_msg.update(highscore)
if home_btn.draw(win):
home_page = True
score_page = False
game_page = False
score = 0
score_msg = Message(WIDTH//2, HEIGHT//2, 50, f'{score}', score_font, (100, 100, 100), win)
if replay_btn.draw(win):
home_page = False
score_page = False
game_page = True
score = 0
score_msg = Message(WIDTH//2, HEIGHT//2, 50, f'{score}', score_font, (100, 100, 100), win)
player_alive = True
p.reset()
p.reset_path_variables()
for tile in tile_group:
tile.color = WHITE
if sound_btn.draw(win):
sound_on = not sound_on
if sound_on:
sound_btn.update_image(sound_on_img)
pygame.mixer.music.play(loops=-1)
else:
sound_btn.update_image(sound_off_img)
pygame.mixer.music.stop()
if game_page:
if p.first_tile and auto_generate_deadly_tile:
target_tile = generate_target_tile(color)
generate_deadly_tile(death_color)
auto_generate_deadly_tile = False
if score and score % 3 == 0 and len(skull_group) == 0 and player_alive:
type_ = random.randint(1, 2)
print(type_)
y = random.randint(200, HEIGHT - 190)
if type_ == 1:
x = 0
elif type_ == 2:
x = WIDTH + 5
skull = SkullCircle(x, y, type_, death_color, win)
skull_group.add(skull)
score_msg.update(score)
particle_group.update()
skull_group.update()
p.update(color, player_alive)
tile_group.update()
if pygame.sprite.spritecollide(p, skull_group, False) and player_alive:
deadly_tile_fx.play()
x, y = p.x, p.y
for i in range(20):
particle = Particle(x, y, color, win)
particle_group.add(particle)
player_alive = False
skull_group.empty()
if player_alive:
for tile in tile_group:
collision = tile.check_collision(p)
if collision and target_tile:
if tile.is_deadly_tile:
deadly_tile_fx.play()
for i in range(30):
particle = Particle(x, y, color, win)
particle_group.
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
game.zip (19个子文件)
HyperTile Dash
main.py 9KB
objects.py 8KB
Assets
skull.png 443B
soundOffBtn.png 3KB
homeBtn.png 7KB
soundOnBtn.png 5KB
replay.png 8KB
Sounds
score_page.mp3 38KB
target.mp3 24KB
empty.mp3 14KB
cbpd.mp3 3.03MB
dash.mp3 11KB
dead.mp3 15KB
Fonts
Aladin-Regular.ttf 41KB
ghostclan.ttf 25KB
DalelandsUncialBold-82zA.ttf 51KB
BubblegumSans-Regular.ttf 38KB
__pycache__
objects.cpython-310.pyc 10KB
objects.cpython-39.pyc 10KB
共 19 条
- 1
资源评论
听风吹等浪起
- 粉丝: 1w+
- 资源: 1012
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功