コード例 #1
0
        protected void AutoPosition()
        {
            int   lines   = TTutil.LineCount(TextItems[0]);
            float yOffset = -((float)(lines - 1)) * VerticalLineSpacing - VerticalLineSpacing;

            Position = new Vector3(TTGame.Instance.BuildScreen.GetComponent <ScreenComp>().Center.X, 1f + yOffset, 0.5f); // TODO move up for long texts
            // Use entire text size for calculating middle offsets
            totalTextSize = SubtitleFont.MeasureString(TextItems[0]);
        }
コード例 #2
0
        public override void Process(Entity entity, ThingComp tc, ThingControlComp tcc)
        {
            tcc.TimeBeforeNextMove -= dt;

            // check how much push I get. If get pushed, try to move
            if (tcc.PushFromOthers.LengthSquared() > tcc.PushingForce)
            {
                tcc.TargetMove = tcc.PushFromOthers;
                tcc.TargetMove.Normalize();
            }
            else
            {
                // if not yet time to make my move, return
                if (tcc.TimeBeforeNextMove > 0)
                {
                    return;
                }
            }

            // reset the countdown timer back to its value
            if (tcc.TimeBeforeNextMove <= 0)
            {
                tcc.TimeBeforeNextMove = tcc.DeltaTimeBetweenMoves;
            }

            // if no move to make, return
            if (tcc.TargetMove.LengthSquared() == 0f)
            {
                return;
            }

            // compute new facingDirection from final TargetMove
            tc.FacingDirection = tcc.TargetMove;
            tc.FacingDirection.Normalize();

            // check if passable...
            List <Entity> cols = tc.DetectCollisions(entity, tcc.TargetMove);

            if (!tc.IsCollisionFree && cols.Count > 0 && tcc.PushingForce > 0f)
            {
                // no - so try to push neighbouring things away
                foreach (Entity t in cols)
                {
                    if (t.HasComponent <ThingControlComp>())
                    {
                        t.GetComponent <ThingControlComp>().BePushed(tcc.TargetMove, tcc.PushingForce);
                    }
                }
            }

            if (tc.IsCollisionFree || (!tc.CollidesWithBackground(tcc.TargetMove) && cols.Count == 0))
            {
                // yes - passable
                tc.Target += tcc.TargetMove;
                TTutil.Round(ref tc.Target);
            }
        }
コード例 #3
0
ファイル: TestGame.cs プロジェクト: IndiegameGarden/Quest
        private void DoTest(Test t)
        {
            var c = ChannelMgr.CreateChannel();
            c.Screen.GetComponent<ScreenComp>().BackgroundColor = t.BackgroundColor;

            channels.Add(c);
            t.Initialize(Factory);
            t.Create();

            // add framerate counter
            var col = TTutil.InvertColor(t.BackgroundColor);
            FrameRateCounter.Create(col);

            Factory.CreateTextlet(new Vector2(2f, 750f), t.GetType().Name, col);

        }
コード例 #4
0
        protected void AutoPosition()
        {
            int   lines   = TTutil.LineCount(text[0]);
            float yOffset = -((float)(lines - 1)) * VerticalLineSpacing - VerticalLineSpacing;

            if (Parent != null && Parent is SubtitleText)
            {
                Motion.Position = new Vector2(0f, yOffset);
                // Use entire text size for calculating middle offsets
                totalTextSize = SubtitleFont.MeasureString(text[0]);
            }
            else
            {
                Motion.Position = new Vector2(Screen.Center.X, 1f + yOffset); // TODO move up for long texts
                // Use entire text size for calculating middle offsets
                totalTextSize = SubtitleFont.MeasureString(text[0]);
            }
        }
コード例 #5
0
        public override void OnUserInput(GamesPanel.UserInput inp, Vector2 pointerPos)
        {
            //((mousepos / screenheight - screen.center) / motionparent.zoom ) + MotionParent.zoomcenter
            Vector2 panelPos = (((pointerPos / Screen.HeightPixels) - Screen.Center) / Motion.Zoom) + Motion.ZoomCenter;

            Vector2 gridPos = new Vector2(panelPos.X / PANEL_DELTA_GRID_X, panelPos.Y / PANEL_DELTA_GRID_Y) + PanelShiftPos;

            TTutil.Round(ref gridPos);
            //cursor.Motion.TargetPos = (cursor.GridPosition - PanelShiftPos) * new Vector2(PANEL_DELTA_GRID_X, PANEL_DELTA_GRID_Y);
            //cursor.Motion.TargetPos = panelPos;

            if (gridPos.Equals(cursor.GridPosition))
            {
                OnUserInput(GamesPanel.UserInput.START_SELECT);
            }

            cursor.GridPosition = gridPos;

            SelectGameBelowCursor();
        }
