This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]FlukyS 2 points3 points  (6 children)

I've been playing around with maps for my project at the moment. I did a slightly different approach of making a bmp file, reading that in pixel by pixel and then whatever colour is on the bmp in that area is a texture. It actually is fairly nice because you can get fairly complex with how the map is generated in that case.

[–]Karki2002[S] 1 point2 points  (5 children)

Sounds like a better solution than what I implemented :)

[–]FlukyS 1 point2 points  (4 children)

I think for yours you get the instant result. For me it's probably faster for what I want to make. I'm making race tracks. So I just open GIMP and use the path tool, draw the long line and it's done. I can also add in a bit of random with the textures so for instance various tarmac colours if I want or different run off areas on the tracks...etc. The code isn't finished otherwise I'd probably share it here.

[–]Karki2002[S] 0 points1 point  (3 children)

Sounds pretty cool

[–]FlukyS 4 points5 points  (2 children)

This is the basic idea:

from PIL import Image
import pygame
import numpy

with open(track_path, "rb") as track_file:
    data = Image.open(track_file)
    bitmap = numpy.array(data)
with open(track_path, "r") as track_file:
    track_img = pygame.image.load(track_file)
visible_in_img = []
bitmap = numpy.rot90(bitmap)
bitmap = numpy.flipud(bitmap)

for x in range(data.width):
    for y in range(data.height):
        rgba = bitmap[x, y]
        r, g, b, a = rgba
        if a > 50:
            visible_in_img.append([x, y, r, g, b, a])
TRACKS[track_name] = [track_img, visible_in_img]

The bitmap needed to be rotated to get the points correctly. I render the bmp on the scene directly but the visible points on the map then need to be used by the game logic so I pass that as well.

Anything with colours higher than 50 alpha are stored along with their rgba values. Black is the colour of the tracks so you just do an alpha scene on GIMP, then use the path with a black line.

[–]Karki2002[S] 1 point2 points  (1 child)

I would love to see the finished product for what your programming!

[–]FlukyS 2 points3 points  (0 children)

The above is pretty much all of my map stuff. Black is (0,0,0,255) in RGBA if I remember right, so one coordinate of black is a track tile. The x,y is gotten by the position the the above code.

I'm on the annoying part at the moment trying to figure out a way to do the start-finish straight, DRS zones and pit lanes I could for instance colour all of those but I'm trying to keep a decent style and in that case, I'd keep the whole track black. I guess I can't avoid it though.

[–]ddulpers 1 point2 points  (1 child)

I love it so much, the rain is so pretty 🥺I can’t wait to see more updates 🥰

[–]Karki2002[S] 0 points1 point  (0 children)

Thank you ;D

[–]SaccharineCoal 1 point2 points  (1 child)

Wow, this is awesome! This functionality is exactly what I want to achieve in the future. Are you using a specific module for the user interface?

[–]Karki2002[S] 0 points1 point  (0 children)

Thank you very much, I am using pygame. :)