All pastes #76719 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-07-02 01:14 UTC
rendered paste body
## PLAYER ACTIONS

RUN = 0

JUMP = 1

DOUBLEJUMP = 2





jHeight = 150



class Player:

    def __init__(self):

        self.pos     = (0,0)

        self.size    = (60,90)

        self.surface = pygame.Surface(self.size)

        self.surface.fill((0,0,0))

        self.action  = None

        self.jumps   = 0

        



## MAIN FILE

import pygame

from pygame.locals import *



pygame.init()



window = (800, 600)



screen = pygame.display.set_mode(window)

pygame.display.set_caption("Game")

pygame.mouse.set_visible(1)



bg = pygame.Surface((800,600))

bg.fill((255,255,255))



player1 = Player()



q = 0

pygame.key.set_repeat(1)

gameClock = pygame.time.Clock()



while q == 0:

    fps = gameClock.get_fps(1)

    print fps

    #print dir(gameClock)

    #gameClock.tick_busy_loop(30)

    events      = pygame.event.get()



    for event in events:

        if event.type == QUIT:

            q = 1

        if event.type == KEYDOWN and event.key == K_LEFT:

            (x,y) = player1.pos

            player1.pos = (x-5,y)

            player1.action = RUN



        if event.type == KEYDOWN and event.key == K_RIGHT:

            (x,y) = player1.pos

            player1.pos = (x+5,y)

            player1.action = RUN

            

        if event.type == KEYDOWN and event.key == K_UP:

            (x,y) = player1.pos

            if player1.action != JUMP and y < jHeight*2 and player1.jumps <= 1:

                y = y+jHeight

                if y > 300:

                    y = 300

                player1.pos = (x,y)

                player1.action = JUMP

                player1.jumps += 1

                

        else:

            player1.action = RUN

    if player1.action != JUMP and player1.pos[1] != 0:

        (x,y) = player1.pos

        player1.pos = (x,y-5)

    if player1.jumps == 2 and player1.pos[1] == 0:

        player1.jumps = 0

        

    screen.blit(bg, (0,0))

    (x,y) = player1.pos

    screen.blit(player1.surface,(x,600-y-player1.size[1]))

    pygame.display.flip()

    gameClock.tick()