10 Replies - 873 Views - Last Post: 28 February 2011 - 10:08 AM

#1 ekeak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 19-February 11

Error correction

Posted 21 February 2011 - 04:09 PM

Well, I have recently decided to enter the 3 week competition, and now I'm discovering I have a hard time keeping track of things. I've gotten to the point where the code works, but it's getting so extensive that I'm running into logic errors and bits of unnecessary code all over the place. Right now, I've got collision detections working, but my enemies refuse to fire bullets and I can't rotate a simple rectangle. Any good resources related to error correction techniques?

This post has been edited by ekeak: 21 February 2011 - 04:09 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Error correction

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Error correction

Posted 21 February 2011 - 05:56 PM

Asking questions about specific errors on this site is a good start. What kind of errors are you getting?
Was This Post Helpful? 0
  • +
  • -

#3 ekeak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 19-February 11

Re: Error correction

Posted 21 February 2011 - 07:03 PM

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame7
{
    class GameObject
    {
        public Rectangle rect;
        public Texture2D sprite;
        public Boolean active = true;
        public int counthits = 0;
        public int hitsnecessary = 0;
        public int speed = 0;
        public Boolean rot = false;
        public Boolean containtsbullet = false;
    }
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        List<GameObject> enemylist = new List<GameObject>();
        List<GameObject> bulletlist = new List<GameObject>();
        List<GameObject> enemybulletlist = new List<GameObject>();
        GameObject tempExplosion = new GameObject();
        Texture2D background;
        Texture2D ship;
        Texture2D enemy1;
        Texture2D enemy2;
        Texture2D enemy3;
        Texture2D enemy4;
        Texture2D enemy5;
        Texture2D bullet;
        Texture2D enemybullet;
        Texture2D explosion;
        Rectangle shiprect;
        Rectangle backgroundrect;
        Boolean ShotBool = true;
        System.Random EnemyPosition = new System.Random();
        int timer = -200;
        int enemybullettimer = -100;
        int timercount = 0;
        int explosiontimer = -4;
        int randomposition;
        int rotatetimer;
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }


        protected override void Initialize()
        {
            tempExplosion.active = false;
            shiprect = new Rectangle(0, 0, 103, 88);
            backgroundrect = new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            base.Initialize();
        }


        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            background = Content.Load<Texture2D>("background");
            ship = Content.Load<Texture2D>("ship");
            enemy1 = Content.Load<Texture2D>("enemy1");
            enemy2 = Content.Load<Texture2D>("enemy2");
            enemy3 = Content.Load<Texture2D>("enemy3");
            enemy4 = Content.Load<Texture2D>("enemy4");
            enemy5 = Content.Load<Texture2D>("enemy5");
            bullet = Content.Load<Texture2D>("bullet");
            enemybullet = Content.Load<Texture2D>("bullet2");
            explosion = Content.Load<Texture2D>("explosion");
        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            timer++;
            enemybullettimer++;
            rotatetimer++;

            GameObject tempEnemy1 = new GameObject();
            GameObject tempEnemy2 = new GameObject();
            GameObject tempEnemy3 = new GameObject();
            GameObject tempEnemy4 = new GameObject();
            GameObject tempEnemy5 = new GameObject();

            if ((timer > -1) & (timercount < 10))
            {
                randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                timercount = timercount + 1;
                timer = -200;
                tempEnemy1.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 47, 47);
                tempEnemy1.sprite = enemy1;
                tempEnemy1.counthits = 0;
                tempEnemy1.hitsnecessary = 1;
                tempEnemy1.speed = 2;
                tempEnemy1.rot = false;
                enemylist.Add(tempEnemy1);
            }
            if ((timer > -1) & (timercount < 20))
            {
                randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                timercount = timercount + 1;
                timer = -100;
                tempEnemy1.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 47, 47);
                tempEnemy1.sprite = enemy1;
                tempEnemy1.counthits = 0;
                tempEnemy1.hitsnecessary = 1;
                tempEnemy1.speed = 2;
                tempEnemy1.rot = false;
                enemylist.Add(tempEnemy1);
            }
            if ((timer > -1) & (timercount >= 20) & (timercount < 40))
            {
                if (timercount % 4 == 0)
                {
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    timercount = timercount + 1;
                    timer = -50;
                    tempEnemy2.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 55, 62);
                    tempEnemy2.sprite = enemy2;
                    tempEnemy2.counthits = 0;
                    tempEnemy2.hitsnecessary = 2;
                    tempEnemy2.speed = 2;
                    tempEnemy2.rot = false;
                    enemylist.Add(tempEnemy2);
                }
                else
                {
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    timercount = timercount + 1;
                    timer = -50;
                    tempEnemy1.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 47, 47);
                    tempEnemy1.sprite = enemy1;
                    tempEnemy1.counthits = 0;
                    tempEnemy1.hitsnecessary = 1;
                    tempEnemy1.speed = 2;
                    tempEnemy1.rot = false;
                    enemylist.Add(tempEnemy1);
                }
            }
            if ((timer > -1) & (timercount >= 40) & (timercount < 60))
            {
                if (timercount % 2 == 0)
                {
                    timercount = timercount + 1;
                    timer = -50;
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    tempEnemy2.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 55, 62);
                    tempEnemy2.sprite = enemy2;
                    tempEnemy2.counthits = 0;
                    tempEnemy2.hitsnecessary = 2;
                    tempEnemy2.speed = 2;
                    tempEnemy2.rot = false;
                    enemylist.Add(tempEnemy2);
                }
                else
                {
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    timercount = timercount + 1;
                    timer = -50;
                    tempEnemy1.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 47, 47);
                    tempEnemy1.sprite = enemy1;
                    tempEnemy1.counthits = 0;
                    tempEnemy1.hitsnecessary = 1;
                    tempEnemy1.speed = 2;
                    tempEnemy1.rot = false;
                    enemylist.Add(tempEnemy1);
                }
            }
            if ((timer > -1) & (timercount >= 60) & (timercount < 80))
            {
                randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                timercount = timercount + 1;
                timer = -50;
                tempEnemy2.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 55, 62);
                tempEnemy2.sprite = enemy2;
                tempEnemy2.counthits = 0;
                tempEnemy2.hitsnecessary = 2;
                tempEnemy2.speed = 2;
                tempEnemy2.rot = false;
                enemylist.Add(tempEnemy2);
            }
            if ((timer > -1) & (timercount >= 80) & (timercount < 100))
            {
                if (timercount % 4 == 0)
                {
                    timercount = timercount + 1;
                    timer = -50;
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    tempEnemy3.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 27, 44);
                    tempEnemy3.sprite = enemy3;
                    tempEnemy3.counthits = 0;
                    tempEnemy3.hitsnecessary = 1;
                    tempEnemy3.speed = 2;
                    tempEnemy3.containtsbullet = true;
                    enemylist.Add(tempEnemy3);

                }
                else
                {
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    timercount = timercount + 1;
                    timer = -50;
                    tempEnemy2.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 55, 62);
                    tempEnemy2.sprite = enemy2;
                    tempEnemy2.counthits = 0;
                    tempEnemy2.hitsnecessary = 2;
                    tempEnemy2.speed = 2;
                    tempEnemy2.rot = false;
                    enemylist.Add(tempEnemy2);
                }
            }
            if ((timer > -1) & (timercount >= 100) & (timercount < 120))
            {
                if (timercount % 2 == 0)
                {
                    timercount = timercount + 1;
                    timer = -50;
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    tempEnemy3.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 27, 44);
                    tempEnemy3.sprite = enemy3;
                    tempEnemy3.counthits = 0;
                    tempEnemy3.hitsnecessary = 1;
                    tempEnemy3.speed = 2;
                    tempEnemy3.containtsbullet = true;
                    enemylist.Add(tempEnemy3);

                }
                else
                {
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    timercount = timercount + 1;
                    timer = -50;
                    tempEnemy2.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 55, 62);
                    tempEnemy2.sprite = enemy2;
                    tempEnemy2.counthits = 0;
                    tempEnemy2.hitsnecessary = 2;
                    tempEnemy2.speed = 2;
                    tempEnemy2.rot = false;
                    enemylist.Add(tempEnemy2);
                }
            }
            if ((timer > -1) & (timercount >= 120) & (timercount < 140))
            {
                timercount = timercount + 1;
                timer = -50;
                randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                tempEnemy3.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 27, 44);
                tempEnemy3.sprite = enemy3;
                tempEnemy3.counthits = 0;
                tempEnemy3.hitsnecessary = 1;
                tempEnemy3.speed = 2;
                tempEnemy3.containtsbullet = true;
                enemylist.Add(tempEnemy3);
            }
            if ((timer > -1) & (timercount >= 140) & (timercount < 160))
            {
                if (timercount % 4 == 0)
                {
                    timercount = timercount + 1;
                    timer = -50;
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    tempEnemy4.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 52, 45);
                    tempEnemy4.sprite = enemy4;
                    tempEnemy4.counthits = 0;
                    tempEnemy4.hitsnecessary = 2;
                    tempEnemy4.speed = 2;
                    tempEnemy4.containtsbullet = true;
                    enemylist.Add(tempEnemy4);

                }
                else
                {
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    timercount = timercount + 1;
                    timer = -50;
                    tempEnemy3.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 27, 44);
                    tempEnemy3.sprite = enemy3;
                    tempEnemy3.counthits = 0;
                    tempEnemy3.hitsnecessary = 1;
                    tempEnemy3.speed = 2;
                    tempEnemy3.containtsbullet = true;
                    enemylist.Add(tempEnemy3);
                }
            }
            if ((timer > -1) & (timercount >= 160) & (timercount < 180))
            {
                if (timercount % 2 == 0)
                {
                    timercount = timercount + 1;
                    timer = -50;
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    tempEnemy4.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 52, 45);
                    tempEnemy4.sprite = enemy4;
                    tempEnemy4.counthits = 0;
                    tempEnemy4.hitsnecessary = 2;
                    tempEnemy4.speed = 2;
                    tempEnemy4.containtsbullet = true;
                    enemylist.Add(tempEnemy4);

                }
                else
                {
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    timercount = timercount + 1;
                    timer = -50;
                    tempEnemy3.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 27, 44);
                    tempEnemy3.sprite = enemy3;
                    tempEnemy3.counthits = 0;
                    tempEnemy3.hitsnecessary = 1;
                    tempEnemy3.speed = 2;
                    tempEnemy3.containtsbullet = true;
                    enemylist.Add(tempEnemy3);
                }
            }
            if ((timer > -1) & (timercount >= 180) & (timercount < 200))
            {
                timercount = timercount + 1;
                timer = -50;
                randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                tempEnemy4.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 52, 45);
                tempEnemy4.sprite = enemy4;
                tempEnemy4.counthits = 0;
                tempEnemy4.hitsnecessary = 2;
                tempEnemy4.speed = 2;
                tempEnemy4.containtsbullet = true;
                enemylist.Add(tempEnemy4);
            }
            if ((timer > -1) & (timercount >= 200) & (timercount < 220))
            {
                if (timercount % 4 == 0)
                {
                    timercount = timercount + 1;
                    timer = -50;
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    tempEnemy5.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 47, 47);
                    tempEnemy5.sprite = enemy5;
                    tempEnemy5.counthits = 0;
                    tempEnemy5.hitsnecessary = 2;
                    tempEnemy5.speed = 4;
                    tempEnemy5.containtsbullet = false;
                    enemylist.Add(tempEnemy4);

                }
                else
                {
                    timercount = timercount + 1;
                    timer = -50;
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    tempEnemy4.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 52, 45);
                    tempEnemy4.sprite = enemy4;
                    tempEnemy4.counthits = 0;
                    tempEnemy4.hitsnecessary = 2;
                    tempEnemy4.speed = 2;
                    tempEnemy4.containtsbullet = true;
                    enemylist.Add(tempEnemy4);
                }
            }
            if ((timer > -1) & (timercount >= 220) & (timercount < 240))
            {
                if (timercount % 2 == 0)
                {
                    timercount = timercount + 1;
                    timer = -50;
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    tempEnemy5.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 47, 47);
                    tempEnemy5.sprite = enemy5;
                    tempEnemy5.counthits = 0;
                    tempEnemy5.hitsnecessary = 2;
                    tempEnemy5.speed = 4;
                    tempEnemy5.containtsbullet = false;
                    enemylist.Add(tempEnemy4);

                }
                else
                {
                    timercount = timercount + 1;
                    timer = -50;
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    tempEnemy4.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 52, 45);
                    tempEnemy4.sprite = enemy4;
                    tempEnemy4.counthits = 0;
                    tempEnemy4.hitsnecessary = 2;
                    tempEnemy4.speed = 2;
                    tempEnemy4.containtsbullet = true;
                    enemylist.Add(tempEnemy4);
                }
            }
            if ((timer > -1) & (timercount >= 240) & (timercount < 260))
                {
                    timercount = timercount + 1;
                    timer = -50;
                    randomposition = EnemyPosition.Next(graphics.PreferredBackBufferHeight - 100);
                    tempEnemy5.rect = new Rectangle(graphics.PreferredBackBufferWidth + 17, randomposition, 47, 47);
                    tempEnemy5.sprite = enemy5;
                    tempEnemy5.counthits = 0;
                    tempEnemy5.hitsnecessary = 2;
                    tempEnemy5.speed = 4;
                    tempEnemy5.containtsbullet = false;
                    enemylist.Add(tempEnemy4);

                }
            for (int i = 0; i < enemylist.Count; i++)
            {
                if (enemybullettimer > -1 & enemylist[i].containtsbullet == true)
                {
                    enemybullettimer = -100;
                    enemybullettimer++;
                    GameObject tempEnemyBullet = new GameObject();
                    tempEnemyBullet.sprite = enemybullet;
                    tempEnemyBullet.rect = new Rectangle(enemylist[i].rect.X, enemylist[i].rect.Y + 22, 16, 16);
                    enemybulletlist.Add(tempEnemyBullet);
                }
            }

            if (timer % 25 == 0)
            {
                ShotBool = true;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();
            if (Keyboard.GetState().IsKeyDown(Keys.Up) & (shiprect.Y > 0))
                shiprect.Y = shiprect.Y - 5;
            if (Keyboard.GetState().IsKeyDown(Keys.Right) & (shiprect.X + 103 < graphics.PreferredBackBufferWidth))
                shiprect.X = shiprect.X + 5;
            if (Keyboard.GetState().IsKeyDown(Keys.Down) & (shiprect.Y + 88 < graphics.PreferredBackBufferHeight))
                shiprect.Y = shiprect.Y + 5;
            if (Keyboard.GetState().IsKeyDown(Keys.Left) & (shiprect.X > 0))
                shiprect.X = shiprect.X - 5;
            if ((Keyboard.GetState().IsKeyDown(Keys.Space)) & (ShotBool == true))
            {
                ShotBool = false;
                GameObject tempBullet = new GameObject();
                tempBullet.sprite = bullet;
                tempBullet.rect = new Rectangle(shiprect.X + 95, shiprect.Y + 36, 16, 16);
                bulletlist.Add(tempBullet);
            }

            for (int i = 0; i < bulletlist.Count; i++)
            {
                for (int y = 0; y < enemylist.Count; y++)
                {
                    if (bulletlist[i].rect.Intersects(enemylist[y].rect) == true)
                    {
                        enemylist[y].counthits++;
                        if (enemylist[y].counthits != enemylist[y].hitsnecessary)
                        {
                            bulletlist[i].active = false;
                            bulletlist[i].rect.Y = -300;
                        }
                        else
                            enemylist[y].counthits = 0;
                    }
                }
            }

            for (int i = 0; i < enemylist.Count; i++)
            {
                for (int y = 0; y < bulletlist.Count; y++)
                {
                    if (enemylist[i].rect.Intersects(bulletlist[y].rect) == true)
                    {
                        enemylist[i].counthits++;
                        enemylist[i].active = false;
                        tempExplosion.sprite = explosion;
                        tempExplosion.rect = new Rectangle(enemylist[i].rect.X - 5, enemylist[i].rect.Y - 5, 73, 82);
                        enemylist[i].rect.X = -100;
                        tempExplosion.active = true;
                    }

                }
            }

            for (int i = 0; i < bulletlist.Count; i++)
            {
                bulletlist[i].rect.X = bulletlist[i].rect.X + 10;
            }
            for (int i = 0; i < enemylist.Count; i++)
            {
                enemylist[i].rect.X = enemylist[i].rect.X - enemylist[i].speed;
            }
            for (int i = 0; i < enemybulletlist.Count; i++)
            {
                enemybulletlist[i].rect.X = enemybulletlist[i].rect.X - 5;
            }
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {

            GraphicsDevice.Clear(Color.White);

            spriteBatch.Begin();
            spriteBatch.Draw(background, backgroundrect, Color.White);
            spriteBatch.Draw(ship, shiprect, Color.White);
            for (int i = 0; i < enemylist.Count; i++)
            {
                if (enemylist[i].active == true)
                {
                    if (enemylist[i].rot == true)
                    {
                        spriteBatch.Draw(enemylist[i].sprite, enemylist[i].rect, null, Color.White, rotatetimer, new Vector2(enemylist[i].sprite.Width / 2, enemylist[i].sprite.Height / 2), SpriteEffects.None, 0);
                    }
                    else
                    {
                        spriteBatch.Draw(enemylist[i].sprite, enemylist[i].rect, Color.White);
                    }
                }


            }
            for (int i = 0; i < bulletlist.Count; i++)
            {
                if (bulletlist[i].active == true)
                {
                    spriteBatch.Draw(bulletlist[i].sprite, bulletlist[i].rect, Color.White);
                }
            }
            for (int i = 0; i < enemybulletlist.Count; i++)
            {
                spriteBatch.Draw(enemybulletlist[i].sprite, enemybulletlist[i].rect, Color.White);
            }
            if (tempExplosion.active == true)
            {
                explosiontimer++;
                spriteBatch.Draw(tempExplosion.sprite, tempExplosion.rect, Color.White);
                if (explosiontimer > -1)
                {
                    tempExplosion.active = false;
                    explosiontimer = -4;
                }
            }
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}



well, the rectangles in my enemy list don't rotate and only the first enemy that spawns fires bullets. Thanks..
Was This Post Helpful? 0
  • +
  • -

#4 ekeak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 19-February 11

Re: Error correction

Posted 21 February 2011 - 09:25 PM

don't work on this any more its fixed.
Was This Post Helpful? 0
  • +
  • -

#5 Fib  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 161
  • View blog
  • Posts: 554
  • Joined: 12-March 09

Re: Error correction

Posted 25 February 2011 - 09:43 AM

Its good to see someone else is participating in the competition. I'm just hoping I can finish mine before the deadline.
Was This Post Helpful? 0
  • +
  • -

#6 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Error correction

Posted 25 February 2011 - 09:44 AM

Only 8 days left.
Was This Post Helpful? 1
  • +
  • -

#7 ekeak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 19-February 11

Re: Error correction

Posted 27 February 2011 - 11:24 AM

ok, my next issue (and i honestly don't think i can solve this one myself), is that I have a few methods that work improperly. My problem is that the .intersects method is picking up empty space around a rectangle. I would like it to react when the player touches the sprite, not when it touches thin air.
Here's my code:
if (Keyboard.GetState().IsKeyDown(Keys.Up) & (shiprect.Y > 0))
                shiprect.Y = shiprect.Y - 5;
                    }
                        if (Keyboard.GetState().IsKeyDown(Keys.Right) & (shiprect.X + 103 < graphics.PreferredBackBufferWidth))
                            shiprect.X = shiprect.X + 5;
                    if ((shiprect.Intersects(mothershiprect) == false) & shiprect.Y != mothershiprect.Y - 1)
                    {
                        if (Keyboard.GetState().IsKeyDown(Keys.Down) & (shiprect.Y + 88 < graphics.PreferredBackBufferHeight))
                            shiprect.Y = shiprect.Y + 5;
                    }
                    if ((shiprect.Intersects(mothershiprect) == false) & shiprect.Y != mothershiprect.X + 1)
                    {
                        if (Keyboard.GetState().IsKeyDown(Keys.Left) & (shiprect.X > 0))
                            shiprect.X = shiprect.X - 5;
                    }

Thanks, ekeak

This post has been edited by ekeak: 27 February 2011 - 11:26 AM

Was This Post Helpful? 0
  • +
  • -

#8 bonyjoe  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 175
  • View blog
  • Posts: 548
  • Joined: 08-September 10

Re: Error correction

Posted 27 February 2011 - 12:36 PM

Make the rectangles smaller, so they only include the parts with graphics there.

So either ensure the texture is as cropped as it can be without clipping and create the rectangle from that or make the rectangle like so:

boundingRect = new Rectangle(ship.pos.x + 5, ship.pos.y + 5, shipt.texture.width - 10, ship.texture.height - 10);

This will make a rectangle that shaves 5 pixels off all sides of the texture assuming you are using 0,0 as your origin.
Was This Post Helpful? 1
  • +
  • -

#9 ekeak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 19-February 11

Re: Error correction

Posted 27 February 2011 - 03:00 PM

it is as cropped as it can be, thanks for the tip though.
Was This Post Helpful? 0
  • +
  • -

#10 ekeak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 19-February 11

Re: Error correction

Posted 27 February 2011 - 11:38 PM

dude, like, it's ok now i got it.
Was This Post Helpful? 0
  • +
  • -

#11 bonyjoe  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 175
  • View blog
  • Posts: 548
  • Joined: 08-September 10

Re: Error correction

Posted 28 February 2011 - 10:08 AM

what was the problem?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1