예제 #1
0
 public static Vector2 GetCollisionCenter(Node node)
 {
     Bounds2 bounds = new Bounds2 ();
     node.GetlContentLocalBounds (ref bounds);
     Vector2 center = node.LocalToWorld (bounds.Center);
     return center;
 }
예제 #2
0
        // CONSTRUCTOR -----------------------------------------------------------------------
        public Slider(int trackLength=320)
        {
            active = false;

            Title = new Label() {
                FontMap = FontManager.Instance.GetMap( FontManager.Instance.GetInGame("Bariol", 32, "Bold") ),
                Position = new Vector2(-TICK_WIDTH/2.0f, 29.0f),
                Color = Colors.Black
            };
            this.AddChild(Title);

            min = 0.0f;
            max = 100.0f;
            val = min;
            Track = Support.UnicolorSprite("white", 255, 255, 255, 255);
            Track.Scale = new Vector2((float)trackLength/16.0f, 0.625f);
            this.AddChild(Track);
            length = (float)trackLength;

            //			Knob = Support.UnicolorSprite("white", 255, 255, 255, 255);
            //			Knob = Support.SpriteFromFile("/Application/assets/images/UI/sliderLozenge.png");
            Knob = Support.SpriteFromAtlas("crystallonUI", "sliderLozenge.png");
            Knob.CenterSprite(new Vector2(0.5f, 0.36f));
            //			Knob.Position = new Vector2((pValue/(max-min+min))*length, 0.0f);
            this.AddChild(Knob,100);

            bounds = new Bounds2( new Vector2(-20.0f, -20.0f), new Vector2(length+20.0f, 36.0f) );
            #if DEBUG
            Console.WriteLine(GetType().ToString() + " created" );
            #endif
        }
예제 #3
0
        public Bullet(Vector2 pos)
        {
            sprite = new SpriteUV();

            if (texInfo == null)
            {
                texInfo = new TextureInfo ("/Application/assets/bubble.png");
                //texInfo = new TextureInfo(AssetManager.GetTexture("bubble"), new Vector2i(4,1),TRS.Quad0_1);
            }

            if (spriteList == null)
            {
                spriteList = new SpriteList(texInfo);
                spriteList.Position = new Vector2(0.0f,0.0f);
            }

            spriteList.AddChild(sprite);
            sprite.Quad.S = texInfo.TextureSizef; // map 1:1 on screen -- necessary? !!!\
            sprite.RunAction(new ScaleTo(new Vector2(0.15f,0.15f),0.0f));

            sprite.GetContentWorldBounds(ref boundingBox);
            boundingBox = new Bounds2(pos, new Vector2(38,38));
            //sprite.CenterSprite();
            sprite.Position = pos;
            sprite.Schedule((dt) => Update());
        }
 public WanderMovementStrategy(Actor actor, Int32 minDuration, Int32 maxDuration, Bounds2 bounds)
     : base(actor)
 {
     MinDuration = minDuration;
     MaxDuration = maxDuration;
     Bounds = bounds;
 }
예제 #5
0
        public PlayerCreature()
        {
            Dead = false;
            Animations = new Dictionary<string, Animation>();
            texInfo = new TextureInfo(AssetManager.GetTexture("catanimation"), new Vector2i(5,1),TRS.Quad0_1);
            Animations.Add("idle" , new Animation(0, 3, 0.1f, false));
            CurrentAnimation = Animations["idle"];
            CurrentAnimation.Play();
            sprite = new SpriteTile(texInfo);
            sprite.TileIndex1D = CurrentAnimation.CurrentFrame;
            sprite.Quad.S = new Vector2(258, 214);
            sprite.CenterSprite();
            isJumping = false;

            BoundingBox = new Bounds2(new Vector2(0, 258), new Vector2(0, 214));
        }
