Jump to content
Lewis2907

Pac_Man Eat n Run

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Thanks. I was thinking too many on gosub. I will probably work on it as tomorrow when I get some free time.

 

Share this post


Link to post
Share on other sites
Posted (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 by bogax

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

  • Like 1

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites

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 

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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

  • Like 2

Share this post


Link to post
Share on other sites

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

  • Like 1

Share this post


Link to post
Share on other sites

Figured out the sound issue. Working on other stuff. Should have a ruff demo next week hopefully.

  • Like 2

Share this post


Link to post
Share on other sites

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

  • Like 3

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

  • Like 1

Share this post


Link to post
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.

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...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...