I have just finished my second Python game with pygame, but this time I'm facing a new problem. When I tried the game on another pc, the game speed was so fast, way faster than it was supposed to be, I tried to adjust the FPS but that didn't help. How could this be fixed and why is this even happening when I've already set all the settings like the moving speed and game FPS?
import pygame
from settings import Settings
import game_functions as gf
from ship import Ship
from pygame.sprite import Group
from game_stats import Stats
from animation import spriteSheet
from scoreboard import ScoreBoard
from button import Button
def run_game():
pygame.init()
icon = pygame.image.load('icons/icon.png')
pygame.display.set_icon(icon)
so_settings = Settings()
screen = pygame.display.set_mode((so_settings.screen_width, so_settings.screen_height))
pygame.display.set_caption('Space Vikers')
last_tick = 0
ship = Ship(screen, so_settings)
stats = Stats(so_settings, screen)
bullets = Group()
bullets_enemy = Group()
enemies = Group()
explosion = Group()
exploAni = spriteSheet("animations/explosion.png", 5, 4)
sb = ScoreBoard(so_settings, screen, stats, bullets, ship)
btn = Button(screen)
gf.start_background_music()
clock = pygame.time.Clock()
FPS = 120
while True:
clock.tick(FPS)
while stats.main_menu:
gf.move_bg(so_settings, screen, sb, stats, last_tick)
btn.draw_button()
pygame.display.flip()
gf.check_event(screen, so_settings, ship, bullets, sb, stats, btn)
if stats.game_active:
gf.update_enemy_bullet(bullets_enemy, so_settings, screen)
gf.update_bullet(bullets, so_settings, sb)
gf.generate_enemy(so_settings, stats, last_tick, screen, ship, enemies, bullets_enemy, bullets, explosion, sb)
gf.update(so_settings, screen, bullets, enemies, bullets_enemy, ship, exploAni, explosion, stats, sb)
gf.move_bg(so_settings, screen, sb, stats, last_tick)
gf.check_event(screen, so_settings, ship, bullets, sb, stats, btn)
else:
gf.move_bg(so_settings, screen, sb, stats, last_tick)
gf.check_event(screen, so_settings, ship, bullets, sb, stats, btn)
run_game()