예제 #6
0
        public void Update(float dt)
        {
            CurrentAnimation.Update(dt);
            sprite.TileIndex1D = CurrentAnimation.CurrentFrame;

            if (this.isJumping)
            {
                float newX = this.sprite.Position.X;
                float newY = _waterLevel + 150-(_jumpOffset*_jumpOffset);

                _jumpOffset++;
                if (newY < _waterLevel)
                {
                    this.isJumping = false;
                    _jumpOffset = 0;
                }
                BoundingBox = new Bounds2(sprite.LocalToWorld( new Vector2(sprite.Position.X - 258/2, sprite.Position.Y  - 214/2)),sprite.LocalToWorld( new Vector2(sprite.Position.X + 258/2, sprite.Position.Y + 214/2)));
                this.sprite.Position = new Vector2(newX,newY);
            }
        }
예제 #7
0
        public override void Update(float dt)
        {
            base.Update (dt);
            var cameraBounds = Parent.Camera.CalcBounds();
            Bounds2 spriteBounds = new Bounds2 ();
            spriteRing[ringIndex].GetContentWorldBounds(ref spriteBounds);

            float cameraFrontLine = cameraBounds.Min.X;
            float spriteFrontLine = spriteBounds.Max.X;
            if (spriteFrontLine < cameraFrontLine) {
                // remove unseen sprite
                RemoveChild (spriteRing[ringIndex], true);

                // add sprite to next of current sprites
                spriteRing[ringIndex] = generateSprite(frontline);
                AddChild (spriteRing[ringIndex]);

                frontline += spriteWidth;
                ringIndex++;
                ringIndex %= ringCount;
            }
        }
예제 #8
0
        public void MakeBox( Bounds2 bounds )
        {
            Planes = new Plane2[ 4 ];

            Planes[0] = new Plane2( bounds.Point00, -Math._10 );
            Planes[1] = new Plane2( bounds.Point10, -Math._01 );
            Planes[2] = new Plane2( bounds.Point11, Math._10 );
            Planes[3] = new Plane2( bounds.Point01, Math._01 );

            m_sphere = new Sphere2( bounds.Center, bounds.Size.Length() * 0.5f );
        }
예제 #9
0
        /// <summary>
        /// Position the camera and set the persective so that it matches
        /// exactly the 2D ortho view (when all sprites are drawn
        /// on the Z=0 plane anyway, which is the default.
        /// </summary>
        public void SetFromCamera2D( Camera2D cam2d )
        {
            Vector2 y = cam2d.Y();
            float eye_distance = y.Length() / FMath.Tan( 0.5f * Frustum.FovY );	// distance to view plane
            Eye = cam2d.Center.Xy0 + eye_distance * Math._001;
            Center = cam2d.Center.Xy0;
            Up = y.Xy0.Normalize();

            m_last_2d_bounds = cam2d.CalcBounds();
        }
예제 #10
0
        /// <summary>
        /// DrawDefaultGrid with a default color/blend.
        /// </summary>
        public void DrawDefaultGrid( Bounds2 clipping_bounds, float step )
        {
            GL.Context.Enable( EnableMode.Blend );
            GL.Context.SetBlendFunc( new BlendFunc( BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.One ) );

            DrawDefaultGrid( clipping_bounds, new Vector2( step ), Colors.Grey30 * 0.5f, Colors.Black );
        }
예제 #11
0
        /// <summary>
        /// Draw a filled axis aligned rectangle.
        /// </summary>
        public void DrawBounds2Fill( Bounds2 bounds )
        {
            ShaderPush();

            ImmBegin( DrawMode.TriangleStrip, 4 );
            //			ImmVertex( new Vertex( bounds.Point01.Xy01, Colors.Green ) ); // debug
            //			ImmVertex( new Vertex( bounds.Point00.Xy01, Colors.Black ) ); // debug
            //			ImmVertex( new Vertex( bounds.Point11.Xy01, Colors.Yellow ) ); // debug
            //			ImmVertex( new Vertex( bounds.Point10.Xy01, Colors.Red ) ); // debug
            ImmVertex( new Vertex( bounds.Point01.Xy01, m_current_color ) );
            ImmVertex( new Vertex( bounds.Point00.Xy01, m_current_color ) );
            ImmVertex( new Vertex( bounds.Point11.Xy01, m_current_color ) );
            ImmVertex( new Vertex( bounds.Point10.Xy01, m_current_color ) );
            ImmEnd();

            ShaderPop();
        }
