Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-02-2009
Member
 
Join Date: May 2008
Posts: 248
Programming - Mat

I played with a "xp/level" system in php.

I would like to increase the number of XP to be used by 50 for each level.

My formula is as follows:
Code:
if($exp>($level*50)+($level*200)) {
$level = $level+1;
)
And I need it to level 1 by using 250 exp to rise. But from 2 to 3 will also use 250, etc., etc.

The idea is that from 2 to 3 you should use 300, etc.

Does anyone know how on earth I will make such a formula?
Reply With Quote
  #2  
Old 02-02-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Programming - Mat

I have read 5 times what you wrote and I still do not quite understand what it is you want
Reply With Quote
  #3  
Old 02-02-2009
Member
 
Join Date: May 2008
Posts: 248
Re: Programming - Mat

haha, it is too hard to explain .. hmm ..

So, from level 1 to level 2 in this game, you need 200 XP.
From level 2 to level 3, then use the 250 XP.
3-4: 300 XP

etc..

So 50 more per level you say, so it finally ends up to be a lot of xp per level ..

Helped it?
Reply With Quote
  #4  
Old 02-02-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Programming - Mat

Code:
$level = 1; 
$xp = 0; 

If($xp >= ($level*50)+150)
( 
$level = $level+1
)
Edit: Did a bit fast. $ needed_xp would not have helped.

And no it is not 200, if we are to start at 200 and stepped 50 up every time.

If this is not what you need, I still didnt understand what you want.
Reply With Quote
  #5  
Old 02-02-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Programming - Mat

Quote:
Originally Posted by kelfro View Post
Code:
$level = 1; 
$xp = 0; 

If($xp >= ($level*50)+150)
( 
$level = $level+1
)
Edit: Did a bit fast. $ needed_xp would not have helped.

And no it is not 200, if we are to start at 200 and stepped 50 up every time.

If this is not what you need, I still didnt understand what you want.
You can not compare with $ needed_xp because it has no value, you should compare with $ xp, and it's proven 200 instead of 150.
Reply With Quote
  #6  
Old 02-02-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Programming - Mat

Try the following:
Code:
//Do the following when you declare other variables. 
$ current_xp = 226 // default value 
$ xp_base_value = 200 // XP needed for next level 
$ increment_modifier = 50; 

//Call when the current xp be updated 
//Example: updateCurrentXP(25) 
function updateCurrentXP($gain) {
$current_xp = $current_xp + $gain;
}

//Call just before checking the level 
//Example: $needed_xp = getNeededXp() 
function getNeededXp() {
return ($xp_base_value + ($level * $increment_modifier));
}

//We get 25 XP so current_xp reach 251, and thus qualify for increase 
updateCurrentXP(25); 

//Perform check and increasing level if we are qualified 
if ($current_xp >= getNeededXp()) {
$level = $level + 1;
}
In order not to have a flat increase (ie, 50 extra xp for each level) you can make the following small addition

Code:
function getNeededXp() {
$modifier = $xp_base_value + ($level * $increment_modifier) * 0.93;
return ($xp_base_value + ($level * $increment_modifier) + $modifier);
}
Here, then instead of 50 extra each level, be an increase in the number of necessary xp .. namely, the higher level, the more xp needed ..

0.93 in the example above, of course adjusted and will probably be adjusted until it feels right.
Reply With Quote
  #7  
Old 02-02-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Programming - Mat

An alternative explanation might be:

Let us look at your first example:
$exp>($level*50)+($level*200)

It can be reduced to:
$exp > $level*250
As you've noticed it a linear increase of 250 for each level.

What you want is a exponential increase. That you must have multiplied by $ level more than once on the right side.

Eg.
$exp > $level*250 * $level

Which provides:
Level 1-2 requires 250 (250 to grow)
Level 2-3 requires 1000 (750 to grow)
Level 3-4 requires 2250 (1250 to grow)
etc.
Reply With Quote
  #8  
Old 02-02-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: Programming - Mat

You can use heltalsdivision to make those 'steps' on 50xp

$level = ($xp - 150) / 50;

(there is a little crunch with the formula until it rounds 150xp that function returns a negative level)

edit: never mind, not the revised questions
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Programming - Mat"
Thread Thread Starter Forum Replies Last Post
What does CVS mean in programming? Gajananvihari Software Development 5 12-03-2010 05:09 PM
What does DOM mean in programming? Gadin Software Development 5 11-03-2010 05:33 PM
Xml with C# in .NET programming Remedy Software Development 4 03-03-2010 08:10 PM
Socket programming: Is any new Programming Language? Kushan Software Development 3 14-11-2009 11:13 AM
JetBrains Introduces a New Programming Paradigm With its Meta Programming System JoeFrat Software Development 3 13-12-2008 01:49 PM


All times are GMT +5.5. The time now is 05:17 AM.