I'm trying to learn a bit more about linked lists, but have hit a bit of a wall, as i cant get the following method to work properly, i keep getting list index out of bounds errors.
In fairness i'm probably doing it in completely the worng way, so if anyone can suggest a better (and preferably working) alternative i'm all ears.
Anyway, the method controls the movement for some enemies that i used in Bullet Candy (which was made using structured programming rather than OO, with everything stored in arrays and suff) that basically chase down little golden ships and kill them. once they have made contact with the golden ship or the player collects the ship they are chasing, the goldenship is removed from the list and the enemies pick another one to chase or, if there are none left, go after the player.
The golden ships are called rescuables in the code, and a list of them is passed to the method as a parameter to the method, along with the players x and y coordinates.
here is the method:
I hope someone can give me some tips or suggest a resolution for this.
Cheers
Charlie
In fairness i'm probably doing it in completely the worng way, so if anyone can suggest a better (and preferably working) alternative i'm all ears.
Anyway, the method controls the movement for some enemies that i used in Bullet Candy (which was made using structured programming rather than OO, with everything stored in arrays and suff) that basically chase down little golden ships and kill them. once they have made contact with the golden ship or the player collects the ship they are chasing, the goldenship is removed from the list and the enemies pick another one to chase or, if there are none left, go after the player.
The golden ships are called rescuables in the code, and a list of them is passed to the method as a parameter to the method, along with the players x and y coordinates.
here is the method:
Method updateHarvesters:TList(inList:TList,inX:Float,inY:Float) If enemyType=2 If inList.count()>0 thisRescuable=rescuable(inList.ValueAtIndex(targetNumber)) targetX=thisRescuable.x targetY=thisRescuable.y If thisRescuable.checkCollision(x,y,1,1) Print inlist.Count() inList.Remove rescuable(inList.ValueAtIndex(targetNumber)) Print inlist.Count() If inList.count()>0 Local i:Int=Rand(0,inList.Count()-1) targetNumber=i Print "t:"+i thisRescuable=Null thisRescuable=rescuable(inList.ValueAtIndex(targetNumber)) targetX=thisRescuable.x targetY=thisRescuable.y Else targetX=inX targetY=inY End If End If Else targetX=inX targetY=inY End If rotation=calculateAngle(x,y,targetX,targetY) radius=xVel*scaleX angle=calculateAngle(x,y,targetX,targetY)-90 x=radius*Cos(angle)+x y=radius*Sin(angle)+y End If Return inList End Method
I hope someone can give me some tips or suggest a resolution for this.
Cheers
Charlie