+Karl G Posted March 24, 2021 Share Posted March 24, 2021 My money is on the layers of nested gosubs. As a rule of thumb, I try to avoid going more than two layers of gosubs deep, and restructure my code to avoid having to go deeper than that. Quote Link to comment Share on other sites More sharing options...
bogax Posted March 24, 2021 Share Posted March 24, 2021 You have 12 copies (or so) of this code (probably the same for Up Down) on _Frame_Counter gosub __Frame_LR_00 __Frame_LR_01 __Frame_LR_02 __Frame_LR_01 : return just put one copy in one place and change it to an on goto then jump to that. eliminate the redundancy and one gosub less deep Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted March 24, 2021 Author Share Posted March 24, 2021 Thanks. I was thinking too many on gosub. I will probably work on it as tomorrow when I get some free time. Quote Link to comment Share on other sites More sharing options...
bogax Posted March 24, 2021 Share Posted March 24, 2021 (edited) 1 hour ago, Lewis2907 said: Thanks. I was thinking too many on gosub. I will probably work on it as tomorrow when I get some free time. I think you've got 5 spots on the stack with the multisprite kernel on gosub uses two but one of them only while it executes on gosub pushes it's target on to the stack from a table then does a return so it "returns" to it's target (it also leaves a real return address on the stack) on goto does the same without first pushing a (real) return address, so on goto uses one level of stack it's possible with a microscopic amount of assembler (a single jmp indirect instruction) to do the on goto without using the stack but then you have to do the address table yourself (not hard) Edited March 24, 2021 by bogax Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted March 24, 2021 Author Share Posted March 24, 2021 Bogax, I will give it a shot in the next few days plus the other variations I still have for code. To be honest I have zero clues on assembly. Not even sure where to start. The only reason I understand Bb is because in the 80s I used Basic as a kid. Thus my style is similar to that and what I can find in the forums. Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted March 24, 2021 Share Posted March 24, 2021 Yeah, I've learned to not use gosubs. Or, at least use them outside the main loop if possible. Had a game called M.M.S.B.C. 2 that eventually rolled the screen due to gosub usage. Instead, I use a lot of "sub" labels with things like "after_" main if debounce > 0 then goto after_joystick else debounce = debounce - 1 joystick if joy0fire then missile0y = missile0y + 1 after_joystick Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted March 24, 2021 Author Share Posted March 24, 2021 I took the advice and got from everyone the program working. Now I'm working on the AI which will be a challenge without pfread, pfpixel etc. like in the standard and DPC Kernels. My plan is exact coordinates then streamline it later (hopefully). What I'm trying to do is only pick certain numbers if at that coordinate. If not the correct one then return. If the number is chosen then move on to move player1 the correct way. Below is a snippet and notes out to the right if anyone has any ideas. Thanks for helping with this as Multisprite is a challenge __AI_Controls_Room_0 ;*************************************************************** ; ; Allows players 1-4 to move down to a level 2 ; Use exact coordinates as they will be on "Auto Pilot" ; 1 = up 2 = down ; 3 = left 4 = right ; if player1x = 28 && player1y = 72 then Red_Ghost = (rand&3)+1 : if Red_Ghost = 1 || 3 then return ; choose 2 or 4 not 1 or 3 if player1x = 85 && player1y = 72 then Red_Ghost = (rand&3)+1 : if Red_Ghost = 1 then return ; works as it chooses left, right or down if player1x = 141 && player1y = 72 then Red_Ghost = (rand&3)+1 : if Red_Ghost = 1 || 4 then return ; choose 2 or 3 not 1 or 4 if Red_Ghost = 1 then _P1_U_D = _P1_U_D + .5 if Red_Ghost = 2 then _P1_U_D = _P1_U_D - .5 if Red_Ghost = 3 then _P1_L_R = _P1_L_R - .5 if Red_Ghost = 4 then _P1_L_R = _P1_L_R + .5 return Quote Link to comment Share on other sites More sharing options...
bogax Posted March 25, 2021 Share Posted March 25, 2021 You don't need to be afraid of gosubs but you do need to use them sparingly because there isn't much stack. Your code is kind of convoluted and I didn't try very hard to follow it so I may misunderstand your intentions. It looks to me like you're using gosubs where you don't need them and probably don't want them. You're also doing way to much bank swithching in my opinion. (bank switching is expensive in both time and space) Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted March 25, 2021 Author Share Posted March 25, 2021 Bogax, Thanks for the tips. What I'm trying to do is use (rand&3)+1 to only pick 1-4. Then only select say two numbers then if others number return. Say rand comes back with 2 or 4 then move on. If not return. Hope it makes sense. Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted March 25, 2021 Share Posted March 25, 2021 Not the best code but maybe this'll demonstrate gosub-less techniques rem //** counter counts up once every iteration of the main loop **// rem //** redghostdir holds the current direction the red ghost wants to go in **// dim counter = a dim redghostdir = b rem //** load up player graphics **// player0: %10010101 %11111111 %11100111 %11000011 %11111111 %01011010 %10111101 %00000001 end player1: %01111110 %11100011 %11000001 %11000001 %11111111 %11011011 %11001001 %01111110 end rem //** set player locations on screen **// player0x = 44 : player0y = 44 player1x = 66 : player1y = 66 main rem //** Do loop maintenance including updating counter and dealing with reset requests **// if switchreset then reboot counter = counter + 1 rem //** Handle player joystick input **// joyevent if joy0up then player1y = player1y - 1 if joy0down then player1y = player1y + 1 if joy0left then player1x = player1x - 1 if joy0right then player1x = player1x + 1 rem //** Put player in ghost trigger position for testing **// if joy0fire then player1y = 72 : player1x = 85 rem //** Instead of moving by a fraction (.5) just call movement event every other frame **// if counter{0} goto aicontrolsroom0 after_aicontrolsroom0 rem //** set up colors and things for drawscreen **// COLUP0 = $0E COLUP1 = $2E drawscreen goto main aicontrolsroom0 rem //** if player is in trigger Y position clear out redghostdir else exit **// if player1y = 72 then redghostdir = 0 else goto after_aicontrolsroom0 rem //** Check for X coordinate triggers and exit if no go **// if player1x = 28 then goto moveghost if player1x = 85 then goto moveghost if player1x = 141 then goto moveghost goto after_aicontrolsroom0 moveghost rem //** set redghostdir to random 0-3 value and jump to appropriate code **// redghostdir = rand&3 on redghostdir goto red_up red_down red_left red_right rem //** This section moves red ghost coordinate by 1 but note this only gets called every other frame **// red_up player0y = player0y - 1 goto after_aicontrolsroom0 red_down player0y = player0y + 1 goto after_aicontrolsroom0 red_left player0x = player0x - 1 goto after_aicontrolsroom0 red_right player0x = player0x + 1 goto after_aicontrolsroom0 pacexample.bas Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted March 25, 2021 Author Share Posted March 25, 2021 Gemintronic, Thanks. I see some ASM in the code. I probably need to learn that or find a book on it. I will try it out tonight. 1 Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted March 25, 2021 Share Posted March 25, 2021 6 minutes ago, Lewis2907 said: Gemintronic, Thanks. I see some ASM in the code. I probably need to learn that or find a book on it. I will try it out tonight. Not sure where I included inline assembly. Maybe your'e talking about the unexplained counter{0} thing? The counter variable goes up by one every main loop. That means the first binary place always flips from 0 to 1 and back again. That makes it perfect to trigger things every other frame. counter{0} means the value in the first binary place 0000000x counter{1} means the value in the second binary place 000000x0 ..and so on Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted March 25, 2021 Author Share Posted March 25, 2021 Gemintronic, Ahh I have, but never quite understood it all the way. Makes more sense now. Similar to the below. if joy0up then c{1}=1:c{2}=0:c{3}=0:c{4}=0:c{5}=0:c{6}=0:c{7}=0:c{0}=0 Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted March 25, 2021 Share Posted March 25, 2021 It also turns out using bits from a variable is a boolean (true/false) kinda thing. That's why you see bitwise operations look like this: rem //** Declare var to later use as 8 true/false values **// maryostate = c rem //** Define first bit in maryostate as hasfireflower for easy reading by the coder **// def hasfireflower = maryostate{0} rem //** Put a 1 or 0 into hasfireflower **// if collision(player0, ball) then maryostate{0} = 1 rem //** don't need to write it as "hasfireflower = 1" because it's going to be 1 (true) or false (0) anyway. if hasfireflower then goto firejoyevent Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted March 26, 2021 Author Share Posted March 26, 2021 I was able to get the program working. Now I need to start streamlining the code for PacMan and the Red Ghost. The AI works pretty well and the exact coordinates (a pain to figure out) simulate the smooth collision that RT always says looks good in games. I turned off the collision of the moving ghost on purpose the other ghost you can hit and the move (code provided by "Collision function for multi sprites By Xan, February 16" saves a lot of space and time. I think i'm about 30% there with the game as most stuff can sort of port over from the DPC version. Any help or ideas to reduce the code would be great. 20210325 -Multisprite_Pac_Man.txt 20210325_Multisprite_Pac_Man.bas 20210325_Multisprite_Pac_Man.bas.bin 2 Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted March 26, 2021 Author Share Posted March 26, 2021 Bb Team, Update. The version with NC "No Collision" the other you will die and reset the level. All 4 ghost move now. I can't figure out why there is no sound. Probably something easy I guess. It's the same sound from the DPC version. I'm making progress. unless I shring the code. It won't be 25 screens more like 9 based off the calculations I'm coming up with. 20210326_Multisprite_Pac_Man_(NC).bas.bin 20210326_Multisprite_Pac_Man.bas.bin 20210326_Multisprite_Pac_Man_(NC).bas.bin 20210326_Multisprite_Pac_Man.bas.bin 20210326 -Multisprite_Pac_Man.txt 1 Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted March 26, 2021 Author Share Posted March 26, 2021 Figured out the sound issue. Working on other stuff. Should have a ruff demo next week hopefully. 2 Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted April 2, 2021 Author Share Posted April 2, 2021 Bb Team, Here is an update. So I went back with Bogax code as it saves space. I did strip it down to understand it more. I have included a small version if someone wants a copy (They are named Bogax) as it's the code that was given to me. Basically I'm doing "brute" force to have smooth collision effects. You can move around the rooms (9 total vice 25 like DPC+). The reason is the brute force so far and probably shrinking the code. Only one room has the ghost move for proof of concept on AI. Below is what I plan to work on next. 1. Move the code around to maximize space. 2. Use 5 digit or center the score. I can't remember how to do it. Looking through my old stuff and online. 3. Random color playfields. I have to reteach myself that one as I kind of forgot how. 5. Work on the AI for the other screens. ///Game Play/// 1. For now you can just move around the screen. Can't open and close like DPC+ because of Pfpixel not working. a.) I have an idea, but I would need more memory to accomplish this 2. Just waiting on feed or ideas to improve this game. 3. Multisprite is tuff to work with as I see there are a lot of limitations. 20210401_Multisprite_Pac_Man.bas 20210401 - Multisprite_Pac_Man.txt 20210401_Multisprite_Pac_Man.bas.bin 20210330_Multisprite_Pac_Man_Bogax.bas.bin 20210330 - Multisprite_Pac_Man_Bogax.txt 3 Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted April 4, 2021 Author Share Posted April 4, 2021 When I paste into Bb the cursor jumps to another part of the program. I recall this happing before once the code gets very long, but I can't recall what was the solution. It makes it hard to code now with all the jumping around. This also happens at times when I het return to start another line. Any thought or fixes for this? Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted April 4, 2021 Author Share Posted April 4, 2021 I'm making progress with the Multisprite version and possibly some other games come to mind. With the limitations it's a challenge. I have been playing around with Karl G (https://atariage.com/forums/applications/core/interface/file/attachment.php?id=630314) text kernel and stripped it down for me to learn more and hopefully the other novice programmers like myself. Hopefully I loaded it up correctly online. It took me a few hrs to figure out I needed the asm stuff. in the file. I think when it compiles and is ready as bin it includes the asm? I still can't figure out why I can't move the data for the text to another bank? I just left it there in bank. Just figured textbank = (the actual bank to put data). I'm still learning. I still could never figure out the title screen kernel. That would make this game better. and others better Hopefully there is a video or some easier instructions on how to make it for all three kernels. I think that is next thing I will try to tackle hopefully to help us novice programmers. As for the game, it's about 65% complete, but I'm thinking of a small revamp. It would make it harder to figure out the end of the game if I go that route. I would go back up to 25 rooms, but they would all almost look the same, but you have to figure out the exits and the pattern to make it the last room which would be different to let the player know they made it to the last level. So far in my test of the current 9 rooms it's a challenge, but the above idea would make it harder. Then use switch b for a map to help younger players beat the game. So far just thoughts as I try to cram everything into this game, then move on to making something else in my spare time. 200210404_Multisprite_Text.zip 20200404_Multisprite_Text.bas.bin 20210404_Multisprite_Text.txt 1 Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted April 13, 2021 Author Share Posted April 13, 2021 Here is an update. I have made a lot of progress, but still have a ways to go to get this to work that way I want it to. 1. 25 rooms - Complete. a.) They do look the same and there is no Pfpixel to simulate closing and opeing. b.) There are exits, but all of the don't work on purpose. 2. Better titlescreen - WIP as this is first real attempt with it. a.) Need to color each ghost. Karl G is explain what I can do. Still trying to figure that one out and it will probably be a while. 3. Next WIP to complete. a.) Pause the game with the fire button. b.) Change PacMan color to different color and have the score the same color. c.) Map Screen using switch a / b to make the game harder. d.) Ending of game e.) Fruits and collision. Working, but still testing f.) Text Kernel. I have some stuff working. Things like "Save us Pac" Get Him Inky" to go above the score g) Feedback on the game and game testing. 4. I made several notes especially a PowerPoint for the Titlescreen as that was a challenge. Then the "Brute" force for smooth collisions since the mirrored playfields make it hard to almost impossible from what I can gather. 5. Once this is complete go back and mirror the DPC version to this version. 6. I have a standard Kernel vision, but that is long ways down the road way down the road lol. I doubt if it's even possible for the below based upon what I know. a.) Idea #1 is a 2 player eat-n-run. Player0 is Pac and Player1 could change between the ghost and the other 3 move on their own. b.) Idea #2: Player0 is Pac and Player1 run from the ghost and collect fruits as a challenge. c.) I saw / saved a program where someone was able to change missiles into sprite etc. I think with ASM. Then another program using player1 and repositioning the player all the time d.) Or a scrolling Pac game variation, but i'm a huge Robotech fan and I think I can tackle a game like that now. 20210411_PacMan.bas.bin 2 Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted April 15, 2021 Author Share Posted April 15, 2021 (edited) Is there a way to reduce the "gosubs" and do a formula similar to what Bogax provided to me a few years ago? I think there is a way to link/combine the code to the exit flags as it shows which room you are in. ;*************************************************************** ; ; Select the correct room and floor based on player0y positions ; if room = 0 then gosub __Room_0_Controls bank2 if room = 4 then gosub __Room_0_Controls bank2 if room = 8 then gosub __Room_0_Controls bank2 if room = 16 then gosub __Room_0_Controls bank2 if room = 20 then gosub __Room_0_Controls bank2 if room = 24 then gosub __Room_0_Controls bank2 if room = 1 then gosub __Room_1_Controls bank2 if room = 5 then gosub __Room_1_Controls bank2 if room = 9 then gosub __Room_1_Controls bank2 if room = 13 then gosub __Room_1_Controls bank2 if room = 17 then gosub __Room_1_Controls bank2 if room = 21 then gosub __Room_1_Controls bank2 if room = 2 then gosub __Room_2_Controls bank3 if room = 6 then gosub __Room_2_Controls bank3 if room = 10 then gosub __Room_2_Controls bank3 if room = 14 then gosub __Room_2_Controls bank3 if room = 18 then gosub __Room_2_Controls bank3 if room = 22 then gosub __Room_2_Controls bank3 if room = 3 then gosub __Room_3_Controls bank3 if room = 7 then gosub __Room_3_Controls bank3 if room = 11 then gosub __Room_3_Controls bank3 if room = 15 then gosub __Room_3_Controls bank3 if room = 19 then gosub __Room_3_Controls bank3 if room = 23 then gosub __Room_3_Controls bank3 if room = 12 then gosub __Room_4_Controls bank4 ;**************************************************************** ; ; Check ; Exit Boundaries ; temp1 codes provided by Bogax. ; temp1 = exit_flags[room] ; Pac_Man_Exit_Top if player0y < 74 then goto __Skip1 temp1 = exit_flags[room] : if temp1{0} then if _P0_L_R = 77 && joy0up then _BitO_P0_Direction = 7 if _BitO_P0_Direction = 7 then _P0_U_D = _P0_U_D + .2 if player0y > 75 then goto __Exit_Return __Skip1 ; Pac_Man_Exit_Bottom if player0y > 18 then goto __Skip2 temp1 = exit_flags[room] : if temp1{1} then if _P0_L_R = 77 && joy0down then _BitO_P0_Direction = 8 if _BitO_P0_Direction = 8 then _P0_U_D = _P0_U_D - .2 if player0y < 18 then goto __Exit_Return __Skip2 ; Pac_Man_Exit_Right if _P0_U_D <> 46 then goto __Exit_Return temp1 = exit_flags[room] : if !temp1{2} then goto __Skip3 temp1 = exit_flags[room] : if temp1{2} then if player0x = 132 && joy0right then _Bit6_Flip_P0{6} = 0 : _BitO_P0_Direction = 5 if _BitO_P0_Direction = 5 then c{3}=1 : _P0_L_R = _P0_L_R + .3 if player0x > 133 then goto __Exit_Return __Skip3 ; Pac_Man_Exit_Left if _P0_U_D <> 46 then goto __Exit_Return temp1 = exit_flags[room] : if !temp1{3} then goto __Exit_Return temp1 = exit_flags[room] : if temp1{3} then if player0x = 20 && joy0left then _Bit6_Flip_P0{6} = 1 : _BitO_P0_Direction = 6 if _BitO_P0_Direction = 6 then c{4}=1 : _P0_L_R = _P0_L_R - .3 __Exit_Return ;**************************************************************** ; ; Exit Boundaries ; Data references each room is based upon bank6 ; %00000101 is room 0 with top and right exits ; %00001100 is room 1 with left and right exits ; %00001000 is room 2 with just a left exit ; %00001111 is room 18 with all four exits ; data exit_flags %00000101, %00001100, %00001000, %00001100, %00001001, %00001001, %00001101, %00001101, %00000101, %00000011, %00000011, %00000011, %00000010, %00000101, %00001011, %00001011, %00001110, %00001100, %00001111, %00000111, %00001100, %00001110, %00001100, %00001000, %00001010 end ******************************************************************************************************** *******************************The below may be a better, but would have to be adapted*************************** ******************************************************************************************************** __PO_D_FL1RS0 if player0x = P0_D_FL1_RS0[temp1] then gosub __Down bank6 temp1 = temp1 - 1 if temp1 then __PO_D_FL1RS0 if player0y = 60 then _Bit0_P0_Floor = 2 : return otherbank if player0y < 74 then return otherbank ;*************************************************************** ; ; Data to move down to Floor 2 ; data Dat_FL1RS0_D 20, 77, 132 end Edited April 15, 2021 by Lewis2907 Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted April 16, 2021 Author Share Posted April 16, 2021 (edited) Bb Team, Attached is a demo (WIP). Still a ways to go, but the red ghost will kill you. The others won't hurt you for now. Working on reducing all my gosub's. I did the below to reduce all the gosub's. ;*************************************************************** ; ; Allows player0 to move to room 0, 4, 8, 16, 20, 24 ; temp5 = 6 __Room_Shape_0 if room = _Room_0[temp5] then gosub __Room_0_Controls bank2 : goto __Skip_Rooms_2 temp5 = temp5 - 1 if temp5 then __Room_Shape_0 ;*************************************************************** ; ; Data to move rooms shape 0 ; data Dat_Room_0 0, 4, 8, 16, 20, 24 end 20210415_Pacman_Eat_n_Run.bas.bin Edited April 16, 2021 by Lewis2907 1 Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted April 18, 2021 Author Share Posted April 18, 2021 Bb Team, Attached is another update and the DPC Version (no updates.. yet) 1. Titlescreen a.) Works, but still trying to figure out hoe to color each ghost vice all blue. This may takes some time as this is my first attempt with the title screen. b.) Stella (my version has issues for some reason). Could be I need to update Stella or something c.) Javatari - except the titlescreen jumps around. d.) 2600.emu for Android - Works fine so far e.) AFP - I plan to test this out this week once I get another SIM Card 2. Game Play a.) Map - Use the BW switch to bring up the map. Use the Color switch to go back to game play b.) Harder game play - use the left switch "A" is for expert no map and "B" is for novice and use of the map c.) Pause - use "select" to pause. Then use the fire button to un pause d.) The Red Ghost can kill you. Resets to to the start of the game e.) There is now a green apple to eat for 10 points. 3. Future WIP / Builds a.) Fix the titlescreen b.) center the score to have a cleaner look c.) use the fire button to have Pac change colors. I'm still working on this, but i'm running out of variables d.) Ending of the game. 3 lives, extra life at 500 (or something) find the middle room to clear the game e.) easter eggs. WIP and just a thought here. f.) fix the bugs and issues g.) add more sound. I would like to add back ground sound while playing the game, but that is like the titlescreen. It will take some time as I have not really used any sound execpt for what I can find in the forum. i.) feedback and sugesstions plus find time to work on the DPC version. 20210415_Pacman_Eat_n_Run.bas.bin DPC_Pac_Man_Eat_and_Run.bas.bin Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted April 25, 2021 Author Share Posted April 25, 2021 Bb Team, Attached is another update Karl G has been helping a lot in the last few weeks with this game. I was actually looking back when I first started making stuff with Bb. I have came a long ways, but still so much more to learn. 1. Titlescreen a.) NTSC is the TV format. All the ghosts are there with respective colors. Took me a while to figure this out. b.) AFP - Looking for an 8GB SD Card lol. 2. Game Play a.) Map - Use the BW switch to bring up the map. Use the Color switch to go back to game play b.) Harder game play - use the left switch "A" is for expert no map and "B" is for novice and use of the map c.) Pause - use "select" to pause. Then use the fire button to un pause d.) All ghost can kill you now. You have three lives e.) There is now a green apple to eat for 10 points. f.) use the fire button to have Pac change colors 3. Future WIP / Builds a.) Fix the titlescreen (Maybe) c.) Need more variables if I plan to expand on what is already playable d.) Ending of the game. find the middle room to clear the game WIP e.) 3 lives, extra life at 500 (or something) WIP f.) fix the bugs and issues once found g.) add more sound. I would like to add back ground sound while playing the game, but that is like the titlescreen. It will take some time as I have not really used any sound except for what I can find in the forum. i.) feedback and suggestions plus find time to work on the DPC version. 20210426_Pacman_Eat_n_Run.bas.bin 3 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.