Exemplo n.º 1
0
    def __init__(self):
        self.eventManager = EventManager()
        self.running = True

        self.uid = 0

        self.game = None
        self.state = PlayerState.chooseName
        self.inputManager = InputManager()
        self.gameState = None

        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.serverHost = Server.host
        self.serverPort = Server.port
        self.clientHost = "192.168.0.106"
        self.clientPort = 5002
        self.sock.bind((self.clientHost, self.clientPort))

        self.lock = threading.Lock()
        self.packets = Queue()
        self.networkingThread = threading.Thread(target=self.networking)
        self.networkingThread.daemon = True
        self.networkingThread.start()

        self.sendAlive = Server.checkAlive - 1 / 2
        self.nextAlive = 0

        print "Client started"
Exemplo n.º 2
0
    def __init__(self):
        application = self

        #global initialization
        pyxel.init(255, 255, caption="Nearym Quest", scale=3)
        self.debugOverlay = False
        self.camera = Camera()
        self.streamingArea = Box()
        self.streamingArea.size = Vector2f(512, 512)
        self.streamingArea.center = Vector2f(0, 0)
        self.renderer = Renderer()
        self.physics = Physics()
        random.seed(0)

        # Event Manager
        self.inputManager = InputManager()
        self.inputManager.addInput(
            Input(InputType.BUTTON, InputNotify.PRESSED, [pyxel.KEY_F1],
                  'debug'))

        # world and player
        self.LoadMap()

        self.draw_count = 0

        # has to be completely at the end of init
        pyxel.run(self.update, self.draw)
Exemplo n.º 3
0
    def __init__(self, uid, pos, name):
        # Unique ID associated with character
        self.uid = uid
        self.pos = pos
        self.name = name

        self.player = None
        self.game = None

        self.health = maxHealth

        self.vel = [0.0, 0.0]
        # Velocity delta
        self.velDel = [1.5, 1.5]
        self.velMax = [10, 10]
        # How much the velocity retains per frame
        self.velRed = [0.8, 0.8]

        self.width = width
        self.height = height
        self.setRect()

        self.mainAbility = Ability(0.5)
        self.reallySmallNumber = 0.0001
        self.inputManager = InputManager()
Exemplo n.º 4
0
 def __new__(cls):
     if cls.__instance is None:
         cls.__instance = super(Managers, cls).__new__(cls)
         cls.__instance.app = QtWidgets.QApplication(sys.argv)
         cls.__instance.input = inputManager.InputManager()
         cls.__instance.scene = scene.SceneManager()
         cls.__instance.scene.resize(1550, 1000)
         cls.__instance.objects = objMan.ObjectManager(cls.__instance.scene)
         cls.__instance.collisionDetection = collision.CollisionDetection(
             cls.__instance.objects)
     return cls.__instance
Exemplo n.º 5
0
	def __init__ (self):
	
		self.lll = LowLevelLib ()
		self.inputmanager = InputManager (self)
		
		#self.display = Display ()
		self.viewspace = ViewSpace ()
		self.curmap = Map (40)
		# just for test
		self.curmap.heights.setHeight(2,3,-1)
		self.curmap.heights.setHeight(2,5,1)
		self.curmap.heights.setHeight(4,5,-1)
		self.gfxengine = GFXEngine (self.lll, self.viewspace, self.curmap)
		self.gamecontroller = GameController (self)
		self.running = False
		self.starttime = 0
Exemplo n.º 6
0
 def __init__(self):
     self.game_constants = Counter()
     self.game_constants['level'] = 0
     # Set up blitting surfaces
     self.generic_surf = Engine.create_surface((GC.WINWIDTH, GC.WINHEIGHT))
     # Build starting stateMachine
     self.stateMachine = StateMachine.StateMachine(['start_start'], [])
     self.input_manager = InputManager.InputManager()
     # Menu slots
     self.activeMenu = None
     self.childMenu = None
     self.background = None
     # Surface holder
     self.info_surf = None
     # playtime
     self.playtime = 0
     # mode
     self.mode = self.default_mode()
