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()
fpsClock.tick(fps)
def floorDraw(blockSize, floorAmt, floorY, grass):
for i in range(floorAmt):
floorX = i*blockSize
grassRect = (floorX, floorY, blockSize, blockSize)
floor.add(grass)
displayScreen.blit(grass, grassRect)
v
if __name__ == "__main__":
main()
basically I just want to know how to make these grass blocks into sprites in a group, so that when I add my player (also a sprite) I can determine whether or not he is in the air or not through the collision system. Can someone please explain to me how I would do this. All I am looking for is basically a kick starter because some of the documentation is quite bad in my opinion as it doesn't completely tell you how to use it. Any help is greatly appreciated :)