How to use the pygame.init 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 kangsterizer / Audio_PPM_Linux / ppm.py View on Github external
import os
import pygame
from pygame import locals
import threading, thread, sys, Queue, signal

try:
	import pygtk
	pygtk.require("2.6")
except: pass
try:
	import gtk, gobject
except:
	sys.exit(1)

gobject.threads_init()
pygame.init()
pygame.joystick.init()

class SoundFile:
   def  __init__(self, signal, path):
       self.file = wave.open(path, 'wb')
       self.signal = signal
       self.sr = 44100

   def write(self):
       self.file.setparams((2, 2, self.sr, 192000*4, 'NONE', 'noncompressed'))
       self.file.writeframes(self.signal)
       self.file.close()

#some functions i didn't use after all. :P
def getsign(i):
	if i == 0: return 0
github chozabu / Neinjarz / main.py View on Github external
#try:
import pygame, sys
#import Numeric as N
#from pygame.locals import *
import pygame.locals as pgl
surfarray = pygame.surfarray
#if not surfarray:raise ImportError
#except ImportError:
#    raise ImportError, 'need pygame and numeric'

import settings

from math import hypot


pygame.init()

import display
display.loadtex("nothing.png")
import terrain
#import walker, ball, player #walker is like a lemming, and ball a simpler player
import player
import timer, time

import simplenet
import particles
import menu

#from cPickle import *
#import zlib
#from zlib import *
import OpenGL.GL as GL
github meyer9 / PixelBuild / PB.py View on Github external
except:
            # if i cant load file create it from default.map
            os.system ("cp %s %s" % ("default.map", "level0000.map"))
            #load the file i created
            self.level.loadFile("level0000.map")
            #Spawn either a forest or clearing
            if random.randint(1,8)==1:
                for i in range(2):
                    self.level.spawntree()
                del(i)
            else:
                for i in range(5):
                    self.level.spawntree()
                del(i)
        # Initialize pygame
        pygame.init()
        # Initialize pygame window size 800 x 600
        self.screen = pygame.display.set_mode((800, 600))
        # Set window title
        pygame.display.set_caption('PixelBuild')
        # Run titlescreen scene
        self.titlescreen()
    def titlescreen(self):
github asweigart / PythonStdioGames / src / gamesbyexample / pygame_games / simulate.py View on Github external
def main():
    global FPSCLOCK, DISPLAYSURF, BASICFONT, BEEP1, BEEP2, BEEP3, BEEP4

    pygame.init()
    FPSCLOCK = pygame.time.Clock()
    DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
    pygame.display.set_caption('Simulate')

    BASICFONT = pygame.font.Font('freesansbold.ttf', 16)
    infoSurf = BASICFONT.render('Match the pattern by clicking on the button or using the Q, W, A, S keys.', 1, DARKGRAY)
    infoRect = infoSurf.get_rect()
    infoRect.topleft = (10, WINDOWHEIGHT - 25)

    # load the sound files
    BEEP1 = pygame.mixer.Sound('beep1.ogg')
    BEEP2 = pygame.mixer.Sound('beep2.ogg')
    BEEP3 = pygame.mixer.Sound('beep3.ogg')
    BEEP4 = pygame.mixer.Sound('beep4.ogg')

    # Initialize some variables for a new game
github felipecode / coiltraine / model_view / carla09interface.py View on Github external
def game_loop(args, agent):
    pygame.init()
    pygame.font.init()
    world = None

    try:
        client = carla.Client(args.host, args.port)
        client.set_timeout(4.0)

        display = pygame.display.set_mode(
            (args.width, args.height),
            pygame.HWSURFACE | pygame.DOUBLEBUF)

        # We create an output image to save footage "
        if args.output_folder is not None:
            if not os.path.exists(args.output_folder):
                os.mkdir(args.output_folder)
github Eronarn / libRPG / librpg / __init__.py View on Github external
def init(game_name='LibRPG Game', icon=None):
    pygame.init()
    sound.init()

    if icon is not None:
        icon = pygame.image.load(icon)
    else:
        icon = pygame.image.load(path.data_path('icon.png'))
    pygame.display.set_icon(icon)

    virtualscreen.init(config.graphics_config.real_screen_dimensions,
                       config.graphics_config.display_mode,
                       config.graphics_config.screen_dimensions,
                       config.graphics_config.scale)
    pygame.display.set_caption(game_name)
github digiholic / universalSmashSystem / spriteManager.py View on Github external
def test():
    pygame.init()
    screen = pygame.display.set_mode([640,480])
    pygame.display.set_caption("USS Sprite Viewer")
    sprites = SpriteHandler("fighters/hitboxie/sprites", "hitboxie_", "run", 92, {(0,0,0)       : (0,0,255),
                                                                                   (128,128,128) : (0,0,128),
                                                                                   (166,166,166) : (0,0,200)})
    clock = pygame.time.Clock()
    index = 0
    
    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return -1
            if event.type == pygame.KEYDOWN:
                sprites.flipX()
        
        screen.fill([100, 100, 100])
github wesleywerner / mvc-game-design / code-02 / view.py View on Github external
def initialize(self):
        """
        Set up the pygame graphical display and loads graphical resources.
        """

        result = pygame.init()
        pygame.font.init()
        pygame.display.set_caption('demo game')
        self.screen = pygame.display.set_mode((600, 60))
        self.clock = pygame.time.Clock()
        self.smallfont = pygame.font.Font(None, 40)
        self.isinitialized = True
github ECreates / py-mandelbrot / mandelbrot / main.py View on Github external
def pg_window(width, height):
    pg.init()
    
    fill_color = 255, 255, 255 # White
    window = pg.display.set_mode((width, height))

    set_img = pg.image.load('mandelbrot.png')
    zoom_x = int(width * .15)
    zoom_y = int(height * .15)

    while True:
        window.fill(fill_color)

        mouse_pos = pg.mouse.get_pos()
        zoom_rect = pg.Rect((0,0), (zoom_x * 2 + 1, zoom_y * 2 + 1))
        zoom_rect.center = mouse_pos
        # zoom variables are the distance from mouse position to edge of rect
        # Multiplying each variable by 2 and adding 1 gives the rect its size
github BrunoTh / ETS2Autopilot / thread_autopilot.py View on Github external
def __init__(self, statusbar, controller_thread, steering_wheel, image_front):
        threading.Thread.__init__(self, daemon=True)

        with AutopilotThread.lock:
            AutopilotThread.running = True

        pygame.init()
        pygame.joystick.init()

        self.statusbar = statusbar
        self.controller_thread = controller_thread
        self.steering_wheel = steering_wheel
        self.image_front = image_front

        self.running = True
        self.country_code = Settings().get_value(Settings.COUNTRY_DEFAULT)
        self.b_autopilot = Settings().get_value(Settings.AUTOPILOT)
        self.steering_axis = Settings().get_value(Settings.STEERING_AXIS)
        self.joystick = pygame.joystick.Joystick(Settings().get_value(Settings.CONTROLLER))
        self.joystick.init()

        self.sess = tf.InteractiveSession()
        saver = tf.train.Saver()