KevKelley Posted December 11, 2020 Share Posted December 11, 2020 (edited) I was working on a little program and made a section with two sprites that can shoot in seven directions. I had initially gotten the code working for P0. I pretty much copied it for P1 but I couldn't get it working right and I don't know what I screwed up but I've been staring at the screen and my brain is dead. Here is the P0 code that works: if g{1} || f{1} then goto SKIP_FIRE if !joy0fire then goto SKIP_FIRE if joy0left then f{0}=1 if joy0up then f{2}=1 if joy0down then f{3}=1 if joy0up && joy0right then g{2}=1:f{0}=1 if joy0down && joy0right then g{2}=1:f{0}=1 if joy0up && !joy0left then g{3}=1:f{0}=1 if joy0down && !joy0left then g{3}=1:f{0}=1 if f{0} then missile0x=player0x+3:missile0y=player0y-4:f{1}=1 SKIP_FIRE if g{2} then missile0x=missile0x+4 if g{3} then missile0x=missile0x+2 if f{1} then missile0x=missile0x-2:f{0}=0 if f{2} then missile0y=missile0y-1:if g{3} then missile0y=missile0y-1 if f{3} then missile0y=missile0y+1:if g{3} then missile0y=missile0y+1 if collision(missile0,playfield) then f{0}=0:f{1}=0:f{2}=0:f{3}=0:g{2}=0:g{3}=0 if !f{1} then missile0y=200 SKIP_SHOOTING_0 Here is the P1 code: if g{0} || f{5} then goto SKIP_FIRE2 if !joy1fire then goto SKIP_FIRE2 if joy1right then f{4}=1 if joy1up then f{6}=1 if joy1down then f{7}=1 if joy1up && joy1left then g{4}=1:f{4}=1 if joy1down && joy1left then g{4}=1:f{4}=1 if joy1up && !joy1right then g{5}=1:f{4}=1 if joy1down && !joy1right then g{5}=1:f{4}=1 if f{4} then missile1x=player1x+5:missile1y=player1y-4:f{5}=1 SKIP_FIRE2 if g{4} then missile1x=missile1x-4 if g{5} then missile1x=missile1x-2 if f{5} then missile1x=missile1x+2:f{4}=0 if f{6} then missile1y=missile1y-1:if g{5} then missile1y=missile1y-1 if f{7} then missile1y=missile1y+1:if g{5} then missile1y=missile1y+1 if collision(missile1,playfield) then f{4}=0:f{5}=0:f{6}=0:f{7}=0:g{4}=0:g{5}=0 if !f{5} then missile1y=200 It seems to only work firing UP, DOWN, RIGHT, UP LEFT It does not go UP RIGHT, DOWN RIGHT, or DOWN LEFT. Now I did notice that when I deleted this line for the P1 code it kind of worked (except that you wouldn't have to hit the fire button.) if !joy1fire then goto SKIP_FIRE2 Here is the bB file too. Am I blind? CB_12_11_2020.bas Edited December 12, 2020 by KevKelley Added detail. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted December 11, 2020 Share Posted December 11, 2020 I sent someone a PM about something in your code. When they get back to me, I'll get back to you. May not even have anything to do with the problem you're having. 1 Quote Link to comment Share on other sites More sharing options...
KevKelley Posted December 12, 2020 Author Share Posted December 12, 2020 9 minutes ago, Random Terrain said: I sent someone a PM about something in your code. When they get back to me, I'll get back to you. May not even have anything to do with the problem you're having. Thanks. It was driving me crazy. It kept throwing me off thinking it was something that related to either the fire or one of the directionals I made or some weird interaction with some of the other code in the program but I would comment sections out to see if it changed and nothing was different. I also was wondering if something was getting lost in the operations but the P0 was throwing me off.yp And I did notice after testing that I would get an occasional shot here or there and every once and a while the shot would freeze. I was hoping to pick it back up tonight and see if I can find the issue. Quote Link to comment Share on other sites More sharing options...
KevKelley Posted December 12, 2020 Author Share Posted December 12, 2020 I was looking over the code and was wondering... Is it possible that because of how I have it written, with there being multiple checks (if joy1up then..., if joy1up && joyleft then...) and because I have the part with the !joy1fire, that the game happens to take my first entry, and then goes with it, essentially locking out some of the other options? If that is the case, the only thing I don't get is why it would work for P) and not P1. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted December 12, 2020 Share Posted December 12, 2020 Have you looked at this program on the bB page: randomterrain.com/atari-2600-memories-batari-basic-commands.html#sprite_missile_example Quote Link to comment Share on other sites More sharing options...
KevKelley Posted December 12, 2020 Author Share Posted December 12, 2020 19 minutes ago, Random Terrain said: Have you looked at this program on the bB page: randomterrain.com/atari-2600-memories-batari-basic-commands.html#sprite_missile_example I had not. I was looking at some of the other programs though in developing this. Originally I had a simpler shooting but then kept expanding on it to be multi-directional. Looking at that program that is a hell of a lot simpler then what my brain was putting together. That would probably make things easier down the road, too. 1 Quote Link to comment Share on other sites More sharing options...
bogax Posted December 12, 2020 Share Posted December 12, 2020 My suggestion is to read Advanced Joystick Reading with SWCHA then abandon that mess of if-then spaghetti and do your missile move with look up tables (instead of on gosub/goto as in the examples) 1 Quote Link to comment Share on other sites More sharing options...
KevKelley Posted December 12, 2020 Author Share Posted December 12, 2020 2 hours ago, bogax said: My suggestion is to read Advanced Joystick Reading with SWCHA then abandon that mess of if-then spaghetti and do your missile move with look up tables (instead of on gosub/goto as in the examples) I had played around with SWCHA before. I am definitely going to look at that. Some of it confused me when I had first tried to implement it in some programs before. Funny. I would sometimes start with a simple program and then just playing around with things I tend to over complicate stuff. Sometimes I don't think about it much because I figure it is something small and I don't need the space. With this I thought I'd just cut and paste some of my code and go from there. Quote Link to comment Share on other sites More sharing options...
KevKelley Posted December 12, 2020 Author Share Posted December 12, 2020 Quote Instead of using a long list of if…then statements, an on…gosub or on…goto statement can be used. For Joy0, we read the value in SWCHA and divide it by 16 which discards the Joy1 bits and shifts the joy0 bits into the lower 4 bit positons, so we'd use temp1 = SWCHA / 16. For Joy1, temp1 = SWCHA & %00001111 would be used. -from Random Terrain's website So, if I were to use it, I would essentially set 2 temp variables for each controller and then do something like this: on temp2=%01000000 goto... on temp1=%00001100 goto... with it going to which ever directional issue? Quote Link to comment Share on other sites More sharing options...
KevKelley Posted December 12, 2020 Author Share Posted December 12, 2020 So I was playing around with SWCHA and I think I understand it much better then a year ago when I first started messing around with it (also with on...goto statements). You are right. Instead of cooked spaghetti my code looks like uncooked spaghetti! temp1 = SWCHA / 16 on temp1 goto P0_STILL P0_STILL P0_STILL P0_STILL P0_STILL P0_GO_DR P0_GO_UR P0_GO_R P0_STILL P0_GO_DL P0_GO_UL P0_GO_L P0_STILL P0_GO_D P0_GO_U P0_STILL DONE_JOY0 I have the various movements off in a different section where I have the speed at which they move. I guess I can then also add in those sections the direction for the missile direction. It will probably get me a little to get comfortable with it and play around but this is definitely much cleaner and looks like it will help in the longrun! Thanks! Quote Link to comment Share on other sites More sharing options...
bogax Posted December 12, 2020 Share Posted December 12, 2020 (edited) this is something like what I had in mind (untested) dim pj0f = temp1 dim m0d = m ; missile 0 direction pj0f = j0f ; remember if joy0fire was pressed before if joy0fire then j0f = 1 else j0f = 0 ; remember if joy0fire is pressed now if !pj0f then skip_m0_direction ; skip setting the m0 direction if joy0fire wasn't pressed before if j0f then skip_m0_direction ; joy0fire was pressed before skip setting the m0 direction if it's still pressed ; set missile 0 direction m0d = (SWCHA ^ %11111111) / 16 ; joy0 bits are rlduxxxx of SWCHA ; if a direction is active the bit is 0 eg right-up is 0110xxxx ; ^ with 1 will flip a 1 bit to 0 and a 0 bit to 1 so right-up will be 1001xxxx ; then divide by 16 to get 0000rldu so right up will be 00001001 skip_m0_direction if !m0d then skip_move_m0 ; if m0d is 0 then the missile is parked off screen don't move it ; move missile 0 missile0x = missile0x + m0x[m0d] missile0y = missile0y + m0y[m0d] skip_move_m0 ; 0 1 2 3 4 5 6 7 8 9 10 ; u d du l lu ld ldu r ru rd data m0x 0, 0, 0, 0, 0, -1, -1, 0, 1, 1, 1 end data m0y 0, -1, 1, 0, 0, -1, 1, 0, 0, -1, 1 end the value in the table is the speed Edited December 13, 2020 by bogax Quote Link to comment Share on other sites More sharing options...
KevKelley Posted December 12, 2020 Author Share Posted December 12, 2020 Ah. I was just playing around with the example program to see what I could do with that. I haven't really used data tables too much but I like it. I guess I had not gotten to the point where I kind of understand some of these things but to determine what purpose they serve sometimes eludes me. I was curious. In the example you posted above, what is the j0f? I did not see it defined. 27 minutes ago, bogax said: pj0f = j0f Quote Link to comment Share on other sites More sharing options...
bogax Posted December 12, 2020 Share Posted December 12, 2020 (edited) 6 minutes ago, KevKelley said: I was curious. In the example you posted above, what is the j0f? I did not see it defined. oops a flag to remember the state of joy0fire the code is written as if its a full variable, but it only needs a single bit Edited December 12, 2020 by bogax Quote Link to comment Share on other sites More sharing options...
KevKelley Posted December 12, 2020 Author Share Posted December 12, 2020 Okay. So if I were to also make something like this for Missile1, I would use something like this for Joy1 inputs: m1d= SWCHA^%11111111 And I can use the same data tables as m0d? and thank you so much! This is very helpful! Quote Link to comment Share on other sites More sharing options...
bogax Posted December 12, 2020 Share Posted December 12, 2020 (edited) yes except you need to mask out the joy0 bits of SWCHA m1d= SWCHA ^ %11111111 & %00001111 Edited December 12, 2020 by bogax Quote Link to comment Share on other sites More sharing options...
KevKelley Posted December 13, 2020 Author Share Posted December 13, 2020 (edited) Thank you @bogax! So I was playing around with the code inside my original program to get it to work and after some tweaking here and there I fit it in! I had made a couple adjustments to get it to work. Here is what I did: if collision(ball,player0) then goto skip_m0_direction if j0f{0} then missile0x=player0x+3:missile0y=player0y-4 pj0f = j0f if joy0fire then j0f{0} = 1 else j0f{0} = 0 if !pj0f then skip_m0_direction if j0f then skip_m0_direction m0d = (SWCHA ^ %11111111) / 16 skip_m0_direction if !m0d then missile0x=200:missile0y=200: goto skip_move_m0 missile0x = missile0x + m0x[m] missile0y = missile0y + m0y[m] skip_move_m0 if collision(missile0,playfield) then m0d=0 data m0x 0, 0, 0, 0, -1, -1, -1, 0, 1, 1, 1 end data m0y 0, -1, 1, 0, 0, -1, 1, 0, 0, -1, 1 end I had added the check so that it spawns the missile by the player. I had added the coordinates to put the missile off screen. I deleted the 0 in the data table bracket. I changed a value in the table to allow for shooting in all directions (originally I was going to not shoot backwards but this method made it much easier). I also added where if you grab the ball in the game the shot continues but it is still locked out. This has been a very good lesson for me, as I had always been confused by some concepts, like SWCHA or data tables. I had only previously used a data table for the lightning sound in Bag Boy when I tried using data tables for sound for some reason (I kept it because I liked the effect even though it didn't end up how I expected). And looking at my old code for the SWCHA, I don't know what I was thinking. I think I just inserted the defining of the temp value but then never did anything with it. Now all I gotta do is copy this for Player1 and delete my old code and check any other code that previously used the spaghetti code. Thank you @Random Terrain too! Your site and sample programs have again proven to be invaluable! I truly wish one day it could be in a book form so I can bring it with me everywhere! Edited December 13, 2020 by KevKelley Quote Link to comment Share on other sites More sharing options...
KevKelley Posted December 13, 2020 Author Share Posted December 13, 2020 (edited) I just replaced the shooting code in my program with the new shooting code and I noticed that the same issue with the P1 shooting exists, where it does not shoot in certain directions (UR, DR, and DL). By chance I played the file in z26 and it seemed that all directions seems to work. I tried again in Stella 6.0.2 and it didn't work. Weird. CB_12_12_2020_A.bas Edited December 13, 2020 by KevKelley Quote Link to comment Share on other sites More sharing options...
bogax Posted December 13, 2020 Share Posted December 13, 2020 (edited) 2 hours ago, KevKelley said: I just replaced the shooting code in my program with the new shooting code and I noticed that the same issue with the P1 shooting exists, where it does not shoot in certain directions (UR, DR, and DL). By chance I played the file in z26 and it seemed that all directions seems to work. I tried again in Stella 6.0.2 and it didn't work. Weird. CB_12_12_2020_A.bas 10.75 kB · 2 downloads I'm not sure what to make of it I suspect it may be a keyboard-instead-of-joystick problem I noticed a couple other things You're doing something with bit 1 of f so you should use a different bit for the fire button flag If you're going to use a single bit you have to use a single bit in the if statments too You should move the initialization of the missile position to where missile direction gets set Edited December 13, 2020 by bogax Quote Link to comment Share on other sites More sharing options...
KevKelley Posted December 13, 2020 Author Share Posted December 13, 2020 12 hours ago, bogax said: You're doing something with bit 1 of f so you should use a different bit for the fire button flag If you're going to use a single bit you have to use a single bit in the if statments too You should move the initialization of the missile position to where missile direction gets set I apologize. I am a little confused. I did notice that I had forgotten to indicate the bit in a couple of the if...thens but in regards to the fire button flag I wasn't sure what you had meant. I know in the original example you had it as a full variable so I had thought that I could use a single bit for the flag for P1 and a different bit from that variable for P0. I had also tried the initialization of the missile position in other parts of the code but noticed that it would interfere with how the missile fired. Quote Link to comment Share on other sites More sharing options...
bogax Posted December 14, 2020 Share Posted December 14, 2020 (edited) line 283 of the .bas file you posted sets f{1} = 0 so presumably you want a different bit for the fire flag I've been molesting your code so I'm not sure its right but this is what I did not in order the call to park goes any where the missile is parked not just this excerpt edit: the way this code is set up, you can only fire if you're moving and it fires when you press the fire button not when its released def park_m0 = gosub pkm0 def park_m1 = gosub pkm1 pkm0 m0d = 0 : missile0x = 200 : missile0y = 200 : return pkm1 m1d = 0 : missile1x = 200 : missile1y = 200 : return ;BALL if collision(missile0,player1) then g{0} = 1 : park_m0 if collision(missile1,player0) then g{1} = 1 : park_m1 ;P0 SHOOTING if collision(ball,player0) then skip_m0_direction pj0f = j0f if joy0fire then j0f{2} = 1 else j0f{2} = 0 if pj0f{2} then skip_m0_direction if !j0f{2} then skip_m0_direction m0d = (SWCHA ^ %11111111) / 16 if m0d then missile0x = player0x + 3 : missile0y = player0y - 4 skip_m0_direction if !m0d then skip_move_m0 missile0x = missile0x + mvx[m] missile0y = missile0y + mvy[m] skip_move_m0 if collision(missile0,playfield) then park_m0 ;P1 SHOOTING if collision(ball,player1) then goto skip_m1_direction pj1f = j1f if joy1fire then j1f{3} = 1 else j1f{3} = 0 if pj1f{3} then skip_m1_direction if !j1f{3} then skip_m1_direction m1d = (SWCHA ^ %11111111) & %00001111 if m1d then missile1x = player1x + 3 : missile1y = player1y - 4 skip_m1_direction if !m1d then skip_move_m1 missile1x = missile1x + mvx[n] missile1y = missile1y + mvy[n] skip_move_m1 if collision(missile1,playfield) then park_m1 SKIP_SHOOTING_1 Edited December 14, 2020 by bogax Quote Link to comment Share on other sites More sharing options...
KevKelley Posted December 14, 2020 Author Share Posted December 14, 2020 Okay. I understand! When I changed the shooting code I forgot I didn't need the bit check on Line 283. I deleted that along with the other check for f{5} for now and when I get home I will do the other changes. Thank you again. 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.