예제 #12
0
        /// <summary>
        /// Draw axis lines (x=0 and y=0 lines) with a thickness.
        /// </summary>
        public void DrawAxis( Bounds2 clipping_bounds, float thickness )
        {
            GL.Context.SetLineWidth( thickness );

            float x = 0.0f;
            float y = 0.0f;

            ShaderPush();

            ImmBegin( DrawMode.Lines, 4 );

            // x=0
            ImmVertex( new Vector2( clipping_bounds.Min.X /*left*/, y ) );
            ImmVertex( new Vector2( clipping_bounds.Max.X/*right*/, y ) );

            // y=0
            ImmVertex( new Vector2( x, clipping_bounds.Min.Y/*bottom*/ ) );
            ImmVertex( new Vector2( x, clipping_bounds.Max.Y/*top*/ ) );

            ImmEnd();

            ShaderPop();

            GL.Context.SetLineWidth( 1.0f );
        }
예제 #13
0
        public void UpdateEnemyState(float dt)
        {
            float newX = this.sprite.Position.X;
            float newY = this.sprite.Position.Y;

            if (this.sprite.Position.X < player.sprite.Position.X)
            {
                newX += speed;
            }
            else if (this.sprite.Position.X > player.sprite.Position.X)
            {
                newX -= speed;
            }
            if (this.sprite.Position.Y < player.sprite.Position.Y)
            {
                newY += speed;
            }
            else if (this.sprite.Position.Y > player.sprite.Position.Y)
            {
                newY -= speed;
            }
            sprite.DebugDrawContentLocalBounds();
            sprite.DebugInfo();
            this.sprite.Position = new Vector2(newX,newY);
            boundingBox = new Bounds2(sprite.LocalToWorld( new Vector2(sprite.Position.X - 258/2, sprite.Position.Y  - 214/2)), sprite.LocalToWorld(new Vector2(sprite.Position.X + 258/2, sprite.Position.Y + 214/2)));

            if(isCollidingWith(player.BoundingBox))
            {
                Die ();
            }
        }
예제 #14
0
        /// <summary>
        /// Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.
        /// One vector is enough to determine the orientation and scale of the sprite. The aspect ratio is
        /// by default the same was the size of the 'uv' domain covered (in texels).
        /// </summary>
        /// <param name="x">The len and direction of the bottom edge of the sprite.</param>
        /// <param name="bottom_left_start_pos">The bottom left point of the sprite.</param>
        /// <param name="uv_bounds">The uv bounds (Bounds2 in uv domain).</param>
        public void AddSprite( Vector2 bottom_left_start_pos, Vector2 x, Bounds2 uv_bounds )
        {
            Vector2 ssize = uv_bounds.Size.Abs() * m_current_texture_info.TextureSizef;	// sprite size in texel units - if bounds is invalid, use uv_bounds.Size.Abs()

            Vector2 y = Math.Perp( x ) * ssize.Y / ssize.X;

            m_v0 = new Vector4( bottom_left_start_pos , uv_bounds.Point00 );
            m_v1 = new Vector4( bottom_left_start_pos + x , uv_bounds.Point10 );
            m_v2 = new Vector4( bottom_left_start_pos + y , uv_bounds.Point01 );
            m_v3 = new Vector4( bottom_left_start_pos + x + y , uv_bounds.Point11 );

            add_quad();
        }
예제 #15
0
 /// <summary>Return the Bounds2 object containing the text, in local space.</summary>
 public override bool GetlContentLocalBounds( ref Bounds2 bounds )
 {
     bounds = GetlContentLocalBounds();
     return true;
 }
예제 #16
0
 public bool isCollidingWith(Bounds2 otherBounds)
 {
     return boundingBox.Overlaps(otherBounds);
 }
