XNA Creators Club Online
Page 1 of 1 (7 items)
Sort Posts: Previous Next

How do I get my enemy to go down screen

Last post 04-18-2008 11:27 AM by Nick Gravelyn. 6 replies.
  • 04-18-2008 1:47 AM

    How do I get my enemy to go down screen

    I was working on my vertical shooter.Right now I'm working on my enemy  class.For rival planes.What I'm trying to do is to get the plane to appear on a random portion on the x axis which it does.And then for it to move down the screen.The problem is the plane is not moving down the screen and I can't figure out exactly why.Can anyone tell me what I forgot to add?
     
     
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Storage;
    using Microsoft.Xna.Framework.Audio;

    using Microsoft.Xna.Framework.Input;
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.Graphics;

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace VerticalShot
    {
    class Enemy : Sprite
    {
    Random Enemy_Start_Position = new Random();
    const string ENEMY_ASSETNAME = "enemy";
    int START_POSITION_X = 0;
    const int START_POSITION_Y = -3;
    const int ENEMY_SPEED = 160;
    const int MOVE_DOWN = 1;

    Vector2 mDirection = Vector2.Zero;
    Vector2 mSpeed = Vector2.Zero;

    public void LoadContent(ContentManager theContentManager)
    {
    START_POSITION_X = Enemy_Start_Position.Next(700);
    Position = new Vector2(START_POSITION_X, START_POSITION_Y);
    base.LoadContent(theContentManager, ENEMY_ASSETNAME);
    }

    public void Update(GameTime theGameTime)
    {
    UpdateMovement();
    base.Update(theGameTime, mSpeed, mDirection);
    }

    private void UpdateMovement()
    {
    mSpeed = Vector2.Zero;
    mDirection = Vector2.Zero;

    if(START_POSITION_Y < 650)
    {
    mSpeed.X = ENEMY_SPEED;
    mDirection.Y = MOVE_DOWN;
    }
    }
    }
    }
    Fortune Favors The Bold
  • 04-18-2008 1:53 AM In reply to

    Re: How do I get my enemy to go down screen

    You forgot to set the new position. You have an UpdateMovement, but it never modifies the sprites Position value.
    -----------------------------------------------
    Jim Welch
  • 04-18-2008 1:59 AM In reply to

    Re: How do I get my enemy to go down screen

    Jim W:
    You forgot to set the new position. You have an UpdateMovement, but it never modifies the sprites Position value.

    Alright I guess I'm missing something then I thought  that's what the MOVE_DOWN variable was for.Could you give me a quick example?

    Fortune Favors The Bold
  • 04-18-2008 2:33 AM In reply to

    Re: How do I get my enemy to go down screen

    Where's your draw code?

    Whatever variable you use for the sprite's Position, just say this.Position = new Vector2(this.Position.X, this.Position.Y+1); where 1 is how far to move it down.
    -----------------------------------------------
    Jim Welch
  • 04-18-2008 9:18 AM In reply to

    Re: How do I get my enemy to go down screen

    Could you post the update and render functions for your Sprite class.  It looks like the problem may lie in one of those.
  • 04-18-2008 9:20 AM In reply to

    Re: How do I get my enemy to go down screen

    Jim W:
    Where's your draw code?

    Whatever variable you use for the sprite's Position, just say this.Position = new Vector2(this.Position.X, this.Position.Y+1); where 1 is how far to move it down.

     

    Thanks alot that worked perfectly! Thanks alot Jim.I have alot to learn.As you can tell I'm still having trouble sometimes understanding the code.But I am working on it.I figure if I keep working on different projects that sooner or later I will be able to understand everything enentually.

     

    Anyway Thanks

    Fortune Favors The Bold
  • 04-18-2008 11:27 AM In reply to

    Re: How do I get my enemy to go down screen

    You might want to check out xnadevelopment.com. There are a lot of nice, basic tutorials covering moving sprites, making them jump, and other 2D things.

    NickGravelyn -- Microsoft XNA MVP
    Blog | XNA wiki | My Projects
    Write an Article, Win a Zune!
Page 1 of 1 (7 items) Previous Next