Example #1
0
class tree(object):
    def __init__(self, tree, x, y):
        self.tree = tree
        self.get = Spritesheet(tree)
        self.image = self.get.get_spritte()
        self.rect = self.image[0].get_rect()
        self.rect.x = x
        self.rect.y = y
        self.vel = pygame.math.Vector2(0, 0)
        self.acceleration = pygame.math.Vector2(0, .1)
        self.on_ground = False
        self.drop = False
        self.col = False

    def draw(self, win):
        if not self.col and not self.drop:
            win.blit(self.image[random.randint(1, 10)],
                     (self.rect.x, self.rect.y))
        elif self.col or self.drop:
            self.rect.x = random.randint(100, 1700)
            self.rect.y = 40
            self.col = False

    def update(self, dt, plat):
        self.checkCollisionspy(plat)

    def checkCollisionspy(self, platform):
        if not self.on_ground:
            self.rect.bottom += 4
        if self.rect.y >= 1000:
            self.col = True

    def get_hits(self, players):
        hits = []
        for player in players:
            if self.rect.colliderect(player):
                hits.append(player)
        return hits
Example #2
0
def game():
    global timer
    win = pygame.display.set_mode((1900, 1000))

    pygame.display.set_caption("First Game")
    # char = pygame.image.load('standing.png')

    clock = pygame.time.Clock()
    bg = pygame.image.load('Recursos/Backgroung/bg.png')
    board = pygame.image.load('Recursos/Board.png')
    label1 = pygame.font.SysFont('arial',28).render("Player1:", 1,(0,255,0))
    label2 = pygame.font.SysFont('arial',28).render("Player2:", 1,(0,255,0))
    label3 = pygame.font.SysFont('arial',28).render("Vidas:", 1,(0,255,0))
    label4 = pygame.font.SysFont('arial',28).render("Vidas:", 1,(0,255,0))
    label8 = pygame.font.SysFont('arial',28).render("Time: ",1,(0,255,0))
    labelwin = pygame.font.SysFont('arial',100).render("PLAYER 1 is the WINNER!",1,(0,0,0))
    labelwin1 = pygame.font.SysFont('arial',100).render("PLAYER 2 is the WINNER!",1,(0,0,0))


    counter = 120

    #Inicializar control
    joysticks = []
    for i in range(pygame.joystick.get_count()):
        joysticks.append(pygame.joystick.Joystick(i))
    for joystick in joysticks:
        joystick.init()
    with open(os.path.join("ps4_keys.json"),'r+') as file:
        button_keys = json.load(file)

    #analog keys
    analog_keys = {0:0, 1:0, 2:0, 3:0, 4:-1, 5: -1}

    # bulletSound = pygame.mixer.Sound('bullet.wav')
    # hitSound = pygame.mixer.Sound('hit.wav')

    # music = pygame.mixer.music.load('music.mp3')
    # pygame.mixer.music.play(-1)

    P1 = Spritesheet("platform")
    Platform1 = P1.get_spritte()

    P2 = Spritesheet("platform1")
    Platform2 = P2.get_spritte()

    TARGET_FPS = 60
    def redrawGameWindow():
        win.blit(bg, (0, 0))
        win.blit(board, (1500, 0))
        win.blit(label1,(1530,140))
        win.blit(label2,(1530,550))
        win.blit(label3,(1530,180))
        win.blit(label4,(1530,630))
        win.blit(label5,(1630,180))
        win.blit(label6,(1630,630))

        win.blit(label8,(1530,40))
        win.blit(label7,(1600,40))



        if player1.vidas == 0:
            win.blit(labelwin1, (300, 500))
        elif player2.vidas == 0:
            win.blit(labelwin, (300, 500))
        else:
            piso.draw(win)
            plataform1.draw(win)
            platform2.draw(win)
            pow1.draw(win)
            pow2.draw(win)
            pow3.draw(win)
            player2.draw(win)
            player1.draw(win)
            AVL.draw(win)

        pygame.display.update()


    # mainloop
    font = pygame.font.SysFont('comicsans', 30, True)
    player1 = player()
    player1.position.x = 500
    player1.position.y = 700
    player1.rect.y = player1.position.y
    player2 = player()
    player2.position.x = 600
    player2.position.y = 700


    pow1 = powers(random.choice(["shield"]), random.randint(100, 1500), 40)
    pow2 = powers(random.choice(["jump"]), random.randint(100, 1500), 40)
    pow3 = powers(random.choice(["punch"]), random.randint(100, 1500), 40)

    AVL = tree("AVL",random.randint(100,1500),40)


    piso = platform(Platform1[0],250,860)
    plataform1 = platform(Platform2[0],1200,650)
    platform2 = platform(Platform2[1],100,650)

    run = True
    while run:
        dt = clock.tick(60) * .001 * TARGET_FPS

        for event in pygame.event.get():
            if event.type == pygame.USEREVENT:
                counter  -= 1
                timer = str(counter).rjust(3) if counter > 0 else quit()
            else:
                clock.tick(60)
            if event.type == pygame.QUIT:
                run = False
            label5 = pygame.font.SysFont('arial', 28).render(str(player1.vidas), 1, (0, 255, 0))
            label6 = pygame.font.SysFont('arial', 28).render(str(player2.vidas), 1, (0, 255, 0))
            label7 = pygame.font.SysFont('arial', 28).render(str(timer), 1, (0, 255, 0))
            if event.type == pygame.JOYBUTTONDOWN:
                if event.button == button_keys['left_arrow']:
                    player1.LEFT_KEY = True
                    player1.left = True
                    player1.right = False
                    player1.standing = False
                    player1.punch = False
                if event.button == button_keys['right_arrow']:
                    player1.RIGHT_KEY = True
                    player1.left = False
                    player1.right = True
                    player1.standing = False
                    player1.punch = False
                if event.button == button_keys['up_arrow']:
                    player1.jump()
                if event.button ==  button_keys['square']:
                    if player1.pow:
                        if player1.powpunch:
                            player1.punchCount = 0
                            player1.punch = True
                            player1.standing = False
                            player1.pow = False
                        elif player1.jumpow:
                            player1.usejump = True
                            player1.jump()
                            player1.pow = False
                        elif player1.shield:
                            player1.useshield = True
                            player1.pow = False
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_a:#or event.button == button_keys['x']
                    player1.LEFT_KEY = True
                    player1.left = True
                    player1.right = False
                    player1.standing = False
                    player1.punch = False
                elif event.key == pygame.K_d:
                    player1.RIGHT_KEY = True
                    player1.left = False
                    player1.right = True
                    player1.standing = False
                    player1.punch = False
                elif event.key == pygame.K_w:
                    player1.jump()
                elif event.key == pygame.K_j:
                    player2.LEFT_KEY = True
                    player2.left = True
                    player2.right = False
                    player2.standing = False
                    player2.punch = False
                elif event.key == pygame.K_l:
                    player2.RIGHT_KEY = True
                    player2.left = False
                    player2.right = True
                    player2.standing = False
                    player2.punch = False
                elif event.key == pygame.K_i:
                    player2.jump()
                elif event.key == pygame.K_s:
                    if player1.pow:
                        if player1.powpunch:
                            player1.punchCount = 0
                            player1.punch = True
                            player1.standing = False
                            player1.pow = False
                        elif player1.jumpow:
                            player1.usejump = True
                            player1.jump()
                            player1.pow = False
                        elif player1.shield:
                            player1.useshield = True
                            player1.pow = False
                elif event.key == pygame.K_k:
                    if player2.pow:
                        if player2.powpunch:
                            player2.punchCount = 0
                            player2.punch = True
                            player2.standing = False
                            player2.pow = False
                        elif player2.jumpow:
                            player2.usejump = True
                            player2.jump()
                            player2.pow = False
                        elif player2.shield:
                            player2.useshield = True
                            player2.pow = False
            ############################################
            if event.type == pygame.JOYBUTTONUP:
                if event.button == button_keys['left_arrow']:
                    player1.LEFT_KEY = False
                    player1.right = False
                    player1.standing = True
                if event.button == button_keys['right_arrow']:
                    player1.RIGHT_KEY = False
                    player1.LEFT_KEY = False
                    player1.left = False
                    player1.standing = True
                if event.button == button_keys['up_arrow']:
                    if player1.isJump:
                        player1.vel.y *= .25
                        player1.isJump = False
                if event.button ==  button_keys['square']:
                    if player1.catch != None:
                        player1.catch.drop = False
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_a:
                    player1.LEFT_KEY = False
                    player1.right = False
                    player1.standing = True
                elif event.key == pygame.K_d:
                    player1.RIGHT_KEY = False
                    player1.LEFT_KEY = False
                    player1.left = False
                    player1.standing = True
                elif event.key == pygame.K_w:
                    if player1.isJump:
                        player1.vel.y *= .25
                        player1.isJump = False
                if event.key == pygame.K_j:
                    player2.LEFT_KEY = False
                    player2.right = False
                    player2.standing = True
                elif event.key == pygame.K_l:
                    player2.RIGHT_KEY = False
                    player2.left = False
                    player2.standing = True
                elif event.key == pygame.K_i:
                    if player2.isJump:
                        player2.vel.y *= .25
                        player2.isJump = False
                elif event.key == pygame.K_s:
                    if player1.catch != None:
                        player1.catch.drop = False
                elif event.key == pygame.K_k:
                    if player2.catch !=None:
                        player2.catch.drop = False
        AVL.update(dt,[piso,platform2,plataform1])
        pow1.update(dt,[piso,platform2,plataform1])
        pow2.update(dt, [piso, platform2, plataform1])
        pow3.update(dt, [piso, platform2, plataform1])
        player2.update(dt,[player1],[piso,platform2,plataform1],[pow1,pow2,pow3],[[AVL],"AVL"])
        player1.update(dt,[player2],[piso,platform2,plataform1],[pow1,pow2,pow3],[[AVL],"AVL"])
        redrawGameWindow()
Example #3
0
import pygame
from spritesheet import Spritesheet
from time import sleep
#####################################################################################
W1 = Spritesheet('WalkR')
walkRight = W1.get_spritte()

W2 = Spritesheet('WalkL')
walkLeft = W2.get_spritte()

G1 = Spritesheet('GolpeL')
golpeI = G1.get_spritte()

G2 = Spritesheet('GolpeR')
golpeD = G2.get_spritte()

P1 = Spritesheet('punchL')
punchI = P1.get_spritte()

P2 = Spritesheet('punchR')
punchD = P2.get_spritte()

J1 = Spritesheet('jumpR')
jumpD = J1.get_spritte()

J2 = Spritesheet('jumpL')
jumpI = J2.get_spritte()

S1 = Spritesheet('Stand')
Stand = S1.get_spritte()