public virtual void UpdateDraggerWithHSV(HSV hsv)
        {
            // Set the position of the slider to the correct saturation and brightness
			var pos = new CCPoint(StartPos.X + boxPos + (boxSize * (1f - hsv.S)), StartPos.Y + boxPos + (boxSize * hsv.V));

            UpdateSliderPosition(pos);
        }
        void AddNewSpriteWithCoords(CCPoint p)
        {
            CCSpriteBatchNode BatchNode = (CCSpriteBatchNode)this[(int)kTags.kTagSpriteBatchNode];

            int idx = (int)(CCRandom.NextDouble() * 1400 / 100);
            int x = (idx % 5) * 85;
            int y = (idx / 5) * 121;


            CCSprite sprite = new CCSprite(BatchNode.Texture, new CCRect(x, y, 85, 121));
            sprite.Position = (new CCPoint(p.X, p.Y));
            BatchNode.AddChild(sprite);


            CCFiniteTimeAction action = null;
            var random = (float)CCRandom.NextDouble();

            if (random < 0.20)
                action = scaleBy;
            else if (random < 0.40)
                action = rotateBy;
            else if (random < 0.60)
                action = blink;
            else if (random < 0.8)
                action = tintBy;
            else
                action = fadeOut;

            sprite.RepeatForever(action, action.Reverse());

        }
        public static List<Platform> LoadPlatformFromLayer(CCTileMap TileMap, CCTileMapObjectGroup PlatformHolder, Container gameContainer)
        {
            List<Platform> LoadedPlatforms = new List<Platform> ();

            foreach (Dictionary<string,string> LayerObject in PlatformHolder.Objects) {
                if (LayerObject.ContainsKey ("type") == true) {
                    if (LayerObject ["type"] == "platform") {
                        int LoadedSpeed = 200;
                        if (LayerObject.ContainsKey ("speed"))
                            LoadedSpeed = Convert.ToInt32 (LayerObject ["speed"]);
                        List<CCPoint> LoadedWaipoints = new List<CCPoint> ();
                        LoadedWaipoints.Add (new CCPoint ((float)Convert.ToInt32 (LayerObject ["x"]) * TileMap.ScaleX, (float)Convert.ToInt32 (LayerObject ["y"]) * TileMap.ScaleY));
                        if (LayerObject.ContainsKey ("waypoints") == true) {
                            foreach (string WayPointPair in LayerObject ["waypoints"].Split(new char[]{';'},StringSplitOptions.RemoveEmptyEntries)) {
                                CCPoint TempLoadedPoint = new CCPoint ();
                                string[] Waypoint = WayPointPair.Split (new char[]{ ',' }, StringSplitOptions.RemoveEmptyEntries);
                                if (Waypoint.Length > 1) {
                                    TempLoadedPoint.X = LoadedWaipoints [LoadedWaipoints.Count - 1].X + (float)Convert.ToInt32 (Waypoint [0]) * TileMap.ScaleX * TileMap.TileTexelSize.Width;
                                    TempLoadedPoint.Y = LoadedWaipoints [LoadedWaipoints.Count - 1].Y + (float)Convert.ToInt32 (Waypoint [1]) * TileMap.ScaleY * TileMap.TileTexelSize.Height;
                                } else {
                                    throw new ArgumentException ("Incorrect Waypoints");
                                }
                                LoadedWaipoints.Add (TempLoadedPoint);
                            }
                        }
                        LoadedPlatforms.Add (new Platform (LoadedWaipoints, LoadedSpeed, gameContainer));
                    }
                }
            }

            return LoadedPlatforms;
        }
Example #4
0
        void AddNewSpriteWithCoords(CCPoint p)
        {
            CCSpriteBatchNode BatchNode = (CCSpriteBatchNode)GetChildByTag((int)kTags.kTagSpriteBatchNode);

            int idx = (int)(CCRandom.NextDouble() * 1400 / 100);
            int x = (idx % 5) * 85;
            int y = (idx / 5) * 121;


            CCSprite sprite = new CCSprite(BatchNode.Texture, new CCRect(x, y, 85, 121));
            sprite.Position = (new CCPoint(p.X, p.Y));
            BatchNode.AddChild(sprite);


            CCFiniteTimeAction action = null;
            float random = (float)CCRandom.NextDouble();

            if (random < 0.20)
                action = new CCScaleBy(3, 2);
            else if (random < 0.40)
                action = new CCRotateBy (3, 360);
            else if (random < 0.60)
                action = new CCBlink (1, 3);
            else if (random < 0.8)
                action = new CCTintBy (2, 0, -255, -255);
            else
                action = new CCFadeOut  (2);

            CCFiniteTimeAction action_back = (CCFiniteTimeAction)action.Reverse();
            CCFiniteTimeAction seq = (CCFiniteTimeAction)(new CCSequence(action, action_back));

            sprite.RunAction(new CCRepeatForever (seq));
        }
