# Wall

1

Kr87 2021-05-29 07:58

Help my dumdum Brain understan please

2021-05-29 08:00
2021-05-29 07:58

Timo 2021-05-29 09:13

There are some topics already, search for "collision" in the forum. Not sure now which is the best of them. It's a tricky topic. If it's an option for your game, you could do cell-based movement (not smooth pixel based). Then it's easier to check if the next cell is free.

Dan 2021-05-29 10:36 (Edited)

Here is an working example.

the code:

```
X=0
Y=0

DO
DX=0
DY=0
BG COPY 0,0,32,32 TO 0,0
'MY CODE HERE

IF RIGHT(0) THEN
IF CELL.C(INT((X+8)/8),INT(Y/8))=0 AND CELL.C(INT((X+8)/8),((Y+7)/8))=0 THEN
X=X+1
END IF
END IF

IF LEFT(0) THEN
IF CELL.C(INT((X-1)/8),INT(Y/8))=0 AND CELL.C(INT((X-1)/8),INT((Y+7)/8))=0 THEN
X=X-1
END IF
END IF

IF UP(0) THEN
IF CELL.C(INT((X)/8),INT((Y-1)/8))=0 AND CELL.C(INT((X+7)/8),INT((Y-1)/8))=0 THEN
Y=Y-1
END IF
END IF

IF DOWN(0) THEN
IF CELL.C(INT(X/8),INT((Y+8)/8))=0 AND CELL.C(INT((X+7)/8),INT((Y+8)/8))=0 THEN
Y=Y+1
END IF
END IF

SPRITE 0,X,Y,1
WAIT 1
LOOP
```

The code works, as well, without the INT conversion.

2021-05-29 10:36

Kr87 2021-05-30 04:21

Thank you!

was8bit 2021-05-31 13:15 (Edited)

Another approach is if your game mostly cell based you can create a sprite movement that is restricted to 8x8 movements at a time, meaning you can use CELL.C(X,Y) for an easy check for an open space to move into, yet you still get the smooth pixel level sprite movement...

I kinda do this here... https://lowresnx.inutilis.com/topic.php?id=1896