Hero extends from Character, and is used for the main character
상속: Character
예제 #1
0
        public MainGameScreen()
        {
            h1 = Hero.instance;

            InGameMenu.init();
            InGameMenu.refreshPanelLists();
        }
예제 #2
0
        public static void updateCameraOffset(Hero p_hero)
        {
            Point l_cameraOffset = new Point();
            l_cameraOffset.X = (int) (p_hero.getXCenter() - m_gd.Viewport.Width / m_scaleFactor / 2);
            l_cameraOffset.Y = (int) (p_hero.getYCenter() - m_gd.Viewport.Height / m_scaleFactor / 2);

            int l_maxCameraX = (int) (m_currentRoom.background.Width * m_currentRoom.background.TileWidth - m_gd.Viewport.Width / m_scaleFactor);
            int l_maxCameraY = (int) (m_currentRoom.background.Height * m_currentRoom.background.TileHeight - m_gd.Viewport.Height / m_scaleFactor);

            if (l_cameraOffset.X < 0) { l_cameraOffset.X = 0; }
            if (l_cameraOffset.Y < 0) { l_cameraOffset.Y = 0; }
            if (l_cameraOffset.X > l_maxCameraX) { l_cameraOffset.X = l_maxCameraX; }
            if (l_cameraOffset.Y > l_maxCameraY) { l_cameraOffset.Y = l_maxCameraY; }

            Point l_previousCameraOffset;
            l_previousCameraOffset.X = m_currentCameraOffset.X;
            l_previousCameraOffset.Y = m_currentCameraOffset.Y;

            int l_dx_offset = l_cameraOffset.X - l_previousCameraOffset.X;
            int l_dy_offset = l_cameraOffset.Y - l_previousCameraOffset.Y;

            //update
            m_currentCameraOffset = l_cameraOffset;
            if (!(l_dx_offset == 0 && l_dy_offset == 0))
            {
                CameraOffsetEventArgs args = new CameraOffsetEventArgs();
                args.dx_offset = l_dx_offset;
                args.dy_offset = l_dy_offset;
                if (OffsetChanged != null)
                {
                    OffsetChanged(null, args);  //call all registered listeners
                }
            }
        }
예제 #3
0
        public static void handleWarp(Hero p_hero)
        {
            Rectangle l_heroBounds = new Rectangle(p_hero.getX(), p_hero.getY(), p_hero.getWidth() - 4, p_hero.getHeight() - 4); //NOTE!! warp collision boxes must be bigger
            MapObject l_collidedObject = CollisionManager.collisionWithTeleport(p_hero);

            if (l_collidedObject != null && l_collidedObject.Bounds.Contains(l_heroBounds)) {
                int l_newX = m_currentRoom.background.TileWidth * (int) l_collidedObject.Properties["warpX"];
                int l_newY = m_currentRoom.background.TileHeight * (int) l_collidedObject.Properties["warpY"];
                string l_newRoomName = (string)l_collidedObject.Properties["warpMap"];
                if (l_newRoomName.StartsWith("map_")) l_newRoomName = l_newRoomName.Substring("map_".Length);
                PlaceID l_newRoomID = SunsetUtils.parseEnum<PlaceID>(l_newRoomName);
                setRoom(l_newRoomID, l_newX, l_newY, Hero.instance.getDirection());
            }
        }
예제 #4
0
파일: Hero.cs 프로젝트: ErraticUnicorn/MOSH
            public void update(Hero h, float elapsed)
            {
                //set initial positions
                arrow.setXCenter(h.getXCenter());
                arrow.setYCenter(h.getYCenter() + ARROW_Y_OFFSET);
                negativeBar.setXCenter(h.getXCenter());
                negativeBar.setYCenter(h.getYCenter() + BAR_Y_OFFSET);
                positiveBar.setXCenter(h.getXCenter());
                positiveBar.setYCenter(h.getYCenter() + BAR_Y_OFFSET);

                //update moving arrow
                //moves sinusoidally
                arrowTimer += elapsed;
                displacement = (int)(NEGATIVE_WIDTH / 2 * Math.Sin(arrowTimer * speedFactor + randomOffset));
                arrow.setX(arrow.getX() + displacement);
            }
예제 #5
0
 /// <summary>
 /// Handles Hero's "weapon" ability; call this method in the Game's update cycle (AFTER
 /// calling KeyboardManager.update())
 /// </summary>
 /// <param name="character">The main character</param>
 public static void handleShooting(Hero hero)
 {
     if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.Shoot]))
     {
         hero.shoot();
     }
 }
예제 #6
0
 /// <summary>
 /// Handles the Hero's pickpocketing ability; call this method in the Game's update
 /// cycle (AFTER calling KeyboardManager.update())
 /// </summary>
 /// <param name="hero">The main character</param>
 /// <param name="targets">List of characters in the scene; one that is in range is chosen randomly</param>
 public static void handlePickpocketing(Hero hero, List<Character> targets)
 {
     nullCheck();
     if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.Pickpocket]))
     {
         if (hero.isPickpocketing())
         {
             Item item = hero.stopPickpocket();
             System.Diagnostics.Debug.WriteLine("Stole " + Enum.GetName(typeof(Item), item));
         }
         else if (!hero.isPickpocketing())
         {
             //naive search through a list of characters
             // We should probably do this on a per-room basis later, for efficiency.
             // And/or use some sort of "expanding circle" search.
             for(int i = 0; i < targets.Count; i++)
             {
                 if (hero.inRangeAction(targets[i]))
                 {
                     hero.startPickpocket(targets[i]);
                     break;
                 }
             }
         }
     }
 }
예제 #7
0
 /// <summary>
 /// Handles the Hero talking with Characters. Will be expanded later to "interact" with
 /// scenery as well.
 /// </summary>
 /// <param name="hero">The main character</param>
 /// <param name="targets">List of interactables in the scene</param>
 public static void handleInteractions(Hero hero, List<IInteractable> targets)
 {
     nullCheck();
     if (!hero.isTalking())
     {
         if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.Action]))
         {
             bool foundTarget = false;
             for (int i = 0; i < targets.Count; i++)
             {
                 if (hero.inRangeAction(targets[i]) && hero.facing(targets[i]))
                 {
                     targets[i].onInteract();
                     foundTarget = true;
                     break;
                 }
             }
             if (!foundTarget)
             {
                 hero.talkToSelf();
             }
         }
     }
     else
     {
         if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.MoveNorth]))
             hero.dialogueChoiceMove(Direction.North);
         else if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.MoveSouth]))
             hero.dialogueChoiceMove(Direction.South);
         else if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.Action]))
             hero.dialogueConfirm();
         else if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.Cancel]))
             hero.dialogueCancel();
     }
 }