Example #5
0
		public float DistanceTo(ref CCPoint vector, out Segment connectingSegment)
		{
			float segmentLength = (float)this.GetLength();

			CCPoint normalizedLine = new CCPoint(
				(float)(Point2.X - Point1.X) / segmentLength,
				(float)(Point2.Y - Point1.Y) / segmentLength);

			CCPoint pointVector = new CCPoint((float)(vector.X - Point1.X), (float)(vector.Y - Point1.Y));

			float length = CCPoint.Dot(pointVector, normalizedLine);
			connectingSegment = new Segment ();
			if (length < 0)
			{
				connectingSegment.Point1 = vector;
				connectingSegment.Point2 = Point1;

				return (float) connectingSegment.GetLength();
			}
			else if (length > segmentLength)
			{
				connectingSegment.Point1 = vector;
				connectingSegment.Point2 = Point2;

				return (float) connectingSegment.GetLength();
			}
			else
			{
				connectingSegment.Point1 = vector;
				connectingSegment.Point2 = new CCPoint(Point1.X + length * normalizedLine.X,
					Point1.Y + length * normalizedLine.Y);

				return (float)connectingSegment.GetLength();
			}
		}
Example #6
0
        public JumpPad(b2Vec2 JumpImpuls, CCPoint Position, b2World gameWorld)
        {
            this.Texture = new CCTexture2D ("jumppad");
            this.Scale = SpriteScale;
            this.Position = Position;
            this.IsAntialiased = false;

            jumpImpuls = JumpImpuls;
            totalJumps = 0;

            //box2d
            b2BodyDef jumpPadDef = new b2BodyDef ();
            jumpPadDef.type = b2BodyType.b2_kinematicBody;
            jumpPadDef.position = new b2Vec2 ((Position.X + this.ScaledContentSize.Width/2)/PhysicsHandler.pixelPerMeter, (Position.Y + this.ScaledContentSize.Height/4) / PhysicsHandler.pixelPerMeter);
            JumpPadBody = gameWorld.CreateBody (jumpPadDef);

            b2PolygonShape jumpPadShape = new b2PolygonShape ();
            jumpPadShape.SetAsBox ((float)this.ScaledContentSize.Width / PhysicsHandler.pixelPerMeter / 2, (float)this.ScaledContentSize.Height / PhysicsHandler.pixelPerMeter / 4);// /4 weil die hitbox nur die hälfte der textur ist

            b2FixtureDef jumpPadFixture = new b2FixtureDef ();
            jumpPadFixture.shape = jumpPadShape;
            jumpPadFixture.density = 0.0f; //Dichte
            jumpPadFixture.restitution = 0f; //Rückprall
            jumpPadFixture.friction = 0f;
            jumpPadFixture.userData = WorldFixtureData.jumppad;
            JumpPadBody.CreateFixture (jumpPadFixture);
            //
        }
Example #7
0
        public RubeBasicLayer(string jsonfile)
        {
            AnchorPoint = new CCPoint(0, 0);

            HasWheel = true;

            JSON_FILE = jsonfile;

            TouchPanel.EnabledGestures = GestureType.Pinch | GestureType.PinchComplete;

            var touchListener = new CCEventListenerTouchAllAtOnce();
            touchListener.OnTouchesBegan = OnTouchesBegan;
            touchListener.OnTouchesMoved = OnTouchesMoved;
            touchListener.OnTouchesEnded = OnTouchesEnded;
            touchListener.OnTouchesCancelled = OnTouchesCancelled;
            AddEventListener(touchListener, this);

            var mouseListener = new CCEventListenerMouse();
            mouseListener.OnMouseScroll = OnMouseScroll;
            AddEventListener(mouseListener, this);

            // set the starting scale and offset values from the subclass
            Position = InitialWorldOffset();
            Scale = InitialWorldScale();

            // load the world from RUBE .json file (this will also call afterLoadProcessing)
            LoadWorld();
        }
        bool enemyCantBeDamagedForShortInterval; // after damage occurs the enemy gets a moment of un-damage-abilty, which should play better ( I think)


        public Enemy(b2World world,
                      CCPoint location,
                      string spriteFileName,
                      bool isTheRotationFixed,
                      bool getsDamageFromGround,
                      bool doesGetDamageFromDamageEnabledStackObjects,
                      int breaksFromHowMuchContact,
                      bool hasDifferentSpritesForDamage,
                      int numberOfFramesToAnimateOnBreak,
                      float density,
                      CreationMethod createHow,
                      int points,
                      BreakEffect simpleScoreVisualFXType)
        {
            InitWithWorld(world,
                           location,
                           spriteFileName,
                           isTheRotationFixed,
                           getsDamageFromGround,
                           doesGetDamageFromDamageEnabledStackObjects,
                           breaksFromHowMuchContact,
                           hasDifferentSpritesForDamage,
                           numberOfFramesToAnimateOnBreak,
                           density,
                           createHow,
                           points,
                           simpleScoreVisualFXType);
        }
Example #9
0
        public override void DrawSolidCircle(Box2D.Common.b2Vec2 center, float radius, Box2D.Common.b2Vec2 axis, Box2D.Common.b2Color color)
        {
            CCPoint centerToPoint = new CCPoint (center.x * 50f, center.y * 50f);
            //CCColor4B Color = new CCColor4B (color.r, color.g, color.b, 255);

            DrawNode.DrawCircle (centerToPoint, radius, CollusionColor);
        }
