1

Ok so I created a 900x600 window and whenever I move my character to the right side I'd like it to swap my background to another one.

Question n°2 How can I display "You died" message with an option to restart game (Like "Press Key to restart the game").

I've been trying to figure it out, unfortunately I wasn't able to solve it. For the record I have yet to upload my background images, just saying...

import pygame
from pygame.locals import *
import sys, time, threading
from objects import Player, Enemy


window_x, window_y = 900,600

window = pygame.display.set_mode((window_x, window_y))
pygame.display.set_caption("Hemmed")
clock = pygame.time.Clock()

class Player(pygame.sprite.Sprite):
    ''' :Main Player Class: '''
    def __init__(self):
        self.image = pygame.image.load('C:/Users/HP/Desktop/JumpingJack/playerImage.png')
        self.rect = self.image.get_rect(topleft = (player_x,player_y))


class Enemy(pygame.sprite.Sprite):
    ''' :Main Enemy Class: '''
    def __init__(self):
        self.image = pygame.image.load('C:/Users/HP/Desktop/JumpingJack/enemy1.png')
        self.rect = self.image.get_rect(topleft = (player_x,player_y))

'''Objects positions'''
# PLAYER
player_x, player_y = 35, 399
import_player_character = Player()
player_character = import_player_character.image

# ENEMY
enemy_x, enemy_y = 550, 399
import_enemy_character = Enemy()
enemy_character = import_enemy_character.image

# BACKGROUNDS
background_1 = pygame.image.load('')


isRunning = True

while isRunning == True:
  
  window.blit(player_character,(player_x, player_y))
  window.blit(enemy_character,(enemy_x, enemy_y))
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      isRunning = False
  
  keyboard = pygame.key.get_pressed()

  if keyboard[pygame.K_LEFT]:
    player_x -= 5
  if keyboard[pygame.K_RIGHT]:
    player_x += 5
  if keyboard[pygame.K_UP]:
    player_y -= 5
  if keyboard[pygame.K_DOWN]:
    player_y += 5


  pygame.display.flip()
  pygame.display.update()
  clock.tick(120)
D_00
  • 1,440
  • 2
  • 13
  • 32
FUTURE
  • 48
  • 3

0 Answers0