Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.display.MovieClip;
- public class LevelSystem extends MovieClip {
- const MAX_LEVEL = 50;
- const XP_INCREMENT = 500;
- public var int iXP; // Total amount of gathered XP
- public var int iLevel; // Current level
- public var int iXPGatheredForNextLevel; // Amount of XP gathered for the next level
- public var int iXPRequiredForNextLevel; // Amount of XP required for the next level
- public function LevelSystem {
- CalculateLevelProgress();
- }
- public function GiveXP(int amount) {
- XP += amount;
- CalculateLevelProgress();
- while (XPGatheredForNextLevel >= XPRequiredForNextLevel && Level < MAX_LEVEL) {
- Level++;
- // Recalculate level progress after leveling up
- CalculateLevelProgress();
- }
- }
- public function CalculateLevelProgress() {
- local int xpToCurrentLevel; // Total amount of XP gathered with current and previous levels
- xpToCurrentLevel = 0.5 * Level * (Level-1) * XP_INCREMENT;
- XPGatheredForNextLevel = XP - xpToCurrentLevel;
- XPRequiredForNextLevel = Level * XP_INCREMENT;
- }
- }
- }
Add Comment
Please, Sign In to add comment