Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7580133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:50:24+00:00 2026-05-30T17:50:24+00:00

Hey im programming a simple game using directX and C++ and i have hit

  • 0

Hey im programming a simple game using directX and C++ and i have hit a slight problem which im sure some genius can fix.

I currently have an array of 8 Aliens and i currently use this code to move them left to right and down a line.

bool turnaround=false;
if ((Aliens[0].pos.x<-5 & Aliens[0].vel.x<0)|(Aliens[3].pos.x>5&Aliens[3].vel.x>0))
{
    turnaround=true;
    if(Aliens[0].vel.x<0)
        Aliens[0].animCtrl->SetTrackSpeed(0,1);
    else
        Aliens[0].animCtrl->SetTrackSpeed(0,-1);
}

However this currently stops them short if ones to the left or right have been destroyed (they are destroyed by a variable Aliens[i].dead = true

I was wondering if anyone can come up with the if statement or nested if’s required to say if ones furthest left or right are destroyed go further across :/

Thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:50:26+00:00Added an answer on May 30, 2026 at 5:50 pm

    I presume from your question that you are constructing some sort of space invaders type game. Here would be one way to approach this that might be better than what you currently have (in a pseudo-code form):

    For each alien:
      If alien is currently on an odd row:
        Set direction to left
        If alien x position is near 0:
           Set direction to down
      Else
        Set direction to right
        If alien x position is near screen width:
           Set direction to down
    

    This should cause the aliens to move down towards the bottom of the screen row by row. (Of course there are many different formations aliens could take in this type of game, this is just one). You aren’t clear about what sort of behaviour you want them to exhibit when they are killed (“go further across” is ambiguious, is this the player or some of the aliens, or what?), however, if you elaborate on that I may be able to lend further advice here.

    I would also suggest you reconsider your design for a minute. You have what appears to be a fixed size array that holds the 8 aliens. While this may allow you to construct a particular level, it is likely to prove very restrictive. What if in another level you want 12 aliens? I suggest you turn your Aliens array into an std::vector, so you can add them to a level as you like at will. Even better, if you have different types of enemies that all share the same properties, you could create a superclass CEnemy that these enemies all inherit from. This is likely to make your design more robust and expandable.

    Also, as has been stated by others already, use logical operators when you want to run an AND or OR operation, not bitwise. (That is, use || instead of |, etc) There is an important difference between the two.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey so i'm making a simple text game using the pdCurses library and a
Hey, i've a simple question. Task: Program a backup system which can be used
hey guys, maybe some of you have experience with programming wordpress plugins. I have
Hey everyone! I am new to blackberry programming although I do have some java
Hey i have a situation in which i need to pass some variable value
Hey everyone, great community you got here. I'm an Electrical Engineer doing some programming
Hey there, I'm pretty new to programming and I've got a problem with the
Hey everyone I am trying to get back into Spring programming on tomcat6. Can
Hey, while programming stuff, I have found that it is often very helpful to
Hey,...very simple question I usually write php but happen to be programming with ASP.NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.