Even though this guy is a troll, he's right. This tutorial is really shitty, and not at all newbie-friendly. There's a lot of unnecessary and unexplained code. I remember in the first tutorial, something like "simple" screen rendering or whatever, where there were dozens of different functions and shit, none of which was explained in any coherent way. If you're wondering how to bring up a simple screen, it can be done in a few lines of code, and I'm not sure why this guy is bringing up all this garbage.
import pygame
screen = pygame.display.set_mode((640,400))
while True:
pass
That's literally all it takes.
I agree with you; a lot of what this tutorial has in the script isn't explained. I do like the concept of using a class to have the game in, even though there is no real need for it. It's not like we need to make to games that are exactly the same in one script.
This is just explaining a general setup for pygame which is understandable if you're already familiar with python, which this tutorial assumes you are.
Also it's demonstrating an object oriented approach, your few lines of code would be fine but it will quickly become hard to manage the complexity of your game and add to it, meanwhile the object oriented approach has got his framework setup and can easily and quickly add content and features to the game.
The code works. Wish you could have shown how to loop load different images too.
But cool. thanks.
If you want to load multiple images in a loop, you'll probably want to use a for loop to get the job done. If there's a specific set of different images you want in a specific order, you might want to try something like:
for i in range(number_of_images):
if i == 0:
image1 = pygame.image.load etc etc etc
if i == 1:
image2 = pygame etc etc etc
why not store the images in a dict and access them in a more straightforward way?
sprite_dict = {
"hero" : "hero.png",
"badguy" : "orc.png"
}
imgs = []
for key in sprite_dict :
imgs.append( pygame.image.load(sprite_dict[key] )
…
You could dynamically create your sprite_dict and load from what's in there each loop.