Python Forum
[PyGame] Best way to pass data to the few game states with the same superclass?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Best way to pass data to the few game states with the same superclass?
#3
Thanks for the answer Smile
(Oct-16-2021, 03:59 PM)Windspar Wrote: Avoid global variables like the plague
Is it called global variables if I store some stuff in a module and just import it in almost each module? Because I made something like this and for example i use 'SCREEN' variable in almost every other module. Is it wrong way? Why?

import pygame

from game_data import GameData


WIN_SIZE = (1024, 768)
FRAMERATE = 80

SCREEN = pygame.display.set_mode(WIN_SIZE)
SCREEN_RECT = SCREEN.get_rect()

MOVE_RATIO = 30


START_TIME = 140  # Time of 'intro' before each level
END_TIME = 180  # Time of 'outro' after each level

pygame.init()
FONT = pygame.font.Font('../resources/fonts/OpenSans-Bold.ttf', 100)

MOVE = pygame.USEREVENT  # User event for moving enemy
pygame.time.set_timer(MOVE, MOVE_RATIO)

game_data = GameData()
GFX = game_data.textures
SFX = game_data.sounds
ENEMIES_ARGS = game_data.enemies_args
Reply


Messages In This Thread
RE: Best way to pass data to the few game states with the same superclass? - by Milosz - Oct-16-2021, 07:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Variables shared between game states, how to? michael1789 5 3,575 Dec-10-2019, 10:09 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020