Side Scrolling Platform Game

  1. tmcd35
    Okay, here it goes! I thought I'd start off and see where it takes us. This is my first ever python program, and the first ever game I've written from scratch without using a game making engine like Greenfoot or Scratch. Although I suppose pygame - which this is using - can be counted among that number.

    Doesn't do much at the moment, literately just draws a singe platform on the screen but it's a start!

    The formatting of the code portrays my procedural programming origins (mostly Pascal), in fact I'm finding Python to be very similar to the more advanced BASIC's or Turbo Pascal.

     import pygame
    #Global Variables
    clock = None
    gameExit = None
    screen = None
    def initialiseGame():
        #global variables
        global clock
        global screen
        #Open Game Screen
        size = (640,480)
        screen = pygame.display.set_mode(size)
        pygame.display.set_caption("Side Scrolling Platform Game")
        #initialise clock
        clock = pygame.time.Clock()
    def getUserInput():
        #global variables
        global gameExit
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                gameExit = 1
    def updateScreen():
        #global variables
        global screen
        black = (0,0,0)
        white = (255,255,255)
        #clear screen
        #draw background
        #draw sprites
        #commit display
    #Game Loop
    gameExit = 0
    while gameExit < 1:
        #Move Enemies
        #frames per second
    Having played I'm a little more happy that Python is capable of doing what we want, but it definitely feels like the wrong language to be using. It's an interpreted/scripting language not a gaming language.
  2. X-13
    Dagnabit. I haven't even started on a pong clone yet and you're already working on Mario...
  3. X-13
    Also, "wrong language to be using"?

    EVE online is coded in python. And Civ IV.
  4. tmcd35
    I thought @Rawns in another thread suggested a side scroller? I thought why not, I haven't tried one of them yet I'm pretty sure the main part of Civ IV is C++ with Python as an interface/scripting language for the AI? I think the same can be said for EVE - the GUI and graphics are almost likely C++ with Python used to talk back to the servers, etc.

    Back to the code. My starting point - trying to all procedual and creating functions for each main segment seems to be back firing some what when it come to variable handling. I'm finding myself having to make almost everything a global variable to pass data between code segments. I think I'm going to have to look at a more object-oriented approach, then I probably won't be fighting the language so much.
  5. tmcd35
    Actually I think the code shell above is only a few lines away from pong...
    Turn the platform on it's side
    Make two of them
    Get some user input to alter the vertical position of the platforms/bats each screen refresh
    Create a rectangle that moves in one direction unless it hits a bat
    Collision detection
  6. Rawns
    Awesome stuff. I decided I did not want to be crammed up in the spare room like a crazy programmer so installed ubuntu on the wifes netbook so I could code in the front room. SOI hadf a play last night and I've done the usual 'Hello world' bits and also made a "Guess the number within 6 goes" game! Nothing cutting edge, but the fact it worked, and the fact I understood what the code was doing was good enough for me!

    I'll continue to crack on tonight!
  7. bondbill2k2
    Nice work guys, I'm yet to even start as I've been busy the past few evenings!
  8. CAM
    Are we just doing Python?
  9. X-13
    @CAM at the moment. It's super easy to pick up and once we've made something with that, we're moving to something more complex. [Until we can code the call of dooties in binary. ]
  10. tmcd35
    Okay, so I've added a stickman sprite hand drawn in Paint (a 5year old could do better - always my problem with graphics). But I'm thinking, to do this right, the sprite needs to be implemented as a class...

    class coolPlayerDude:
        #player variables
        xPos = None
        yPos = None
        Collision = None
        Sprite = None
        Score =  None
        #load sprite
        def loadSprite(filename):
            Sprite = pygame.image.load(filenae).convert()
        def displaySprite():
             #return sprite and position details to screen.nlit
        def setPlayerX(X):
              xPos = X
        def setPlayerY(Y):
              yPos = Y
    Okay, that's just some thoughts. Totally untested code - probably have time for a proper stab at this on Sunday.
Results 1 to 10 of 10