void EnemyShip::update(float dt,Vector2d shippos,Vector2d bulletpos) { timespawn-=dt; newposition=(shippos-position); newvelocity=(velocity.x*normalize(newposition)); angle=(shippos.y>= position.y) ? acos(newvelocity.x/velocity.x) : -acos(newvelocity.x/velocity.x); float hitvec=length(bulletpos-position); if(!dead) { position = position + dt*newvelocity; } if(!dead && hitvec <= 20.0f) { dead=true; hit=true; } if(length(newposition) <= 10) { dead=true; gameOver=true; } if(dead) { position=Vector2d(randy.randomInRange(-1000,2000),randy.randomInRange(-1000,2000)); while(position.x<=1920&&position.x>=0&&position.y<=1080&&position.y>=0) { position=Vector2d(randy.randomInRange(-1000,2000),randy.randomInRange(-1000,1800)); } if(timespawn<=0 && !shipnotspawn) { shipnotspawn=true; dead=false; timespawn=50.0f; } } if(hit) { part.createEffect(1,1,position,100); part.update(dt); part.deleteparts(dt); dead=true; hit=false; position=Vector2d(randy.randomInRange(-1000,2000),randy.randomInRange(-1000,1800)); } if(timespawn<=0) { shipnotspawn=false; } }