Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

TIC-80

Fantasy computer for making, playing and sharing tiny games. · By Nesbox

Pix function

A topic by ATSxp created Aug 05, 2021 Views: 451 Replies: 9
Viewing posts 1 to 4

Hi, it's me again.  I don't understand why the "pix" function isn't working, I programmed it so when the white pixel (in the purple monster) touches the red line it disappears.  What do you think is going on?

Developer

Don't know what to say, please show your code.

(1 edit)

I want that when the purple monster touches something red (the line) it is removed from its table, but as you can see in the gif it's not working.  

This is the code I made:

if pix(v.x+4,v.y-1)== 2 then
    table.remove(ents,i)
   end
(+1)

I think it's something to do with the order you're drawing it, the lines are just being drawn over that pixel, you need to draw it before draw the pixel.

so... Should I put the order of this "if" statement above the line drawing function?

I misread your post actually, I thought you just wanted to show the white pixel on top of the red line, but what you want is to destroy the enemy when it touches the red line, right? If it is the case I do not recommend the use of drawing functions like pix to check this type of collisions but rather implement a function that checks for line and rectangle intersections.

That's why I chose the pix function, I don't know how to create a collision involving line with math ;_;

(+1)

Because of this post I tried to make a simple cart example of how to check this type of intersections, if you're interested you can check it here:
https://tic80.com/play?cart=2073

I read your source code and I see it's pretty cool, pretty professional, it looks like it's going to take me a while to figure it out.

(2 edits)

Wow!  I did it, what EliasJosue said was right, i should have put the drawing function above the "if" statement.  Thank you so much for helping me :)