예제 #17
0
        /// Render all nodes's content bounding boxes in world space. This is mostly
        /// to debug GetContentWorldBounds. Note that this function ignores Plane3D 
        /// at the moment, so if your scene has any Plane3D, the debug primitive 
        /// drawn will look confusing.
        internal void draw_content_world_bounds()
        {
            Traverse(

                ( node, depth ) =>

                {
                    Bounds2 bounds = new Bounds2();

                    if ( node.GetContentWorldBounds( ref bounds ) )
                    {
                        Director.Instance.GL.SetBlendMode( BlendMode.Additive );
                        Director.Instance.DrawHelpers.SetColor( Colors.Grey20 );
                        Director.Instance.DrawHelpers.DrawBounds2( bounds );
                    }

                    return true;

                }

            , 0 );
        }
예제 #18
0
        /// <summary>
        /// Convert to Bounds2. Note that end points won't match if there is a Rotation,
        /// but in all cases the returned bounds fully contains the TRS.
        /// </summary>
        public Bounds2 Bounds2()
        {
            Bounds2 ret = new Bounds2( Point00, Point00 );

            ret.Add( Point10 );
            ret.Add( Point01 );
            ret.Add( Point11 );

            return ret;
        }
예제 #19
0
        /// <summary>
        /// Initialize the specified pWidth and pHeight.
        /// </summary>
        /// <param name='pWidth'>
        /// Desired button width in pixels.
        /// </param>
        /// <param name='pHeight'>
        /// Desired button height in pixels.
        /// </param>
        public void Initialize(float pWidth, float pHeight)
        {
            Width = pWidth;
            Height = pHeight;
            _textOffset = Vector2.Zero;
            _iconAndTextOffset = Vector2.Zero;
            Vector2 size = new Vector2(pWidth, pHeight);

            _status = NORMAL;
            _onToggle = true;
            _pressed = false;
            _bounds = new Bounds2(Vector2.Zero, size);

            // DEFAULT BACKGROUND IMAGE
            if (background == null) {
                background = Support.TiledSpriteFromFile("/Application/assets/images/UI/BetterButton.png", 1, 3);
                background.Scale = size / DefaultDimensions;
            }
            this.AddChild(background);

            // DEFAULT BUTTON TYPEFACE
            if (_textFont == null) {
                _textFont = Crystallography.UI.FontManager.Instance.GetInGame("Bariol", 36, "Bold");
            }
            var map = Crystallography.UI.FontManager.Instance.GetMap( _textFont );

            _buttonText = new Label() {
                Text = "",
                FontMap = map,
                Position = new Vector2(0.0f, 0.5f * (Height - map.CharPixelHeight) )
            };
            this.AddChild(_buttonText);

            ScheduleUpdate(0);
            #if DEBUG
            Console.WriteLine(GetType().ToString() + " created" );
            #endif
        }
예제 #20
0
 /// <summary>Convert from Bounds2: a_bounds.Min becomes T and a_bounds.Size becomes S (no rotation).</summary>
 public TRS( Bounds2 a_bounds )
 {
     T = a_bounds.Min;
     R = Math._10;
     S = a_bounds.Size;
 }
예제 #21
0
        /// <summary>
        /// Draw a wireframe axis aligned rectangle.
        /// </summary>
        public void DrawBounds2( Bounds2 bounds )
        {
            ShaderPush();

            ImmBegin( DrawMode.LineStrip, 5 );
            ImmVertex( new Vertex( bounds.Point00.Xy01, m_current_color ) );
            ImmVertex( new Vertex( bounds.Point10.Xy01, m_current_color ) );
            ImmVertex( new Vertex( bounds.Point11.Xy01, m_current_color ) );
            ImmVertex( new Vertex( bounds.Point01.Xy01, m_current_color ) );
            ImmVertex( new Vertex( bounds.Point00.Xy01, m_current_color ) );
            ImmEnd();

            ShaderPop();
        }
