How to use the pygame.image.load function in pygame

To help you get started, we’ve selected a few pygame examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexdu / piggyphoto / preview.py View on Github external
def show(file):
    picture = pygame.image.load(file)
    main_surface.blit(picture, (0, 0))
    pygame.display.flip()
github turkishviking / Python-Robocode / Python-Robocode / components / TeamEditorMenu.py View on Github external
def teamSelect(screen,action):
    menuimage = pygame.image.load('menuImages/BotSelected.jpg') #Load in an image
    robotSelectedImage = pygame.image.load('menuImages/botSelected.png') #Load in an image
    robotTargettedImage = pygame.image.load('menuImages/botTargetted.png') #Load in an image
    allimage = pygame.image.load('menuImages/botImageLarge.png') #Load in an image
    randomimage = pygame.image.load('menuImages/botImageLarge.png') #Load in an image
    hideimage = pygame.image.load('menuImages/startBattleHider.jpg') #Load in an image
    screen.blit(menuimage,(0,0))
    screen.blit(hideimage,(541,452))#Place your image
    pygame.display.flip()     #Refreshes Screen
    Robots = []
    SelectedRobots = []
    x = 15
    y= 273
    bots = []
    for filename in os.listdir("teams"): #Code for displaying robot .py files
        if filename[-3:] == ".py" and filename != ".svn":
            #Name
            robotName = pygame.font.RobotNameFont.render(str(filename[:-3]), True, (255,255, 255))
            colour = parseForColour("teams/"+filename)
            bots = parseForRobots(filename)
github SodaCookie / rpeg / engine / ui / old_menu / item_icon.py View on Github external
def draw(self, item):
        surface = pygame.image.load(ItemIcon.SLOTIMAGE).convert()
        surface = pygame.transform.scale(surface, (surface.get_width()*3, surface.get_height()*3))
        if item: # we draw the image on top
            # do some move blah blah....
            if item.icon: # if we have a given icon
                icon_image = pygame.image.load(item.icon).convert()
            else: # do a default icon
                icon_image = pygame.image.load(ItemIcon.DEFAULTICON).convert()
            icon_image = pygame.transform.scale(icon_image,
                (icon_image.get_width()*3, icon_image.get_height()*3))
            surface.blit(icon_image, (3, 3))
        return surface
github MarxMustermann / OfMiceAndMechs / config / tileMap.py View on Github external
import pygame

itemUpgrader = pygame.image.load('config/Images/perspectiveTry/itemUpgrader.png')
bloomShredder = pygame.image.load('config/Images/perspectiveTry/bloomShredder.png')
corpseShredder = pygame.image.load('config/Images/perspectiveTry/corpseShredder.png')
sporeExtractor = pygame.image.load('config/Images/perspectiveTry/sporeExtractor.png')
bloomContainer = pygame.image.load('config/Images/perspectiveTry/bloomContainer.png')
container = pygame.image.load('config/Images/perspectiveTry/container.png')
moldFeed = pygame.image.load('config/Images/perspectiveTry/moldFeed.png')
seededMoldFeed = pygame.image.load('config/Images/perspectiveTry/seededMoldFeed.png')
monster_spore = pygame.image.load('config/Images/perspectiveTry/monster_spore.png')
monster_feeder = pygame.image.load('config/Images/perspectiveTry/monster_feeder.png')
monster_grazer = pygame.image.load('config/Images/perspectiveTry/monster_grazer.png')
monster_corpseGrazer = pygame.image.load('config/Images/perspectiveTry/monster_corpseGrazer.png')
monster_hunter = pygame.image.load('config/Images/perspectiveTry/monster_hunter.png')
monster_exploder = pygame.image.load('config/Images/perspectiveTry/monster_exploder.png')
moss = pygame.image.load('config/Images/perspectiveTry/mold.png')
sprout = pygame.image.load('config/Images/perspectiveTry/sprout.png')
sprout2 = pygame.image.load('config/Images/perspectiveTry/sprout2.png')
bloom = pygame.image.load('config/Images/perspectiveTry/bloom.png')
sickBloom = pygame.image.load('config/Images/perspectiveTry/sickBloom.png')
poisonBloom = pygame.image.load('config/Images/perspectiveTry/poisonBloom.png')
bush = pygame.image.load('config/Images/perspectiveTry/bush.png')
encrustedBush = pygame.image.load('config/Images/perspectiveTry/encrustedBush.png')
poisonBush = pygame.image.load('config/Images/perspectiveTry/poisonBush.png')
encrustedPoisonBush = pygame.image.load('config/Images/perspectiveTry/encrustedPoisonBush.png')
reactionChamber = pygame.image.load('config/Images/perspectiveTry/reactionChamber.png')
explosive = pygame.image.load('config/Images/perspectiveTry/explosive.png')
fireCrystals = pygame.image.load('config/Images/perspectiveTry/fireCrystals.png')
bomb = pygame.image.load('config/Images/perspectiveTry/bomb.png')
mortar = pygame.image.load('config/Images/perspectiveTry/mortar.png')
pocketFrame = pygame.image.load('config/Images/perspectiveTry/pocketFrame.png')
github visionegg / visionegg / VisionEgg / Core.py View on Github external
append_str = " (%d %d %d %d RGBA)."%(cp.red_bits,
                                                 cp.green_bits,
                                                 cp.blue_bits,
                                                 cp.alpha_bits)

        logger.info("Requesting %s %d x %d %d bpp%s"%
                    (screen_mode,self.size[0],self.size[1],
                     try_bpp,append_str))

        pygame.display.set_mode(self.size, flags, try_bpp )
        # set a global variable so we know workaround avoid pygame bug
        VisionEgg.config._pygame_started = 1

        try:
            if sys.platform != 'darwin':
                pygame.display.set_icon(pygame.transform.scale(pygame.image.load(
                    os.path.join(VisionEgg.config.VISIONEGG_SYSTEM_DIR,
                                 'data','visionegg.bmp')).convert(),(32,32)))
            else:
                import AppKit # requires PyObjC, which is required by pygame osx
                im = AppKit.NSImage.alloc()
                im.initWithContentsOfFile_(
                    os.path.join(VisionEgg.config.VISIONEGG_SYSTEM_DIR,
                                 'data','visionegg.tif'))
                AppKit.NSApplication.setApplicationIconImage_(AppKit.NSApp(),im)

        except Exception,x:
            logger.info("Error while trying to set_icon: %s: %s"%
                        (str(x.__class__),str(x)))

        global gl_vendor, gl_renderer, gl_version
        gl_vendor = gl.glGetString(gl.GL_VENDOR)
