Saturday, 1 June 2013

PyGame sprite assistance

PyGame sprite assistance

I've basically just started developing with PyGame and I am having trouble with the whole Sprite concept. I have been looking every where for guides on how to use it, I just can't seem to find any. I would like to know the basic concept of how it all works. This is the code I have been working on:
import pygame, sys, os, time
from pygame.locals import *

windowWidth = 320
windowHeight = 640
halfWidth = int(windowWidth / 2)
halfHeight = int(windowHeight / 2)

#main blocks width and height (32x32)
blockSize = 32

#rgb
red = [255,000,000]
green = [000,255,000]
blue = [000,000,255]
black = [000,000,000]
white = [255,255,255]

bgColor = black
playerColor = white
blockColor = green

fps = 60

assert windowWidth % blockSize == 0, "Too much space/not enough space for the ground"
floorAmt = windowWidth/blockSize
print floorAmt

floorY = windowHeight-blockSize
print floorY

floor = pygame.sprite.Group()


def main():

    global fpsClock, displayScreen

    inAir = False

    upVel = 0
    downVel = 0
    leftVel = 0
    rightVel = 0

    fpsClock = pygame.time.Clock()
    displayScreen = pygame.display.set_mode((windowWidth, windowHeight))
    pygame.display.set_caption("Jump Test")

    grass = pygame.image.load("grass.png")
    grass = grass.convert_alpha()
    grassRadius = blockSize

    floorDraw(blockSize, floorAmt, floorY, grass)

    while True:
        fpsClock.tick(fps)

        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
                pygame.quit()
                sys.exit()
                raise SystemExit, "Exit"

        displayScreen.fill(black)
        floorDraw(blockSize, floorAmt, floorY)

        pygame.display.flip()
        pygame.display.update()

No comments:

Post a Comment