As you can see, the following code can be compared to Snake. In fact it works pretty good.
In fact it's part of a larger program, but I got the code smaller to be able to see the error with less difficulty. My problem is the slow down, when I have more than 10 spheres following each other.
BACKDROP ON : SYNC ON : RANDOMIZE TIMER()
COLOR BACKDROP RGB(205,205,205)
People = 20
DIM DancingPeople(People)
PeopleDancing = 1 : DancingPeople(1) = 1
MAKE MATRIX 1,2500,2500,50,50 : POSITION MATRIX 1,-1250,0,-1250
FOR x = 1 to People
MAKE OBJECT SPHERE x,50
POSITION OBJECT x, RND(2400)-1200,0,RND(2400)-1200
NEXT x
REPEAT
GOSUB MovePeople
GOSUB JoinIn
SYNC
UNTIL MOUSECLICK()=1
DELETE MATRIX 1
FOR x = 1 to People
DELETE OBJECT x
NEXT x
UNDIM DancingPeople(People)
END
JoinIn:
IF OBJECT COLLISION(DancingPeople(1),0) > 0
ok = 1
FOR y = 1 TO PeopleDancing
IF OBJECT COLLISION(DancingPeople(1),0) = DancingPeople(y)
ok = 0
ENDIF
NEXT y
IF ok = 1
INC PeopleDancing
FOR x = PeopleDancing TO 2 STEP -1
DancingPeople(x) = DancingPeople(x-1)
NEXT x
DancingPeople(1) = OBJECT COLLISION(DancingPeople(2),0)
YROTATE OBJECT DancingPeople(1),wrapvalue(object angle y(DancingPeople(2)))
YROTATE OBJECT DancingPeople(1),wrapvalue(object angle y(DancingPeople(2)))
ENDIF
ENDIF
RETURN
MovePeople:
IF LEFTKEY()=1 THEN YROTATE OBJECT DancingPeople(1),wrapvalue(object angle y(DancingPeople(1))-2)
IF RIGHTKEY()=1 THEN YROTATE OBJECT DancingPeople(1),wrapvalue(object angle y(DancingPeople(1))+2)
IF UPKEY()=1 THEN MOVE OBJECT DancingPeople(1),5 : PushFlag = 1
X# = OBJECT POSITION X(DancingPeople(1))
Z# = OBJECT POSITION Z(DancingPeople(1))
POSITION CAMERA X#/2,500,Z#/2
POINT CAMERA X#,0,Z#
FOR y = 2 to PeopleDancing
POINT OBJECT DancingPeople(y), OBJECT POSITION X(DancingPeople(y-1)),0,OBJECT POSITION Z(DancingPeople(y-1))
IF PushFlag = 1 AND SQRT((OBJECT POSITION X(DancingPeople(y-1))-OBJECT POSITION X(DancingPeople(y)))^2*(OBJECT POSITION Z(DancingPeople(y-1))-OBJECT POSITION Z(DancingPeople(y)))^2) > 50 THEN MOVE OBJECT DancingPeople(y),5
IF OBJECT COLLISION(DancingPeople(y), DancingPeople(y-1)) THEN MOVE OBJECT DancingPeople(y),-.5
NEXT y
PushFlag = 0
RETURN
These are things that are in the game and shall not be changed :
The last touched sphere shall be the new leader and have the direction of the one who touched him.
The way they are following each other is good
These are the things I'd like to get better :
The speed.
The spheres not going into each other
I would be gratefull, id somebody could help me with it. Thanks
- Mind the gap -
