居中的waiting for

本文详细解析了一段CSS代码,该代码定义了一个名为#loading的绝对定位元素,用于展示页面加载时的效果。通过设置背景颜色及图片,实现了加载指示器的功能,并调整了透明度和字体样式。

#loading
{
    position:fixed !important;
 position:absolute;
 top:0;
 left:0;
 height:100%;
 width:100%;
 z-index:999;
 background:#DFFFFF url(images/load.gif) no-repeat center center;
 opacity:0.3;
 filter:alpha(opacity=60);
 font-size:14px;
 line-height:20px;
}
#loading-one
{
    color:#000;
 position:absolute;
 top:50%;
 left:50%;
 margin:20px 0 0 -50px;
 padding:3px 10px;
}

import pygame from pygame.locals import *# import math import random pygame.init() # =========== 初始化界面 =========== def show_start_screen(): global running start_screen_img = pygame.image.load("resources/images/start_screen.png") # 加载启动界面图片 start_screen_img = pygame.transform.scale(start_screen_img, (width, height)) # 调整图片大小以适配窗口 waiting_for_start = True while waiting_for_start: screen.blit(start_screen_img, (0, 0)) # 绘制启动界面 # 添加文字提示 font = pygame.font.Font("resources/fonts/MONACO.TTF", 36) start_text = font.render("按任意键开始游戏", True, (255, 255, 255)) text_rect = start_text.get_rect(center=(width // 2, height // 2 + 100)) screen.blit(start_text, text_rect) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit(0) if event.type == pygame.KEYDOWN: # 检测任意键按下 waiting_for_start = False # =========== game =========== running = True game_over = False score = 0 last_second = 0 time_interval = 3 # 设置固定帧率 FPS = 60 clock = pygame.time.Clock() width, height = 640, 480 screen = pygame.display.set_mode((width, height), 0, 32) pygame.display.set_caption('FlappyBird') background_img = pygame.image.load("resources/images/background.png") gameover_img = pygame.image.load("resources/images/gameover.png") jump_msc = pygame.mixer.Sound("resources/audios/jump.wav") jump_msc.set_volume(0.5) pygame.mixer.music.load('resources/audios/moonlight.wav') pygame.mixer.music.play(-1, 0.0) pygame.mixer.music.set_volume(1.0) # =========== game =========== # =========== pipe =========== pipe_body_img = pygame.image.load("resources/images/pipe_body.png") pipe_head_img = pygame.image.load("resources/images/pipe_head.png") body_hight = pipe_body_img.get_height() head_hight = pipe_head_img.get_height() body_width = pipe_body_img.get_width() head_width = pipe_head_img.get_width() max_n = (height - 2 * head_hight) // body_hight gap_n = 12 # =========== pipe =========== # =========== bird =========== bird_img = pygame.image.load("resources/images/bird.png") down_speed = 200 angle_speed = 300 angle_max = 15 jump_speed = 200 jump_height = 12 # =========== bird =========== class Bird(): def __init__(self): self.angle = 0 self.x = 150 self.y = (height - bird_img.get_height()) / 2.0 self.cur_jump_height = 0 self.is_jumping = False def draw(self): rotate_image = pygame.transform.rotate(bird_img, self.angle) delta_width = (rotate_image.get_rect().width - bird_img.get_rect().width) / 2 delta_height = (rotate_image.get_rect().height - bird_img.get_rect().height) / 2 (draw_x, draw_y) = (self.x - delta_width, self.y - delta_height) screen.blit(rotate_image, (draw_x, draw_y)) def die(self, time_passed): global running if self.angle > -angle_max: self.angle -= angle_speed * time_passed if self.angle <= -angle_max: self.angle = -angle_max self.draw() return self.y += down_speed * time_passed self.draw() if self.y >= height: screen.blit(gameover_img, (0,0)) running = False def update(self, time_passed): global game_over if self.is_jumping: if self.angle < angle_max: self.angle += time_passed * angle_speed if self.angle >= angle_max: self.angle = angle_max self.draw() return if self.cur_jump_height < jump_height: self.cur_jump_height += time_passed * jump_speed self.y -= self.cur_jump_height if self.y <= 0: game_over = True self.draw() return self.cur_jump_height = 0 self.is_jumping = False if self.angle > -angle_max: self.angle -= angle_speed * time_passed if self.angle <= -angle_max: self.angle = -angle_max self.draw() return self.y += down_speed * time_passed if self.y >= height: game_over = True return self.draw() class Pipe(): def __init__(self): self.x = 600 self.speed = 80 self.random_n = random.randint(0, max_n - gap_n) self.up_n = self.random_n self.down_n = max_n - self.up_n - gap_n self.appearance = [] self.added = False self.construct() def construct(self): for i in range(self.up_n): self.appearance.append((0, i * body_hight, pipe_body_img)) self.appearance.append((-(head_width - body_width) // 2, self.up_n * body_hight, pipe_head_img)) for i in range(self.down_n): self.appearance.append((0, height - (i + 1) * body_hight, pipe_body_img)) self.appearance.append((-(head_width - body_width) // 2, height - self.down_n * body_hight - head_hight, pipe_head_img)) def update(self, time_passed): global score self.x -= time_passed * self.speed if not self.added: if self.x + (head_width - body_width) // 2 + body_width <= bird.x: score += 1 self.added = True self.draw() def draw(self): for a in self.appearance: screen.blit(a[2], (self.x + a[0], a[1])) def collide_with_bird(self, bird): bird_rect = pygame.Rect(bird_img.get_rect()) bird_rect.topleft = (bird.x, bird.y) for a in self.appearance: pipe_rect = pygame.Rect(a[2].get_rect()) pipe_rect.left = self.x + a[0] pipe_rect.top = a[1] if pipe_rect.colliderect(bird_rect): return True return False def draw_background_img(): for x in range(width // background_img.get_width() + 1): for y in range(height // background_img.get_height() + 1): screen.blit(background_img, (x * background_img.get_width(), y * background_img.get_height())) def draw_text(text): font = pygame.font.Font("resources/fonts/MONACO.TTF", 24) survivedtext = font.render(str(text), True, (0, 0, 0)) textRect = survivedtext.get_rect() textRect.topleft = [10, 10] screen.blit(survivedtext, textRect) pipes = [] bird = Bird() while running: screen.fill(0) draw_background_img() draw_text(score) time_passed = clock.tick(FPS) / 1000.0 if game_over: for p in pipes: p.update(0) bird.die(time_passed) pygame.display.flip() continue currend_second = pygame.time.get_ticks() // 1000 if currend_second - last_second >= time_interval: last_second = currend_second pipes.append(Pipe()) bird.update(time_passed) for p in pipes: p.update(time_passed) pygame.display.flip() index = 0 for p in pipes: if p.x + (head_width - body_width) // 2 + body_width <= 0: pipes.pop(index) elif p.collide_with_bird(bird): game_over = True index += 1 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit(0) if event.type == pygame.KEYDOWN: if event.key == K_SPACE: jump_msc.play() bird.cur_jump_height = 0 bird.is_jumping = True # 在主循环之前调用启动界面 show_start_screen() # 主游戏循环 while running: screen.fill(0) draw_background_img() draw_text(score) time_passed = clock.tick(FPS) / 1000.0 if game_over: for p in pipes: p.update(0) bird.die(time_passed) pygame.display.flip() continue current_second = pygame.time.get_ticks() // 1000 if current_second - last_second >= time_interval: last_second = current_second pipes.append(Pipe()) bird.update(time_passed) for p in pipes: p.update(time_passed) pygame.display.flip() index = 0 for p in pipes: if p.x + (head_width - body_width) // 2 + body_width <= 0: pipes.pop(index) elif p.collide_with_bird(bird): game_over = True index += 1 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit(0) if event.type == pygame.KEYDOWN: if event.key == K_SPACE: jump_msc.play() bird.cur_jump_height = 0 bird.is_jumping = True # 游戏结束后的无限循环 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit(0) pygame.display.flip() 修改代码
06-04
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值