A downloadable game for Windows

Airhockey Game:

This game is an airhockey arcade game. it is very bad. This game is a bad recration of The Airhockey game on Sega Megadrive. It is written in Pygame


Code:

import pygame, sys, random
from pygame import mixer
pygame.init()
mixer.init()
#Setup for variables 
Sound1 = pygame.mixer.Sound("data/SFX/soundfx_1.wav")
Sound2 = pygame.mixer.Sound("data/SFX/soundfx_2.wav")
clock = pygame.time.Clock()
SCREEN_WIDTH = 600
SCREEN_HEIGTH = 400
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGTH))
pygame.display.set_caption("Airhockey")
bakgrund = pygame.image.load('data/assets/Bakgrund.png')
bakgrund = pygame.transform.scale(bakgrund, (SCREEN_WIDTH, SCREEN_HEIGTH))
Wall_left_top = 60
Wall_rigth = SCREEN_WIDTH - 60
Wall_bottom = SCREEN_HEIGTH - 60
Puck = pygame.Rect(SCREEN_WIDTH//2, SCREEN_HEIGTH//2, 45, 45)
Goal_1 = pygame.Rect(60, 150, 10, 100)
Goal_2 = pygame.Rect(SCREEN_WIDTH-70, 150, 10, 100)
# WALL 60 PIXELS AWAY FROM EDGE
Player_1 = pygame.Rect(200, SCREEN_HEIGTH//2, 45, 45)
Player_2 = pygame.Rect(400, SCREEN_HEIGTH//2, 45, 45)
Score1 = 0
Score2 = 0
Sound = True
Player_Velocity_x = 0
Player_Velocity_2_x = 0
Player_Velocity_y = 0
Player_Velocity_2_y = 0
Puck_velocity = [random.choice((-3, 3)),random.choice((-3, 3))]
#Fuctions
def Puck_movement():
    global Score2, Score1
    Puck.x += Puck_velocity[0]
    Puck.y += Puck_velocity[1]
    
    # Handle collisions with walls
    if Puck.bottom >= Wall_bottom:
        Puck_velocity[1] *= -1
        Puck.bottom = Wall_bottom - 1
        Sound2.play()
    if Puck.top <= Wall_left_top:
        Puck_velocity[1] *= -1
        Puck.top = Wall_left_top + 1 
        Sound2.play()
    if Puck.right >= Wall_rigth or Puck.left <= Wall_left_top:
        Puck_velocity[0] *= -1
        Sound2.play()
    
    # Handle collisions with players
    if Puck.colliderect(Player_1):
        Puck_velocity[0] *= -1
        if Puck.centery > Player_1.centery:
            Puck_velocity[1] *= -1
        Sound2.play()
        while Puck.colliderect(Player_1):
            Puck.x += Puck_velocity[0]
            Puck.y += Puck_velocity[1]
    if Puck.colliderect(Player_2):
        Puck_velocity[0] *= -1
        if Puck.centery > Player_2.centery:
            Puck_velocity[1] *= -1
        Sound2.play()
        while Puck.colliderect(Player_2):
            Puck.x += Puck_velocity[0]
            Puck.y += Puck_velocity[1]
    
    # Handle scoring
    if Puck.colliderect(Goal_1):
        Score1 += 1
        reset()
        Sound1.play()
    if Puck.colliderect(Goal_2):
        Score2 += 1
        reset()
        Sound1.play()
def Menu():
    menuTrue = True<img src="https://img.itch.zone/aW1nLzE1OTkwNjQ3LnBuZw==/original/ZhIyay.png">
    Button_1 = pygame.Rect(120, 120, SCREEN_WIDTH-400, 50)
    Button_2 = pygame.Rect(120, 180, SCREEN_WIDTH-400, 50)
    Button_3 = pygame.Rect(120, 240, SCREEN_WIDTH-400, 50)
    while menuTrue:
        global Sound
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    menuTrue = False
            if event.type == pygame.MOUSEBUTTONDOWN:
                clicked_pos = pygame.mouse.get_pos()
                if Button_1.collidepoint(clicked_pos):
                    pygame.quit()
                    sys.exit()
                if Button_2.collidepoint(clicked_pos):
                    if Sound == True:
                        Sound = False
                    else:
                        Sound = True
                if Button_3.collidepoint(clicked_pos):
                    menuTrue = False
        
        pygame.draw.rect(screen, (0,0,0), (100, 100, SCREEN_WIDTH-200, SCREEN_HEIGTH-200))
        pygame.draw.rect(screen, (100,100,100), Button_1)
        pygame.draw.rect(screen, (100,100,100), Button_2)
        pygame.draw.rect(screen, (100,100,100), Button_3)
        Text(None, 50, "QUIT", (0,0,0), None, Button_1.x, Button_1.y)
        Text(None, 50, "SOUND: " + "ON" if Sound == True else "SOUND: OFF", (0,0,0), None, Button_2.x, Button_2.y)
        Text(None, 50, "COUNTINUE", (0,0,0), None, Button_3.x, Button_3.y)
        pygame.display.flip()
def reset():
    global Puck, Goal_1, Goal_2, Player_1, Player_2, Player_Velocity_2_x, Player_Velocity_2_y, Player_Velocity_x, Player_Velocity_y
    Puck = pygame.Rect(SCREEN_WIDTH//2, SCREEN_HEIGTH//2, 45, 45)
    Goal_1 = pygame.Rect(60, 150, 10, 100)
    Goal_2 = pygame.Rect(SCREEN_WIDTH-70, 150, 10, 100)
    Player_1 = pygame.Rect(200, SCREEN_HEIGTH//2, 45, 45)
    Player_2 = pygame.Rect(400, SCREEN_HEIGTH//2, 45, 45)
    Puck.x += Puck_velocity[0]
    Puck.y += Puck_velocity[1]
def Text(Font, Size, String_, Color, BGColor,x,y):
    font =  pygame.font.Font(Font, Size)
    String = font.render(String_, True, Color, BGColor)
    screen.blit(String, (x, y))
#Main Loop
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        #check keys pressed
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_a:
                Player_Velocity_x -= 3
            if event.key == pygame.K_d:
                Player_Velocity_x += 3
            if event.key == pygame.K_w:
                Player_Velocity_y -= 3
            if event.key == pygame.K_s:
                Player_Velocity_y += 3
            if event.key == pygame.K_LEFT:
                Player_Velocity_2_x += 3
            if event.key == pygame.K_RIGHT:
                Player_Velocity_2_x -= 3
            if event.key == pygame.K_UP:
                Player_Velocity_2_y += 3
            if event.key == pygame.K_DOWN:
                Player_Velocity_2_y -= 3
            if event.key == pygame.K_ESCAPE:
                Menu()
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_a:
                Player_Velocity_x += 3
            if event.key == pygame.K_d:
                Player_Velocity_x -= 3
            if event.key == pygame.K_w:
                Player_Velocity_y += 3
            if event.key == pygame.K_s:
                Player_Velocity_y -= 3
            if event.key == pygame.K_LEFT:
                Player_Velocity_2_x -= 3
            if event.key == pygame.K_RIGHT:
                Player_Velocity_2_x += 3
            if event.key == pygame.K_UP:
                Player_Velocity_2_y -= 3
            if event.key == pygame.K_DOWN:
                Player_Velocity_2_y += 3
            
    Puck_movement()
    #Collision for player1/2
    while Player_1.left <= Wall_left_top:
        Player_1.x += 1
    while Player_1.top <= Wall_left_top:
        Player_1.y += 1
    while Player_1.bottom >= Wall_bottom:
        Player_1.y -= 1
    while Player_1.right >= SCREEN_WIDTH//2:
        Player_1.x -= 1
    while Player_2.left <= SCREEN_WIDTH//2:
        Player_2.x += 1
    while Player_2.top <= Wall_left_top:
        Player_2.y += 1
    while Player_2.bottom >= Wall_bottom:
        Player_2.y -= 1
    while Player_2.right >= Wall_rigth:
        Player_2.x -= 1
    #Move Players
    Player_1.x += Player_Velocity_x
    Player_1.y += Player_Velocity_y                
    Player_2.x -= Player_Velocity_2_x
    Player_2.y -= Player_Velocity_2_y
    #Draw
    screen.blit(bakgrund, (0,0))
    pygame.draw.ellipse(screen, 'black', Puck)
    pygame.draw.ellipse(screen, "red", Player_1)
    pygame.draw.ellipse(screen, "blue", Player_2)
    Text(None, 40, "Player 1    " + str(Score2) + "-" + str(Score1) + "    Player 2", (0,0,0), (255,255,255), 140, 10)
    pygame.display.flip()
    clock.tick(60)


All donations go to Kebab

Published 14 days ago
StatusIn development
PlatformsWindows
AuthorWilliamRE
GenreSports
Tags2D, Arcade, Multiplayer, Pixel Art, Remake

Download

Download
Airhockey.zip.zip 14 MB

Install instructions

Dowload from the dowload thing higher up. Unzip the zip file and run the file named main.  if this comes notice comes on your screen press more info then run anyways


Leave a comment

Log in with itch.io to leave a comment.