Car Game

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
paco72
Prole
Posts: 6
Joined: Wed Jul 07, 2021 8:58 pm

Car Game

Post 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?
Attachments
car_pruebas_5.love
(81.86 KiB) Downloaded 38 times
User avatar
pgimeno
Party member
Posts: 3609
Joined: Sun Oct 18, 2015 2:58 pm

Re: Car Game

Post 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).
paco72
Prole
Posts: 6
Joined: Wed Jul 07, 2021 8:58 pm

Re: Car Game

Post 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!
Attachments
car_pruebas_6.love
(183.85 KiB) Downloaded 28 times
User avatar
dusoft
Party member
Posts: 551
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Car Game

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 7 guests