Example #10
0
        public GameMenu()
        {
            var screenSize = Director.WindowSizeInPixels;

            voiceButtonName = "VoiceFX";
            voiceButtonNameDim = "VoiceFX";

            soundButtonName = "SoundFX";
            soundButtonNameDim = "SoundFX";

            ambientButtonName = "AmbientFX";
            ambientButtonNameDim = "AmbientFX";


            SoundFXMenuLocation = new CCPoint(110, 55);
            VoiceFXMenuLocation = new CCPoint(230, 55);
            AmbientFXMenuLocation = new CCPoint(355, 55);


            // TouchEnabled = true;


            IsSoundFXMenuItemActive = !GameData.SharedData.AreSoundFXMuted;

            IsVoiceFXMenuActive = !GameData.SharedData.AreVoiceFXMuted;

            IsAmbientFXMenuActive = !GameData.SharedData.AreAmbientFXMuted;

        }
Example #11
0
        public List<CCPoint> FindPath (CCPoint start, CCPoint end)
        {
            startTile = mapLayer.ClosestTileCoordAtNodePosition(start);
            endTile = mapLayer.ClosestTileCoordAtNodePosition(end);
            InitializeMap();
            startNode = nodes[startTile.Column, startTile.Row];
            startNode.State = Node.NodeState.open;
            endNode = nodes[endTile.Column, endTile.Row];

            List<CCPoint> path = new List<CCPoint>();
            bool success = Search(startNode);
            if(success)
            {
                // If a path was found, follow the parents from the end node to build a list of locations
                Node node = this.endNode;
                while (node.ParentNode != null)
                {
                    var centeredPoint = mapLayer.TilePosition(node.Location);
                    centeredPoint = new CCPoint(centeredPoint.X + map.TileTexelSize.Width / 2, centeredPoint.Y + map.TileTexelSize.Width / 2);
                    path.Add(centeredPoint);
                    node = node.ParentNode;
                }

                // Reverse the list so it's in the correct order when returned
                path.Reverse();
            }

            return path;
        }
        public static CCJumpBy actionWithDuration(float duration, CCPoint position, float height, uint jumps)
        {
            CCJumpBy ret = new CCJumpBy();
            ret.initWithDuration(duration, position, height, jumps);

            return ret;
        }
Example #13
0
 public bool InitWithCcPoint(CCPoint ratio, CCPoint offset)
 {
     Ratio = ratio;
     Offset = offset;
     Child = null;
     return true;
 }
Example #14
0
 public void SetTouchInfo(int nViewId, float x, float y)
 {
     m_nViewId = nViewId;
     m_prevPoint = new CCPoint(m_point.X, m_point.Y);
     m_point.X = x;
     m_point.Y = y;
 }
Example #15
0
        public static new CCMoveBy actionWithDuration(float duration, CCPoint position)
        {
            CCMoveBy ret = new CCMoveBy();
            ret.initWithDuration(duration, position);

            return ret;
        }
Example #16
0
 public CCRipple3D (float duration, CCGridSize gridSize, CCPoint position, float radius, int waves, float amplitude)
     : base (duration, gridSize, amplitude)
 {
     Position = position;
     Radius = radius;
     Waves = waves;
 }
Example #17
0
 internal CCTouch(int id, float x, float y)
 {
     Id = id;
     point = new CCPoint(x, y);
     prevPoint = point;
     startPoint = point;
 }
Example #18
0
 internal void SetTouchInfo(int id, float x, float y)
 {
     Id = id;
     prevPoint = point;
     point.X = x;
     point.Y = y;
 }
        // -1 = ClockWise / 1 = CounterClockWise

        #region Constructors

        public CCRotateAroundTo(float duration, CCPoint origin, float angle, float rotationDirection = -1)
            : base(duration)
        {
            DistanceAngle = angle;
            Origin = origin;
            RotationDirection = rotationDirection;
        }
Example #20
0
 public CCLens3D (float duration, CCGridSize gridSize, CCPoint position, float radius) : base (duration, gridSize)
 {
     Position = position;
     Radius = radius;
     LensScale = 0.7f;
     Concave = false;
 }
		public BreakEffect  SimpleScoreVisualFX { get; set; } //defined in Constants.cs

		public StackObject (b2World world, 
		                    CCPoint location,
		                    string spriteFileName,
		                    bool breaksOnGround,
		                    bool breaksFromNinja,
		                    bool hasAnimatedBreakFrames,
		                    bool damagesEnemy,
		                    float density,
		                    CreationMethod createHow,
		                    int angleChange,
		                    bool makeImmovable,
		                    int points,
		                    BreakEffect simpleScoreVisualFXType)
		{
			InitWithWorld(world, 
			              location, 
			              spriteFileName, 
			              breaksOnGround,
			              breaksFromNinja,
			              hasAnimatedBreakFrames,
			              damagesEnemy,
			              density,
			              createHow,
			              angleChange,
			              makeImmovable,
			              points,
			              simpleScoreVisualFXType);
		}
Example #22
0
        protected void ProjectVelocityOnSurface(CCPoint reposition)
        {
            if (reposition.X != 0 || reposition.Y != 0)
            {
                var repositionNormalized = reposition;

                //vector归一化
                repositionNormalized.Normalize ();

                CCPoint velocity = new CCPoint (VelocityX, VelocityY);

                //计算velocity和repositionNormalized的点积,得到瓦片位移向量作用后的位置
                var dot = CCPoint.Dot (velocity, repositionNormalized);

                // falling into the collision, rather than out of
                //如果dot小于0,则entity掉入瓦片中(掉入被撞击的物体中)
                //掉入是正常现象
                //之后把entity的速度更改下
                //如果是在地面,速度会被改为0
                //不太懂这个算法
                if (dot < 0)
                {
                    velocity -= repositionNormalized * dot;

                    VelocityX = velocity.X;
                    VelocityY = velocity.Y;

                }
            }
        }