github skoam / fumiko-pygame / master.py View on Github external
def main():
	# Global Variables (They aren't so evil after all)
	global DISPLAYSURF, FPSCLOCK, FPS, PLAYER_LIST, LIST_OF_OBJECTS, LIST_OF_ENEMIES, IMAGE_LIBRARY, WINDOWWIDTH, WINDOWHEIGHT, scale_X, scale_Y
	
	# A Library for all the graphics
	IMAGE_LIBRARY =	{			'Fumiko': pygame.image.load("Fumiko.png"),
								'empty': pygame.image.load("charempty.png"),
								'Chipset_1': pygame.image.load("Chipset_1.png"),
								'BG_1': pygame.image.load("BG_2.jpg"),
								'Object_Rock': pygame.image.load("rock_smaller.png"),
								'Object_Rock_2': pygame.image.load("rock.png"),
								'Object_Grass': pygame.image.load("grass.png"),
								'Object_Grass_2': pygame.image.load("grass_2.png"),
								'Boss_A': pygame.image.load("mons6.png"),
								'Monsters': pygame.image.load("Monster_Charset.png"),
								'Monsters_Bigger': pygame.image.load("Monster_Charset_Bigger.png")
							}
	
	PLAYER_LIST = []
	LIST_OF_OBJECTS = []
	LIST_OF_ENEMIES = []
	
	FPS = 30
	WINDOWWIDTH = 800
	WINDOWHEIGHT = 600
	FULLSCREEN = False
github zork9 / pygame-pyZeldaII / mithran2.py View on Github external
self.stimlibup.addpicture(image)

	image = pygame.image.load('./pics/mithranup2-48x48.bmp').convert()
        image.set_colorkey((0,0,0)) 
	self.stimlibup.addpicture(image)
	image = pygame.image.load('./pics/mithranup2-48x48.bmp').convert()
        image.set_colorkey((0,0,0)) 
	self.stimlibup.addpicture(image)
	image = pygame.image.load('./pics/mithranup2-48x48.bmp').convert()
        image.set_colorkey((0,0,0)) 
	self.stimlibup.addpicture(image)
	image = pygame.image.load('./pics/mithranup2-48x48.bmp').convert()
        image.set_colorkey((0,0,0)) 
	self.stimlibup.addpicture(image)

	image = pygame.image.load('./pics/mithranup3-48x48.bmp').convert()
        image.set_colorkey((0,0,0)) 
	self.stimlibup.addpicture(image)
	image = pygame.image.load('./pics/mithranup3-48x48.bmp').convert()
        image.set_colorkey((0,0,0)) 
	self.stimlibup.addpicture(image)
	image = pygame.image.load('./pics/mithranup3-48x48.bmp').convert()
        image.set_colorkey((0,0,0)) 
	self.stimlibup.addpicture(image)
	image = pygame.image.load('./pics/mithranup3-48x48.bmp').convert()
        image.set_colorkey((0,0,0)) 
	self.stimlibup.addpicture(image)
        	
        image = pygame.image.load('./pics/mithranup2-48x48.bmp').convert()
        image.set_colorkey((0,0,0)) 
	self.stimlibup.addpicture(image)
	image = pygame.image.load('./pics/mithranup2-48x48.bmp').convert()
