# Is there a better way of checking for colliding

the code (my code unchanged) runs fine on my arduboy. also sorry if its messy after being deleted i rushed to get back the basic concept! also thanks all trying it now!

now how to use this for a block solid cant go through it but i can stand on it?

Create a variable call it floor or something

If player location x > block location x and less than block location x plus the width of the block, have variable floor change to floor - height of block

youyouāt need collision detection for that

ive tried if he gets above it he teleports to the floor!
and if i set it other way round he melts through the block!

That depends, is this a top down game or a vertical side scroller?

The reason he falls to the floor is because your code tells him to always fall to the floor if he is above it (makes sense) however the floor needs to change temporarily whenever he is on a place you donāt want him to sink through, that being said you will also need to set the floor back to where you want it if the players x location is no longer on the platform

There is probably a better way to do this but I usually have a check on both sides of the platform,

There are infinite ways to do what you want to do just got to play with it till you like it

The game is one were you cannot leave the screen you must climb up platforms and thatās all I can say

So itās a vertical scroller like ice climbers?

1 Like

P1x is platforms x location
Locx is players location on x axis
Locy is players y location

Cgd is can go down (elsewhere I have code that makes the player fall to the floor if can go down = 1

• if locy15 == p1y) { //if 1px above plat 1
if (locx + 16 < p1x) { cgd = 0; } //changed back to 16
if (locx > (p1x + p1w)) { cgd = 0; } //reset cgd if right of plat 1
if (locx <= (p1x + p1w) && (locx + 16 >= p1x)) { cgd = 1; } //stop from going down
}

See the full code here https://github.com/curlyc/arduel/blob/master/arduel.ino

But note that there are alot of things in there I did wrong I I did learn a lot wright ing that and will soon clean up that code alot

2 Likes

Sorta I guess same climbing idea just no brick breakingā¦yet

1 Like

Thanks curly will run it in todayā¦ Itās 6:00

Well if you want to break bricks by all means break them just make Shure to adjust the floor accordingly so you donāt float on an empty block, if I was mining blocks though Iād probably take another approach to begin with, the best way to figure it out is to play with the code till you like it ( in my uneducated oppenion) try it for a while if you get stuck I have a few ideas

1 Like

the sketch doesnt read the == signs unless its a booleen

fixed the problem but can i use for to draw a row of them?

A row of what? Are you wanting a tile or a box?

My box the thing I was working on

1 Like

Well you draw a box like you draw anything else, o use drawfasthline and drawfastvline to make boxes, take a look at the loot demo, there is a good example in there

When you have one box next you have to decide, do you want them all the same size?

If you didnāt need them all the same height or width for that matterā¦ You could randomise it there are a million ways, the fun part is finding something you like and making it work

Yes but if I use fo I can draw boxes ten pixel apart and have them all have the same traights?

Or just use `arduboy.drawRect(x, y, w, h)`.

No idea what ātraigthsā is, but you can draw rectangles 10 pixels apart easily:

``````for(uint8_t x = 0; x < (128 / (8 + 10)); ++x)
{
arduboy.drawRect(x * (8 + 10), 0, 8, 8);
}
``````

Thereās an article here discussing various different techniques used for vertical platformers.

2 Likes