Python pygame.K_g() Examples

The following are 3 code examples of pygame.K_g(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pygame , or try the search function .
Example #1
Source File: gifmaker.py    From stuntcat with GNU Lesser General Public License v2.1 6 votes vote down vote up
def update(self, events, screen):
        """ To integrate with the main program.

        Call it once per frame after drawing is done.
        """
        for event in events:
            if event.type == pg.KEYDOWN:
                if event.key == pg.K_g and not self.start_saving:
                    self.start_saving = time.time()
                    self.finished_saving = False
                    print("recording surfs, press g")
                elif event.key == pg.K_g and self.start_saving:
                    self.start_saving = False
                    self.finished_saving = True

        if self.finished_saving:
            self.finish()
        if self.start_saving:
            self.surfs.append(screen.copy())
            if self.seconds is not None:
                if time.time() - self.start_saving > self.seconds:
                    self.finish() 
Example #2
Source File: pyint.py    From Pyint_Pixel-Painter with GNU General Public License v3.0 5 votes vote down vote up
def key_event_up(event):
    global penSize, undoed, holdingCTRL, colorScheme, selectedTool


    if event.key == pg.K_1:
        colorScheme = 1
    elif event.key == pg.K_2:
        colorScheme = 2

    if event.key == pg.K_e:
        selectedTool = 1
        B_Buttons[1].clicked = True
        for subbutton in B_Buttons:
            if B_Buttons.index(subbutton) != selectedTool:
                subbutton.clicked = False
    elif event.key == pg.K_b:
        selectedTool = 0
        B_Buttons[0].clicked = True
        for subbutton in B_Buttons:
            if B_Buttons.index(subbutton) != selectedTool:
                subbutton.clicked = False
    elif event.key == pg.K_g:
        selectedTool = 2
        B_Buttons[2].clicked = True
        for subbutton in B_Buttons:
            if B_Buttons.index(subbutton) != selectedTool:
                subbutton.clicked = False
    elif event.key == pg.K_i:
        selectedTool = 3
        B_Buttons[3].clicked = True
        for subbutton in B_Buttons:
            if B_Buttons.index(subbutton) != selectedTool:
                subbutton.clicked = False

    if event.key == pg.K_LCTRL:
        holdingCTRL = False

    if event.key == pg.K_SPACE:
        if holdingCTRL:
            g1.clean()
            undoed = True

    if event.key == pg.K_s:
        if holdingCTRL:
            shortcutPath = FileManager(1)
            SaveFile(g1, shortcutPath)

    if event.key == pg.K_z:
        if holdingCTRL:

            for i in range(g1.yCount):
                for j in range(g1.xCount):
                    if round == 1:
                        g1.change_color(j, i, g1.undoList[1][i][j])
                    if round == -1:
                        g1.change_color(j, i, g1.undoList[0][i][j])
            undoed = True 
Example #3
Source File: creeps.py    From code-for-blog with The Unlicense 4 votes vote down vote up
def run(self):
        # The main game loop
        #
        while True:
            # Limit frame speed to 30 FPS
            #
            time_passed = self.clock.tick(30)
            #~ time_passed = self.clock.tick()
            #~ print time_passed
            
            # If too long has passed between two frames, don't
            # update (the game must have been suspended for some
            # reason, and we don't want it to "jump forward"
            # suddenly)
            #
            if time_passed > 100:
                continue
            
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.quit()
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_SPACE:
                        self.paused = not self.paused
                    elif event.key == pygame.K_g:
                        if pygame.key.get_mods() & pygame.KMOD_CTRL:
                            self.options['draw_grid'] = not self.options['draw_grid']
                elif (  event.type == pygame.MOUSEBUTTONDOWN and
                        event.button == 1):
                    for creep in self.creeps:
                        creep.mouse_click_event(event.pos)
            
            if not self.paused:
                msg1 = 'Creeps: %d' % len(self.creeps)
                msg2 = ''

                self.mboard_text = [msg1, msg2]
                
                self.creep_spawn_timer.update(time_passed)
                
                # Update and all creeps
                for creep in self.creeps:
                    creep.update(time_passed)
                    
                self.draw()
                
            pygame.display.flip()