コード例 #6
0
ファイル: Thing.cs プロジェクト: IndiegameGarden/PixelStorm
        protected override void OnUpdate(ref UpdateParams p)
        {
            base.OnUpdate(ref p);

            // update BoundingRectangle values to latest and greatest
            BoundingRectangle.X = TargetX;
            BoundingRectangle.Y = TargetY;

            // update position of the smooth motion of this Thing in the TTengine
            // update position when attached to a parent Thing
            if (Parent is Thing)
            {
                Thing t = Parent as Thing;
                Target          = t.Target + AttachmentPosition;
                Motion.Position = Motion.ScaleAbs * FromPixels(AttachmentPosition);
            }
            else
            {                                                                                         // not attached to a parent Thing
                Motion.Position = Screen.Center + Motion.ScaleAbs * (FromPixels(Position - ViewPos)); // TODO ViewPos smoothing using Draw cache?
                //Motion.Position = Position - ViewPos; // alternative to above
            }

            // compute target move for this thing based on child controls
            TargetMove = Vector2.Zero;
            foreach (Gamelet g in Children)
            {
                if (g is ThingControl)
                {
                    ThingControl control = g as ThingControl;
                    if (control.IsTargetMoveDefined)
                    {
                        TargetMove += control.TargetMove;
                        TargetMove *= control.TargetMoveMultiplier;
                    }
                }
            }

            // compute new facingDirection from final TargetMove
            if (TargetMove.LengthSquared() > 0f)
            {
                FacingDirection = TargetMove;
                FacingDirection.Normalize();

                // take steering inputs if any, and move Thing, applying collision detection
                // if passable...
                List <Thing> cols = DetectCollisions(TargetMove);
                cols.RemoveAll(item => Children.Contains(item)); // do not heed my own attached-items in collision - they move along
                if (IsCollisionFree || (!CollidesWithBackground(TargetMove) && cols.Count == 0))
                {
                    bool ok = true;
                    if (!IsCollisionFree)
                    {
                        // check all attached Things too
                        foreach (Gamelet g in Children)
                        {
                            if (g is Thing && g.Visible)
                            {
                                Thing t = g as Thing;
                                if (t.IsCollisionFree)
                                {
                                    continue;
                                }

                                // first, test if hits background
                                if (t.CollidesWithBackground(TargetMove))
                                {
                                    ok = false;
                                    break;
                                }

                                // if not, test if it hits others that are not attached to same parent and are not pixie
                                List <Thing> colsChild = t.DetectCollisions(TargetMove);
                                colsChild.RemoveAll(item => Children.Contains(item));
                                colsChild.Remove(Level.Current.pixie);
                                if (colsChild.Count > 0)
                                {
                                    ok = false;
                                    break;
                                }
                            }
                        }
                    }
                    // if there are no objections of main Thing (or its attachment) to the move, then move.
                    if (ok)
                    {
                        Target += TargetMove;
                        TTutil.Round(ref Target);
                    }
                }
            }

            Vector2 vdif = Target - Position;

            if (vdif.LengthSquared() > 0f) // if target not reached yet
            {
                if (false)
                {
                    Position = Target; // debug
                }
                else
                {
                    Vector2 vmove = vdif;
                    vmove.Normalize();
                    vmove *= TargetSpeed * Velocity;
                    // convert speed vector to move vector (x = v * t)
                    vmove *= p.Dt;
                    // check if target reached already (i.e. move would overshoot target)
                    if (vmove.LengthSquared() >= vdif.LengthSquared())
                    {
                        Position = Target;
                    }
                    else
                    {
                        // apply move towards target
                        Position += vmove;
                    }
                }
            }
        }
