Have you had fun reading these articles and creating basic games over the course of 2013? I hope so, because my New Years resolution is to make things a lot more entertaining! Print("Hello") to graphics!
Not only graphics, but getting sound as well is difficult. It has to do with operating systems, graphics cards, and a lot of other random things you most likely don't know about. Don't worry, though. Remember last article, when I talked about downloading standard modules? I have (a safe) one here, at
pygame.org!
Just so you know, Pygame doesn't run on Python 3.3.0. You'll have to find a version of Python that supports it. And me? I'm using Python 2.5. Also, Pygame needs to be supported by Numeric, which can also be found on the site.
Alright, I hope everything's cleared up. Type this in the new window of your new Python IDLE window.
import pygame
pygame.init()
screen=pygame.display.set_mode([640, 480])
If you run this program, you should get a window that's just a black screen for a second.
Either that, or it crashes instantly.
Games aren't independent. They interact with the user. Pygame is meant for creating games. But, it has something called event loops. They constantly check for things the user does, such as jamming on the keyboard or flinging the mouse. The "game" we just made had no event loop started in the first place. The Pygame window stays open while the program is running. Let's keep it running. Add this to the bottom of the program.
while True:
pass
You see, True means... True, and pass means... Do nothing. This may seem confusing at first. Seeing the entire program might help.
import pygame
pygame.init()
screen=pygame.display.set_mode([640, 480])
while True:
pass
So, you might have found out by now. This basically means, "while the window is open, do NOTHING." So, it does nothing. That means it doesn't even close or crash. So, let's run it. Remember, you can use CTRL+C to close it (as long as IDLE is the active window).
It didn't crash that time! Alright! We're getting somewhere! But, try running the program again. What happens when you press that X button in the corner, you know, the one that closes every window?
Not again! We've got to make that thing work.
I suppose we'll discuss X next article. See ya!