# Simplify code

**URL:** <https://forum.kirupa.com/t/simplify-code/288032>\
**Category:** Uncategorized\
**Created:** [May 9, 2009, 7:05pm UTC](https://forum.kirupa.com/t/simplify-code/288032 "2009-05-09T19:05:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TZP](https://avatars.discourse-cdn.com/v4/letter/t/5f9b8f/32.png) [@TZP](https://forum.kirupa.com/u/TZP)\
**Post date:** [May 9, 2009, 7:05pm UTC](https://forum.kirupa.com/t/simplify-code/288032/1 "2009-05-09T19:05:12Z")

</div>

Greetings.  
Please excuse me if I got some mistakes withing my language. But I hope someone can help me out with this. I got a spaceship with top-view and I want to shoot in the direction the ship is pointing. So I got this function:

```auto

private function _shoot(te:TimerEvent):void {
 
   if (_degrees < 0) _degrees += 360;
 
   if (_degrees >= 0 && _degrees <= 90) {
    _gun.x += _degrees; 
    _gun.y -= 90 - _degrees;
   }
   else if (_degrees > 90 && _degrees <= 180) {
    _degrees -= 90;
    _gun.x += 90 - _degrees;
    _gun.y += _degrees;
   }
 
   else if (_degrees > 180 && _degrees <= 270) {
    _degrees -= 180;
    _gun.x -= _degrees;
    _gun.y += 90 - _degrees;
   }
 
   else if (_degrees > 270 && _degrees <= 360) {
    _degrees -= 270;
    _gun.x -= 90 - _degrees;
    _gun.y -= _degrees;
   }   
 
  }

```

What does it do? It get´s the current degree of my ship…a value between -360° and 360°. Then it checks in which direction the ship points and shoots into the same direction. It works pretty well so far but the code seems to be bulky. I knew there is an easier way but I m not that good with math. ^^  
If you got an idea please let me know.

Thanks!  
TZP
