Python Forum
Pygame loads only part of images
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pygame loads only part of images
#1
Hey there!

I'm struggeling a bit, I recoded my "game" to avoid problems with local variables, but now my game doesn't react to anything anymore and pictures are only half visible.
At least it doesn't crash anymore like it used to...

I would be very thankful if someone could look over my code and would help with that problem!
(I am very new to Python and programming in general, so don't be too harsh on my inefficient coding ^^)

Here is the code:
(For an explanation: I am trying to code a "Picross" Game)

This is my gameloop:

def game_loop():
    End = False
    while not End:
                 
        menu(mx,my)
        mposx = 0
        mposy = 0
        Lifecounter = 3
        Main = True
        q1check = False
        q2check = False
        q3check = False
        q4check = False
        q5check = False
        q6check = False
    
# MAIN MENU ##################################

        while Main:
            menu (mx,my)

            for event in pygame.event.get():
                if event.type == QUIT:
                    Main = False
                    End = True

                if event.type == pygame.MOUSEBUTTONUP:
                    if 1:
                        if q1check == False:
                            q1 = True
                            Game = True
                            Main = False
                    if 2:
                        if q2check == False:
                            q2 = True
                            Game = True
                            Main = False
                    if 3:
                        if q3check == False:
                            q3 = True
                            Game = True
                            Main = False
                    if 4:
                        if q4check == False:
                            q4 = True
                            Game = True
                            Main = False
                    if 5:
                        if q5check == False:
                            q5 = True
                            Game = True
                            Main = False
                    if 6:
                        if q6check == False:
                            q6 = True
                            Game = True
                            Main = False

            if q1check == True and q2check == True and q3check == True and q4check == True and q5check == True and q6check == True:
                win(winx,winy)
                Main = win(winx,winy)
                End = win(winx,winy)
                        
    
# GAME #######################################

        while Game:

            for event in pygame.event.get():

                if event.type == QUIT:
                    End = True
                
            if q1 == True:
                Fenster.fill(BLACK)
                Fenster.blit(q1png, (qpngx,qpngy))
                q1game(q1png,qpngx,qpngy)
                q1check = q1game()
                q1 = False
            if q2 == True:
                Fenster.fill(BLACK)
                Fenster.blit(q2png, (qpngx,qpngy))
                q2game()
                q2check = q2game()
                q1 = False
            if q3 == True:
                Fenster.fill(BLACK)
                Fenster.blit(q3png, (qpngx,qpngy))
                q3game()
                q3check = q3game()
                q3 = False
            if q4 == True:
                Fenster.fill(BLACK)
                Fenster.blit(q4png, (qpngx,qpngy))
                q4game()
                q4 = False
            if q5 == True:
                Fenster.fill(BLACK)
                Fenster.blit(q5png, (qpngx,qpngy))
                q5game()
                q5check = q5game()
                q5 = False
            if q6 == True:
                Fenster.fill(BLACK)
                Fenster.blit(q6png, (qpngx,qpngy))
                q6game()
                q6check = q6game()
                q6 = False
        
        pygame.display.update()
        clock.tick(FPS)
The qXgame() parts are defined like this example:

def q1game(q1png,qpngx,qpngy):

    Fenster.blit(q1png, (qpngx,qpngy))
    loop1 = True
    LC1 = 3
    RC1 = 0

    c1a1 = False
    c1a2 = False
    c1a3 = False
    c1a4 = False
    c1a5 = False
    c1a6 = False
    c1a7 = False
    c1a8 = False
    c1a9 = False
    c1a10 = False
    c1a11 = False
    c1b1 = False
    c1b2 = False
    c1b3 = False
    c1b4 = False
    c1b5 = False
    c1b6 = False
    c1b7 = False
    c1b8 = False
    c1b9 = False
    c1b10 = False
    c1b11 = False
    c1c1 = False
    c1c2 = False
    c1c3 = False
    c1c4 = False
    c1c5 = False
    c1c6 = False
    c1c7 = False
    c1c8 = False
    c1c9 = False
    c1c10 = False
    c1c11 = False
# and so on (I cut the rest out) 
    c1j8 = False
    c1j9 = False
    c1j10 = False
    c1j11 = False
                 
    while loop1 == True:
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONUP:
                mposx, mposy = pygame.mouse.get_pos()
                rectangle (wx, wy, ww, wh, BLACK)

                # Q1 ### Row 1 ###

                if mposy >= qpngy+70 and mposy <= qpngy+100:
                    if mposx >= qpngx+70 and mposx <= qpngy+99 and c1a1 == False:
                        rectangle (qpngx+70, qpngy+70, 30, 30, ROSA)
                        c1a1 = True
                    if mposx >= qpngx+103 and mposx <= qpngy+132 and c1a2 == False:
                        rectangle (qpngx+103, qpngy+70, 30, 30, ROSA)
                        c1a2 = True                       
                    if mposx >= qpngx+136 and mposx <= qpngy+165 and c1a3 == False:
                        rectangle (qpngx+136, qpngy+70, 30, 30, ROSA)
                        c1a3 = True
                    if mposx >= qpngx+169 and mposx <= qpngy+198 and c1a4 == False:
                        rectangle (qpngx+169, qpngy+70, 30, 30, ROSA)
                        c1a4 = True
                    if mposx >= qpngx+202 and mposx <= qpngy+231 and c1a5 == False:
                        rectangle (qpngx+202, qpngy+70, 30, 30, ROSA)
                        c1a5 = True
                    if mposx >= qpngx+235 and mposx <= qpngy+264 and c1a6 == False:
                        rectangle (qpngx+235, qpngy+70, 30, 30, ROSA)
                        c1a6 = True
                    if mposx >= qpngx+268 and mposx <= qpngy+297 and c1a7 == False:
                        Fenster.blit(wrongpng (wx,wy))
                        LC1 = LC1 - 1
                        c1a7 = True
                    if mposx >= qpngx+301 and mposx <= qpngy+330 and c1a8 == False:
                        Fenster.blit(wrongpng (wx,wy))
                        LC1 = LC1 - 1
                        c1a8 = True
                    if mposx >= qpngx+334 and mposx <= qpngy+363 and c1a9 == False:
                        Fenster.blit(wrongpng (wx,wy))
                        LC1 = LC1 - 1
                        c1a9 = True
                    if mposx >= qpngx+367 and mposx <= qpngy+396 and c1a10 == False:
                        Fenster.blit(wrongpng (wx,wy))
                        LC1 = LC1 - 1
                        c1a10 = True
                    if mposx >= qpngx+400 and mposx <= qpngy+429 and c1a11 == False:
                        Fenster.blit(wrongpng (wx,wy))
                        LC1 = LC1 - 1
                        c1a11 = True
# Then there are the 9 other rows equally designed (I used just this for testing, before copying it)

        if LC1 == 0:
            loop1 = False
            q1check = False

        if RC1 == 61:
            loop1 = False
            q1check = True
In case you are wondering, these are the other definitions I made and the overall structure

import pygame, sys
from pygame.locals import *
import time
import random
import pygame
pygame.init()

# CLOCK ######################################

FPS = 30
clock = pygame.time.Clock()

# WINDOW ####################################

width = 1200
height = 600

Fenster = pygame.display.set_mode((width,height))
pygame.display.set_caption('Sudoku in Cool')

# VARIABLES ##################################

BLACK = (0,0,0)
GREY = (40,40,40)
WHITE = (255,255,255)
ROSA = (255,174,201)

Main = True
Game = False
End = False

menupng = pygame.image.load('Menu.png')
mx = 0
my = 0
mw = 1200
mh = 600
wrongpng = pygame.image.load('wrong.png')
wx = 500
wy = 300
ww = 75
wh = 75
winpng = pygame.image.load('win.png')
winx = 30
winy = 400
winw = 100
winh = 50
picture = pygame.image.load('picture.png')

qpngw = 435  
qpngh = 402
qpngx = width/2 - qpngw/2
qpngy = height/2 - qpngh/2
q1png = pygame.image.load('Raster 1.png')
q2png = pygame.image.load('Raster 2.png')
q3png = pygame.image.load('Raster 3.png')
q4png = pygame.image.load('Raster 4.png')
q5png = pygame.image.load('Raster 5.png')
q6png = pygame.image.load('Raster 6.png')

def menu (mx,my):
    Fenster.blit(menupng, (mx,my))

menu (mx,my)

def win(winx,winy):
    Main = True
    End = False
    Fenster.blit(winpng, (winx,winy))
    for event in pygame.event.get():
        if event.type == pygame.MOUSEBUTTONUP:
            mposx, mposy = pygame.mouse.get_pos()
            if mposx > winx and mposx < winx+winw and mposy > winy and mposy < winy+winh:
                 Fenster.blit(picture, (0,0))
        if event.type == pygame.QUIT:
            Main = False
            End = True
            return Main
            return End

def rectangle(rex, rey, rew, reh, color):
    pygame.draw.rect(Fenster, color, [rex, rey, rew, reh])

game_loop()
pygame.quit ()
Again, so thankful for feedback!
Reply
#2
Looks like you need to learn the basic of python.
List and Dict are your friends.
c1 = []
# a - j
for i in range(10):
    new_list = []
    for j in range(11):
        new_list.append(False)
    c1.append(new_list)

for c in c1:
    print(c)

print()
c1[1][9] = True
print(c1[0][9])
print(c1[1][9])
print()
for c in c1:
    print(c)
pygame.Rect will help you too.
location = pygame.Rect(20,20,10,10) # left, top, width, height
Pygame has built in colors.
pygame.Color('white) . pygame.Color('black')

import pygame
print(pygame.color.THECOLORS.keys())
99 percent of computer problems exists between chair and keyboard.
Reply
#3
Thanks, I will see wether I figure that thing with the list out, any idea though, why I can only see half of the images I load?
Reply
#4
Can't test it myself. Don't have the images.
Maybe telling images they are alpha images will help.
Converting to pygame format will allow image to rendering a little faster.
So add .convert_alpha() after all png and jpg images.
Bitmaps just use .convert()
menupng = pygame.image.load('Menu.png').convert_alpha()
99 percent of computer problems exists between chair and keyboard.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] drawing images onto pygame window djwilson0495 1 3,425 Feb-22-2021, 05:39 PM
Last Post: nilamo
  Pygame - Images As Buttons vman44 3 12,820 Mar-20-2020, 08:13 PM
Last Post: vman44

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020