Ok this is what I finished with. Would this be acceptable coding?
Sorry if I've been difficult as I said in the first post, I'm trying to get my head around this stuff.
Correct me if I'm wrong, classes contain methods for transporting/handling data. You can group the data a paticular object. Like I been experimenting with. Anything containingg the background window can be stored and used or manipulated e.g."the background color or window size can be changed".
When getting ready to add a character to the window, I can create a class that will contain everything about this character. Start position, movement, abilities and so forth. All of these classes can be in the same file or another file. The file would have to be imported.
Is my analogy correct? All comments welcome. Final question, I should be able to do this without using the __init__, correct? I realize the coding would be a little different but, the argument passing would be along the same lines?
test.py
import pygame
from myclass import Game
pygame.init()
window = Game(width = 800, height = 600, r = 30, g = 10, b = 90)
window.window()
window.background()
def main():
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.update()
if __name__ == "__main__":
window.py
import pygame
class Game:
def __init__(self, width, height, r, g, b):
self.width = width
self.height = height
self.r = r
self.g = g
self.b = b
def window(self):
window = pygame.display.set_mode((self.width, self.height))
self.window = window
window = window.fill((self.r, self.g, self.b))
return window
def background(self):
bgimage = pygame.image.load("../Python_Projects/Game2/images/space.png")
window = self.window.blit(bgimage, (0, 0))
return window