- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我一直在尝试制作片尾画面,但我知道怎么做,我看过一些教程,但对我来说没有一个真正有意义。我也尝试过使用我的开始屏幕,但将其调高一点并将其放在不同的位置,但它不起作用。我正在尝试在我的播放器与我的其中一个平台发生碰撞时显示结束屏幕,但我不知道如何制作结束屏幕。
I do not know what to really put here but this is my start screen code
##############################################
#START MENUE
def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()
def button(msg,x,y,w,h,ic,ac,action=None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
#print(click)
if x+w > mouse[0] > x and y+h > mouse[1] > y:
pygame.draw.rect(window, ac,(x,y,w,h))
if click[0] == 1 and action != None:
action()
else:
pygame.draw.rect(window, ic,(x,y,w,h))
smallText = pygame.font.SysFont("comicsansms",20)
textSurf, textRect = text_objects(msg, smallText)
textRect.center = ( (x+(w/2)), (y+(h/2)) )
window.blit(textSurf, textRect)
def quitgame():
pygame.quit()
def game_intro():
intro = True
while intro:
for event in pygame.event.get():
#print(event)
if event.type == pygame.QUIT:
pygame.quit()
quit()
window.fill((255,255,255))
largeText = pygame.font.Font('freesansbold.ttf',115)
TextSurf, TextRect = text_objects("Jump", largeText)
TextRect.center = ((500/2),(500/2))
window.blit(TextSurf, TextRect)
button("GO!",100,350,100,50,green,darkgreen,main_loop)
button("Quit",300,350,100,50,orange,darkred,quitgame)
pygame.display.update()
clock.tick(15)
############################################
my Full code
import pygame
import time
import random
pygame.init()
#this is screem height
window = pygame.display.set_mode((500,500))
#know we put screem name
pygame.display.set_caption("Noobs first Game")
bg = pygame.image.load("New.png")
gg = pygame.image.load("lol.png")
Rule2 = pygame.image.load("one1.png")
Rule1 = pygame.image.load("two2.png")
Rule3 = pygame.image.load("three3.png")
Rule4 = pygame.image.load("four4.png")
Rule5 = pygame.image.load("five5.png")
Rule6 = pygame.image.load("six6.png")
#player class
class player:
def __init__(self,x,y,width,height,color):
self.x = x
self.y = y
self.width = width
self.height = height
self.color = color
self.speed = 5
self.isJump = False
self.JumpCount = 10
self.fall = 0
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
pygame.draw.rect(window,self.color,self.rect)
class platform:
def __init__(self,x,y,width,height,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.rect = pygame.Rect(x,y,height,width)
self.ss1 = pygame.image.load("Rock.png")
self.ss1 = pygame.transform.scale(self.ss1,(self.ss1.get_width()//2,self.ss1.get_height()//2))
self.hitbox = (self.x + 20 , self.y,58,60)
def draw(self):
self.rect.topleft=(self.x,self.y)
player_rect = self.ss1.get_rect(center = self.rect.center)
player_rect.centerx += 70
player_rect.centery += 88
window.blit(self.ss1,player_rect)
self.hitbox = (self.x + 20 , self.y,58,60)
class item:
def __init__(self,x,y,width,height,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.rect = pygame.Rect(x,y,height,width)
self.ss1 = pygame.image.load("H6.png")
self.ss1 = pygame.transform.scale(self.ss1,(self.ss1.get_width()//2,self.ss1.get_height()//2))
def draw(self):
self.rect.topleft = (self.x,self.y)
window.blit(self.ss1,self.rect)
class wall:
def __init__(self,x,y,width,height,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
pygame.draw.rect(window,self.color,self.rect)
#draw player
white = (255,255,255)
player1 = player(255,400,30,30,white)
darkred = (200,0,0)
darkgreen = (0,200,0)
black = (0,0,0)
item1 = item(200,-500,50,50,white)
item2 = item(250,250,50,50,white)
item3 = item(330,-1030,50,50,white)
item4 = item(400,-2290,50,50,white)
item5 = item(300,-1600,50,50,white)
item6 = item(200,130,50,50,white)
item7 = item(230,-1830,50,50,white)
item8 = item(300,0,50,50,white)
item9 = item(330,-1440,50,50,white)
item10 = item(20,-160,50,50,white)
items = [item1,item2,item3,item4,item5,item6,item7,item8,item9,item10]
green = (0,255,0)
orange = (255,0,0)
platform1 = platform(100,300,10,60,orange)
platform2 = platform(5,200,10,60,orange)
platform3 = platform(5,400,10,60,orange)
platform4 = platform(100,100,10,60,orange)
platform5 = platform(5,-50,10,60,orange)
platform6 = platform(100,-200,10,60,orange)
platform7 = platform(5,400,60,600,orange)
platform8 = platform(300,-2430,10,60,orange)
platform9 = platform (350,-340,10,60,orange)
platform10 = platform (100,-470,10,60,orange)
platform13 = platform(330,-600,10,60,orange)
platform14 = platform(100,-790,10,60,orange)
platform15 = platform(330,-990,10,60,orange)
platform16 = platform(70,-1130,10,60,orange)
platform17 = platform(200,-1340,10,60,orange)
platform18 = platform(400,-1500,10,60,orange)
platform19 = platform(300,-1700,10,60,orange)
platform20 = platform(100,-1950,10,60,orange)
platform21 = platform (350,-2140,10,60,orange)
platform22 = platform (100,-2270,10,60,orange)
platform23 = platform(0,-2500,60,500,green)
#walls
platform11 = wall (485,-9600,10000,10,orange)
platform12 = wall (0,-9600,10000,10,orange)
wall1 = wall (0,400,60,500,orange)
wall2 = wall (0,-2500,60,500,green)
wall3 = wall (485,-9600,10000,10,orange)
wall4 = wall (0,-9600,10000,10,orange)
walls = [wall1,wall2]
platforms = (platform1,platform2,platform3,platform4,platform5,platform6,platform7,platform8,platform9,platform10,platform13,platform14,platform15,platform16,platform17,platform18,platform19,platform20,platform21,platform22,platform23)
fps = (60)
clock = pygame.time.Clock()
##############################################
#START MENUE
def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()
def button(msg,x,y,w,h,ic,ac,action=None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
#print(click)
if x+w > mouse[0] > x and y+h > mouse[1] > y:
pygame.draw.rect(window, ac,(x,y,w,h))
if click[0] == 1 and action != None:
action()
else:
pygame.draw.rect(window, ic,(x,y,w,h))
smallText = pygame.font.SysFont("comicsansms",20)
textSurf, textRect = text_objects(msg, smallText)
textRect.center = ( (x+(w/2)), (y+(h/2)) )
window.blit(textSurf, textRect)
def quitgame():
pygame.quit()
def game_intro():
intro = True
while intro:
for event in pygame.event.get():
#print(event)
if event.type == pygame.QUIT:
pygame.quit()
quit()
window.fill((255,255,255))
largeText = pygame.font.Font('freesansbold.ttf',115)
TextSurf, TextRect = text_objects("Jump", largeText)
TextRect.center = ((500/2),(500/2))
window.blit(TextSurf, TextRect)
button("GO!",100,350,100,50,green,darkgreen,main_loop)
button("Quit",300,350,100,50,orange,darkred,quitgame)
pygame.display.update()
clock.tick(15)
############################################
def main_loop():
#window
def redrawwindow():
window.fill((0,0,0))
window.blit(bg,(0,0))
#draw plyer
player1.draw()
platform11.draw()
platform12.draw()
wall3.draw()
wall4.draw()
for platform in platforms:
platform.draw()
for wall in walls:
wall.draw()
# the score draw it on the screen
window.blit(text,textRect)
for item in items:
item.draw()
font = pygame.font.Font("freesansbold.ttf",30)
score = 0
text = font.render("Coins = "+str(score),True,(255,255,255))
textRect = text.get_rect()
textRect.center = ((100,40))
run = True
while run:
clock.tick(fps)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
#walls
if player1.rect.colliderect(platform11) and player1.rect.colliderect(platform12):
player1.x = 40
# this makes you scroll up
if player1.y < 250:
player1.y += 1
#platforms
for platform in platforms:
platform.y += player1.speed
for item in items:
item.y += player1.speed
for wall in walls:
wall.y += player1.speed
#walls
platform11.y += player1.speed
platform12.y += player1.speed
# this makes you scroll down
if player1.y > 450:
player1.y -= player1.fall
for platform in platforms:
platform.y -= player1.fall
platform11.y -= player1.fall
platform12.y -= player1.fall
for item in items:
item.y -= player1.fall
for wall in walls:
wall.y -= player1.fall
# coin collisions
for item in items:
for one in range(len(items)-1,-1,-1):
if player1.rect.colliderect(items[one].rect):
del items[one]
score += 1
text = font.render("Coins = "+str(score),True,(255,255,255))
textRect.center = ((100,40))
keys = pygame.key.get_pressed()
if keys[pygame.K_a]and player1.x > player1.speed:
player1.x -= player1.speed
if keys[pygame.K_d]and player1.x <500 - player1.height - player1.speed:
player1.x += player1.speed
if keys[pygame.K_w]and player1.y > player1.speed:
player1.y -= player1.speed
if keys[pygame.K_s]and player1.y <500 - player1.width - player1.speed:
player1.y += player1.speed
if not player1.isJump:
player1.y += player1.fall
player1.fall += 1
player1.isJump = False
collide = False
# this part lets you jump on platform
for platform in platforms:
if player1.rect.colliderect(platform.rect):
collide = True
player1.isJump = False
player1.y = platform.rect.top - player1.height + 1
if player1.rect.right > platform.rect.left and player1.rect.left < platform.rect.left - player1.width:
player1.x = platform.rect.left - player1.width
if player1.rect.left < platform.rect.right and player1.rect.right > platform.rect.right + player1.width:
player1.x = platform.rect.right
if player1.rect.bottom >= 500:
collide = True
player1.isJump = False
player1.JumpCount = 10
player1.y = 500 - player1.height
if collide:
if keys[pygame.K_SPACE]:
player1.isJump = True
player1.fall = 0
else:
if player1.JumpCount >= 0:
player1.y -= (player1.JumpCount*abs(player1.JumpCount))*0.3
player1.JumpCount -= 1
else:
player1.JumpCount = 10
player1.isJump = False
redrawwindow()
if player1.rect.colliderect(platform6):
window.blit(Rule3,(-150,-80))
if player1.rect.colliderect(platform2.rect):
window.blit(Rule1,(-30,0))
if player1.rect.colliderect(platform23.rect):
window.blit(gg,(100,100))
if player1.rect.colliderect(platform7.rect):
window.blit(Rule2,(-70,0))
if player1.rect.colliderect(platform1.rect):
window.blit(Rule4,(-40,100))
if player1.rect.colliderect(platform14.rect):
window.blit(Rule5,(-50,0))
if player1.rect.colliderect(platform17.rect):
window.blit(Rule6,(-50,0))
pygame.display.update()
pygame.quit()
game_intro()
main_loop()
最佳答案
这是一个可能会帮助您的框架。与上面的评论相同。您需要一个 bool 变量来跟踪何时显示结束屏幕(发生了不好的事情),然后使用它来决定在主循环中绘制哪个屏幕...
def redrawwindow():
# basically what you have now...
def draw_end_screen():
# make this new function such that it shows your end-screen
run=True
end_condition=False # a new boolean variable to keep track if collision (or something else happened)
while run:
# basically what you have now....
# check for collision (in pseudo-code) check for game-ending events
if player1.collides_with_death...:
end_condition=True
if player1.falls_into_pit()...:
end_condition=True
# use the boolean variable to decide what to do next, and in next loop
if end_condition:
draw_end_screen()
else:
redrawwindow()
pygame.display.update()
关于python - 当我的播放器类与我的平台类之一发生碰撞时,如何制作和结束屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63210196/
我正在编写一个类,我想知道哪一对方法更适合描述流程周期: start() -> stop() start() -> end() start() -> finish() 基本上这些方法将在执行任务之前和
对于 Android 小部件类名称是否应以“View”、“Layout”或两者都不结尾,是否存在模式或命名约定? 最佳答案 如果该类扩展了 View(或在其层次结构中扩展了 View),那么它应该以“
我正在尝试找到一个插件,该插件将使用 Verilog 突出显示匹配的开始/结束语句。 VIM 让它与花括号/括号一起工作,但它不能与它的开始/结束一起工作。我希望 VIM 突出显示正确的开始到正确的结
给出以下代码: % Generate some random data n = 10; A = cell(n, 1); for i=1:n A{i} = timeseries; A{i
我需要知道是否可以检测输入何时开始聚焦以及何时结束焦点 HTML 代码: JQuery 代码(仅示例我如何需要它): $('.datas').on('focusStart', alert("fo
所以我一直在思考一款游戏的想法,一款需要穿越时空的游戏。因此,我编写了一个 JFrame 来显示螺旋的 .gif,但它并没有在对话框显示时结束,而是保留在后台。我可以解决这个问题吗? import j
给出以下使用多线程的 Java 示例: import java.util.concurrent.*; public class SquareCalculator { private Ex
好吧,我有一个 do-while 循环,应该在使用点击“q”时结束,但它给了我错误消息,请帮忙。 package Assignments; import java.util.*; public cla
我如何有选择地匹配开始 ^或结束 $正则表达式中的一行? 例如: /(?\\1', $str); 我的字符串开头和结尾处的粗体边缘情况没有被匹配。我在使用其他变体时遇到的一些极端情况包括字符串内匹配、
我试图让程序在总数达到 10 时结束,但由于某种原因,我的 while 循环在达到 10 时继续计数。一旦回答了 10 个问题,我就有 int 百分比来查找百分比。 import java.util.
jQuery 中的 end() 函数将元素集恢复到上次破坏性更改之前的状态,因此我可以看到它应该如何使用,但我已经看到了一些代码示例,例如:on alistapart (可能来自旧版本的 jQuery
这个问题在这里已经有了答案: How to check if a string "StartsWith" another string? (18 个答案) 关闭 9 年前。 var file =
我正在尝试在 travis 上设置两个数据库,但它只是在 before_install 声明的中途停止: (END) No output has been received in the last 1
我创建了一个简单的存储过程,它循环遍历一个表的行并将它们插入到另一个表中。由于某种原因,END WHILE 循环抛出缺少分号错误。所有代码对我来说都是正确的,并且所有分隔符都设置正确。我只是不明白为什
您好,我正在使用 AVSpeechSynthesizer 和 AVSpeechUtterance 构建一个 iOS 7 应用程序,我想弄清楚合成何时完成。更具体地说,我想在合成结束时更改播放/暂停按钮
这是我的代码,我试图在响应后显示警报。但没有显示操作系统警报 string filepath = ConfigurationManager.AppSettings["USPPath"].ToStri
我想创建一个循环,在提供的时间段、第一天和最后一天返回每个月(考虑到月份在第 28-31 天结束):(“function_to_increase_month”尚未定义) for beg in pd.d
我目前正在用 Python 3.6 为一个骰子游戏编写代码,我知道我的编码在这方面有点不对劲,但是,我真的只是想知道如何开始我的 while 循环。游戏说明如下…… 人类玩家与计算机对战。 玩家 1
所以我已经了解了如何打开 fragment。这是我的困境。我的 view 旁边有一个元素列表(元素周期表元素)。当您选择一个元素时,它会显示它的信息。 我的问题是我需要能够从(我们称之为详细信息 fr
我想检测用户何时停止滚动页面/元素。这可能很棘手,因为最近对 OSX 滚动行为的增强创造了这种新的惯性效应。是否触发了事件? 我能想到的唯一其他解决方案是在页面/元素的滚动位置不再改变时使用间隔来拾取
我是一名优秀的程序员,十分优秀!