gekido_ken Posted April 9, 2018 Share Posted April 9, 2018 Hi! I've a request for TI BASIC and EXTENDED BASIC. I need to learn a routine for control two object on screen in idependent movement, char or sprite, in CALL KEY and CALL JOY. I try but 2nd control freeze 1st.Please help me!Thanks 1 Quote Link to comment Share on other sites More sharing options...
Tursi Posted April 9, 2018 Share Posted April 9, 2018 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 Quote Link to comment Share on other sites More sharing options...
RXB Posted April 10, 2018 Share Posted April 10, 2018 (edited) 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 April 10, 2018 by RXB Quote Link to comment Share on other sites More sharing options...
+OLD CS1 Posted April 10, 2018 Share Posted April 10, 2018 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 1 Quote Link to comment Share on other sites More sharing options...
RXB Posted April 10, 2018 Share Posted April 10, 2018 (edited) 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 April 10, 2018 by RXB Quote Link to comment Share on other sites More sharing options...
gekido_ken Posted April 10, 2018 Author Share Posted April 10, 2018 (edited) I've solved so in XB: The keys are "E" and "X" for SX keyboard, with "O" and ","(comma) for DX keyboard. 50 CALL CLEAR100 CALL KEY(1,K1,S1) :: CALL KEY(2,K2,S2)105 DISPLAY AT(1,1):"K1=":K1,"K2=":K2110 IF S1=1 THEN 120120 SUM=K1+K2130 IF SUM=-2 THEN 250140 IF SUM=5 THEN 270150 IF SUM=13 THEN 270160 IF SUM=-1 THEN 260170 IF SUM=4 THEN 260180 IF SUM=14 THEN 280190 IF SUM=6 THEN 280200 IF SUM=11 THEN 280210 IF SUM=19 THEN 280250 DISPLAY AT(12,10):"NESSUN CONTROLLO",SUM :: GOTO 100260 DISPLAY AT(12,10):"CONTROLLO 1",SUM :: GOTO 100270 DISPLAY AT(12,10):"CONTROLLO 2",SUM :: GOTO 100280 DISPLAY AT(12,10):"CONTROLLI 1 E 2",SUM :: GOTO 100 Edited April 10, 2018 by gekido_ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.