Author Topic: Enable Joystick  (Read 16779 times)

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Enable Joystick
« Reply #15 on: 2007-11-18, 08:28:46 AM »
thanks, it worked!
may i ask you what the "mn" means at the end of your nickname?

edit: it is not a real problem left, but the fact the player type durnurd wrote for me isn't working. do you have a gamepad to try it out?
« Last Edit: 2007-11-18, 08:32:27 AM by Morgengrauen »

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Enable Joystick
« Reply #16 on: 2007-11-18, 10:34:43 AM »
1) The "MN" at the end of my name is a hint that I am from Minnesota.
2) If you upload your project to http://sgdk2.enigmadream.com/support I'll take a look next time I get a chance.  I have a joystick I could test it with.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Enable Joystick
« Reply #17 on: 2007-11-18, 10:57:57 AM »
I've tried this out as a more generalized approach.  Rather than combining exactly one keyboard player and one controller player, it combines two IPlayer interfaces of any type, so I was able to test it with two keyboard inputs which worked.  So the idea is that you initialize it by passing in the types of players you want to use, and it will figure it out from there.

The downside here is that the controller options dialog won't work until a specific controller type is selected by using it.  So here's the player code:

Code: [Select]
[Serializable()]
public class AnyInputPlayer : IPlayer
{
   private GameForm gf;
   private int index;
   private IPlayer pa;
   private IPlayer pb;

   public EitherInputPlayer(IPlayer p1, IPlayer p2, GameForm gameForm, int myIndex)
   {
      gf = gameForm;
      index = myIndex;
      pa = p1;
      pb = p2;
   }

   new public bool Up
   {
      get
      {
     return a(pa.Up) || b(pb.Up);
      }
   }

   new public bool Left
   {
      get
      {
     return a(pa.Left) || b(pb.Left);
      }
   }

   new public bool Right
   {
      get
      {
     return a(pa.Right) || b(pb.Right);
      }
   }

   new public bool Down
   {
      get
      {
     return a(pa.Down) || b(pb.Down);
      }
   }

   new public bool Button1
   {
      get
      {
     return a(pa.Button1) || b(pb.Button1);
      }
   }

   new public bool Button2
   {
      get
      {
     return a(pa.Button2) || b(pb.Button2);
      }
   }

   new public bool Button3
   {
      get
      {
     return a(pa.Button3) || b(pb.Button3);
       }
   }

   new public bool Button4
   {
      get
      {
     return a(pa.Button4) || b(pb.Button4);
       }
   }
   
   private bool a(bool input)
   {
      if (input)
     gf.Players[index] = pa;
  return input;
   }
   
   private bool b(bool input)
   {
      if (input)
     gf.Players[index] = pb;
  return input;
   }
}

and you'll have to make this change to Controls.cs:

if (Project.GameWindow.Players[SelectedPlayer] is KeyboardPlayer)
      {
         bLoading = true;
         KeyboardPlayer player = (KeyboardPlayer)Project.GameWindow.Players[SelectedPlayer];
         rdoKeyboard.Checked = true;
         txtUp.Text = System.Enum.Format(typeof(Microsoft.DirectX.DirectInput.Key), player.key_up, "g");
         txtLeft.Text = System.Enum.Format(typeof(Microsoft.DirectX.DirectInput.Key), player.key_left, "g");
         txtRight.Text = System.Enum.Format(typeof(Microsoft.DirectX.DirectInput.Key), player.key_right, "g");
         txtDown.Text = System.Enum.Format(typeof(Microsoft.DirectX.DirectInput.Key), player.key_down, "g");
         txtButton1.Text = System.Enum.Format(typeof(Microsoft.DirectX.DirectInput.Key), player.key_button1, "g");
         txtButton2.Text = System.Enum.Format(typeof(Microsoft.DirectX.DirectInput.Key), player.key_button2, "g");
         txtButton3.Text = System.Enum.Format(typeof(Microsoft.DirectX.DirectInput.Key), player.key_button3, "g");
         txtButton4.Text = System.Enum.Format(typeof(Microsoft.DirectX.DirectInput.Key), player.key_button4, "g");
         bLoading = false;
      }
      else if (Project.GameWindow.Players[SelectedPlayer] is ControllerPlayer)


and this change to GameForm.cs:

      if (controllers != null && controllers.Length > 0)
          Players[0] = new EitherInputPlayer(new KeyboardPlayer(0), new ControllerPlayer(0), this, 0);
      else

          Players[0] = new KeyboardPlayer(0);
