|
Title: Balls Can Hurt You Post by: Shakhal on November 18, 2011, 08:41:10 PM (http://i1092.photobucket.com/albums/i406/Shackhal/bchysst1.png)(http://i1092.photobucket.com/albums/i406/Shackhal/bchysst2.png) This is my first game. It's called Balls Can Hurt You and was made with Game Maker 8.1 after i purchased. Is about a guy who have to evade all the balls that keep bouncing all around a closed room. The more time evading them, the more score you can get. But one touch and you lose. I would like to put a high-score list and a better physics in the game, but i didn't know how, so i'm leaving for now like that. And i appreciate all the feedback you can say. This way, i can get better and create more complex and awesome games. Here is the download (http://dl.dropbox.com/u/51655828/Balls%20Can%20Hurt%20You.zip). And thanks for playing it :) Title: Re: Balls Can Hurt You Post by: anonymous on November 18, 2011, 11:18:12 PM mmm repressed childhood nightmares flooding back :'(
Title: Re: Balls Can Hurt You Post by: ink.inc on November 18, 2011, 11:48:56 PM Luckily for you, high score lists aren't particularly difficult.
Merely save/load them from an external file. In the following example, I show you how to load numbers from an .ini file, determine if the current score is higher than any of the high scores, and then rewrite the .ini file. To start with, create the ini file. To do so, open up Notepad and save it as "name.ini". In the following example, I named the file "dum.ini" You can set the .ini up as such: Quote [highscores] score1 = 0 score2 = 0 score3 = 0 score4 = 0 score5 = 0 What you have just done is created a file with 5 variables, each capable of holding high scores. Score1 will hold the highest, score2 will hold the second highest, etc, etc. The following will require you to use GML, but I've set it up so that you can just copy/paste the code into a control object. In the Create Event: Code: ini_open("dum.ini")//opens the .ini file for the data to be read score_grid=ds_grid_create(1,5)//creates a data grid that holds the values of the high scores ds_grid_set(score_grid,0,0,ini_read_real('highscores','score1',''))//sets the values of the datagrid ds_grid_set(score_grid,0,1,ini_read_real('highscores','score2','')) ds_grid_set(score_grid,0,2,ini_read_real('highscores','score3','')) ds_grid_set(score_grid,0,3,ini_read_real('highscores','score4','')) ds_grid_set(score_grid,0,4,ini_read_real('highscores','score5','')) ini_close()//close the .ini; this is important game_score=0//the current players score Put this code when the round has ended. Code: //sets up a while loop that checks the value of the current score with every single one of the high scores. a=0 //the current ranking of the score being checked. it starts at 0 because data grid numbering starts at 0 while a<5 //while a<the number of items in the data grid { if game_score>ds_grid_get(score_grid,0,a)//if the score is higher than this number { b=4 //this code slides down all the values of the high scores. so if your score is //the new highest score, score 5 is set to score 4, score 4 is set to score 3, etc. while b>=0 { ds_grid_set(score_grid,0,b,ds_grid_get(score_grid,0,b-1)) b-=1 if b=0 break;//if you've run through all the numbers, QUIT } ds_grid_set(score_grid,0,a,game_score) break;//if you've set the new score, QUIT } a+=1 } ini_open("dum.ini")//WRITE THE NEW VALUES TO INI FILE score1=ini_write_real('highscores','score1',ds_grid_get(score_grid,0,0)) score2=ini_write_real('highscores','score2',ds_grid_get(score_grid,0,1)) score3=ini_write_real('highscores','score3',ds_grid_get(score_grid,0,2)) score4=ini_write_real('highscores','score4',ds_grid_get(score_grid,0,3)) score5=ini_write_real('highscores','score5',ds_grid_get(score_grid,0,4)) ini_close() Assuming you want to draw it, put this in the Draw Event. Code: i=0 while i<5 { draw_text(x,y+20*i,ds_grid_get(score_grid,0,i)) i+=1 } Have fun! Title: Re: Balls Can Hurt You Post by: Shakhal on November 19, 2011, 11:26:39 PM Thanks @John Sandoval for the code. I didn't know how to use a external file in the code and about data structure, but thanks to you i learn it (after reading the Game Maker Help just to understand the code you put it :lol:)
But after i read your code, i found an error. Is that part: Code: //sets up a while loop that checks the value of the current score with every single one of the high scores. a=0 //the current ranking of the score being checked. it starts at 0 because data grid numbering starts at 0 while a<5 //while a<the number of items in the data grid { if game_score>ds_grid_get(score_grid,0,a)//if the score is higher than this number { b=4 //this code slides down all the values of the high scores. so if your score is //the new highest score, score 5 is set to score 4, score 4 is set to score 3, etc. while b>=0 { ds_grid_set(score_grid,0,b,ds_grid_get(score_grid,0,b-1)) b-=1 if b=0 break;//if you've run through all the numbers, QUIT } ds_grid_set(score_grid,0,a,game_score) break;//if you've set the new score, QUIT } a+=1 } In that code say that when a high-score is surpassed, always will overwrite all the high-score list and after that, it will overwrite again the position deserved. For example: Before the game the high-score list is:
So, i made some changes in the code (yeah, i learned it :P): Code: //sets up a while loop that checks the value of the current score with every single one of the high scores. a = 0;//the current ranking of the score being checked. it starts at 0 because data grid numbering starts at 0 while (a < 5 && highScoreCheck == 0) //while a < the number of items in the data grid and the high-score list isn't updated //highScoreCheck is created in the Create Event { if (score > ds_grid_get(score_grid, 0, a))//if the score is higher than this number { b = 4; //this code slides down the values of the high scores. so if your new score is //one of the highest scores, score 5 is set to score 4, score 4 is set to score 3, etc. //until reach the place deserved. while (b > a) { ds_grid_set(score_grid, 0, b, ds_grid_get(score_grid, 0, b - 1)); b -= 1; } ds_grid_set(score_grid, 0, a, score); highScoreCheck = 1; } else a += 1; } And of course i organized it, for better reading. Now it runs nicely. But i only will put 1 high score on the list, because is single player. Any way, i learn it to code it so thanks you :gentleman: Title: Re: Balls Can Hurt You Post by: ink.inc on November 19, 2011, 11:28:47 PM Oops, typo! Yeah, changing the check from 0 to A will fix your problems. Sorry about that. :P
Title: Re: Balls Can Hurt You Post by: Shakhal on November 20, 2011, 12:58:03 AM Oops, typo! Yeah, changing the check from 0 to A will fix your problems. Sorry about that. :P Don't worry. Like i said, that help me to understand the code. So thanks for the fast teaching ;) By the way, i update the game with highscore. The link is in the first post. Enjoy :) |