Jump to content
IGNORED

7800basic - fixed point


saxmeister

Recommended Posts

Greetings all, I apologize if this has been covered already, but searches did not turn up anything specific to my issue.

 

I'm following the 7800basic guide at Random Terrain and found the section on fixed point and the instructions stated to use the format:

 dim playerx = j.k

I tried that and then I tried plotting the sprite to the screen and it jumps all over the place. I can't get this to work properly. I go back to declaring the variables like:

 dim playerx = j

And it behaves again, but I want to add smaller numbers to move fractionally. Do I need to convert the numbers to integers before I use them in the plotsprite command?

 

Thanks for any help.

Link to comment
Share on other sites

8 minutes ago, saxmeister said:

Greetings all, I apologize if this has been covered already, but searches did not turn up anything specific to my issue.

 

I'm following the 7800basic guide at Random Terrain and found the section on fixed point and the instructions stated to use the format:


 dim playerx = j.k

I tried that and then I tried plotting the sprite to the screen and it jumps all over the place. I can't get this to work properly. I go back to declaring the variables like:


 dim playerx = j

And it behaves again, but I want to add smaller numbers to move fractionally. Do I need to convert the numbers to integers before I use them in the plotsprite command?

 

Thanks for any help.

 

 

 

Usually if you have a variable defined as you state in your example to get subpixel increments, then using that for a plotsprite is fine.

 

Can you share your source code that you are using where you are having the problem, it might be something else causing the odd behavior.

 

 

  • Like 2
Link to comment
Share on other sites

Thanks @Muddyfunster! This isn't all of the code (too long to place here) but the pieces that are currently running (up to this point).

 

As my programming teacher told me in college, "My cat knows more programming than anyone else I know. I talk through all of my bugs with my cat and, in the course of explaining it I find the answer."

 

Below is the code that wasn't working properly. I found the issue.

 

  displaymode 160A
  set screenheight 224
  set zoneheight 8
  set doublewide off
  BACKGRND=$00
  clearscreen

  dim splitscrn    = a
  dim level        = b
  dim livesleft    = c
  dim playerx      = d.e
  dim playery      = f.g
  dim playerdir    = h
  dim beendefeated = l
  dim levelbgcolor = m
  dim isrunning    = n
  dim levelclear   = o

  rem ** Set default values **
  livesleft        = 3 ; default of three starting lives
  splitscrn        = 0
  level            = 1
  beendefeated     = 0
  levelclear       = 0

  ...


__Main

  ; do stuff here...

  goto __Level01
  ; here we would jump to __Level02, __Level03, etc.

  goto __Main


__Level01

  if beendefeated=0 then gosub __Level01Intro ; shows a text intro unless this level has been played before
  if levelclear=1 then return ; return to __Main

  playerx          = 72
  playery          = 170
  playerdir        = 2
  isrunning        = 0
  v                = 0
  x                = $00
  y                = 0
  z                = 1
  var1             = framecounter