Example #23
0
        //returns a list of tiles with a certain property and value - checks up,down,left,right nodes
        //if you're in the upper left hand corner for instance and check for walkable tiles it will return bottom and right coords
        public static List<CCTileMapCoordinates> getSurroundingTilesWithProperties(CCPoint myPosition,string property, string value)
        {
            var adjacentCoordinates = new List<CCTileMapCoordinates>();
            foreach (CCTileMapLayer layer in map.TileLayersContainer.Children)
            {
                CCTileMapCoordinates currentTile = layer.ClosestTileCoordAtNodePosition(myPosition); // (touchlocation if depending on who passed in)
                CCTileMapCoordinates up, left, right, down;
                //Up
                up = new CCTileMapCoordinates(currentTile.Column + 1, currentTile.Row);
                if (checkSingleTileWithProperties(up, property, value))
                    adjacentCoordinates.Add(up);
                //Left
                left = new CCTileMapCoordinates(currentTile.Column, currentTile.Row - 1);
                if (checkSingleTileWithProperties(left, property, value))
                    adjacentCoordinates.Add(left);
                //Down
                down = new CCTileMapCoordinates(currentTile.Column - 1, currentTile.Row);
                if (checkSingleTileWithProperties(down, property, value))
                    adjacentCoordinates.Add(down);
                //Right
                right = new CCTileMapCoordinates(currentTile.Column, currentTile.Row + 1);
                if (checkSingleTileWithProperties(right, property, value))
                    adjacentCoordinates.Add(right);
            }
            

            return adjacentCoordinates;
        }
Example #24
0
        /** creates the action */
        public static CCMoveTo actionWithDuration(float duration, CCPoint position)
        {
            CCMoveTo moveTo = new CCMoveTo();
            moveTo.initWithDuration(duration, position);

            return moveTo;
        }
		private void InitWithWorld( b2World world, CCPoint location, string spriteFileName)
		{
			this.theWorld = world;
			this.initialLocation = location;
			this.spriteImageName = spriteFileName;
			CreateGround();
		}
        public void UpdateBallTransform()
        {
            if (PhysicsBody != null)
            {
                b2Vec2 pos = PhysicsBody.Position;

                float x = pos.x * ptmRatio;
                float y = pos.y * ptmRatio;

                if (IgnoreAnchorPointForPosition) 
                {
                    x += AnchorPointInPoints.X;
                    y += AnchorPointInPoints.Y;
                }

                // Make matrix
                float radians = PhysicsBody.Angle;
                var c = (float)Math.Cos (radians);
                var s = (float)Math.Sin (radians);

                if (!AnchorPointInPoints.Equals (CCPoint.Zero)) 
                {
                    x += c * -AnchorPointInPoints.X + -s * -AnchorPointInPoints.Y;
                    y += s * -AnchorPointInPoints.X + c * -AnchorPointInPoints.Y;
                }

                Position = new CCPoint(x, y);
            }
        }
Example #27
0
        public override void Update (float time)
        {
            if (Target != null)
            {
                float xa = 0;
                float xb = BezierConfig.ControlPoint1.X;
                float xc = BezierConfig.ControlPoint2.X;
                float xd = BezierConfig.EndPosition.X;

                float ya = 0;
                float yb = BezierConfig.ControlPoint1.Y;
                float yc = BezierConfig.ControlPoint2.Y;
                float yd = BezierConfig.EndPosition.Y;

                float x = CCSplineMath.CubicBezier (xa, xb, xc, xd, time);
                float y = CCSplineMath.CubicBezier (ya, yb, yc, yd, time);

                CCPoint currentPos = Target.Position;
                CCPoint diff = currentPos - PreviousPosition;
                StartPosition = StartPosition + diff;

                CCPoint newPos = StartPosition + new CCPoint (x, y);
                Target.Position = newPos;

                PreviousPosition = newPos;
            }
        }
