is there something that im doing wrong with this calculation
x3 = new Vector2( tank.position.X -bigboss.position.X);
y4 = new Vector2( tank.position.Y-bigboss.position.Y);
x3.Normalize();
y4.Normalize();
bdirection = Vector2.Add(x3,y4);
bull.FireBullet(bigboss.position, bdirection);
also how do i go about changing specific methods within the bullet manager class from the boss class
boss class
using System;
using Microsoft.Xna.Framework;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Input;
namespace Tank
{
class BossManager:BulletManager
{
private Texture2D texture; // sprite texture
private Vector2 position; // current position on screen
private Vector2 bdirection; // current direction
private Vector2 orgin;
private Vector2 startDirection;
private Vector2 bulldirect;
public boss bigboss;
public Vector2 x3;
public Vector2 y4;
const int START_POSITION_X = 1205;
const int START_POSITION_Y = 275;
private float width;
private float height;
private Random random;
public bool back;
public BossManager()
{
bigboss = new boss();
random = new Random(2);
}
public void Initialize(Texture2D bossTexture)
{
bigboss.Initialize(bossTexture, random);
}
public void reset()
{
height = texture.Height;
width = texture.Width;
orgin.X = width / 2f;
orgin.Y = height / 2f;
}
public void Update(GameTime gameTime, ref Hero tank, ref BulletManager bull)
{
float timeDelta = (float)gameTime.ElapsedGameTime.TotalSeconds;
bigboss.position.X = bigboss.position.X - ((bigboss.direction.X * bigboss.speed) * GameConstants.EnemySpeedAdjustment * timeDelta);
if (bigboss.position.X < 990)
{
bigboss.position.X = 990;
bigboss.position.Y = bigboss.position.Y - ((bigboss.direction.Y * bigboss.speed) * GameConstants.EnemySpeedAdjustment * timeDelta);
if (bigboss.position.Y < 150)
{
bigboss.direction.Y =- bigboss.direction.Y;
}
else if (bigboss.position.Y > 600)
{
bigboss.direction.Y = -bigboss.direction.Y;
}
x3 = new Vector2( tank.position.X -bigboss.position.X);
y4 = new Vector2( tank.position.Y-bigboss.position.Y);
x3.Normalize();
y4.Normalize();
bdirection = Vector2.Add(x3,y4);
bull.FireBullet(bigboss.position, bdirection);
}
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(bigboss.texture, bigboss.position,null, Color.White,0f,bigboss.orgin,1f,SpriteEffects.None,0f);
}
}
}
bulletmanager
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using System.Collections;
namespace Tank
{
class BulletManager
{
// the array of bullets
private Bullets[] BulletArray;
public ArrayList bsprites = new ArrayList();
public BulletManager()
{
BulletArray = new Bullets[GameConstants.numBullets];
for (int i = 0; i < GameConstants.numBullets; i++)
{
BulletArray[i] = new Bullets();
}
}
public void Intialize(Texture2D bulletTexture)
{
for (int i = 0; i < GameConstants.numBullets; i++)
{
BulletArray[i].Initialize(bulletTexture);
}
}
public void add(int x, int y, int height, int width)
{
bsprites.Add(new Rectangle(x, y, width, height));
}
public void Draw(SpriteBatch spriteBatch)
{
for (int i = 0; i < GameConstants.numBullets; i++)
{
if (BulletArray[i].alive)
spriteBatch.Draw(BulletArray[i].texture, BulletArray[i].position,
(Rectangle)bsprites[0], Color.White, 0f, BulletArray[i].origin, 1f, SpriteEffects.None, 0f);
}
}
public void FireBullet(Vector2 position, Vector2 direction)
{
for (int i = 0; i < GameConstants.numBullets; i++)
{
if (!BulletArray[i].alive)
{
BulletArray[i].alive = true;
BulletArray[i].position = position;
BulletArray[i].direction = direction;
break;
}
}
}
public void Update(GameTime gameTime, ref EnemyManager enemies)
{
float timeDelta = (float)gameTime.ElapsedGameTime.TotalSeconds;
//for all bullets
for (int i = 0; i < GameConstants.numBullets; i++)
{
if (BulletArray[i].alive)
{//move bullet according to the direction and speed
BulletArray[i].position.X = BulletArray[i].position.X + ((BulletArray[i].direction.X * BulletArray[i].speed) * GameConstants.BulletSpeedAdjustment * timeDelta);
BulletArray[i].position.Y = BulletArray[i].position.Y + ((BulletArray[i].direction.Y * BulletArray[i].speed) * GameConstants.BulletSpeedAdjustment * timeDelta);
//if the bullet goes off screen then its not alive
if (BulletArray[i].position.X < 0 || BulletArray[i].position.X > GameConstants.ScreenWidth || BulletArray[i].position.Y < 0 || BulletArray[i].position.Y > GameConstants.ScreenHieght)
{
BulletArray[i].alive = false;
}
}
if (BulletArray[i].alive)
{
for (int j = 0; j < GameConstants.numBullets; j++)
{// if an enemy is alive
if (enemies.enemyArray[j].ealive)
{// if the bullet and the enemy collide
if (Helper.CollideMidPointRectangles(
BulletArray[i].position, BulletArray[i].width, BulletArray[i].height,
enemies.enemyArray[j].position, enemies.enemyArray[j].width, enemies.enemyArray[j].height))
{ // orgins
BulletArray[i].alive = false;
// set the enemy to be not alive
enemies.enemyArray[j].ealive = false;
//decrement the number of enemiesLeftThisLevel
//enemies.enemiesLeftThisLevel--;
//// increment the score
//score++;
//// create a small explosion at this position
//explosions.CreateExplosion(enemies.enemyArray[j].position,
// GameConstants.SmallScaleExplosionInc);
}
}
}
}
}
}
}
}
This post has been edited by skyerz: 30 March 2011 - 05:45 AM

New Topic/Question
Reply



MultiQuote






|