Jump to content
IGNORED

CALL KEY AND CALL JOY FOR TWO PLAYERS - INDEPENDENT MOVEMENTS


gekido_ken
 Share

Recommended Posts

I'm sure you must be looking for more, but just as the simplest example in XB I can think of:

 

100 CALL CLEAR
110 CALL MAGNIFY(2)
120 CALL SPRITE(#1,65,3,90,60)
130 CALL SPRITE(#2,66,7,90,180)
140 REM MAIN LOOP HERE
150 CALL JOYST(1,X,Y)
160 CALL MOTION(#1,-Y*2,X*2)
170 CALL JOYST(2,X,Y)
180 CALL MOTION(#2,-Y*2,X*2)
190 GOTO 140
Link to comment
Share on other sites

At Fest West this year I will show you my new routines.

 

Not only does it move the sprite per the joystick movements and returns those values of the

sprite and joystick use, but also does a keyboard scan and the fire button using a GOTO

100 CALL CLEAR
110 CALL SPRITE(#1,65,2,9,190,20,0)
120 CALL JOYMOTION(1,X,Y,#1,9,K) GOTO 150
130 PRINT X;Y,K
140 GOTO 120
150 PRINT "FIRE BUTTON"
160 GOTO 120

In RXB this gives a single routine that does joystick sprite and key fire button in one single GPL command.

A really cool feature is the ability to not use the GOTO or KEY routine and just JOYSTICK

100 CALL CLEAR
110 CALL SPRITE(#1,65,2,9,190,20,0)
120 CALL JOYMOTION(1,X,Y,#1,9)
130 PRINT X;Y
140 GOTO 120

Or just eliminate the GOTO and keep KEY

100 CALL CLEAR
110 CALL SPRITE(#1,65,2,9,190,20,0)
120 CALL JOYMOTION(1,X,Y,#1,9,K)
130 PRINT X;Y,K
140 GOTO 120

Edited by RXB
Link to comment
Share on other sites

I have a routine that I have been using in my own programs which runs surprisingly quickly in TI BASIC and even faster in TI Extended BASIC.

 

The source snippet is in Tidbit. The UserInput routine requires P for the player number to scan which equates to the KEY unit and JOYST unit to scan. If P is negative then only JOYST is scanned. You might squeeze a little extra performance by removing the negative P options which would be the IF P<0 test, and replacing ABS(P) where it occurs with just P.

 

After a GOSUB UserInput you will use the return value of J to determine sprite motions.

 

If you are interested in working in another BASIC language, RXB has a new command which takes joystick scans and directly translates them to sprite motions.

 

 

// K$() key scan strings
// 0 - Standard directional scan, should be left as-is
// 1 - Normal key scan, with extra keys to detect, default (space) as sub for fire/select, then
//   AID (FCTN-7), REDO (FCTN-, BACK (FCTN-9)
K$(0)=CHR$(2)&CHR$(3)&CHR$(0)&CHR$(5)&CHR$(18)

K$(1)=" "&CHR$(1)&CHR$(6)&CHR$(15)
 
//
// USER INPUT
//
// P = Player number (used as split keyboard scan mode select)
//
// Needs: K$(0), K$(1)
//
// Uses: J, X, Y, K, S
//
// Returns: J = [1-4] - Left, Right, Down, Up
//              5     - Fire/SPACE (Select)
//              [6-8] - AID, REDO, BACK
UserInput:
J=0
IF P<0 THEN JoyStick
CALL KEY(P,K,S)
IF S THEN UnitKeyPress ELSE JoyStick
UnitKeyPress:
J=POS(K$(0),CHR$(K),1)
IF J=0 THEN KeyScan
RETURN
JoyStick:
CALL JOYST(ABS(P),X,Y)
IF X+Y THEN JoyPress
KeyScan:
CALL KEY(3,K,S)
IF S THEN KeyPress ELSE ExitInput
KeyPress:
J=4+POS(K$(1),CHR$(K),1)
DecodeJoySt:
J=J*-(J>4)
ExitInput: RETURN
JoyPress:
IF SGN(X)*SGN(Y)THEN DecodeJoySt
J=ABS(((SGN(X)+3)/2)*SGN(X))+(ABS(((SGN(Y)+3)/2)*SGN(Y))-2*(Y<>0))
RETURN

 

  • Like 1
Link to comment
Share on other sites

I have a routine that I have been using in my own programs which runs surprisingly quickly in TI BASIC and even faster in TI Extended BASIC.

 

The source snippet is in Tidbit. The UserInput routine requires P for the player number to scan which equates to the KEY unit and JOYST unit to scan. If P is negative then only JOYST is scanned. You might squeeze a little extra performance by removing the negative P options which would be the IF P<0 test, and replacing ABS(P) where it occurs with just P.

 

After a GOSUB UserInput you will use the return value of J to determine sprite motions.

 

If you are interested in working in another BASIC language, RXB has a new command which takes joystick scans and directly translates them to sprite motions.

 

 

// K$() key scan strings
// 0 - Standard directional scan, should be left as-is
// 1 - Normal key scan, with extra keys to detect, default (space) as sub for fire/select, then
//   AID (FCTN-7), REDO (FCTN-, BACK (FCTN-9)
K$(0)=CHR$(2)&CHR$(3)&CHR$(0)&CHR$(5)&CHR$(18)

K$(1)=" "&CHR$(1)&CHR$(6)&CHR$(15)
 
//
// USER INPUT
//
// P = Player number (used as split keyboard scan mode select)
//
// Needs: K$(0), K$(1)
//
// Uses: J, X, Y, K, S
//
// Returns: J = [1-4] - Left, Right, Down, Up
//              5     - Fire/SPACE (Select)
//              [6-8] - AID, REDO, BACK
UserInput:
J=0
IF P<0 THEN JoyStick
CALL KEY(P,K,S)
IF S THEN UnitKeyPress ELSE JoyStick
UnitKeyPress:
J=POS(K$(0),CHR$(K),1)
IF J=0 THEN KeyScan
RETURN
JoyStick:
CALL JOYST(ABS(P),X,Y)
IF X+Y THEN JoyPress
KeyScan:
CALL KEY(3,K,S)
IF S THEN KeyPress ELSE ExitInput
KeyPress:
J=4+POS(K$(1),CHR$(K),1)
DecodeJoySt:
J=J*-(J>4)
ExitInput: RETURN
JoyPress:
IF SGN(X)*SGN(Y)THEN DecodeJoySt
J=ABS(((SGN(X)+3)/2)*SGN(X))+(ABS(((SGN(Y)+3)/2)*SGN(Y))-2*(Y<>0))
RETURN

 

OMG very cool!

 

In RXB 2018 (or RXB 2019) multiple JOYMOTION could look like this:

 

CALL JOYMOTION(1,X1,Y1,SPRITE1,INDEX,KEY1,2,X2,Y2,SPRITE2,INDEX,KEY2) GOTO Line#1,Line#2

 

After KEY1 is Joystick 2 scan so the GOTO Line#1 is for Fire button 1 and Line#2 is Fire button 2

Edited by RXB
Link to comment
Share on other sites

I've solved so in XB:

 

The keys are "E" and "X" for SX keyboard, with "O" and ","(comma) for DX keyboard.

 

50 CALL CLEAR

100 CALL KEY(1,K1,S1) :: CALL KEY(2,K2,S2)
105 DISPLAY AT(1,1):"K1=":K1,"K2=":K2
110 IF S1=1 THEN 120
120 SUM=K1+K2
130 IF SUM=-2 THEN 250
140 IF SUM=5 THEN 270
150 IF SUM=13 THEN 270
160 IF SUM=-1 THEN 260
170 IF SUM=4 THEN 260
180 IF SUM=14 THEN 280
190 IF SUM=6 THEN 280
200 IF SUM=11 THEN 280
210 IF SUM=19 THEN 280




250 DISPLAY AT(12,10):"NESSUN CONTROLLO",SUM :: GOTO 100
260 DISPLAY AT(12,10):"CONTROLLO 1",SUM :: GOTO 100
270 DISPLAY AT(12,10):"CONTROLLO 2",SUM :: GOTO 100
280 DISPLAY AT(12,10):"CONTROLLI 1 E 2",SUM :: GOTO 100

 

Edited by gekido_ken
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...