# Help with DIM on game

0

Tinycloud778 2019-05-29 14:13

On my game harvest time I created a dim that plants crops and when you go to sleep all plants are supposed to update their sprite number value but only the last one planted updates it’s value why does this keep happening?

Timo 2019-05-29 18:12

You're not using it the correct way. I always say I will write a tutorial about DIM but I never do :( Sorry, I really have to! Tomorrow!!

Anyway, I think I wouldn't use sprites for the plants, but cells. Remember you can put the BG COPY before the loop (and without CLS inside of the loop). Then when you plant something, you just change the cell at the correct position.
But you will still need arrays (DIM) to store more info for each plant, like the type and the days etc.

Timo 2019-05-29 18:17

But if you use cells instead of sprites, you have to include the bed into the plant characters, because BG cells are replaced completely when you set them.

Tinycloud778 2019-05-29 20:02

Ok I will use cells

Tinycloud778 2019-05-29 20:12

I’m goign to try to make a lot of games using DIM to understand it better

Tinycloud778 2019-05-29 20:20

Sorry to ask but how do you turn a cell position into a variable position

Timo 2019-05-29 20:46

There are pixel positions and cell positions. A size of a cell is 8x8 pixels. So to calculate from cell to pixel it’s:
X=CX*8
Y=CY*8
And from pixel to cell it’s:
CX=X\8
CY=Y\8
The backslash (\) is integer division, so you always get a round number as a result.

Tinycloud778 2019-05-30 00:56

Awesome thanks

Timo 2019-05-30 08:24

I added a chapter about DIM to the tutorial. It's a first draft, so if it's not clear, please tell me.

https://lowresnx.inutilis.com/topic.php?id=306

was8bit 2019-05-30 15:56

You DO have 2 backgrounds... BG 1 is in the back, and BG 0 is in the front... so you COULD layer the plants onto BG 0 .. but it would be much easier to just draw a plain dirt, then a dirt with a plant, and pop them onto the BG 1...

I try to keep my entire game on BG 1, and reserve BG 0 for game stats and game info ... just my preference...

was8bit 2019-05-30 16:02 (Edited)

DIM is just an easier way of doing this...

X1,X2,X3,X4,X5...X98,X99

Using this method, to add 1 to each X you have to write it all out manually...
X1=X1+1
X2=X2+1
....
X98=X98+1
X99=X99+1

Using DIM...

DIM X(99)

Then using a loop

FOR I=1 TO 99
X(I)=X(I)+1
NEXT I

Does the same thing... just use a variable like I in a loop to catch all numbers 1 to 99 (in this example)...

Think of it as a long road with the same looking houses along the road... each house has a street address... each house can store or hold stuff... you have to say WHICH address you want stuff stored or retrieved....

Tinycloud778 2019-05-30 16:46

Oh ok thanks

was8bit 2019-05-30 20:22

Hope this helps :)