Exemplo n.º 7
0
def InitLoopManager(cScene):
    # Create cSM wrapper
    cSM = pylSoundManager.SoundManager(cScene.GetSoundManagerPtr())

    # Create the states (these three sequences are common to all)
    lSeq_chSustain = LoopSequence('chSustain', [
        Loop('chSustain1', 'chSustain1_head.wav', 5, 1., 'chSustain1_tail.wav')
    ])
    lSeq_bass = LoopSequence(
        'bass', [Loop('bass', 'bass1_head.wav', 5, 1., 'bass1_tail.wav')])
    lSeq_drums = LoopSequence(
        'drums', [Loop('drum1', 'drum1_head.wav', 5, 1., 'drum1_tail.wav')])

    # State 1 just plays lead1, lead2, lead1, lead2...
    s1 = DrawableLoopState(
        'One', {
            lSeq_chSustain, lSeq_bass, lSeq_drums,
            LoopSequence('lead', [
                Loop('lead1', 'lead1.wav'),
                Loop('lead2', 'lead2_head.wav', 5, 1., 'lead2_tail.wav')
            ], itertools.cycle)
        })

    # State 2 just plays lead3, lead4, lead3, lead4...
    s2 = DrawableLoopState(
        'Two', {
            lSeq_chSustain, lSeq_bass, lSeq_drums,
            LoopSequence(
                'lead',
                [Loop('lead3', 'lead3.wav'),
                 Loop('lead4', 'lead4.wav')], itertools.cycle)
        })

    # State 3 plays lead5, lead6, lead7, lead7...
    s3 = DrawableLoopState(
        'Three', {
            lSeq_chSustain, lSeq_bass, lSeq_drums,
            LoopSequence('lead', [
                Loop('lead5', 'lead5.wav'),
                Loop('lead6', 'lead6.wav'),
                Loop('lead7', 'lead7.wav'),
                Loop('lead7', 'lead7.wav')
            ], itertools.cycle)
        })

    s4 = DrawableLoopState('Four', {lSeq_bass, lSeq_drums})
    s5 = DrawableLoopState(
        'Five',
        {lSeq_bass,
         LoopSequence('drums2', [Loop('drum2', 'drum2.wav')])})

    # Store all nodes in a list
    nodes = [s1, s2, s3, s4, s5]

    # Create the directed graph; all nodes connect and self connect
    G = nx.DiGraph()
    G.add_edges_from(itertools.product(nodes, nodes))

    # The advance function just returns a random neighbor
    def fnAdvance(SG):
        # Cartesian product
        def dot(A, B):
            return sum(a * b
                       for a, b in itertools.zip_longest(A, B, fillvalue=0))

        # Return the target of the edge out of activeState whose pathVec is most in line with stim
        return max(SG.G.out_edges_iter(SG.activeState, data=True),
                   key=lambda edge: dot(SG.stim, edge[2]['pathVec']))[1]

    # Define the vectors between edges
    # (used during dot product calculation, SG.stim is one of these)
    diEdges = {n: [1 if n == nn else 0 for nn in nodes] for n in nodes}
    for n in nodes:
        for nn in G.neighbors(n):
            G[n][nn]['pathVec'] = diEdges[nn]

    # Construct the StateGraph with an attribute 'stim' of s1's stimulus,
    # as well as a reference to the scene, so the states can use it
    SG = StateGraph(G, fnAdvance, s1, stim=diEdges[s1], cScene=cScene)

    # Init audio spec
    if cSM.Configure({'freq': 44100, 'channels': 1, 'bufSize': 4096}) == False:
        raise RuntimeError('Invalid aud config dict')

    # Voices (anything that makes sound) need a unique int ID
    voiceID = 0
    diLoopToVoiceID = dict()

    # get the samples per mS
    sampPerMS = int(cSM.GetSampleRate() / 1000)

    # For each loop in the state's loop sequences
    for loopState in nodes:
        # The state's trigger res is its longest loop
        loopState.triggerRes = 0
        for lSeq in loopState.diLoopSequences.values():
            for l in lSeq.loops:
                # Set tailfile to empty string if there is None
                if l.tailFile is None:
                    l.tailFile = ''
                # Add the loop
                if cSM.RegisterClip(l.name, l.headFile, l.tailFile,
                                    int(sampPerMS * l.fadeMS)) == False:
                    raise IOError(l.name)

                # If successful, get a handle to c loop and store head/tail duration
                l.uNumHeadSamples = cSM.GetNumSamplesInClip(l.name, False)
                l.uNumTailSamples = cSM.GetNumSamplesInClip(
                    l.name, True) - l.uNumHeadSamples

                # The state's trigger res is its longest loop
                if l.uNumHeadSamples > loopState.triggerRes:
                    loopState.triggerRes = l.uNumHeadSamples

                # Give this loop a voice ID and inc
                if l not in diLoopToVoiceID.keys():
                    diLoopToVoiceID[l] = voiceID
                    voiceID += 1
                l.voiceID = diLoopToVoiceID[l]

    # This dict maps the number keys to edge vectors defined in diEdges
    # (provided there are less than 10 nodes...)
    # the edge vectors are used during state advancement for the graph
    diKeyToStim = {
        SDLK.SDLK_1 + i: diEdges[n]
        for i, n in zip(range(len(nodes)), nodes)
    }

    # The stimulus update function assigns the stim
    # member of the stategraph based on what the
    # button maps to in the dict
    def fnStimKey(btn, keyMgr):
        nonlocal diKeyToStim
        nonlocal SG
        if btn.code in diKeyToStim.keys():
            SG.stim = diKeyToStim[btn.code]

    liButtons = [Button(k, None, fnStimKey) for k in diKeyToStim.keys()]

    arpClip = Loop('arp', 'arplead1.wav', 5, 1., 'arplead1.wav')
    arpClip.voiceID = voiceID + 1
    if cSM.RegisterClip(arpClip.name, arpClip.headFile, arpClip.tailFile,
                        int(sampPerMS * arpClip.fadeMS)) == False:
        raise IOError(arpClip.name)

    # Hard coded test for now
    def fnOneShotKey(btn, keyMgR):
        nonlocal cSM
        nonlocal arpClip
        t = (arpClip.name, arpClip.voiceID, arpClip.vol,
             int(cSM.GetMaxSampleCount() / 4))
        cSM.SendMessage((pylSoundManager.CMDOneShot, t))

    liButtons.append(Button(SDLK.SDLK_f, None, fnOneShotKey))

    # The escape key callback tells the scene to quit
    def fnEscapeKey(btn, keyMgr):
        nonlocal cScene
        cScene.SetQuitFlag(True)

    liButtons.append(Button(SDLK.SDLK_ESCAPE, None, fnEscapeKey))

    # The space key callback tells the loop manager to play/pause
    def fnSpaceKey(btn, keyMgr):
        nonlocal cSM
        cSM.PlayPause()

    liButtons.append(Button(SDLK.SDLK_SPACE, None, fnSpaceKey))

    # Create the input manager (no mouse manager needed)
    inputManager = InputManager(cScene, KeyboardManager(liButtons),
                                MouseManager([]))

    # Create the sound manager
    loopManager = LoopManager(cScene, SG, inputManager)

    # Start the active loop seq
    activeState = loopManager.GetStateGraph().GetActiveState()
    messageList = [(pylSoundManager.CMDStartLoop, (l.name, l.voiceID, l.vol,
                                                   0))
                   for l in activeState.GetActiveLoopGen()]
    cSM.SendMessages(messageList)

    # return the sound manager
    return loopManager
Exemplo n.º 8
0
import pygame
import time
import GameManager
import InputManager
import traceback

pygame.init()
running = True
screen_width = 1300
screen_height = 700
screen = pygame.display.set_mode([screen_width, screen_height])
pygame.display.set_caption("I love Monkeys... and turtles")

try:
    im = InputManager.InputManager()
    gm = GameManager.GameManager((screen_width, screen_height), im)

    t = pygame.time.get_ticks()

    while running:
        oldtime = t
        t = pygame.time.get_ticks()

        #TODO add event processing system
        for e in pygame.event.get():
            if pygame.QUIT == e.type:
                running = False
            elif e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
                running = False
            else:
                im.process(e)