Example #28
0
        // CatmullRom Spline formula:
        /// <summary>
        /// See http://en.wikipedia.org/wiki/Cubic_Hermite_spline#Cardinal_spline
        /// </summary>
        /// <param name="p0">Control point 1</param>
        /// <param name="p1">Control point 2</param>
        /// <param name="p2">Control point 3</param>
        /// <param name="p3">Control point 4</param>
        /// <param name="tension"> The parameter c is a tension parameter that must be in the interval (0,1). In some sense, this can be interpreted as the "length" of the tangent. c=1 will yield all zero tangents, and c=0 yields a Catmull–Rom spline.</param>
        /// <param name="t">Time along the spline</param>
        /// <returns>The point along the spline for the given time (t)</returns>
		internal static CCPoint CCCardinalSplineAt(CCPoint p0, CCPoint p1, CCPoint p2, CCPoint p3, float tension, float t)
        {
            if (tension < 0f)
            {
                tension = 0f;
            }
            if (tension > 1f)
            {
                tension = 1f;
            }
            float t2 = t * t;
            float t3 = t2 * t;

            /*
             * Formula: s(-ttt + 2tt - t)P1 + s(-ttt + tt)P2 + (2ttt - 3tt + 1)P2 + s(ttt - 2tt + t)P3 + (-2ttt + 3tt)P3 + s(ttt - tt)P4
             */
            float s = (1 - tension) / 2;

            float b1 = s * ((-t3 + (2 * t2)) - t); // s(-t3 + 2 t2 - t)P1
            float b2 = s * (-t3 + t2) + (2 * t3 - 3 * t2 + 1); // s(-t3 + t2)P2 + (2 t3 - 3 t2 + 1)P2
            float b3 = s * (t3 - 2 * t2 + t) + (-2 * t3 + 3 * t2); // s(t3 - 2 t2 + t)P3 + (-2 t3 + 3 t2)P3
            float b4 = s * (t3 - t2); // s(t3 - t2)P4

            float x = (p0.X * b1 + p1.X * b2 + p2.X * b3 + p3.X * b4);
            float y = (p0.Y * b1 + p1.Y * b2 + p2.Y * b3 + p3.Y * b4);

            return new CCPoint(x, y);
        }
        protected override void AddedToScene()
        {
            base.AddedToScene();

            // Use the bounds to layout the positioning of our drawable assets
            var bounds = VisibleBoundsWorldspace;

            // position the label on the center of the screen
            label.Position = bounds.LowerLeft;

            //Ubicar las 6 sillas al inicio
            //TODO hallar el centro de la pantalla
            CCSize tamaño = Scene.Window.WindowSizeInPixels;
            CCPoint centro = tamaño.Center;
            double cx = centro.X;
            double cy = centro.Y;
            double radio = 200;

            for (int i = 0; i < sillas.Count; i++)
            {
                double xpos = cx + radio * Math.Sin(2 * Math.PI / 6 * i);
                double ypos = cy + radio * Math.Cos(2 * Math.PI / 6 * i);
                CCPoint position = new CCPoint((float)xpos, (float)ypos);
                sillas[i].Position = position;
                sillas[i].Rotation = (float)(180 + 360 / 6 * i);
            }

            // Register for touch events
            var touchListener = new CCEventListenerTouchAllAtOnce();
            touchListener.OnTouchesEnded = OnTouchesEnded;
            AddEventListener(touchListener, this);
        }
Example #30
0
        public override void Update(float time)
        {
            if (m_pTarget != null)
            {
                // Is % equal to fmodf()???
                float frac = (time * m_nJumps) % 1f;
                float y = m_height * 4f * frac * (1f - frac);
                y += m_delta.Y * time;
                float x = m_delta.X * time;
#if CC_ENABLE_STACKABLE_ACTIONS
                CCPoint currentPos = m_pTarget.Position;

                CCPoint diff = currentPos - m_previousPos;
                m_startPosition = diff + m_startPosition;

                CCPoint newPos = m_startPosition + new CCPoint(x,y);
                m_pTarget.Position = newPos;

                m_previousPos = newPos;
#else
                m_pTarget.Position = m_startPosition + new CCPoint(x, y);
#endif
                // !CC_ENABLE_STACKABLE_ACTIONS
            }
        }
Example #31
0
        /// <summary>
        /// draws a cubic bezier path
        /// @since v0.8
        /// </summary>
        public void DrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, int segments, float lineWidth, CCColor4B color)
        {
            float t         = 0;
            float increment = 1.0f / segments;

            var vertices = new CCPoint[segments];

            vertices[0] = origin;

            for (int i = 1; i < segments; ++i, t += increment)
            {
                vertices[i].X = SplineMath.CubicBezier(origin.X, control1.X, control2.X, destination.X, t);
                vertices[i].Y = SplineMath.CubicBezier(origin.Y, control1.Y, control2.Y, destination.Y, t);
            }

            vertices[segments - 1] = destination;

            for (int i = 0; i < vertices.Length - 1; i++)
            {
                DrawLine(vertices[i], vertices[i + 1], lineWidth, color, LineCap.Square);
            }

            //DrawPolygon(vertices, vertices.Length, color, lineWidth, color);
        }
Example #32
0
 public void DrawRect(CCPoint p, float size)
 {
     DrawRect(p, size, new CCColor4B(Color.R, Color.G, Color.B, Opacity));
 }
Example #33
0
 public void DrawLine(CCPoint from, CCPoint to, CCColor4B color, LineCap lineCap = LineCap.Butt)
 {
     DrawLine(from, to, 1, color);
 }
Example #34
0
 public void DrawLine(CCPoint from, CCPoint to, float lineWidth = 1, LineCap lineCap = LineCap.Butt)
 {
     DrawLine(from, to, lineWidth, new CCColor4B(Color.R, Color.G, Color.B, Opacity));
 }
Example #35
0
        // See http://slabode.exofire.net/circle_draw.shtml
        // An Efficient Way to Draw Approximate Circles in OpenGL
        // Try to keep from calculating Cos and Sin of values everytime and just use
        // add and subtract where possible to calculate the values.
        public void DrawCircle(CCPoint center, float radius, CCColor4B color)
        {
            int segments = (int)(10 * (float)Math.Sqrt(radius));  //<- Let's try to guess at # segments for a reasonable smoothness

            DrawCircle(center, radius, segments, color);
        }
