我正在学习在pygame中编码。还有一项任务是将星星散布到整个屏幕上。
我已经完成了代码,但是它只在屏幕的左上角散布星星,而且我真的不知道如何在整个屏幕上放置星星。这段代码为传播提供了答案:
private void checkAndRemove(int position, String name) {
if(selectionMap.containsKey(position)){
selectionMap.remove(position);
}else {
selectionMap.put(position, name);
}
}
答案 0 :(得分:1)
除非我缺少任何东西,否则不应该是:
def create_star(screen, custom_settings, number, row_number, stars):
star = Star(screen, custom_settings)
w, h = pygame.display.get_surface().get_size()
x = randint(0, w)
star.rect.x = x
y = randint(0, h)
star.rect.y = y
stars.add(star) #added stars
if len(stars) > 50: #limiter of the star adding
stars.remove(star)
else:
stars.add(star)