Jump to content

  • Log In with Google      Sign In   
  • Create Account

I'm Steve

Member Since 18 Dec 2011
Offline Last Active May 12 2012 09:33 AM

Posts I've Made

In Topic: Mapping Player Actions to one button

02 May 2012 - 05:09 AM

I wanted to again thanks for the suggestions I kinda took the usable object approach with of course switches and ifs etc.

I have abstract class called ActionableObject which has methods

public virtual void Act(ContentObject actingObject) {}
public virtual void Act(ContentObject actingObject, Vector2 location) {}

I set my tileengine to actionableobject and same with all te crops, so I can send a ContentObject (WorldObject more or less) and each of the ActionableObjects take action toward said object.

Partial Main Update method
if (InputManager.IsActionTriggered(InputManager.Action.Ok))
		    {
			    player.State = Character.CharacterState.Acting;
			    if (Session.SelectedInventoryItem is Tool)
				    (Session.SelectedInventoryItem as Tool).ResetAnimation();
			    else if(Session.IsSelectedItemCrop)
				    player.State = Character.CharacterState.Idle;

			    _tileEngine.Act((ContentObject)Session.SelectedInventoryItem, PlayerPosition.SelectionMapVector);
			    /// item used
			    if (_tileEngine.GetCrop(_tileEngine.Map.Name, PlayerPosition.SelectionMapVector) != null &&
				    Session.IsSelectedItemCrop && !(Session.SelectedInventoryItem as Crop).IsGrown)
			    {
				    Session.Inventory.Remove(Session.SelectedInventoryItem);
				    Session.SelectedInventoryItem = null;
			    }
		    }

Act Method for tileEngine
public override void Act(ContentObject actingObject, Vector2 location)
	    {
		    base.Act(actingObject, location);
		    Crop crop = GetCrop(Map.Name, location);
		    int tileIndex = GetTileIndexAtLocation(0, location);
		    int tileIndexValue = GetTileValueAtLocation(0, location);

		    /// IF THERE IS A CROP THERE
		    if (crop != null)
		    {
			    if (actingObject is Tool)
			    {
				    Tool tool = (actingObject as Tool);
				    switch (tool.Type)
				    {
					    case "WateringCan":
						    crop.IsWatered = true;
						    Map.BaseLayer[tileIndex] = (int)TILES.DARKDIRT;
						    /// remove the current handler because we want to have more
						    /// time for the watering <img src='http://public.gamedev.net//public/style_emoticons/<#EMO_DIR#>/tongue.png' class='bbc_emoticon' alt=':P' />
						    crop.OnNoLongerWatered -= new Crop.OnNoLongerWateredHandler(crop_OnNoLongerWatered);
						    crop.OnNoLongerWatered += new Crop.OnNoLongerWateredHandler(crop_OnNoLongerWatered);
						    break;
				    }
			    }
		    }
		    /// THERE IS NO CROP
		    else
		    {
			    if (actingObject is Tool)
			    {
				    Tool tool = (actingObject as Tool);
				    switch (tool.Type)
				    {
					    case "Hoe":
						    if (tileIndexValue == (int)TILES.LIGHTGRASS || tileIndexValue == (int)TILES.MEDIUMGRASS || tileIndexValue == (int)TILES.DARKGRASS)
							    Map.BaseLayer[tileIndex] = (int)TILES.LIGHTDIRT;
						    break;
				    }
			    }
			    else if (actingObject is Crop)
			    {
				    if (tileIndexValue == (int)TILES.LIGHTDIRT || tileIndexValue == (int)TILES.DARKDIRT)
				    {
					    Crop c = actingObject as Crop;
					    c.Coordinates = GetCollidingTileVector2(location);
					    AddCrop(Map.Name, c);
				    }
			    }
		    }
	    }

I know that i will be changing this around a lot but thanks for getting me on my way.

In Topic: Mapping Player Actions to one button

01 May 2012 - 08:18 PM

That was extremely quick :). THanks a lot. I am spending today and tomorrow working on this. I will post later what I ended up finishing if you guys are interested.

PARTNERS