Example #36
0
 public Platform(string filename, PlatformTypes platformType, CCPoint position)
 {
     base.InitWithFile(filename);
     PlatformType = platformType;
     Position     = position;
 }
Example #37
0
 bool OnTouchBegan(CCTouch touch, CCEvent touchEvent)
 {
     beginTouchPos = touch.Location;
     return(true);
 }
Example #38
0
        void CreateGeometry()
        {
            var windowSize = Layer.VisibleBoundsWorldspace.Size;

            // Draw 10 circles
            for (int i = 0; i < 10; i++)
            {
                drawBuffer.DrawSolidCircle(windowSize.Center, 10 * (10 - i),
                                           new CCColor4F(CCRandom.Float_0_1(), CCRandom.Float_0_1(), CCRandom.Float_0_1(), 1));
            }

            // Draw polygons
            CCPoint[] points = new CCPoint[]
            {
                new CCPoint(windowSize.Height / 4, 0),
                new CCPoint(windowSize.Width, windowSize.Height / 5),
                new CCPoint(windowSize.Width / 3 * 2, windowSize.Height)
            };
            drawBuffer.DrawPolygon(points, points.Length, new CCColor4F(1.0f, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1));

            // star poly (triggers buggs)
            {
                const float o    = 80;
                const float w    = 20;
                const float h    = 50;
                CCPoint[]   star = new CCPoint[]
                {
                    new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o),                               // lower spike
                    new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),               // right spike
                };

                drawBuffer.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
            }

            // star poly (doesn't trigger bug... order is important un tesselation is supported.
            {
                const float o    = 180;
                const float w    = 20;
                const float h    = 50;
                var         star = new CCPoint[]
                {
                    new CCPoint(o, o), new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o), // lower spike
                    new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),    // right spike
                    new CCPoint(o + w, o + w * 2 + h), new CCPoint(o, o + w * 2),            // top spike
                    new CCPoint(o - h, o + w),                                               // left spike
                };

                drawBuffer.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
            }


            // Draw segment
            drawBuffer.DrawLine(new CCPoint(20, windowSize.Height), new CCPoint(20, windowSize.Height / 2), 10, new CCColor4F(0, 1, 0, 1), DrawNodeBuffer.LineCap.Round);

            drawBuffer.DrawLine(new CCPoint(10, windowSize.Height / 2), new CCPoint(windowSize.Width / 2, windowSize.Height / 2), 40,
                                new CCColor4F(1, 0, 1, 0.5f), DrawNodeBuffer.LineCap.Round);

            CCSize size = VisibleBoundsWorldspace.Size;

            var visibleRect = VisibleBoundsWorldspace;

            // draw quad bezier path
            drawBuffer.DrawQuadBezier(new CCPoint(0, size.Height),
                                      visibleRect.Center,
                                      (CCPoint)visibleRect.Size,
                                      50, 3,
                                      new CCColor4B(255, 0, 255, 255));

            // draw cubic bezier path
            drawBuffer.DrawCubicBezier(visibleRect.Center,
                                       new CCPoint(size.Width / 2 + 30, size.Height / 2 + 50),
                                       new CCPoint(size.Width / 2 + 60, size.Height / 2 - 50),
                                       new CCPoint(size.Width, size.Height / 2), 100, 2, CCColor4B.Green);

            // draw an ellipse within rectangular region
            drawBuffer.DrawEllipse(new CCRect(100, 300, 100, 200), 8, CCColor4B.AliceBlue);

            var splinePoints = new List <CCPoint>();

            splinePoints.Add(new CCPoint(0, 0));
            splinePoints.Add(new CCPoint(50, 70));
            splinePoints.Add(new CCPoint(0, 140));
            splinePoints.Add(new CCPoint(100, 210));
            splinePoints.Add(new CCPoint(0, 280));
            splinePoints.Add(new CCPoint(150, 350));

            int   numberOfSegments = 64;
            float tension          = .05f;

            drawBuffer.DrawCardinalSpline(splinePoints, tension, numberOfSegments);

            drawBuffer.DrawSolidArc(
                pos: new CCPoint(350, windowSize.Height * 0.75f),
                radius: 100,
                startAngle: CCMathHelper.ToRadians(45),
                sweepAngle: CCMathHelper.Pi / 2, // this is in radians, clockwise
                color: CCColor4B.Aquamarine);
        }
Example #39
0
 public void SetPosition(CCPoint point)
 {
     SetX(point.X); SetY(point.Y);
 }
Example #40
0
 public void HandleInput(CCPoint touchPoint)
 {
     desiredLocation = touchPoint;
 }
Example #41
0
 public void Reset(CCPoint position)
 {
     Position = position;
 }
