Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7805967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:22:55+00:00 2026-06-02T02:22:55+00:00

I am making a space shooter for my final year project and thought it

  • 0

I am making a space shooter for my final year project and thought it will be cool to include a local score/ High score screen. I don’t know how to go about this and would really appreciate if someone can point me in the right direction, all the examples I found online look very complex to me. Also I want the score to be displayed on the game screen which is rendered with opengl es.
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:22:56+00:00Added an answer on June 2, 2026 at 2:22 am

    I have just finished creating a high score board for my OpenGL ES game that I’m currently working on. As it’s for your final year project I won’t be using this as a pastebin, but instead give you some pointers. In my application the scores are sent to my PHP script which stores values in MySQL.

    What I used:

    • new class which handles everything to do with high scores
    • AlertDialog “alertName” – to ask for player name
    • EditText “input” added to the dialog with alertName.setView(input);
    • submitting the score to the server using an AsyncTask
      • this could be replaced with other Data Storage options, either internal, external, or SQLlite db

    When the game is over (all lives gone, timer up, etc) I use a line of code, not too de-similar to this:

    HighScore hs = new HighScore(context, score, level);
    

    The context is required so AlertDialogs and Toasts can be created. The constructor calls the function submit() which shows the AlertDialog asking for the player name, then sends the data to the server.

    My class contains this line of code to let the player know if they reached the top 100 after a response was received from the server:

    Toast.makeText(mContext, "You didn't make the score board", 
            Toast.LENGTH_SHORT).show();
    

    The high score list is stored in an ArrayList

    private ArrayList<String> highscores = new ArrayList<String>();
    

    And the data is padded using String.format in a similar fashion to this:

    highscore_headers = String.format("%7s","rank") + 
            String.format("%11s","name") + 
            String.format("%10s","score") + 
            String.format("%5s","lvl");
    

    And Then:

    within your Renderer’s onDrawFrame you could build the highscore class so you could call something like the one liner below, which would contain your translations, scales pushMatrix and popMatrix calls to draw the highscore data to the screen.

    hs.draw(gl);
    

    Which contains a loop, not too dissimilar to this:

    for(int i=0; i<highscores.size(); i++){
        text.drawText(gl, highscore.get(i).toString());
        gl.glTranslatef(0f, -0.8f, 0f);
    }
    

    Note: Text is a class I wrote to draw various textures on the screen
    depending on the char value of each character, which is then
    translated to a set of x,y coordinates which relate to my
    character map image file.

    Hope this helps to push you in the right direction, and best of luck with your project


    A screenshot of my android app’s high score state rendered using OpenGL ES
    a screenshot of my android app's high score state rendered using OpenGL ES


    EDIT: Sending Scores to PHP

    This won’t be an exact copy and paste of my source, but hopefully there will be enough information here to give you the general idea of it all. My final code also gives the device a uniqid, which users can track all of their scores that have been stored in the database – but that’s something else.

    php file:
    I did mess around with signing requests, hashing scores, but for the purpose of my beta and getting the game published quicker I opted for just plain text entries. The code below, also does not detail highlighting the players submitted score, or getting rank based on time.

    if(isset($_POST['name']) && isset($_POST['score'])){
        $sql = "INSERT INTO highscores(name, score) VALUES (:name, :score)";
        $data = array(":name"=>$_POST['name'], ":score"=>$_POST['score']);
        $db->run($sql, $data);
        echo display();
    }
    function display(){
        $sql = "SELECT name, score FROM highscores ORDER BY score DESC";
        $result = $db->run($sql, array());
        return json_encode($result);
    }
    

    It should be noted that the $db object is a small class I made to wrap PDO methods prepare and execute, which return results as associative arrays

    HighScore Android Class:
    again, i won’t copy/paste but this will illustrate how to post data to a server, receive a JSON string, then pad the string and add it to the highscores ArrayList. The code below is the constructor for the HighScore class, it asks for the users input.

    List<NameValuePair>nameValuePairs = new ArraList<NameValuePair>(2);
    AlertDialog alertName;
    DefaultHttpClient client = new DefaultHttpClient();
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String response = "";
    
    HighScore(Context context, int score){
        nameValuePairs.add(new BasicNameValuePair("score", + score.toString()));
        alertName = new AlertDialog(context).create();
        EditText input = new EditText(context);
        alertName.setTitle('Enter Your Name');
        alertName.setButton(AlertDialog.BUTTON_POSITIVE, "OK", 
            new DialogInterface.OnClickListener(){
                @Override
                public void onClick(DialogInterface dialog, int which){
                    nameValuePairs.add(
                    new BasicNameValuePair("name", input.getText().toString())
                    );
                    SubmitAsync sa = new SubmitAsync();
                    sa.execute();
                }
        });
        alertName.show();
    }
    

    The SubmitAsync class is a subclass of the HighScore class, it will setup the http client to send data, and add the received data. The data is digested as JSON and strings are padded as mentioned previously, then added to the highscore ArrayList

    class SubmitAsync extends AsyncTask<String, Void, Void>{
        @Override
        protected Void doInBackground(String... params){
            HttpPost postMethod = new HttpPost("http://address-of-script.php");
            postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            response = client.execute(postMethod, responseHandler);
            JSONArray jsonArray  = new JSONArray(response);
            for(int i=0; i<jsonArray.length(); i++){
                JSONObject j = jsonArray.getJSONObject(i);
                String name = String.format("%11s", j.get("name"));
                String score = String.format("%10s", j.get("score"));
                highscores.add(name + score);
            }
        }
    }
    

    That’s the very basics and alot more code than I would have liked to have entered onto here at any one time, and most definitely my longest post ever. I would seriously consider the comments of @Dan, and research local storage over my server based approach to a highscore board

    These code snippets will likely not work if copied and pasted. So please try to understand them and code yourself 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a 2D sidescrolling space shooter-type game, where I need a background that
I'm making a Space Invaders game in C#, using Bitmap to store images for
I've been exercising my skills by making a Space Invaders clone. I asked a
What are the difficulties of making Space Invaders using GTK+ (latest stable) in C?
Perhaps making use of jniwrap.jar and winpack.jar so I don't have to roll my
I am making a 2d space game with many moving objects. I have already
I am trying to create a way of making sure that every space has
I'm currently making a whimsical iPhone app that will allow you to change your
I'm looking to make a simple space invaders type shooter for android and i'm
I'm making a space navigation game. So it starts with the user on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.