Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Hi-Score how to code??  (Read 4564 times)

0 Members and 1 Guest are viewing this topic.

Amiten

  • A600
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 128
  • Amos Coder Since 1990
    • Amiten Software
Hi-Score how to code??
« on: July 17, 2013, 11:14:54 PM »

I want to make a hiscore table for a game any idea how to code this??

if some one help me to make a good one the credits go for him in the Game.

Thanks!!!!
Logged
AMIGA is a Style of Life

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Hi-Score how to code??
« Reply #1 on: July 18, 2013, 09:48:26 AM »

Dim hiscores(10), hiscore_name$(10)

Procedure hiscore_update(score, you$)
  Shared hiscores(), hiscore_name$()
  If hiscores(9)<score
    hiscores(9)=score
    hiscore_name$(9)=you$
    For count=8 to 0 step -1
      If score>hiscores(count)
        hiscores(count+1)=hiscores(count)
        hiscore_name$(count+1)=hiscore_name$(count)
        hiscores(count)=score
        hiscore_name$(count)=you$
      Else
        Exit
      End If
    Next Count
  End If
End Proc
Logged

Amiten

  • A600
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 128
  • Amos Coder Since 1990
    • Amiten Software
Re: Hi-Score how to code??
« Reply #2 on: July 18, 2013, 10:45:36 AM »

Cool!

looks great, but this hi-score gone when the program end no?,

I think must include the

open for output#1  or something

I have to work on this

Thanks you To much Samuraicrow
Logged
AMIGA is a Style of Life

Hungry Horace

  • Amorphous Blue-Blob Man
  • Site Admin
  • A4000T
  • ******
  • Karma: 307
  • Offline Offline
  • Gender: Male
  • Posts: 3,364
  • Don't forget... Ameboid's need love too!
    • AUW
Re: Hi-Score how to code??
« Reply #3 on: July 18, 2013, 04:34:42 PM »

I have one somewhere I can dig out that includes saving.... I will have a look when I get a chance.

I don't think it includes typing in a name though !
Logged
Quote from: KillerGorilla
because winuae is made of code and your amiga is made of stuff

Lonewolf10

  • AMOS Extensions Developer
  • AMOS Dev
  • A2000
  • *****
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 618
    • http://www.aliensrcooluk.com
Re: Hi-Score how to code??
« Reply #4 on: July 19, 2013, 08:18:47 PM »

I have one somewhere I can dig out that includes saving.... I will have a look when I get a chance.

I don't think it includes typing in a name though !

If you can't find it, I have one from one of my early AMOS games. Not sure how good the coding is as it would have been written about 10 years ago.
Logged

Hungry Horace

  • Amorphous Blue-Blob Man
  • Site Admin
  • A4000T
  • ******
  • Karma: 307
  • Offline Offline
  • Gender: Male
  • Posts: 3,364
  • Don't forget... Ameboid's need love too!
    • AUW
Re: Hi-Score how to code??
« Reply #5 on: July 20, 2013, 02:35:55 PM »

i've found my code, but sadly i havent found anything that actually adds a new score into the table - this would have to be done with something like SamuraiCrow's code above.

What i have found is a high-score "block file" (i've attached a copy inside a zip file) - if you want to save a nice clean highscore table file (like the ones in many WHDload patches) then i suggest you create something like this first of all - decide what size etc you want the file to be, then work backwards from there.

Step 1:  Decide on a memory block "layout" - mine is a total block size of  280 ($118) bytes long.
For each score entry, this has 24 bytes of text, then 4 bytes (longword) for the score. - this repeated 10 times

if you create one of these 'manually' in a hex editor or something, you then have something to work with - later on you can write some code in AMOS to create a 'default' file like this if an existing one does not exist.

Step 2: When entering the game's menu screens, i load the file into memory with the following (AMCAF?) command:

Code: [Select]
Wload "data/highscores.data",4
Bank Name 4,"HiScores"

The second line is simply to label the bank and make it easier to spot in the AMOS editor.

Step 3: you'll want to start by simply working out how to read the data in the block file. I've used the following code to "write" my entire highscore file onto the screen. You might want to consider using a user-defined function (DEF FN) to read a specific name / score out of the data... it shouldnt be too difficult using the peek commands and adapting the "FINDSCOREDATA:" sub routine below.

You'll notice i dont display text with the TEXT or PRINT commands, but my own "SMALLTYPE:" sub routine, but GOSUB SMALLTYPE could easily be substituted for TEXT MYX,MYY,MYTEXT$

Code: [Select]
MENUEVENTS_002:

     If MENUCLOCK=0

' write scores
         MYTEXT$="High-scores"
         MYX=-1 : MYY=490+4 : MYDELAY=3
         Gosub SMALLTYPE

      For FIND=1 To 10
         Gosub FINDSCOREDATA
         MYTEXT$=HIGHSNAME$+"  "+HIGHSCORE$
         MYX=-1 : MYY=20+490+FIND*12 : MYDELAY=1
         Gosub SMALLTYPE
      Next FIND

' write extra text
         MYTEXT$="press fire to continue"
         MYX=-1 : MYY=660 : MYDELAY=3
         Gosub SMALLTYPE

Else If MENUCLOCK=1
         MYTEXT$="press fire to continue"
         MYX=-1 : MYY=660 : MYDELAY=0
         Gosub SMALLTYPE
Else
         Screen Copy 1,0,650,320,700 To 0,0,650
End If

Return




FINDSCOREDATA:


HIGHSCORE$="" : HIGHSNAME$=""

   If FIND<1 or FIND>10 Then Return
      HIGHSCORE$=Lzstr$(Leek(Start(4)+($1C*(FIND-1))+24),8)
    For E=0 To $17
      HIGHSNAME$=HIGHSNAME$+Chr$(Peek(Start(4)+($1C*(FIND-1))+E))
    Next E

Return

Once you're reading from the highscore data block with ease, it should be simple enough to either load all the scores into an array, and adapt SamuraiCrow's code, then at the end, move the updated scores back into the block with POKE commands.

You can then save the updated block back to disk with ease using the WSAVE command.

I'm sorry this is not a more complete solution / guide, but it's worth having a look at if you are serious about learning, and hopefully this will help you with some of the elements for consideration.




Logged
Quote from: KillerGorilla
because winuae is made of code and your amiga is made of stuff

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Hi-Score how to code??
« Reply #6 on: July 21, 2013, 01:08:36 AM »

WLoad, WSave, and Lzstr$ are AMCAF functions.  If you'd rather save it with BLoad and BSave instead of WLoad and WSave, it will generate a bigger file but still work.
Logged
Pages: [1]   Go Up
 

TinyPortal 2.2.2 © 2005-2022