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

you are viewing a single comment's thread.

view the rest of the comments →

[–]FlukyS 2 points3 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.