00:00
00:00
Newgrounds Background Image Theme

fillup69 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

As: Randomizers, Xp And Levels

1,108 Views | 9 Replies
New Topic Respond to this Topic

As: Randomizers, Xp And Levels 2006-05-01 05:36:51


So maybe you want .. not just a game with names, but a name randomizer too for people who cant think of names. You might also want an XP (experience points) and levels system to level up. This way also is a tutorial of how to make a basic creature you can beat up, exactly (except differently drawn) like the one in the 'Don't know Flash?' area when submitting your movies/games/movies with mini-games. Please dont flame me because you didnt want to make a game with xp/levels/randomizer/names, if you dont want a game with that stuff, dont read this tutorial instead of just going 'Omg I didnt need this because I am making just a normal movie' that is fine but dont bother reading this if that Omg statement is set to true. :P I worked hard on trying to figure out the name randomizers and things, so dont flame.

In the Forum search, choose Author and search Kookas. Then find my name tutorial. Thats for names. For a randomizer, read on.

1. You have read my names tutorial, right? Now make a button next to your name input text box. Press F9 whilst selecting the button and enter:
on (release) {
var namelist = [ "LeRoy The Defender", "Burt The Protector", "Spurk The Killer" ];
yourtextbox.text = namelist[Math.floor(namelist.length * Math.random())];
}

Give the name input text box an instance name, and replace yourtextbox with the instance name. Change the names as you like, and add ones. Edit this line:
[ "LeRoy The Defender", "Burt The Protector", "Spurk The Killer" ];
Change the names (which are obviously the words in brackets) to what you want, and add them too like for example you want to add 'Spekra The Deadly' to it, then you change it to:
[ "LeRoy The Defender", "Burt The Protector", "Spurk The Killer", "Spekra The Deadly" ];
Test your name randomizer. It should work.

XP and Levels, along with working creatures.

OK, so this is a much longer tutorial than the last one. Make two new dynamic text boxes, and set one of their vars to level and the other to xp. On your actions layer, put in:
var xp;
var level;
var enemyhp
xp = 0;
level = 0;
enemyhp = 100;
Then make your creature. Ok, lets go for a basic creature for now. Just draw something, make it into a movie clip. Open it's timeline by selecting it and pressing Ctrl and E at the same time. On frame 1, draw the creature healthy. On frame 2, draw it a bit less healthy. On frame 3, draw it even less healthy. On frame 4, draw it dead. If you want it to be harder to kill, you can add more keyframes between death and healthy. All must be keyframes. Make a new layer in the creature's timeline and call it Actions. Make as much keyframes on Actions as there are on the main layer. On each keyframe, press F9 and input:
stop();
Now then, time for code, but first, make a dynamic textbox on the movie's main timeline and set it's var to enemyhp. Now coding. Open the creatures code, you should know how by now, and enter:
on (release) {
_root.enemyhp = _root.enemyhp - 25;
_root.xp = _root.xp + 10
if (_root.enemyhp == 0) {
_root.testkill_mc.enabled = false;
}
if ( xp == 100 ) {
level = 1;
}
if ( xp == 400 ) {
level = 2;
}
if ( xp == 300 ) {
level = 3;
}
if ( xp == 400 ) {
level = 4;
}
this.nextFrame();

}
Lets go through the code. The first part of the code is the on statement - tells Flash that when you release your mouse button on the movieclip, it has to perform the set of commands between the { and the }. The next part is one you can change. It takes away 25 hp every time you hit it. You must work out what you need and change it. For example - you have 5 frames, then you want to have it take away 10 per click. The next parts perform the experience test. Add more levels if you want, and change the amount of xp needed to get to the next level too. The last part of the code is what makes the creature go through the frames as you click it until it is dead. Overall you now have:
A creature with this code:
on (release) {
_root.enemyhp = _root.enemyhp - 25;
if (_root.enemyhp < 0) {
_root.enemyhp = 0;
}
_root.xp = _root.xp + 10
if (_root.enemyhp == 0) {
_root.testkill_mc.enabled = false;
}
if ( xp == 100 ) {
level = 1;
}
if ( xp == 400 ) {
level = 2;
}
if ( xp == 300 ) {
level = 3;
}
if ( xp == 400 ) {
level = 4;
}
this.nextFrame();

}

3 text boxes, all are dynamic and display either the xp, the level or the enemy's health.

A layer in the creature movie clip with several keyframes each with the stop(); action in them.

A name randomizer which randomizes through your choice of names:
on (release) {
var namelist = [ "LeRoy The Defender", "Burt The Protector", "Spurk The Killer" ];
input_txt.text = namelist[Math.floor(namelist.length * Math.random())];
}

(that is if you called your name text box 'input_txt', you can change it to its instance name and the list of names)
And on my movie's main timeline, on a layer called Actions, I have the following code:
stop();
var xp;
var name;
var level;
xp = 0;
level = 0;
_root.enemyhp = 100;
name = "Type Your Name Here";

Some of it is customization code, for exampe the "Type Your Name Here" part is just to make the name text box say "Type Your Name Here" when you start. Good luck with the rest of your game!

Response to As: Randomizers, Xp And Levels 2006-05-01 05:42:05


At 5/1/06 05:36 AM, Kookas wrote: var xp;
var level;
var enemyhp
xp = 0;
level = 0;
enemyhp = 100;

i beleave this is more correct

var xp:Number = 0;
var level:Number = 0;
var enemyhp:Number = 0;

Response to As: Randomizers, Xp And Levels 2006-05-01 05:44:38


It might be a longer way and it might look more professional but my way is correct and does the same.

Response to As: Randomizers, Xp And Levels 2006-05-01 05:47:49


sure your way works
just
bleh = 20;
works.... but my way IS more correct fool, i define what type of data the variable can hold.

Response to As: Randomizers, Xp And Levels 2006-05-01 05:53:35


Yes but thats not really needed if you are making a variable of which Flash automatically changes. If it was a variable with an input textbox linked to it, then sure.

Response to As: Randomizers, Xp And Levels 2006-05-01 06:39:43


At 5/1/06 05:53 AM, Kookas wrote: Yes but thats not really needed if you are making a variable of which Flash automatically changes. If it was a variable with an input textbox linked to it, then sure.

no it isnt needed for AS, thats not the point of it, the point of it is its good practice, and helps your app to work faster because the flash machine already knows what type of data its storing, and doesnt have to find that out at each occurence of the variable, apart from that , it helps with debugging since with strict data typing, the compiler can tell you when you try to set a number to a string like

var a:Number = 10;

... then somewhere else, a = "hello";

obviously thats not right, if you didnt strict data type, you wouldnt be given that erorr

Response to As: Randomizers, Xp And Levels 2006-05-01 15:55:38


Oh, I see.

Response to As: Randomizers, Xp And Levels 2006-05-01 16:18:25


BTW, Delta's Sigs are just to grant him 10 'HC's, not to go to AS: Main, PHP: Main or C++: Main, or to beta test his 3D First Person Shooter.

Response to As: Randomizers, Xp And Levels 2006-05-01 16:20:33


At 5/1/06 04:18 PM, Kookas wrote: BTW, Delta's Sigs are just to grant him 10 'HC's, not to go to AS: Main, PHP: Main or C++: Main, or to beta test his 3D First Person Shooter.

It's okay though, because we love delta. I click them time to time just to give him reward hits =)


Writer @ www.Johnrickett.com

Response to As: Randomizers, Xp And Levels 2006-05-01 17:32:30


I see.