Example #42
0
        public void DrawPolygon(CCPoint[] verts, int count, CCColor4B fillColor, float borderWidth,
                                CCColor4B borderColor, bool closePolygon = true)
        {
            var polycount = count;

            var colorFill  = fillColor;
            var borderFill = borderColor;

            bool outline = (borderColor.A > 0.0f && borderWidth > 0.0f);
            bool fill    = fillColor.A > 0.0f;

            var numberOfTriangles = outline ? (3 * polycount - 2) : (polycount - 2);

            if (numberOfTriangles > 0 && fill && closePolygon)
            {
                for (int i = 1; i < polycount - 1; i++)
                {
                    AddTriangleVertex(new CCV3F_C4B(verts[0], colorFill));
                    AddTriangleVertex(new CCV3F_C4B(verts[i], colorFill));
                    AddTriangleVertex(new CCV3F_C4B(verts[i + 1], colorFill));
                }
            }
            else
            {
                for (int i = 0; i < polycount - 1; i++)
                {
                    DrawLine(verts[i], verts[i + 1], borderWidth, colorFill);
                }
            }

            if (outline)
            {
                var extrude = new ExtrudeVerts[polycount];

                for (int i = 0; i < polycount; i++)
                {
                    var v0 = verts[(i - 1 + polycount) % polycount];
                    var v1 = verts[i];
                    var v2 = verts[(i + 1) % polycount];

                    var n1 = CCPoint.Normalize(CCPoint.PerpendicularCCW(v1 - v0));
                    var n2 = CCPoint.Normalize(CCPoint.PerpendicularCCW(v2 - v1));

                    var offset = (n1 + n2) * (1.0f / (CCPoint.Dot(n1, n2) + 1.0f));
                    extrude[i] = new ExtrudeVerts()
                    {
                        offset = offset, n = n2
                    };
                }

                float inset = (!outline ? 0.5f : 0.0f);

                for (int i = 0; i < polycount - 2; i++)
                {
                    var v0 = verts[0] - (extrude[0].offset * inset);
                    var v1 = verts[i + 1] - (extrude[i + 1].offset * inset);
                    var v2 = verts[i + 2] - (extrude[i + 2].offset * inset);

                    AddTriangleVertex(new CCV3F_C4B(v0, colorFill)); //__t(v2fzero)
                    AddTriangleVertex(new CCV3F_C4B(v1, colorFill)); //__t(v2fzero)
                    AddTriangleVertex(new CCV3F_C4B(v2, colorFill)); //__t(v2fzero)
                }

                for (int i = 0; i < polycount - 1; i++)
                {
                    int j  = (i + 1) % polycount;
                    var v0 = verts[i];
                    var v1 = verts[j];

                    var offset0 = extrude[i].offset;
                    var offset1 = extrude[j].offset;

                    var inner0 = (v0 - (offset0 * borderWidth));
                    var inner1 = (v1 - (offset1 * borderWidth));
                    var outer0 = (v0 + (offset0 * borderWidth));
                    var outer1 = (v1 + (offset1 * borderWidth));

                    AddTriangleVertex(new CCV3F_C4B(inner0, borderFill));
                    AddTriangleVertex(new CCV3F_C4B(inner1, borderFill));
                    AddTriangleVertex(new CCV3F_C4B(outer1, borderFill));

                    AddTriangleVertex(new CCV3F_C4B(inner0, borderFill));
                    AddTriangleVertex(new CCV3F_C4B(outer0, borderFill));
                    AddTriangleVertex(new CCV3F_C4B(outer1, borderFill));
                }

                if (closePolygon)
                {
                    for (int i = polycount - 1; i < polycount; i++)
                    {
                        int j  = (i + 1) % polycount;
                        var v0 = verts[i];
                        var v1 = verts[j];

                        var offset0 = extrude[i].offset;
                        var offset1 = extrude[j].offset;

                        var inner0 = (v0 - (offset0 * borderWidth));
                        var inner1 = (v1 - (offset1 * borderWidth));
                        var outer0 = (v0 + (offset0 * borderWidth));
                        var outer1 = (v1 + (offset1 * borderWidth));

                        AddTriangleVertex(new CCV3F_C4B(inner0, borderFill));
                        AddTriangleVertex(new CCV3F_C4B(inner1, borderFill));
                        AddTriangleVertex(new CCV3F_C4B(outer1, borderFill));

                        AddTriangleVertex(new CCV3F_C4B(inner0, borderFill));
                        AddTriangleVertex(new CCV3F_C4B(outer0, borderFill));
                        AddTriangleVertex(new CCV3F_C4B(outer1, borderFill));
                    }
                }
            }

            dirty = true;
        }
Example #43
0
        // CatmullRom Spline formula:
        /// <summary>
        /// See http://en.wikipedia.org/wiki/Cubic_Hermite_spline#Cardinal_spline
        /// </summary>
        /// <param name="p0">Control point 1</param>
        /// <param name="p1">Control point 2</param>
        /// <param name="p2">Control point 3</param>
        /// <param name="p3">Control point 4</param>
        /// <param name="tension"> The parameter c is a tension parameter that must be in the interval (0,1). In some sense, this can be interpreted as the "length" of the tangent. c=1 will yield all zero tangents, and c=0 yields a Catmull–Rom spline.</param>
        /// <param name="t">Time along the spline</param>
        /// <returns>The point along the spline for the given time (t)</returns>
        internal static CCPoint CCCardinalSplineAt(CCPoint p0, CCPoint p1, CCPoint p2, CCPoint p3, float tension, float t)
        {
            if (tension < 0f)
            {
                tension = 0f;
            }
            if (tension > 1f)
            {
                tension = 1f;
            }
            float t2 = t * t;
            float t3 = t2 * t;

            /*
             * Formula: s(-ttt + 2tt - t)P1 + s(-ttt + tt)P2 + (2ttt - 3tt + 1)P2 + s(ttt - 2tt + t)P3 + (-2ttt + 3tt)P3 + s(ttt - tt)P4
             */
            float s = (1 - tension) / 2;

            float b1 = s * ((-t3 + (2 * t2)) - t);                 // s(-t3 + 2 t2 - t)P1
            float b2 = s * (-t3 + t2) + (2 * t3 - 3 * t2 + 1);     // s(-t3 + t2)P2 + (2 t3 - 3 t2 + 1)P2
            float b3 = s * (t3 - 2 * t2 + t) + (-2 * t3 + 3 * t2); // s(t3 - 2 t2 + t)P3 + (-2 t3 + 3 t2)P3
            float b4 = s * (t3 - t2);                              // s(t3 - t2)P4

            float x = (p0.X * b1 + p1.X * b2 + p2.X * b3 + p3.X * b4);
            float y = (p0.Y * b1 + p1.Y * b2 + p2.Y * b3 + p3.Y * b4);

            return(new CCPoint(x, y));
        }
