How To

Class?

0

LowRes Oranges are good 2020-03-22 15:36

Is their any way for me to make an object or class? I know there isn't but maybe using other commands you could simulate it? It would be very useful for sprites. Also any tips in general. Thank you!


was8bit 2020-03-22 16:30 (Edited)

Yes....kinda...

by using arrays indexed 0-63.. then

Then make other arrays using the same indexs, so any change in any other array references each other, so changes to index 5 affects sprite 5

Also, then, a non indexed array can be used to affect a range or all sprites at once...


Timo 2020-03-23 21:05

Yes, a big part of classes you can simulate with arrays, also independently from sprites.
I'll try to explain when I'm less tired...


Timo 2020-03-24 14:16

Imagine this in a C++-like language:

class Enemy {
   int x
   int y
   void move() {
      x=x+1
      y=y+1
   }
}

Enemy enemies[10]
for (int i = 0; i < 10; i++) {
   enemies[i].move()
}

You could do something similar in BASIC like this:

DIM GLOBAL X(9),Y(9)

SUB MOVEENEMY(N)
   X(N)=X(N)+1
   Y(N)=Y(N)+1
END SUB

FOR I=0 TO 9
   CALL MOVEENEMY(I)
NEXT I


was8bit 2020-03-24 15:56 (Edited)

Basic+Subs i understand intuitively like i can understand decimal math intuitively..

C to me is like BIT math... I "CAN" understand it, but it isn't intuitive, it takes me more time to think about it to get it right...


Log in to reply.