How to make SPACE INVADERS using Pygame in Python

DO MAKE SURE TO VISIT MY CHANNEL :) import pygame, random pygame.init() health = 100 score = 0 display = pygame.display.set_mode((1200, 673)) bg = pygame.image.load("space.png") player = pygame.image.load("player.png") enemy = pygame.image.load("enemy.png") bullet = pygame.image.load("bullet (2).png") bullet_2 = pygame.image.load("bullet (2).png") bullet_3 = pygame.image.load("bullet (2).png") player_x = 550 player_y = 500 player_bullet = pygame.image.load("bullet (2).png") player_bullet_x = player_x-10 player_bullet_y = player_y+20 enemy_x = random.randint(0, 1000) enemy_2_x = random.randint(0, 1000) enemy_3_x  = random.randint(0, 1000) enemy_y = 0 enemy_bullet_x = enemy_x+17 enemy_bullet_2_x = enemy_2_x+17 enemy_bullet_3_x = enemy_3_x+17 enemy_bullet_y = enemy_y+25 running = True while running:     font = pygame.font.SysFont(None, 40 )     display.blit(bg, (0, 0))     text = font.render(f'Score: {score}', T...

How To Make a Car Game Using Python

import pygame, random
pygame.init()

score = 0

player_x = 170
player_y = 600

police_x = random.randint(35, 400)
police_y = 0

display = pygame.display.set_mode((570, 870))

bg = pygame.image.load("road.png")
player = pygame.image.load("player.png")
police = pygame.image.load("police.png")

running = True
while running:
    display.blit(bg, (0 , 0))
    display.blit(police, (police_x, police_y))
    display.blit(player, (player_x, player_y))
    font = pygame.font.SysFont(None, 40)
    text = font.render(f'{score}', True, (0, 0, 0))
    display.blit(text, (30, 20))
    player_mask = pygame.mask.from_surface(player)
    police_mask = pygame.mask.from_surface(police)

    offset = (int(police_x - player_x), int(police_y - player_y))
    collide = player_mask.overlap(police_mask, offset)
   
    if collide:
        running = False
   
    police_y += 7.5

    if police_y == 870:
        score += 1
        police_x = random.randint(35, 400)
        police_y = 0
        display.blit(police, (police_x, police_y))
   
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                player_x -= 10
            if event.key == pygame.K_RIGHT:
                player_x += 10

    pygame.display.update()

pygame.quit()
quit()

Comments

Popular posts from this blog

How to make Chess game using Python, Pygame

How to make SPACE INVADERS using Pygame in Python