|
| 1 | +from init import * |
| 2 | + |
| 3 | +# -------------------- START ----- SPRITE --------------------------------- |
| 4 | + |
| 5 | +# all sprites in one group (sprites_group) |
| 6 | +sprites_group = pygame.sprite.Group() |
| 7 | + |
| 8 | +# ==================== START ===== ADDING PLAYER SPRITE =================== |
| 9 | + |
| 10 | +player = Player() |
| 11 | +sprites_group.add(player) |
| 12 | + |
| 13 | +# ==================== END === ADDING PLAYER SPRITE ======================= |
| 14 | + |
| 15 | +# -------------------- END --- SPRITE ------------------------------------- |
| 16 | + |
| 17 | +is_running = True |
| 18 | +while is_running: |
| 19 | + |
| 20 | + # -------------------- Setting the FPS --------------------------------- |
| 21 | + |
| 22 | + clock.tick(FPS) |
| 23 | + |
| 24 | + # -------------------- Setting the FPS --------------------------------- |
| 25 | + |
| 26 | + # -------------------- START --- EVENTS -------------------------------- |
| 27 | + |
| 28 | + # group all the events and check them |
| 29 | + for event in pygame.event.get(): |
| 30 | + |
| 31 | + # event (closing the window by pressing the x button) |
| 32 | + if event.type == pygame.QUIT: |
| 33 | + is_running = False |
| 34 | + |
| 35 | + # -------------------- END ----- EVENTS -------------------------------- |
| 36 | + |
| 37 | + # -------------------- START --- UPDATE -------------------------------- |
| 38 | + |
| 39 | + # update sprites_group (all sprites) |
| 40 | + sprites_group.update() |
| 41 | + |
| 42 | + # -------------------- END ----- UPDATE -------------------------------- |
| 43 | + |
| 44 | + # -------------------- START --- RENDER -------------------------------- |
| 45 | + |
| 46 | + # init is the module and screen is a variable within |
| 47 | + screen.fill(BLACK) |
| 48 | + # draw sprites_group (all sprites) |
| 49 | + sprites_group.draw(screen) |
| 50 | + |
| 51 | + # double buffering: draw all then display |
| 52 | + # always AFTER the drawing |
| 53 | + pygame.display.flip() |
| 54 | + |
| 55 | + # -------------------- END ----- RENDER -------------------------------- |
| 56 | + |
| 57 | +pygame.quit() |
0 commit comments