1

I am relatively new to pygame and am trying to make a simple maze game. However, after I imported the texture that I want to use as the ground for my game, my player sprite does not show up because it is beneath it. My many thanks for any help that anyone can offer. This is not a problem with my program not running, but a problem with my player character being blocked by the view of the person playing the game by the ground texture.

from sys import exit
screenwidth = 500
import random
import pygame
running = True
gameExit = False
COLOR = (255, 100, 98)
WALLCOLOR = (255,255,0)
SURFACE_COLOR = (0, 0, 0)
x = 500
y = 500
vel = 5




class Sprite(pygame.sprite.Sprite):
    def __init__(self, color, height, width):
        super().__init__()
 
        self.image = pygame.Surface([100, 100])
        self.image.fill(SURFACE_COLOR)
        self.image.set_colorkey(COLOR)
 
        pygame.draw.rect(self.image,
                         color,
                         pygame.Rect(0, 0, width, height))
 
        self.rect = self.image.get_rect()
 
    def moveRight(self, pixels):
        self.rect.x += pixels
 
    def moveLeft(self, pixels):
        self.rect.x -= pixels
 
    def moveForward(self, speed):
        self.rect.y += speed * speed/10
 
    def moveBack(self, speed):
        self.rect.y -= speed * speed/10
 
display_surface = pygame.display.set_mode((500, 500))
 
# Creating the image surface
image = pygame.image.load('DJ9ZEF.png')
 
# putting our image surface on display
# surface
display_surface.blit(image,(100,100))
 

pygame.init()
 
 
LIGHTGREEN = (0, 255, 0)
 
screenx = 1080
screeny = 600
size = (screenx, screeny)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Project")
 
 
all_sprites_list = pygame.sprite.Group()
 
playerCar = Sprite(LIGHTGREEN, 100, 100)
playerCar.rect.x = 50
playerCar.rect.y = 250
 
 
all_sprites_list.add(playerCar)
 
exit = True
clock = pygame.time.Clock()
 

keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] :
        playerCar.moveLeft(10)
if keys[pygame.K_RIGHT] :
        playerCar.moveRight(10)
if keys[pygame.K_DOWN]:
        playerCar.moveForward(10)
if keys[pygame.K_UP]:
    playerCar.moveBack(10)
 
    all_sprites_list.update()
    screen.fill(SURFACE_COLOR)
    all_sprites_list.draw(screen)
    pygame.display.flip()
    clock.tick(60)
    

wall1size = width, height = (1000, 200)
img = pygame.image.load('bird.png')

grassimg = pygame.image.load('grass.jpg')
screen.blit(grassimg, (0, 0))
grassimg1 = pygame.image.load('grass.jpg')
screen.blit(grassimg, (500, 0))
coinimg = pygame.image.load('coin.png')
coinimg = pygame.transform.scale(coinimg, (200,200))
screen.blit(coinimg, (850, 195))
empty_surface = pygame.Surface(wall1size)
pygame.Surface.fill(empty_surface, (255, 0, 0))
screen.blit(empty_surface, (250, -50)) 

px = 0
py = 0

wall1size1 = width, height = (1200, 2000)
empty_surface1 = pygame.Surface(wall1size1)
pygame.Surface.fill(empty_surface, (255, 0, 0))
screen.blit(empty_surface, (250, 425)) 
px = 0
py = 0
running = True
while running:
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    pygame.display.update()
            

pygame.quit()

I would like to have my player sprite appear above the imported ground texture in pygame.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Milockery
  • 11
  • 2
  • StackOverflow is not a tutorial, a shortcut for beginners or a debugging service. StackOverflow is a knowledge base for experienced developers based on questions and answers. Please consider [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users). You have to learn how to implement and application loop. e.g.: https://stackoverflow.com/questions/65264616/why-is-my-pygame-application-not-running-at-all – Rabbid76 Feb 07 '23 at 20:41

0 Answers0