Exemple #1
0
        public void Hit()
        {
            if (m_nSize > 1)
            {
                //create two smaller asteroids
                Asteroid part;
                part = new Asteroid(m_gameMain, m_nSize-1);
                part.Velocity.Angle = this.Velocity.Angle+(float)Math.PI/2;
                part.Velocity.Length = this.Velocity.Length*1.5f;
                part.Loc = this.Loc + part.Velocity*30*(m_nSize-1);

                part = new Asteroid(m_gameMain, m_nSize-1);
                part.Velocity.Angle = this.Velocity.Angle-(float)Math.PI/2;
                part.Velocity.Length = this.Velocity.Length*1.5f;
                part.Loc = this.Loc + part.Velocity*30*(m_nSize-1);
            }
            this.Dispose();
        }
Exemple #2
0
        public GameMain()
        {
            m_starField = new StarField();
            m_player = new Player(this);
            m_aAsteroids = new ArrayList();

            //The aOKLocs is generated so no asteroids will appear close to the ship
            EPoint pntStageSize = EndogineHub.Instance.Stage.Size;
            ArrayList aOKLocs = new ArrayList();
            EPoint pntNumPositions = new EPoint(6,6);
            ERectangle rctFreePositions = new ERectangle(2,2,2,2);
            for (int y = 0; y < pntNumPositions.Y; y++)
            {
                if (y >= rctFreePositions.Y && y < rctFreePositions.Bottom)
                    y+=rctFreePositions.Height;
                for (int x = 0; x < pntNumPositions.X; x++)
                {
                    if (x >= rctFreePositions.X && x < rctFreePositions.Right)
                        x+=rctFreePositions.Width;
                    EPoint pnt = new EPoint(x,y) * pntStageSize/(pntNumPositions-new EPoint(1,1)) - pntStageSize/2;;
                    aOKLocs.Add(pnt);
                }
            }

            Random rnd = new Random();
            for (int i = 0; i < 4; i++)
            {
                Asteroid asteroid = new Asteroid(this, 3);
                asteroid.Velocity = new EPointF((float)rnd.NextDouble()-0.5f, (float)rnd.NextDouble()-0.5f);

                int nRndPos = rnd.Next(aOKLocs.Count);
                EPoint pntLoc = (EPoint)aOKLocs[nRndPos];
                aOKLocs.RemoveAt(nRndPos);
                asteroid.Loc = pntLoc.ToEPointF();
            }
        }