A little joystick weirdness

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
LoadError
Vic 20 Hobbyist
Posts: 120
Joined: Sat Feb 17, 2007 2:44 pm
Website: http://digilander.libero.it/pyrotech/
Location: Italy
Occupation: FG Soft

A little joystick weirdness

Post by LoadError »

I've noticed a glitch in my BASIC game.
The main character is moved with a joystick. I've introduced some kind of inertial damping in its movements, controlled by a variable. So when the joystick is idle, the variable is set to 1. When the joystick is moved, the damping variable is checked. If it's 1 (the joystick was idle) a little delay is introduced and the variable is set to 0. If it's 0 (the joystick was already "not idle") there is no delay. Then the character is moved across the screen.
Everything works OK when you move the character UP, DOWN, LEFT or RIGHT. There is a slight delay with the first movement, but if you keep the joystick in the same direction, the following movements are, let's say, at a correct speed. Which is what I want. The problem is with diagonal movements.
With diagonal movements, the character is moved in the correct location alright (ie. up+left; up+right; down+left or down+right), but at WARP SPEED (compared to the "main" up/down/left/right movements. Not only there is no noticeable "first movement" damping, but all the subsequent movement along the diagonal are MUCH faster and barely controllable.
I've been through the code carefully, and all the instructions are executed for all 8 movements. I have found no reason to explain why the diagonal moves are much faster.
Any ideas?
Commodore VIC-20 n. WG-C-275517 - manufactured in Western Germany in 1983
norm8332
Vic 20 Nerd
Posts: 626
Joined: Sun Nov 13, 2016 11:04 am
Location: USA

Re: A little joystick weirdness

Post by norm8332 »

If you post the relevant area of your code, I'm pretty sure you will get a better response from some of the programmers on here. :D
“In religion and politics people’s beliefs and convictions are in almost every case gotten at second-hand, and without examination... whose opinions about them were not worth a brass farthing.”

-Autobiography of Mark Twain
User avatar
LoadError
Vic 20 Hobbyist
Posts: 120
Joined: Sat Feb 17, 2007 2:44 pm
Website: http://digilander.libero.it/pyrotech/
Location: Italy
Occupation: FG Soft

Re: A little joystick weirdness

Post by LoadError »

Promise you won't bash me! I know it's probably some lame code :-P
I will post the lines which I think are relevant.
So, I am reading the joystick with J1% and J2%.
DP% is the direction of the movement. LV% is the current location. NL% is the new location. RI% is the current row and CO% is the current column.
ID% is the variable I use for the inertial damping. Line 4 is the beginning of the main routine.
Basically, when I move in diagonal I update both the row and the column, whereas when I move vertically I only update the row and when I move horizontally I only update the column. Row and column are used to detect if the character has reached the border (there is no side scrolling).
Then the character is moved to the new location, if possible.
If you can, please don't focus on the logic itself (even if it sounds weird), I'd just like to understand what, in this code, is causing the character to move faster when it moves diagonally.

Thanks!

---

20 J1%=PEEK(37151):POKE37154,127:J2%=PEEK(37152):POKE37154,255
21 IF(32ANDJ1%)=0ANDTA%=2THENTA%=3:IT%=T%:POKE36877,255:FORC1%=1TO100:NEXT:POKE36877,0:POKE36879,28
22 IF((4ANDJ1%)=0AND(16ANDJ1%)=0)AND(RI%>2ANDCO%>1)THENDP%=1:NL%=LV%-23:GOTO35
23 IF((4ANDJ1%)=0AND(16ANDJ1%)=0)AND(RI%=2ORCO%=1)THENGOTO4
24 IF((4ANDJ1%)=0AND(128ANDJ2%)=0)AND(RI%>2ANDCO%<22)THENDP%=2:NL%=LV%-21:GOTO35
25 IF((4ANDJ1%)=0AND(128ANDJ2%)=0)AND(RI%=2ORCO%=22)THENGOTO4
26 IF((8ANDJ1%)=0AND(16ANDJ1%)=0)AND(RI%<23ANDCO%>1)THENDP%=3:NL%=LV%+21:GOTO35
27 IF((8ANDJ1%)=0AND(16ANDJ1%)=0)AND(RI%=23ORCO%=1)THENGOTO4
28 IF((8ANDJ1%)=0AND(128ANDJ2%)=0)AND(RI%<23ANDCO%<22)THENDP%=4:NL%=LV%+23:GOTO35
29 IF((8ANDJ1%)=0AND(128ANDJ2%)=0)AND(RI%=23ORCO%=22)THENGOTO4
30 IF(4ANDJ1%)=0ANDRI%>2THENDP%=5:NL%=LV%-22:GOTO35
31 IF(8ANDJ1%)=0ANDRI%<23THENDP%=6:NL%=LV%+22:GOTO35
32 IF(16ANDJ1%)=0ANDCO%>1THENDP%=7:NL%=LV%-1:GOTO35
33 IF(128ANDJ2%)=0ANDCO%<22THENDP%=8:NL%=LV%+1:GOTO35
34 ID%=1:GOTO4
35 IFPEEK(NL%)=117ANDBS%=0THENGOTO44
36 IFPEEK(NL%)=117ANDBS%=1THENGOSUB111:GOTO44
37 IFPEEK(NL%)=110AND(PEEK(NL%+LD)AND15)=PC%THENGOSUB92:GOTO44
38 IFPEEK(NL%)=104THENGOSUB92:GOTO44
39 IFPEEK(NL%)=105THENPOKELV%,117:GOSUB126:GOTO163
40 IFPEEK(NL%)>=107ANDPEEK(NL%)<=109THENPOKELV%,117:GOSUB129:GOTO163
41 IFPEEK(NL%)=111THENGOSUB125:TA%=2:GOTO44
42 IFPEEK(NL%)=112THENGOSUB125:TL%=TL%+10:GOTO44
43 GOTO4
44 IFDP%=1THENRI%=RI%-1:CO%=CO%-1:GOTO52
45 IFDP%=2THENRI%=RI%-1:CO%=CO%+1:GOTO52
46 IFDP%=3THENRI%=RI%+1:CO%=CO%-1:GOTO52
47 IFDP%=4THENRI%=RI%+1:CO%=CO%+1:GOTO52
48 IFDP%=5THENRI%=RI%-1:GOTO52
49 IFDP%=6THENRI%=RI%+1:GOTO52
50 IFDP%=7THENCO%=CO%-1:GOTO52
51 IFDP%=8THENCO%=CO%+1
52 IFID%=1THENFORC1%=1TO100:NEXT:ID%=0
53 POKELV%,117:POKENL%,103:POKENL%+LD,PC%:LV%=NL%:GOTO4
Commodore VIC-20 n. WG-C-275517 - manufactured in Western Germany in 1983
Post Reply