コード例 #7
0
ファイル: Thing.cs プロジェクト: IndiegameGarden/Quest14
        protected override void OnUpdate(ref UpdateParams p)
        {
            base.OnUpdate(ref p);

            // update position of the smooth motion of this Thing in the TTengine
            // update position when attached to a parent Thing
            if (Parent is Thing)
            {
                Thing t = Parent as Thing;
                Target          = t.Target + AttachmentPosition;
                Motion.Position = Motion.ScaleAbs * FromPixels(AttachmentPosition);
            }
            else
            {                                                                                         // not attached to a parent Thing
                Motion.Position = Screen.Center + Motion.ScaleAbs * (FromPixels(Position - ViewPos)); // TODO ViewPos smoothing using Draw cache?
                //Motion.Position = Position - ViewPos; // alternative to above
            }

            // compute target move for this thing based on child ThingControl controls
            TargetMove = Vector2.Zero;
            foreach (Gamelet g in Children)
            {
                if (g is ThingControl)
                {
                    ThingControl control = g as ThingControl;
                    if (control.IsTargetMoveDefined)
                    {
                        TargetMove += control.TargetMove;
                        TargetMove *= control.TargetMoveMultiplier;
                    }
                }
            }

            // compute new facingDirection from final TargetMove
            if (TargetMove.LengthSquared() > 0f)
            {
                FacingDirection = TargetMove;
                FacingDirection.Normalize();
            }

            // take steering inputs if any, and move Thing, applying collision detection
            if (TargetMove.LengthSquared() > 0f)
            {
                // check if passable...
                List <Thing> cols = DetectCollisions(TargetMove);

                if (!IsCollisionFree && Pushing != null && !IsCollisionFree && cols.Count > 0 && Pushing.Force > 0f)
                {
                    // no - so try to push neighbouring things away
                    foreach (Thing t in cols)
                    {
                        if (t.Pushing != null)
                        {
                            t.Pushing.BePushed(TargetMove);
                        }
                    }
                }

                if (IsCollisionFree || (!CollidesWithBackground(TargetMove) && cols.Count == 0))
                {
                    // yes - passable
                    bool ok = true;
                    if (!IsCollisionFree)
                    {
                        // check all attached Things too
                        foreach (Gamelet g in Children)
                        {
                            if (g is Thing)
                            {
                                Thing t = g as Thing;
                                if (t.IsCollisionFree)
                                {
                                    continue;
                                }

                                // first, test if hits background
                                if (t.CollidesWithBackground(TargetMove))
                                {
                                    ok = false;
                                    break;
                                }

                                // if not, test if it hits others
                                List <Thing> colsChild = t.DetectCollisions(TargetMove);
                                if (colsChild.Count > 0)
                                {
                                    ok = false;
                                    break;
                                }
                            }
                        }
                    }
                    // if there are no objections of main Thing (or its attachment) to the move, then move.
                    if (ok)
                    {
                        Target += TargetMove;
                        TTutil.Round(ref Target);
                    }
                }
            }

            Vector2 vdif = Target - Position;

            if (vdif.LengthSquared() > 0f) // if target not reached yet
            {
                Vector2 vmove = vdif;
                vmove.Normalize();
                vmove *= TargetSpeed * Velocity;
                // convert speed vector to move vector (x = v * t)
                vmove *= p.Dt;
                // check if target reached already (i.e. move would overshoot target)
                if (vmove.LengthSquared() >= vdif.LengthSquared())
                {
                    Position = Target;
                }
                else
                {
                    // apply move towards target
                    Position += vmove;
                }
            }
        }
コード例 #8
0
        protected override void OnUpdate(ref UpdateParams p)
        {
            base.OnUpdate(ref p);
            Pixie pixie = Level.Current.pixie;

            // if attached, disable motion
            MyMotion.Active = true; // !(Parent is Pixie);

            // hack - not visible at first to avoid position-flicker
            if (SimTime < 0.3f)
            {
                Visible = false;
            }
            else
            {
                Visible = true;
            }

            // when floating free - check start of attachment to pixie
            if (!(Parent is Thing))
            {
                List <Thing> l = DetectCollisions(vecDown);
                if (l.Count > 0)
                {
                    foreach (Thing t in l)
                    {
                        if (t is BadPixel)
                        {
                            BadPixel bp = t as BadPixel;
                            if (bp.Parent is Pixie)
                            {
                                pixie.AddNextUpdate(this);                                                          // become a child - attach to it.
                                AttachmentPosition = new Vector2(TargetX - pixie.TargetX, TargetY - pixie.TargetY); // new relative position
                                TTutil.Round(ref AttachmentPosition);
                                pixie.Score += 1;
                                break;
                            }
                        }
                        else if (t is Pixie)
                        {
                            pixie.AddNextUpdate(this); // become a child - attach to it.
                            //AttachmentPosition = (new Vector2(PositionX, PositionY) - pixie.Target); // new relative position
                            //AttachmentPosition = new Vector2(1f,PositionY-pixie.TargetY); // new relative position
                            AttachmentPosition = new Vector2(TargetX - pixie.TargetX, TargetY - pixie.TargetY); // new relative position
                            TTutil.Round(ref AttachmentPosition);
                            //Level.Current.Subtitles.Show(2, "Ouch! That sticks!",3f);
                            pixie.Score += 1;
                            break;
                        }
                    }
                }
            }

            // check self-delete
            Vector2 pp = pixie.Target;

            if (TargetY > pixie.TargetY + 130f)     // if way down player somewhere, delete
            {
                Delete = true;
            }
            if (SimTime < 0.2f && CollidesWithBackground(Vector2.Zero))  // new entities that get stuck on background - delete
            {
                Delete = true;
            }
        }