Example #44
0
 public void DrawSolidArc(CCPoint position, float radius, float angle, CCColor4B fillColor) => DrawSolidArc(position, radius, 0, angle, fillColor, 0, CCColor4B.Transparent);
Example #45
0
        private static CCPoint ApplyBounce(CCPoint object1Velocity, CCPoint object2Velocity, CCPoint normal, float elasticity)
        {
            CCPoint vectorAsVelocity = new CCPoint(
                object1Velocity.X - object2Velocity.X,
                object1Velocity.Y - object2Velocity.Y);

            float projected = CCPoint.Dot(vectorAsVelocity, normal);

            if (projected < 0)
            {
                CCPoint velocityComponentPerpendicularToTangent =
                    normal * projected;

                object1Velocity.X -= (1 + elasticity) * velocityComponentPerpendicularToTangent.X;
                object1Velocity.Y -= (1 + elasticity) * velocityComponentPerpendicularToTangent.Y;
            }

            return(object1Velocity);
        }
Example #46
0
 public void DrawSolidArc(CCPoint position, float radius, float angle, CCColor4B fillColor, float borderThickness, CCColor4B borderColor) => DrawSolidArc(position, radius, 0, angle, fillColor, borderThickness, borderColor);
Example #47
0
 public void DrawRoundedLine(CCPoint from, CCPoint to, float radius, CCColor4F fill) => DrawRoundedLine(from, to, radius, fill, 0, CCColor4B.Transparent.ToColor4F());
Example #48
0
 public void DrawSolidArc(CCPoint position, float radius, float startAngle, float sweepAngle, CCColor4B fillColor, float borderThickness, CCColor4B borderColor)
 {
     DrawNode.DrawSolidArc(position, radius + borderThickness, startAngle + (float)PI / 2, -sweepAngle, borderColor);
     DrawNode.DrawSolidArc(position, radius, startAngle + (float)PI / 2, -sweepAngle, fillColor);
 }
Example #49
0
 public void DrawRect(CCPoint position, float width, float height, CCColor4B fillColor) => DrawRect(position, width, height, fillColor, 0, CCColor4B.Transparent);
Example #50
0
 public void DrawRoundedLine(CCPoint from, CCPoint to, float radius, CCColor4F fill, float borderThickness, CCColor4F borderColor)
 {
     DrawNode.DrawSegment(from, to, radius + borderThickness, borderColor);
     DrawNode.DrawSegment(from, to, radius, fill);
 }
Example #51
0
 public void DrawRect(CCPoint position, CCSize size, CCColor4B fillColor, float borderThickness, CCColor4B borderColor) => DrawRect(position, size.Width, size.Height, fillColor, borderThickness, borderColor);
Example #52
0
 public void DrawRect(CCPoint position, CCSize size, CCColor4B fillColor) => DrawRect(position, size.Width, size.Height, fillColor, 0, CCColor4B.Transparent);
Example #53
0
 public void DrawLine(CCPoint from, CCPoint to) => DrawLine(from, to, 0, CCColor4B.White);
Example #54
0
 public void DrawRect(CCPoint position, float width, float height, CCColor4B fillColor, float borderThickness, CCColor4B borderColor)
 {
     DrawNode.DrawRect(new CCRect(position.X - width / 2, position.Y - height / 2, width, height), fillColor, borderThickness, borderColor);
 }
Example #55
0
 public void DrawCircle(CCPoint position, float radius, CCColor4B fillColor) => DrawCircle(position, radius, fillColor, 0, CCColor4B.Transparent);
Example #56
0
 public void DrawLine(CCPoint from, CCPoint to, float thickness, CCColor4B color)
 {
     DrawNode.DrawLine(from, to, thickness, color);
 }
Example #57
0
 public void DrawTexture(string texturePath, CCPoint position, CCSize size) => DrawTexture(texturePath, position, size, CCColor3B.White, 1);
Example #58
0
 public void DrawTexture(string texturePath, CCPoint position, CCSize size, float opacity) => DrawTexture(texturePath, position, size, CCColor3B.White, opacity);
Example #59
0
        public void ReactToCollision(CCPoint reposition)
        {
            IsOnGround = reposition.Y > 0;

            ProjectVelocityOnSurface(reposition);
        }
Example #60
0
 public void DrawTexture(CCSpriteFrame spriteFrame, CCPoint position, CCSize size, float opacity) => DrawTexture(spriteFrame, position, size, CCColor3B.White, opacity);