예제 #22
0
        /// <summary>
        /// Draw bounds of local content and pivot, in Node local space.
        /// Normally you don't have to override this function, you just 
        /// override GetlContentLocalBounds() and this function shows it
        /// when DebugFlags.DrawContentLocalBounds is set for example. 
        /// </summary>
        public virtual void DebugDrawContentLocalBounds()
        {
            var content_local_bounds = new Bounds2();
            GetlContentLocalBounds( ref content_local_bounds );

            Director.Instance.DrawHelpers.SetColor( Colors.Yellow );
            Director.Instance.DrawHelpers.DrawBounds2( content_local_bounds );
        }
예제 #23
0
        /// <summary>
        /// This function draws all the vertical and horizontal lines (rulers) regularly placed 
        /// at multiples of 'step' distances that are inside the rectangle 'clipping_bounds'. 
        /// It also draws the the 2 thick axis lines. All lines drawn are clipped again 
        /// 'clipping_bounds'. Blend mode is untouched when drawing the rulers, then blend is 
        /// disabled when drawing axis lines.
        /// </summary>
        /// <param name="clipping_bounds">Clipping rectangle.</param>
        /// <param name="step">Horizontal and vertical spacing between rulers.</param>
        /// <param name="rulers_color">Color of rulers lines.</param>
        /// <param name="axis_color">Color of axis lines.</param>
        public void DrawDefaultGrid( Bounds2 clipping_bounds, Vector2 step, Vector4 rulers_color, Vector4 axis_color )
        {
            //Common.Profiler.Push("DrawHelpers.DrawDefaultGrid");

            ShaderPush();

            SetColor( rulers_color );
            DrawRulers( clipping_bounds, step.X, step.Y );

            GL.Context.Disable( EnableMode.Blend );

            SetColor( axis_color );
            DrawAxis( clipping_bounds, 2.0f );

            ShaderPop();

            //Common.Profiler.Pop();
        }
예제 #24
0
        /// <summary>
        /// Get the bounds for the content of this node (only), in world space (no recursion).
        /// Nodes that don't have any content just return false and don't touch bounds.
        /// </summary>
        public virtual bool GetContentWorldBounds( ref Bounds2 bounds )
        {
            Bounds2 lbounds = new Bounds2();

            if ( !GetlContentLocalBounds( ref lbounds ) )
                return false; // this node had no content

            Matrix3 m = GetWorldTransform();

            bounds = new Bounds2( ( m * lbounds.Point00.Xy1 ).Xy );
            bounds.Add( ( m * lbounds.Point10.Xy1 ).Xy );
            bounds.Add( ( m * lbounds.Point01.Xy1 ).Xy );
            bounds.Add( ( m * lbounds.Point11.Xy1 ).Xy );

            return true;
        }
예제 #25
0
        /// <summary>
        /// Draw all the vertical and horizontal lines in a given rectangle, regularly spaced.
        /// Since the smaller step_x or step_y are, the more lines primitives are generated, 
        /// it is easy to overflow the immediate draw mode vertex buffer. For that reason care 
        /// must be taken when setting the step values respective to the the bounds clip area.
        /// </summary>
        /// <param name="step_x">X spacing (starts at 0).</param>
        /// <param name="step_y">Y spacing (starts at 0).</param> 
        /// <param name="bounds">Clipping rectangle.</param>
        public void DrawRulers( Bounds2 bounds, float step_x, float step_y )
        {
            step_x = FMath.Max( step_x, 0.0f );
            step_y = FMath.Max( step_y, 0.0f );

            if ( step_x < float.Epsilon ) return;
            if ( step_y < float.Epsilon ) return;

            float left = bounds.Min.X;
            float right = bounds.Max.X;
            float bottom = bounds.Min.Y;
            float top = bounds.Max.Y;

            int l = (int)( left / step_x );
            int r = (int)( right / step_x );
            int b = (int)( bottom / step_y );
            int t = (int)( top / step_y );

            ShaderPush();

            bool safe_x = (r-l+1)<1000;
            bool safe_y = (t-b+1)<1000;

            ImmBegin( DrawMode.Lines, ( safe_x ? (uint)((r-l+1)*2) : 0 ) + ( safe_y ? (uint)((t-b+1)*2) : 0 ) );

            if ( safe_x )
            {
                for ( int i=l;i<=r;++i )
                {
                    ImmVertex( new Vector2( (float)i * step_x, bottom ) );
                    ImmVertex( new Vector2( (float)i * step_x, top ) );
                }
            }
            //			else
            //			{
            //				System.Console.WriteLine( "skip drawing of x rulers lines, too many lines" );
            //			}

            if ( safe_y )
            {
                for ( int i=b;i<=t;++i )
                {
                    ImmVertex( new Vector2( left, (float)i * step_y ) );
                    ImmVertex( new Vector2( right, (float)i * step_y ) );
                }
            }
            // 		else
            // 		{
            // 			System.Console.WriteLine( "skip drawing of y rulers lines, too many lines" );
            // 		}

            ImmEnd();

            ShaderPop();
        }
