So I'm a new programmer 2 weeks of learning. I was wondering on how to load an image correctly using Pygame 1.9.6. I'm trying to roll a dice and whatever it rolls loads the correct image. But, I need to know how to load an image first.
Now this is all what I've come up with so far:
import pygame as p
WIDTH = HEIGHT = 250
DIMENSION = 2
SQ_SIZE = HEIGHT // DIMENSION
IMAGES = {}
class DiceState:
def __int__(self):
self.Dice = ['d1', 'd2', 'd3', 'd4', 'd5', 'd6']
def drawBackground(screen):
colors = [p.Color("black")]
for d in range(DIMENSION):
color = colors
p.draw.rect(screen, color, p.Rect(SQ_SIZE, SQ_SIZE))
def loadImages():
dice_sides = ['d1', 'd2', 'd3', 'd4', 'd5', 'd6']
for dice_side in dice_sides:
IMAGES[dice_side] = p.transform.scale(p.image.load("images/" + dice_side + ".png"), SQ_SIZE)
def main():
p.init()
screen = p.display.set_mode((WIDTH, HEIGHT))
screen.fill(p.Color("white"))
ds = DiceState
loadImages()
running = True
if __name__ == "__main__":
main()
d1 means dice 1 for number 1. d2 = number 2
What I've tried is that it's my first time attempting this so I have no idea what to do. I know I shouldn't come on this site and pester you all to fix my issues. But all I want is help. I want to learn like you all too. So please help me if you can and want.