Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pygame缩放健康栏_Python_Math_Pygame_2d Games - Fatal编程技术网

Python Pygame缩放健康栏

Python Pygame缩放健康栏,python,math,pygame,2d-games,Python,Math,Pygame,2d Games,我正在开发一款类似RPG的游戏,在这个游戏中,你的生命值可以持续提高 我正在尝试制作一个脚本,它将为超过100的值绘制一个100像素宽的健康条 随着你的健康水平的提高,健康栏的单位会变小 这是我能想到的最好的: #Draw Bar import pygame def SingleColorBar(surface,color,x,y,value,maxvalue): xx=0 for hp in range(value): pygame.draw.rect(sur

我正在开发一款类似RPG的游戏,在这个游戏中,你的生命值可以持续提高

我正在尝试制作一个脚本,它将为超过100的值绘制一个100像素宽的健康条

随着你的健康水平的提高,健康栏的单位会变小

这是我能想到的最好的:

#Draw Bar
import pygame

def SingleColorBar(surface,color,x,y,value,maxvalue):
    xx=0
    for hp in range(value):
        pygame.draw.rect(surface, color, (x+xx,y,1,32), 0)
        xx+= value/100

这根本没有达到预期效果

您可以将当前的HP转换为最大HP的比率,然后将矩形绘制为许多像素宽

int(max(min(currentHP / float(maxHP) * health_bar_width, health_bar_width), 0))

这将为您提供一个整数百分比,介于0和健康栏像素宽度之间,这样您就不会透支

工作得很好!谢谢你,先生!