예제 #26
0
 /// <summary>
 /// Get the bounds for the content/geometry of this node (only), in node space (no recursion).
 /// Nodes that don't have any content just return false.
 /// </summary>
 public virtual bool GetlContentLocalBounds( ref Bounds2 bounds )
 {
     return false;
 }
        // CONSTRUCTOR ----------------------------------------------------------------------------------------------------------------------------
        public LevelSelectItem(float pComplete, bool pLocked)
        {
            if (pComplete == 1.0f) {
            //				background = Support.TiledSpriteFromFile("Application/assets/images/UI/LevelSelectItemButton.png", 1, 3);
                background = Support.TiledSpriteFromAtlas("crystallonUI", "LevelSelectItemButton.png", 1, 3);
            } else {
            //				background = Support.TiledSpriteFromFile("Application/assets/images/UI/LevelSelectItemButtonDisabled.png", 1, 3);
                background = Support.TiledSpriteFromAtlas("crystallonUI", "LevelSelectItemButtonDisabled.png", 1, 3);
            }
            background.CenterSprite();
            var size = background.CalcSizeInPixels();

            Initialize(size.X, size.Y);
            Console.WriteLine(size.X.ToString() + " " + size.Y.ToString());
            Console.WriteLine(Scale.ToString());
            _bounds = new Bounds2( new Vector2(-Width/2.0f, -Height/2.0f), new Vector2(Width/2.0f, Height/2.0f) );
            locked = pLocked;
            if (locked) {
            //				var lockIcon = Support.SpriteFromFile("Application/assets/images/UI/lockIcon.png");
                var lockIcon = Support.SpriteFromAtlas("crystallonUI", "lockIcon.png");
                lockIcon.Position = new Vector2( 25.0f, -38.0f);
                this.AddChild( lockIcon );
            }
            this.On(!locked);
        }
예제 #28
0
        /// <summary>
        /// Return true if 'world_position' is inside the content oriented bounding box.
        /// </summary>
        public bool IsWorldPointInsideContentLocalBounds( Vector2 world_position )
        {
            Bounds2 bounds = new Bounds2();

            if ( !GetlContentLocalBounds( ref bounds ) )
                return false;

            return bounds.IsInside( WorldToLocal( world_position ) );
        }
예제 #29
0
        /// <summary>Calculate the bounds of this poly.</summary>
        public Bounds2 CalcBounds()
        {
            if ( Size() == 0 )
                return Bounds2.Zero;

            Bounds2 retval = new Bounds2( GetPoint( 0 ), GetPoint( 0 ) );
            for ( int i = 1; i != (int)Size(); ++i )
                retval.Add( GetPoint( i ) );
            return retval;
        }
예제 #30
0
        /// <summary>Return true if this and 'bounds' overlap.</summary>
        public bool Overlaps( Bounds2 bounds )
        {
            if ( Min.X > bounds.Max.X || bounds.Min.X > Max.X )	return false;
            if ( Min.Y > bounds.Max.Y || bounds.Min.Y > Max.Y )	return false;

            return true;
        }