__Level01Loop

  clearscreen

  if livesleft then gosub __ShowLivesLeft
  gosub __UpdateScore

  isrunning=0

  if x>$FE then x=$00
  if !(var1//121) then x=x+1:P5C2=x

  if joy0up    then playery=playery-1:playerdir=0:isrunning=1 ; 0=north
  if joy0down  then playery=playery+1:playerdir=1:isrunning=1 ; 1=south
  if joy0left  then playerx=playerx-1:playerdir=2:isrunning=1 ; 2=west
  if joy0right then playerx=playerx+1:playerdir=3:isrunning=1 ; 3=east

  if joy0left  && joy0up   then playerx=playerx-0.5:playery=playery-0.5:playerdir=4:isrunning=1 ; 4=northwest
  if joy0right && joy0up   then playerx=playerx+0.5:playery=playery-0.5:playerdir=5:isrunning=1 ; 5=northeast
  if joy0left  && joy0down then playerx=playerx-0.5:playery=playery+0.5:playerdir=6:isrunning=1 ; 6=southwest
  if joy0right && joy0down then playerx=playerx+0.5:playery=playery+0.5:playerdir=7:isrunning=1 ; 7=southeast

  if !joy0any then isrunning=0

  y=y+1
  if y > 15 then y=1
  z=(y/4) ; calculate the frame to show

  if isrunning=1 then gosub __DrawMoving
  if isrunning=0 then gosub __DrawStill

  isrunning=0

  drawscreen

  goto __Level01Loop

  ...


__DrawMoving
  rem ** Draw character: If isrunning=1 then animate **
  if playerdir=0 then plotsprite north01     7 playerx playery z
  if playerdir=1 then plotsprite south01     7 playerx playery z
  if playerdir=2 then plotsprite west01      7 playerx playery z
  if playerdir=3 then plotsprite east01      7 playerx playery z

  if playerdir=4 then plotsprite northwest01 7 playerx playery z
  if playerdir=5 then plotsprite northeast01 7 playerx playery z
  if playerdir=6 then plotsprite southwest01 7 playerx playery z
  if playerdir=7 then plotsprite southeast01 7 playerx playery z
  return



__DrawStill
  rem ** Draw character: If isrunning=0 then don't animate **
  if playerdir=0 then plotsprite north01     7 playerx playery
  if playerdir=1 then plotsprite south01     7 playerx playery
  if playerdir=2 then plotsprite west01      7 playerx playery
  if playerdir=3 then plotsprite east01      7 playerx playery

  if playerdir=4 then plotsprite northwest01 7 playerx playery
  if playerdir=5 then plotsprite northeast01 7 playerx playery
  if playerdir=6 then plotsprite southwest01 7 playerx playery
  if playerdir=7 then plotsprite southeast01 7 playerx playery
  return


__UpdateScore
  rem ** Update the score in the 320 area up top **
  plotvalue atascii 1 score0 2 0 3
  return


__ShowLivesLeft
  rem ** Display the number of lives left **
  rem ** Displays in the 320 area up top **
  temp9=140
  for i = 1 to livesleft
    plotsprite oneup 0 temp9 10
    temp9=temp9-9 ; move back 9 pixels for each life displayed
  next
  return

In the lines where I read the joystick movements, the playerx and playery variables were being added multiple times and causing overflows.

 

I re-ordered the joystick reading to read the diagonal movements first, then the regular compass points. Then, at the end of each of these lines I added a "goto" command to bypass all of the others.

 

Updated code:

  if joy0left  && joy0up   then playerx=playerx-0.5:playery=playery-0.5:playerdir=4:isrunning=1:goto __Loop01Movement ; 4=northwest
  if joy0right && joy0up   then playerx=playerx+0.5:playery=playery-0.5:playerdir=5:isrunning=1:goto __Loop01Movement ; 5=northeast
  if joy0left  && joy0down then playerx=playerx-0.5:playery=playery+0.5:playerdir=6:isrunning=1:goto __Loop01Movement ; 6=southwest
  if joy0right && joy0down then playerx=playerx+0.5:playery=playery+0.5:playerdir=7:isrunning=1:goto __Loop01Movement ; 7=southeast

  if joy0up    && !joy0left then playery=playery-0.5:playerdir=0:isrunning=1:goto __Loop01Movement ; 0=north
  if joy0down  && !joy0left then playery=playery+0.5:playerdir=1:isrunning=1:goto __Loop01Movement ; 1=south
  if joy0left  && !joy0up   then playerx=playerx-0.5:playerdir=2:isrunning=1:goto __Loop01Movement ; 2=west
  if joy0right && !joy0up   then playerx=playerx+0.5:playerdir=3:isrunning=1:goto __Loop01Movement ; 3=east

  if !joy0any then isrunning=0

__Loop01Movement

That fixed it and I was able to get the movements to render correctly.

 

Thanks for jumping in to help. That's what is so great about this community. I'm hoping this helps someone else out...

  • Like 6
Link to comment
Share on other sites

8 hours ago, saxmeister said:

As my programming teacher told me in college, "My cat knows more programming than anyone else I know. I talk through all of my bugs with my cat and, in the course of explaining it I find the answer."

Yup! There's actually a term for it: Rubber Duck Debugging.  :)

 

Anyway; I'm glad you found the cause of your issue.

  • Like 3
Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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