Page 1 of 1

Car Game

Posted: Sat Aug 26, 2023 10:12 pm
by paco72
I've been trying to port car game on holydays from:
msx80
https://tic80.com/play?cart=573

The code is not mine, i have adapted some parts to run in love2d ... I'm a total beginner, sorry for my code :-)

To find out if the car is on asphalt or grass, the original author did it by comparing colors... I haven't found how to do it this way or any tutorial where someone describes how to check that in a car game.

And for what?

Well, so that the cars go more slowly when they leave the road.

Does anyone have an idea how to do it?

Re: Car Game

Posted: Sun Aug 27, 2023 6:31 am
by pgimeno
You can try loading the road image as ImageData instead of Image.

You can then create an Image out of the ImageData, but also keep the ImageData because that way you can access ImageData:getPixel.

So, instead of this:

Code: Select all

imageFile =     love.graphics.newImage("img/carretera2.png")
you'd do this:

Code: Select all

imageData = love.image.newImageData("img/carretera2.png")
imageFile = love.graphics.newImage(imageData)
and then you can draw the image using imageFile just as before, and check pixels with imageData:getPixel(x, y).

Re: Car Game

Posted: Sun Aug 27, 2023 11:20 am
by paco72
Hello good morning!

Thank you very much for your answer :)

This morning I have modified the code and I have added the modifications that you have proposed, as I am learning it is difficult for me to understand the logic, but I am working on it. I am attaching a modified version where I try to see the friction that is applied to the car when it is on and off the road... so far without much success. I'm still working and thank you very much for your help!

Re: Car Game

Posted: Sun Aug 27, 2023 1:28 pm
by dusoft
paco72 wrote: Sat Aug 26, 2023 10:12 pm To find out if the car is on asphalt or grass, the original author did it by comparing colors... I haven't found how to do it this way or any tutorial where someone describes how to check that in a car game.

And for what?

Well, so that the cars go more slowly when they leave the road.

Does anyone have an idea how to do it?
That's probably the limitation of that platform. Doing color comparisons is probably less straightforward way to do it than comparing car position with an underlying map. Another option instead of position checking is to do collision checking, where grass is a sensor and once car collides with a grass, sensor collision is triggered.