Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: gamemaker6.1[request]for my 3d zelda game concerning joysticks in code  (Read 1631 times)

0 Members and 1 Guest are viewing this topic.

brucem91

gamemaker6.1[request]for my 3d zelda game concer...
« on: November 19, 2006, 12:10:09 am »
Okay, u guys know of my zelda3d game, Rise of Darkness in the WIP section of this forum. Well, I am making this game to be compatable with a joypad, I am using my ps2 controller via a cord I got at radioshack. Well, when it comes to weapons and attacks, its a no brainer, got it done. Well, my problem is using a joystick in a code. For my code in the beginning, it uses for selecting the up arrow

if (keyboard_check_released(vk_up))



Well, how do I convert that to say, if joystick up is pressed. I tried this

 if (keyboard_check_released(vk_numpad8))


which I got from the manual, but no luck. So how do i program the up, down, left, and right arrows in code?



Question 2
In the beginning of my dialog box script, it uses

keyboard_clear(ord('A'))

for obvious reasons. My text button is the 'x' button on my joypad, or computer equililent of joypad key 4
so how do I clear it, and the end uses


while(keyboard_check_pressed(ord('A'))=false){
  sleep(30)

how do i add in button 4 from the joypad





Thanks, BruceM
Logged
Re: gamemaker6.1[request]for my 3d zelda game co...
« Reply #1 on: November 19, 2006, 12:14:42 am »
  • Fear my Blades
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 562
The Joystick has it's own functions:

Quote
joystick_exists(id) Returns whether joystick id (1 or 2) exists.
joystick_name(id) Returns the name of the joystick
joystick_axes(id) Returns the number of axes of the joystick.
joystick_buttons(id) Returns the number of buttons of the joystick.
joystick_has_pov(id) Returns whether the joystick has point-of-view capabilities.
joystick_direction(id) Returns the keycode (vk_numpad1 to vk_numpad9) corresponding to the direction of joystick id (1 or 2).
joystick_check_button(id,numb) Returns whether the joystick button is pressed (numb in the range 1-32).
joystick_xpos(id) Returns the position (-1 to 1) of the x-axis of joystick id.
joystick_ypos(id) Returns the joysticks y-position.
joystick_zpos(id) Returns the joysticks z-position (if it has a z-axis).
joystick_rpos(id) Returns the joysticks rudder position (or fourth axis).
joystick_upos(id) Returns the joysticks u-position (or fifth axis).
joystick_vpos(id) Returns the joysticks v-position (or sixth axis).
joystick_pov(id) Returns the joysticks point-of view position. This is an angle between 0 and 360 degrees. 0 is forwards, 90 to the right, 180 backwards and 270 to the left. When no point-of-view direction is pressed by the user -1 is returned.

Now whether those functions work with a joypad, I have no idea.
Logged

I've done it (sorta)!  Bloom Lighting in GameMaker, and 3D mode too!  Check out the awesome Screen Saver.
  • Kousou Games
Re: gamemaker6.1[request]for my 3d zelda game co...
« Reply #2 on: November 19, 2006, 12:53:09 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2374
Quote
joystick_check_button(id,numb) Returns whether the joystick button is pressed (numb in the range 1-32).
That answers question 2.
Logged

brucem91

Re: gamemaker6.1[request]for my 3d zelda game co...
« Reply #3 on: November 19, 2006, 01:09:56 am »
Quote
joystick_check_button(id,numb) Returns whether the joystick button is pressed (numb in the range 1-32).
That answers question 2.
Thanks, so what is the code for joystick one button 4(which is the ps2's x button)
Logged

Antidote

>.>
Re: gamemaker6.1[request]for my 3d zelda game co...
« Reply #4 on: November 21, 2006, 11:56:39 pm »
  • In all seriousness who's serious?
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1485
*cough*the number 4*cough*
I have a controller example lying around somewhere with variable speed depending on how far the analog stick is pressed
Logged
  • Axiomatic Data Laboratories

brucem91

Re: gamemaker6.1[request]for my 3d zelda game co...
« Reply #5 on: November 22, 2006, 02:22:04 am »
yeah, i have that laying around somewhere as well, got it from the gamemaker community. Well, what i really need is, for example:
the script would say something like
if keyboard_check_pressed(ord'A')=true then
{
///blah bla happens
}
so what is the code for if joypad button four is presses, blah blah blah happens? I know it is uner the mouse funtions, but for say, ending text and whatnot, like if it called in code from a step event or what not
Logged

Goodnight

Once and future Captain
Re: gamemaker6.1[request]for my 3d zelda game co...
« Reply #6 on: November 22, 2006, 11:11:50 pm »
  • With a Capital G
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 706
Okay, bunch of problems here.

I've done joystick controls for my own game, and it could be a fairly simple process, or much more difficult, depending on what you need.

1) This PS2 controller adapter of yours; does it plug into the joystick port, or does map the gamepad to keyboard keys (so it thinks you're using a keyboard)?

2) Those joystick functions can check if certain directions or buttons are being held, like keyboard_check(), but they can't check if they were just pressed or released, like keyboard_check_pressed() or keyboard_check_released(). There are no such functions for joysticks, but they can be recreated. Which ones do you need?

3)
Code: [Select]
while(keyboard_check_pressed(ord('A'))=false){
  sleep(30)
What are you trying to do with this code? Pressing "A" only advances the game by 1 frame, no matter how long you hold it (unless you take off the _pressed). Unless I'm wrong, that doesn't seem useful.
Logged

brucem91

Re: gamemaker6.1[request]for my 3d zelda game co...
« Reply #7 on: November 23, 2006, 02:51:04 am »
USB port, there is a special cable i got from radioshack that is between my laptop's usb and the ps2 controller(yes, i know this is a zelda forum, zelda meaning nintendo, please dont burn me to the stake). Is the keymapping feature you told me about avaibabble in gamemaker? I could always send u the text script i am curently using if that helps. Forgive my english, i am slightly tired. I am not trying to be confusing, if that is what you were wondering?
Logged
Re: gamemaker6.1[request]for my 3d zelda game co...
« Reply #8 on: November 23, 2006, 04:25:57 pm »
  • Fear my Blades
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 562
I really doubt you could map it to the keyboard easily.

If it's working as a joystick which it should be, this program I wrote will tell you everything GM can get from it, just mess around with it to figure out what everything is.

I did Joystick controls for my game, and needed to check if it was just pressed.

I wrote a few scripts for handling them
First though I have a global variable that I just call 'k' as in key, it contains numbers like this:
global.k[0,0] = Keycode / Joystick button (made negative so it can be told apart from keycodes)  #0
global.k[0,1] = Control #0's pressed/held/released info

global.k[1,0] = Keycode / Joystick button #1
global.k[2,1] = Control #1's pressed/held/released info

But the Keycode /Joystick button variables are only used in my control_check_direct script which I won't be giving you, so you may not need them depending on how you write your control_check_direct script.

This script I run at the beginning of each step in my HUD object which handles nearly everything that should be global, and persistent.  Doesn't really matter what you call it, and it doesn't take any arguments.
Code: [Select]
var a;

a=0;
repeat (8)
{
 if control_check_direct(a)
 {
  if global.k[a,1]>=-2
   global.k[a,1]=min(global.k[a,1]+1,2)+.1*(global.k[a,1]=-2)
  else
   global.k[a,1]+=.01
 }
 else
 {
  if global.k[a,1]<0
   global.k[a,1]=0
  else
   global.k[a,1]=-1
 }
 a+=1
}

It calls to control_check_direct, which is a script I wrote that actually checks the buttons to see if they're held down.  For the purposes of my program each one was given a constant value 0-7 which you give to each of these scripts as an argument.  It's their location in the global.k array.  All of the code under the first if statement is there to help simulate the effects of clearing the key input in GM where it pauses for a second, then starts recognizing it as being pressed rapidly.

Heres the script I call control_check(control), it's works the same as keyboard_check(key) except that key is a value 0-7 in my game.
Code: [Select]
return (global.k[argument0,1]>0)
This is control_check_pressed(control), same as keyboard_check_pressed(key) except key is a value 0-7 in my game.
Code: [Select]
return (global.k[argument0,1]=1)
control_check_released(control), same deal as the other two.
Code: [Select]
return (global.k[argument0,1]=-1)
control_clear(control), same as keyboard_clear(key) key is a value 0-7 in my game.
Code: [Select]
if global.k[argument0,1]>0
 global.k[argument0,1]=-2.15+.13*(frac(global.k[argument0,1])!=0)
else if global.k[argument0,1]=-1
 global.k[argument0,1]=0

A little more complex than the others to properly simulate keyboard_clear(key).  Where it says '2.15+.13*(frac'  You can tweak those decimal values to change how long it waits before recognizing the key being pressed again, and how rapidly it recognizes them after that.  the decimal is pretty much the number of steps, so I have it set to wait 15 steps before recognizing it again.  the .13 is actually subtracted from .15 to find the other value so it would be .02.  The second value should always be smaller than the first, if you want to use 1 digit put a zero before it (after the decimal)


You'll have to write your own control_check_direct(control) script, it should return a 1 if the key is held, and a 0 if it isn't.  Afterwards I'd go into the global game settings and create constants for the keys  so you don't have to memorize what each ones number is.  You shouldn't have any trouble increasing the number of controls if you need to, just change the number in the repeat statement in the first script to your number of controls and add them in the control_check_direct script.
Logged

I've done it (sorta)!  Bloom Lighting in GameMaker, and 3D mode too!  Check out the awesome Screen Saver.
  • Kousou Games
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.15 seconds with 56 queries.