BigSteve/PyGame/practice/gameprac/hybrid.py

72 lines
1.5 KiB
Python

# https://www.youtube.com/watch?v=f4coFYbYQzw&list=PLjcN1EyupaQkAQyBCYKyf1jt1M1PiRJEp
import os
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
from pygame.sprite import Group
import pygame
from pygame.locals import *
import random
WIDTH = 600
HEIGHT = 800
WINDOW_SIZE = (WIDTH, HEIGHT)
FPS = 60
# load background image
bg = pygame.image.load("img/bg.png") # FUCK THIS IN THE ASS FIXXED IT FUCK YEA
def draw_bg():
screen.blit(bg, (0, 0))
# create spaceship class
class Spaceship(pygame.sprite.Sprite):
def __init__(self,x ,y):
pygame.sprite.Sprite.__init__(self) # review init function
self.image = pygame.image.load("img/spaceship.png")
self.rect = self.image.get_rect()
self.rect.center = [x,y]
# create sprite groups
spaceship_group = pygame.sprite.Group()
# create player
spaceship = Spaceship(int(WIDTH / 2), HEIGHT - 100)
spaceship_group.add(spaceship)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode(WINDOW_SIZE)
pygame.display.set_caption("Spave Invaders")
clock = pygame.time.Clock()
running = True
while running:
clock.tick(FPS)
#draw background
draw_bg()
# event handlers
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# draw sprite groups on screen
spaceship_group.draw(screen)
pygame.display.update() # Go over it again FLIP vs UPDATE Which to use When
pygame.quit()