Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this is my entire main file
- import pygame as pg
- from settings import *
- from sprites import *
- #initializes pygame
- pg.init()
- pg.mixer.init()
- screen = pg.display.set_mode((WIDTH,HEIGHT))
- pg.display.set_caption("My Game")
- clock = pg.time.Clock()
- #adds and spawns them in group
- all_sprites = pg.sprite.Group()
- platforms = pg.sprite.Group()
- #adds the sprite to group and spawns the sprites
- player = Player()
- all_sprites.add(player)
- p1 = Platform(0, HEIGHT - 40, WIDTH, 40)
- all_sprites.add(p1)
- platforms.add(p1)
- p2 = Platform(WIDTH / 2 - 50, HEIGHT - 300, 100, 20)
- all_sprites.add(p2)
- platforms.add(p2)
- #Game loop
- running = True
- while running:
- #keep loop running at the right speed
- clock.tick(FPS)
- #proccess input(events)
- for event in pg.event.get():
- #check for closing the window
- if event.type == pg.QUIT:
- running = False
- if event.type == pg.KEYDOWN:
- if event.key == pg.K_SPACE:
- player.jump()
- #Update
- all_sprites.update()
- hits = pg.sprite.spritecollide(player, platforms, False)
- if hits:
- player.pos.y = hits[0].rect.top + 1
- player.vel.y = 0
- #Draw / render
- screen.fill(BLACK)
- all_sprites.draw(screen)
- #after drawing everything_flip the display
- pg.display.flip()
- pg.quit()
Advertisement
Add Comment
Please, Sign In to add comment