Jump to content

Recommended Posts

Posted

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
pygame.init()

#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()
   return

def getUserInput():
   #global variables
   global gameExit
   
   for event in pygame.event.get():
       if event.type == pygame.QUIT:
           gameExit = 1
   return

def updateScreen():
   #global variables
   global screen

   #colours
   black = (0,0,0)
   white = (255,255,255)
   
   #clear screen
   screen.fill(white)
   #draw background
   pygame.draw.line(screen,black,[50,400],[200,400],10)
   #draw sprites
   #commit display
   pygame.display.flip()
   return

#MAIN
initialiseGame()	

#Game Loop
gameExit = 0
while gameExit < 1:
   #Input
   getUserInput()
   #AI
   #Move Enemies
   #Collisions
   #Graphics
   updateScreen()
   #Sounds
   #frames per second
   clock.tick(30)

pygame.quit()

 

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.

Posted

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.

Posted

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
Scoring

Posted

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! :D

Posted
@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. :p]
Posted

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.




×
×
  • Create New...