github replit / play / play / play.py View on Github external
def _compute_primary_surface(self):
        try:
            self._primary_pygame_surface = pygame.image.load(_os.path.join(self._image))
        except pygame.error as exc:
            raise Oops(f"""We couldn't find the image file you provided named "{self._image}".
If the file is in a folder, make sure you add the folder name, too.""") from exc
        self._primary_pygame_surface.set_colorkey((255,255,255, 255)) # set background to transparent

        self._should_recompute_primary_surface = False

        # always recompute secondary surface if the primary surface changes
        self._compute_secondary_surface(force=True)
github strin / curriculum-deep-RL / pyrl / tasks / pyale / london.py View on Github external
''' warning: london simulator should be singleton, as it changes pygame behavior '''
from pyrl.common import *
from pyrl.tasks.pyale import PygameSimulator, function_intercept
from pyrl.evaluate import DrunkLearner
from pygame.locals import *
from pyrl.config import floatX
import time
import pygame

_name = 'london'

WINNING_SCORE = 1

path_prefix = os.path.join(os.path.dirname(__file__), 'games', _name)
pygame.image._old_load = pygame.image.load
pygame.image.load = lambda path: pygame.image._old_load(os.path.join(path_prefix, path))
pygame.font._old_Font = pygame.font.Font
pygame.font.Font = lambda path, size: pygame.font._old_Font(os.path.join(path_prefix, path), size)

class LondonSimulator(PygameSimulator):
    def __init__(self, state_type='pixel'):
        PygameSimulator.__init__(self, 'london', [chr(ord('0') + k) for k in range(30)],
                state_type=state_type)


    def is_end(self):
        try:
            game_handler = self._get_attr('stateHandler').gameHandler
            if game_handler is None:
                return False
            return game_handler.gameOver
        except:
github MarxMustermann / OfMiceAndMechs / config / tileMap.py View on Github external
monster_spore = pygame.image.load('config/Images/perspectiveTry/monster_spore.png')
monster_feeder = pygame.image.load('config/Images/perspectiveTry/monster_feeder.png')
monster_grazer = pygame.image.load('config/Images/perspectiveTry/monster_grazer.png')
monster_corpseGrazer = pygame.image.load('config/Images/perspectiveTry/monster_corpseGrazer.png')
monster_hunter = pygame.image.load('config/Images/perspectiveTry/monster_hunter.png')
monster_exploder = pygame.image.load('config/Images/perspectiveTry/monster_exploder.png')
moss = pygame.image.load('config/Images/perspectiveTry/mold.png')
sprout = pygame.image.load('config/Images/perspectiveTry/sprout.png')
sprout2 = pygame.image.load('config/Images/perspectiveTry/sprout2.png')
bloom = pygame.image.load('config/Images/perspectiveTry/bloom.png')
sickBloom = pygame.image.load('config/Images/perspectiveTry/sickBloom.png')
poisonBloom = pygame.image.load('config/Images/perspectiveTry/poisonBloom.png')
bush = pygame.image.load('config/Images/perspectiveTry/bush.png')
encrustedBush = pygame.image.load('config/Images/perspectiveTry/encrustedBush.png')
poisonBush = pygame.image.load('config/Images/perspectiveTry/poisonBush.png')
encrustedPoisonBush = pygame.image.load('config/Images/perspectiveTry/encrustedPoisonBush.png')
reactionChamber = pygame.image.load('config/Images/perspectiveTry/reactionChamber.png')
explosive = pygame.image.load('config/Images/perspectiveTry/explosive.png')
fireCrystals = pygame.image.load('config/Images/perspectiveTry/fireCrystals.png')
bomb = pygame.image.load('config/Images/perspectiveTry/bomb.png')
mortar = pygame.image.load('config/Images/perspectiveTry/mortar.png')
pocketFrame = pygame.image.load('config/Images/perspectiveTry/pocketFrame.png')
case = pygame.image.load('config/Images/perspectiveTry/case.png')
memoryCell = pygame.image.load('config/Images/perspectiveTry/memoryCell.png')
frame = pygame.image.load('config/Images/perspectiveTry/Frame.png')
watch = pygame.image.load('config/Images/perspectiveTry/watch.png')
backTracker = pygame.image.load('config/Images/perspectiveTry/backTracker.png')
tumbler = pygame.image.load('config/Images/perspectiveTry/tumbler.png')
positioningDevice = pygame.image.load('config/Images/perspectiveTry/positioningDevice.png')
stasisTank = pygame.image.load('config/Images/perspectiveTry/stasisTank.png')
engraver = pygame.image.load('config/Images/perspectiveTry/engraver.png')
gameTestingProducer = pygame.image.load('config/Images/perspectiveTry/gameTestingProducer.png')