Exemplo n.º 1
0
def handleEvents(events=None, escape_exits=True):
    global next_screen, forceUpdate, quitPrompt
    
    # update last events
    Input.update()
    
    # Update our mouse position and 3 button state
    Input.update_mouse(pygame.mouse.get_pressed(), pygame.mouse.get_pos())
        
    # Add all events from the event queue to the input module
    # for this loop cycle.
    if events is None:
        events = pygame.event.get()
        
    Input.add_events(events)
    
    if (Input.down(K_ESCAPE) and escape_exits) or Input.isset("QUIT"):
        if not quitPrompt:
            quitPrompt = True
            if game.yesno_prompt("Exit RED -spider lily-?"):
                next_screen = None
                return "quit"
            quitPrompt = False
            
            forceUpdate = True
            Input.update()
    
#    if Input.up(K_F9):
#        level = int(getInput("Goto level #:", pygame.Rect(0, 550, 800, 50), default="0"))
#        forceUpdate = True
#        game.load_level(level, game.mc)
    
    if Input.up(K_F8):
        mapeditor.map_editor()
        forceUpdate = True
Exemplo n.º 2
0
def map_editor():
    
    mapa, filename = new_map()
    
    tiles = [
        map.oTile(0, 25, True),
        map.oTile(1, 25, True),
        map.oTile(2, 25, True),
        map.oTile(3, 25, True),
        map.oTile(4, 25, False),
        map.oTile(5, 25, False),
        map.oTile(6, 25, True)
    ]
        
    selector = core.load_image("selector.png", directory="gfx")
    current_tile = 0
    number = 0
    op = 0
    task = 0
    ox = 0
    oy = 0
    tw, th = mapa.tileSize

    while True:
        lag = core.clock.tick(core.MAX_FPS)
        
        
        mx, my = pygame.mouse.get_pos()
        ox = int(math.floor( (mx-mapa.x) / tw ))
        oy = int(math.floor( (my-mapa.y) / th ))
        if ox >= mapa.width:
            ox = mapa.width-1
        if oy >= mapa.height:
            oy = mapa.height-1
        if ox < 0:
            ox = 0
        if oy < 0:
            oy = 0
        
        dx, dy = ox, oy
        
        events = pygame.event.get()
        for event in events:
            if event.type == QUIT:
                exit()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    return
                if event.key == K_LEFT:
                    if task == 0: # tile
                        current_tile -= 1
                        if current_tile < 0:
                            current_tile = len(tiles)-1
                    elif task == 1: # number
                        number -= 1
                        if number < 0:
                            number = 9
                    elif task == 2: # op
                        op -= 1
                        if op < 0:
                            op = 4
                            
                if event.key == K_RIGHT:
                    if task == 0:
                        current_tile += 1
                        if current_tile >= len(tiles):
                            current_tile = 0
                    if task == 1:
                        number += 1
                        if number > 9:
                            number = 0
                    if task == 2:
                        op += 1
                        if op > 4:
                            op = 0

                if event.key == K_UP:                            
                    task -= 1
                    if task < 0:
                        task = 3
                if event.key == K_DOWN:
                    task += 1
                    if task > 3:
                        task = 0
                if event.key == K_F1:
                    mapa, filename = new_map()
                if event.key == K_F2:
                    mapa.save(filename)
                if event.key == K_F3:
                    mapa, filename = load_map()
                if event.key == K_F4:
                    mapa = edit_map(mapa)
        core.handleEvents(events)            
                
        if Input.down("MB1"):
            p = oy*mapa.width + ox
            if task == 0:
                if mapa.mapData[p] is None:
                    mapa.mapData[p] = map.oTile(0,0,False)
                mapa.mapData[p].imageID = tiles[current_tile].imageID
                mapa.mapData[p].height  = tiles[current_tile].height
                mapa.mapData[p].walkable = tiles[current_tile].walkable
            elif task == 1 and mapa.mapData[p] is not None:
                mapa.mapData[p].number = number
            elif task == 2 and mapa.mapData[p] is not None:
                mapa.mapData[p].op = op
            elif task == 3 and mapa.mapData[p] is not None:
                mapa.mapData[p].portal = True
        if Input.down("MB3"):
            p = oy*mapa.width + ox
            if task == 0:
                mapa.mapData[p] = None
            elif task == 1 and mapa.mapData[p] is not None:
                mapa.mapData[p].number = -1
            elif task == 2 and mapa.mapData[p] is not None:
                mapa.mapData[p].op = -1
            elif task == 3 and mapa.mapData[p] is not None:
                mapa.mapData[p].portal = False
        
        
        core.screen.fill((180,180,180,255))
        
        mapa.draw(core.screen)
        if task == 0:
            core.screen.blit( mapa.tileset[tiles[current_tile].imageID], (dx*tw,dy*th), special_flags=BLEND_RGBA_MULT )
        elif task == 1:
            core.screen.blit(mapa.tileset[10+number], (dx*tw, dy*th-25))
        elif task == 2:
            core.screen.blit(mapa.tileset[20+op], (dx*tw, dy*th-25))
        elif task == 3:
            core.screen.blit(mapa.tileset[8], (dx*tw, dy*th-25))
        core.screen.blit( selector, (dx*tw,dy*th-25) )
            
        
        core.fonts.Draw(core.screen, None, 24, 'x, y: ' + str(ox) + ', ' + str(oy), (10, 10), (255,255,255,255))
        
        core.updateScreen()