lunes, 9 de junio de 2014

First Game with Graphics, part 2

On the last post we managed to draw an image to the screen, and now we are going to make a program that allows us to move that image.

First of all, since our program is going to become a little longer, we must give it a little more structure. It's time to divide the program into classes, and give each piece a specific job. This will make it much easier to modify parts of the program without affecting others. Let's start by drawing the same image to the screen, but this time with classes

jueves, 5 de junio de 2014

Must-watch video!!!

As you may know, I'm no expert programmer. What I add to this blog is whatever I'm learning at the moment. As I got more and more into pygame I found this video, and it's very, very helpful. This guy really knows what he's talking about. Enjoy!

miércoles, 4 de junio de 2014

First Game with Graphics

We are done with console programs. The fact is that we want to make video games, and while making console programs is a great exercise, they require a lot of effort that we could just as easily spend doing graphical games. Let's get started!

Installing pygame


First of all, there seems to be a bit of a version gap between python and pygame. I had Python 3.4 64-bit installed, but pygame can only work with python 3.2 32 bit. I uninstalled 3.4 first, and then downloaded 3.2. Here's where you can get python: Python's Homepage. Pygame can be downloaded here: Pygame's Homepage,

When downloading pygame make sure to notice the version number. The file you're looking for is pygame-1.9.2a0.win32-py3.2.msi.

Install python first, then pygame.

lunes, 2 de junio de 2014

Guess the number, part 5

Finally, the high score system works, and the program now runs from start to finish without trouble, and has all the features that we set as goals in the beginning. Let's take a look at the different files:


main.py

 

from functions import *
from mainGame import *

gamestate = 'menu'  

def GameManager(state):

    while True:
        if state == 'menu':

            state = ShowMenu()

        elif state == 'game':

            MainGame()

            state = ShowMenu()

        elif state == 'score':

            ViewHighScores(LoadScoreFileData())

            state = ShowMenu()

        elif state  == 'quit':

            print("\nSee you soon!\n")

            break

GameManager(gamestate)

This file is the one from which we are going to access the program. It imports all the functions we're going to need, and serves as a sort of 'hub' where the program returns to receive new instructions. This while loop is the main game loop.