Edward Dassmesser

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Enable Joystick
« Reply #18 on: 2007-11-18, 11:57:36 AM »
you could test it and it worked? strange, i get these errors:

meins4\Controls.cs(723,1) : error CS0116: A namespace does not directly contain members such as fields or methods
meins4\Controls.cs(723,48) : error CS1518: Expected class, delegate, enum, interface, or struct
meins4\Controls.cs(726,92) : error CS1518: Expected class, delegate, enum, interface, or struct
meins4\Controls.cs(737,7) : error CS1022: Type or namespace definition, or end-of-file expected
meins4\Player.cs(480,11) : error CS1520: Class, struct, or interface method must have a return type

and i resetted the three .cs files before, so code from the previous tries couldn't affect the new code.
maybe you could send me your three .cs files so i can copy them into my game?

oh, and could someone tell me how to create these code objects?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Enable Joystick
« Reply #19 on: 2007-11-18, 09:16:36 PM »
Did you paste the code for Controls.cs at the end of the file?  Looks like there were no instructions on where to put it, but I think it should replace some similar-looking code on line 619 instead of just being added to the end of the file.

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Enable Joystick
« Reply #20 on: 2007-11-19, 10:57:15 AM »
oh, you are right!
the errors for controls.cs are gone.

but this line remains:
meins4\Player.cs(480,11) : error CS1520: Class, struct, or interface method must have a return type

in the code, line 480 starts this way:

public EitherInputPlayer(IPlayer p1, IPlayer p2, GameForm gameForm, int myIndex)
   {
      gf = gameForm;
      index = myIndex;
      pa = p1;
      pb = p2;
   }


durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Enable Joystick
« Reply #21 on: 2007-11-19, 12:33:48 PM »
Whoops, I renamed the class without renaming the constructor.  Just change EitherInputPlayer to AnyInputPlayer to fix that.
Edward Dassmesser

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Enable Joystick
« Reply #22 on: 2007-11-19, 02:05:05 PM »
i'm sad.
it has been so many changes, maybe i lost the overview. could someone please do the changes and send me the three .cs files please?

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Enable Joystick
« Reply #23 on: 2007-11-19, 04:01:29 PM »
Here's an SGDK2 file containing the code you'll need.  Just import the three objects into the source code folder of your project.

http://www.findmyed.com/files/AnyInputPlayer.zip
Edward Dassmesser

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Enable Joystick
« Reply #24 on: 2007-11-19, 04:18:43 PM »
man, i hate it. every thing that is step more advanced than the easiest thing, doesn't work here.
i imported the files into my actual game and my first version. the same error occured again. then i tried it with the sample project. it works there!

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Enable Joystick
« Reply #25 on: 2007-11-19, 09:58:49 PM »
Try resetting the source code in your project and then import it again.  Either I'm working off of a different version than the default or you are.  I built it based on the sample project, so if that's different, that may be the problem, but I don't see why the any differences in that project would affect this problem.

Better yet, reset it to the code in the sample project.  That would probably work best.
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Enable Joystick
« Reply #26 on: 2007-11-20, 07:14:24 AM »
man, i hate it. every thing that is step more advanced than the easiest thing, doesn't work here.
i imported the files into my actual game and my first version. the same error occured again. then i tried it with the sample project. it works there!

You're welcome to keep at it and durnurd will probably get enough information to you that your project will work.  But you should understand that you are writing code, which of course is a very sensitive thing.  Even the smallest error in copying or writing code will cause fatal errors in your project.  If you're not prepared to deal with these kinds of problems, you might want to avoid fiddling with the code, and just accept the built-in features as they are instead of getting into the coding.  If you want to get into the coding, you should be prepared to take some time to study how coding works and do some trial and error to learn from the mistakes.  Then you could work out many of these problems on your own.  But it would take patience to learn how to write code.  Viel Gluck! :)

SmartBoy16

  • Contributor
  • Fanatic
  • **
  • Posts: 587
  • Looking for inspiration.....
    • View Profile
    • Email
Re: Enable Joystick
« Reply #27 on: 2007-11-21, 08:02:04 AM »
as a c++ programmer myself, i know its fustrating.  :( >:(
Looking to the skies.....

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Enable Joystick
« Reply #28 on: 2007-11-21, 08:36:55 AM »
interest = yes
time = no
anyway i have to try...