# Aim and Shoot with Mouse CodeHS

**URL:** <https://forum.freecodecamp.org/t/aim-and-shoot-with-mouse-codehs/381074>\
**Category:** General\
**Created:** [April 29, 2020, 6:58pm UTC](https://forum.freecodecamp.org/t/aim-and-shoot-with-mouse-codehs/381074 "2020-04-29T18:58:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adibak](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@adibak](https://forum.freecodecamp.org/u/adibak)\
**Post date:** [April 29, 2020, 6:58pm UTC](https://forum.freecodecamp.org/t/aim-and-shoot-with-mouse-codehs/381074/1 "2020-04-29T18:58:06Z")

</div>

Hello,

I’m trying to make a game in CodeHS Graphics where the user can shoot circles by aiming with the mouse. The circles should point and move in the direction the mouse is. But I’m stuck on this. Can someone please help? Thank you.

Here’s my code so far:

```auto
var arr = [];

var mis = [];

var eX;
var eY;

var ship = new Rectangle(40, 60);
ship.setPosition(getWidth()/2, getHeight() * 7/8);
add(ship);

function start(){
    setTimer(game, 50);    
    mouseMoveMethod(move);
    mouseClickMethod(shoot);
}

function move(e){
    eX = e.getX();
    eY = e.getY();
    var angle = Math.atan2(eY - ship.getY(), eX - ship.getX() - ship.getWidth()/2);
    angle = angle * (180/Math.PI);
    if (angle < 0){
        angle = 360 - (-angle);
    }
    ship.setRotation(90 + angle);
}

function shoot(e){
    eX = e.getX();
    eY = e.getY();
    var m = new Circle(10);
    m.setPosition(ship.getX(), ship.getY());
    m.setColor(Color.blue);
    //m.tarX = e
    var angle = Math.atan2(eY - ship.getY(), eX - ship.getX());
    angle = angle * (180/Math.PI);
    if (angle < 0){
        angle = 360 - (-angle);
    }
    m.setRotation(90 + angle);
    println(90 + angle);
    add(m);
    mis.push(m);
    
    
}

function game(){
    for (var k = 0; k < mis.length; k++){
        var par = mis[k];
        par.setPosition(par.getX(), par.getY()-1);
    }
    
}

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:56pm UTC](https://forum.freecodecamp.org/t/aim-and-shoot-with-mouse-codehs/381074/2 "2021-06-01T18:56:10Z")

</div>

Closed on June 1, 2021, 6:56pm UTC


