I'm having a little problem with inheritance. The way i see it, my enemy2 type over rides the updatePosition method, but when i have an object of type enemy and enemy2 there is some strange behavior. Can you see what i'm doing wrong
Cheers
Charlie
Cheers
Charlie
Strict Import "test2.bmx" Type enemy Global enemyX:Float Global enemyY:Float Global enemyDirection:Float Global enemyAngle:Float Global enemyRadius:Float Global enemyVelocity:Float Method getX:Float() Return enemyX End Method Method setX(inX:Float) enemyX=inX End Method Method getY:Float() Return enemyY End Method Method setY:Float(inY:Float) enemyY=inY End Method Method getDirection:Float() Return enemyDirection End Method Method getAngle:Float() Return enemyAngle End Method Method setDirection(inDirection:Float) enemyDirection=inDirection End Method Method getRadius:Float() Return enemyRadius End Method Method getVelocity:Float() Return enemyVelocity End Method Method setAngle(inX:Float,inY:Float) enemyAngle=calculateAngle(enemyX,enemyY,inX,inY) End Method Method setVelocity(inVel:Float) enemyVelocity=inVel End Method Method updatePosition(inX:Float,inY:Float) enemyDirection=calculateAngle(enemyX,enemyY,inX,inY) enemyRadius=enemyVelocity enemyX=enemyRadius*Cos(enemyDirection)+enemyX enemyY=enemyRadius*Sin(enemyDirection)+enemyY End Method Method setup(inX:Float, inY:Float, inVelocity:Float, inRadius:Float) enemyX=inX enemyY=inY enemyVelocity=inVelocity enemyRadius=inRadius End Method Method paint() SetColor(255,255,255) DrawRect(enemyX,enemyY,5,5) End Method Function Create:enemy() Return New enemy End Function End Type Type enemy2 Extends enemy Method updatePosition(inX:Float,inY:Float) enemyDirection:+enemyVelocity enemyX=enemyRadius*Cos(enemyDirection)+inX enemyY=enemyRadius*Sin(enemyDirection)+inY End Method End Type Graphics 640,480,0 Local en:enemy=New enemy Local en2:enemy2=New enemy2 Local i:Int en.setup(100.0,100.0,1.1,100.0) en2.setup(100.0,100.0,5,100.0) For i=0 To 100 'en.updatePosition(MouseX(),MouseY()) 'en.paint() en2.updatePosition(320,240) en2.paint() Flip Cls Next Function calculateAngle(x1:Float, y1:Float, x2:Float, y2:Float) Local x:Float=0 Local y:Float=0 Local angle:Float=0 x=x1-x2 y=y1-y2 angle=-ATan2(x,y )-90 Return angle End Function