pygamegsoc12 / alchemymadness / main.py

import pygame
from pygame.locals import *

import resources
import layout
import potion
import blocks

def main():
    """ your app starts here
    """

    pygame.init()
    screen = pygame.display.set_mode(layout.screen_size)
    pygame.display.set_caption("Alchemy Madness")
    clock = pygame.time.Clock()
    going = True

    resources.init()

    screen.fill((0,0,0))

    screen.blit(resources.background, (0,0))
    pygame.display.flip()

    # Initialise level
    pot = potion.Potion()
    pot.set_formula(3, 5, 3)
    sprites = pygame.sprite.LayeredDirty(pot)
    sprites.clear(screen, resources.background)

    grds = blocks.Grids(sprites)

    # player index we are controlling.
    which_player = 0
    blks = grds.grids[which_player].blocks


    #TEST
    pot.add_color((0,0,255))

    while going:
        time = clock.tick(30)

        events = pygame.event.get()
        for e in events:
            if e.type == KEYDOWN and e.key == K_SPACE:
                pot.add_color((255,0,0))
            if e.type == KEYDOWN and e.key == K_s:
                pygame.image.save(screen, "screeny.png")

            if e.type == KEYDOWN:
                if e.key == K_LEFT:
                    blks.action_move_left()
                if e.key == K_RIGHT:
                    blks.action_move_right()
                if e.key == K_UP:
                    blks.action_move_up()
                if e.key == K_DOWN:
                    blks.action_move_down()

                # press keys 1-4 to control player 1-4.
                if e.key in [K_1, K_2, K_3, K_4]:
                    which_player = [K_1, K_2, K_3, K_4].index(e.key)
                    blks = grds.grids[which_player].blocks

            if e.type == QUIT or e.type == KEYDOWN and e.key == K_ESCAPE:
                going = False

        # Update sprites
        sprites.update(time)
        # Draw sprites
        rects = sprites.draw(screen)
        # TODO: Move text code somewhere else
        screen.blit(resources.font[40].render('Alchemy Madness', True, (255,255,255)), (10,555))
        pygame.display.update(rects)


    # End game
    score = pot.get_score()

    pygame.quit()

if __name__ == "__main__":
    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.