Thread: 2d shooter

  1. #1

    2d shooter

    I am trying to make a 2d shooter. The idea is that it will be a sqaire map with ships that can fly about in any direction. What I can't work out is how to make them go in lots of different directons.

    //up left
    ship.y-1 ship.x-1
    doing this I can see how it would be possible to make ships go in 8 directions and I can see how it would be possible to make ships go in 16 directions but what would be a good way of making ships able to travel in all 360 degrees?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Use a control that moves the ship forwards/backwards by pressing UP/DOWN, and change the angle it is looking at by pressing LEFT/RIGHT.
    Use trigonometric functions (cos/sin) for the math part.

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Programming is fun, mkay?
    Join Date
    Oct 2001

    Lightbulb I think this is what you need... =)

    You can try this:

    // Where angle is the ship's rotation angle (0° - 360°)
    ship.x += sin(angle) * ship.speed;
    ship.y += cos(angle) * ship.speed;

    I think that is what you want. Try that and let me know if it worked =).


    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Göteborg, Sweden
    Remember to use floating-points instead of integers as coordinates for your objects. Temporarily convert the coordinates to integers when you draw them.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    thanx for replies

    This is exacly the info I needed and seams to do the trick thanx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D in directX
    By fighter92 in forum Game Programming
    Replies: 6
    Last Post: 01-25-2009, 11:23 AM
  2. 2D Shooter
    By bobbelPoP in forum Game Programming
    Replies: 7
    Last Post: 09-17-2008, 05:27 AM
  3. 2D Spaceship shooter online - Need 2 keen programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 05-19-2005, 07:40 AM
  4. 2D Shooter using Windows GDI
    By Jontay in forum Game Programming
    Replies: 2
    Last Post: 12-09-2003, 08:37 PM
  5. Help with 2d OpenGL top-down shooter.
    By TonyP in forum Game Programming
    Replies: 4
    Last Post: 09-11-2002, 11:39 AM