Python Forum

Full Version: Radar/minimap
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm facing great frustration with making a minimap/radar that follows the player. It's an open space game and I really need to implement one.

Everything in the game has a vector position, and I keep the player in the middle of the screen by subtracting the it's velocity from everything else. I've made a map by just scaling everything down, but my attempts to center and follow the player on the map are just a mess.

Google hasn't yielded any examples I can follow. Here is what I have now after gutting it. It's not working (at all) but it shows what I've been trying.

the map_pos is the just the sprites position divided 10 for a start.

class Mini_map(pg.sprite.Sprite):
    def __init__(self, game, screen):
        pg.sprite.Sprite.__init__(self)
        self.surface = pg.Surface((200, 200))
        self.surface.fill((0, 0, 0))
        self.rect = self.surface.get_rect()
        self.game = game
        self.screen = screen
        self.image = self.surface
        


    def update(self):

        self.image = self.surface.copy()

        for sprite in self.game.objects:
            sprite.map_pos -= self.game.player.velocity / 10
            pg.draw.circle(self.image, (200, 200, 200), (round(sprite.map_pos.x), 
                                                         round(sprite.map_pos.y)), 1)

        self.game.player.map_pos + self.game.player.velocity / 10
        pg.draw.circle(self.image, (200, 0, 200), self.rect.center, 1) #this is to represent 
                                                                       #the player
The frustration is that this should be easy lol. Could someone point out an example to look at or suggest what numbers I should be working with. Thanks.
Got it. I was just staring at it too long. Took a break and figured it out when I went back.

It'll do.
class Mini_map(pg.sprite.Sprite):
    def __init__(self, game, screen):
        pg.sprite.Sprite.__init__(self)
        self.surface = pg.Surface((200, 200))
        self.surface.fill((0, 0, 0))
        self.rect = self.surface.get_rect()
        self.game = game
        self.screen = screen
        self.image = self.surface

    def update(self):
        self.image = self.surface.copy()
        player_map_pos = (self.game.player.position/20 - self.game.camera /20) + (80,80)
        station_pos = (self.game.station.position / 20) + (80, 80)
        pg.draw.line(self.image, ((0, 0, 150)), (int(player_map_pos.x), int(player_map_pos.y)), (int(station_pos.x), int(station_pos.y)))
        pg.draw.circle(self.image, (0, 0, 0), (int(player_map_pos.x), int(player_map_pos.y)), 50)
        pg.draw.circle(self.image, (200, 0, 200), (int(player_map_pos.x), int(player_map_pos.y)), 1)
        print(self.game.player.position, player_map_pos)
        pg.draw.rect(self.image, ((20, 200, 5)), (0, 0, 200, 200), 2)

        for sprite in self.game.objects:
            sprite.map_pos = (sprite.position / 20) + (80, 80)
            pg.draw.circle(self.image, (200, 200, 200), (round(sprite.map_pos.x), 
                                                         round(sprite.map_pos.y)), 1)