Pro Flash Beat
Would you like to react to this message? Create an account in a few clicks or log in to continue.



 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

 

 Game-Life simulation

Go down 
4 posters
AuthorMessage
devilz-fury
Admin
devilz-fury


Posts : 16
Join date : 2008-06-08
Age : 29
Location : In a suit of metal!!!

Game-Life simulation Empty
PostSubject: Game-Life simulation   Game-Life simulation Icon_minitimeThu Jul 24, 2008 10:28 am

In this tutorial I will show you how to create a simple Life Simulation Game with flash/AS2.

First thing we need to do is set up some variables like 'tiredness' and 'hunger', because this is going to be our actual game engine. Select the 1st frame and hit F9 to enter the actions window, and enter the following syntax:

stop(); //this code will make the game stay on this frame
_root.hpBar = 100; //this variable will need to be set at 100 because the character has full health at the start of the game
_root.tiredness = 100; //this variable will need to be set at 100 because the character is not tired at the start of the game, and we need to decrease this amount during the game.
_root.hunger = 100; //this variable's story is the same as for the _root.tiredness variable.

Now we need to create a second keyframe to go to when the character dies. Select the second frame and hit F6 to create a keyframe.
Give this frame the following syntax:

stop();

Next, create a character... Any character... Seriously, I couldn't care less what it looks like...
Once you've drawn your superhero (mine was a ball), select it and hit F8 to convert it into a movieClip.
MAKE SURE TO GIVE IT THE INSTANCE NAME OF 'man'.
Then hit F9 to enter the actions window, and enter the following syntax:

onClipEvent (enterFrame) { //This makes sure that the following actions will be repeated every time the game enters the frame this character is on.
_root.tiredness -= 0.01; //so, every time the game hits this frame the tiredness variable wil be reduced with 0,01.
_root.hunger -= 0.02; //and this variable will be reduced with 0,02
}//end of onClipEvent's block.

onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) { //when right key is pressed
this._x += 5; //this movieClip will move 5 pixels to the right.
}
if (Key.isDown(Key.LEFT)) { //when left key is pressed
this._x -= 5; //this movieClip will move 5 pixels to the left.
}
if (Key.isDown(Key.UP)) { //when up key is pressed
this._y -= 5; //this movieClip will move up 5 pixels.
}
if (Key.isDown(Key.DOWN)) { //when down key is pressed
this._y += 5; //this movieClip will move down 5 pixels.
}
}

Maybe you'd like to hit CTRL+ENTER to test your game.
(not nessecary because at this point you will only be able to move your hero (YAY))

so, lets start adding some status bars to show the amounts of hunger and tiredness.

Create a rectangle (width 100, height 15) and make it red or some other color. Now select it and hit F8 to convert it into a movieClip. MAKE SURE YOU SET THE REGISTRATION POINT TO LEFT!!!
Next, create another rectangle of the same size, and give it another color as u gave the other one. Place it exactly underneath the other rectangle you just converted to movieClip.
Now add the folowing syntax to your rectangle movieClip:

onClipEvent(enterFrame){
this._xscale = _root.hunger; //This sets the horizontal size of your movieClip similar to the amount of the hunger variable.
if(_root.hunger < 0){ //if the hunger variable gets any lower than 0
_root.hunger = 0; // reset it to 0
_root.hpBar -= 0.1; // and decrease the health by 0,1.
}
if(_root.hunger > 100){ //if the hunger variable gets any higher than 100
_root.hunger = 100; //reset it to 100.
}
}

Now Copy/Paste the rectangle movieClip and the rectangle underneath it twice to create status bars for the tiredness and health variable.
This movieClip needs to be almost exactly the same as the one you just duplicated, but you will only need to replace the "_root.hunger" variables with "_root.tiredness" or "_root.hpBar", and you will need to make the game skip to frame 2 when your character dies.
their syntaxes will look like this:

onClipEvent(enterFrame){
this._xscale = _root.tiredness;
if(_root.tiredness < 0){
_root.tiredness = 0;
_root.hpBar -= 0.1;
}
if(_root.tiredness > 100){
_root.tiredness = 100;
}
}

and

onClipEvent(enterFrame){
this._xscale = _root.hpBar;
if(_root.hpBar < 0){
_root.hpBar = 0;
_root.gotoAndStop(2);
}
if(_root.hpBar > 100){
_root.hpBar = 100;
}
}

Try to hit CTRL+ENTER now.
we just programmed it so that the status bars will run empty very slow, and when empty the health will be decreased by 0,1 until the character dies, in which case the game will skip to frame 2.

Well, this is quite nice and all, but what good is the game if the hunger and tiredness can only decrease, and we are doomed to die? nothing! exactly!
So we need to create some objects that will increase these amounts to keep us alive. I chose to draw a bed and an oven.
When you've drawn the bed, hit F8 to convert it to a movieClip, and add the folowing syntax:

onClipEvent (enterFrame) {
if (_root.man.hitTest(this)) { //when the man touches the bed
_root.tiredness += 0.03; //the tiredness variable will be increased with 0.03
}
}

Do the same for the oven, and add the following syntax:

onClipEvent (enterFrame) {
if (_root.man.hitTest(this)) { //when the man touches the oven
_root.hunger += 0.05; //the hunger variable will be increased with 0.05
}
}

Hit CTRL+ENTER to test your game.
It is finished!!

well, the basic part is finished. We can still improve it a little.
The EA-games classic game 'The Sims' used something called skillpoints.
These were used to improve your skills to get better at painting, for example.
So, here we go...

Select the 1st frame in the timeline and hit F9. we need to add 2 different variables for the skillpoint. The first one is to increase when the character touches the object. the second is to increase the actual skillpoint itself, when the first variable reaches a certain level. Assuming we make our character a Bob Ross like type of person, we will create creativity points.
Change the frame's syntax to this:

stop();
_root.tiredness = 100;
_root.hunger = 100;
_root.hpBar = 100;
_root.creaPoints = 0; // this variable will be used to increase when the character touches the painting we will create shortly.
_root.creativity = 0; // this variable will be used to set the skillpoint itself.
if(_root.creaPoints > 100){
_root.creaPoints = 100;
}

We need the creativity variable to increase when the creaPoints variable reaches a certain level. To do so, you need to select your character, and hit F9 to change the syntax to this:

onClipEvent (enterFrame) {
_root.tiredness -= 0.01;
_root.hunger -= 0.02;

if (_root.creaPoints > 200){ //when the _root.creaPoints variable's amount is bigger than 200
_root.creativity = 1; // set the _root.creativity variable to 1
}
if (_root.creaPoints > 600){ //when the _root.creaPoints variable's amount is bigger than 600
_root.creativity = 2; // set the _root.creativity variable to 2
}
if (_root.creaPoints > 1200){ //when the _root.creaPoints variable's amount is bigger than 1200
_root.creativity = 3; // set the _root.creativity variable to 3
}
if (_root.creaPoints > 2000){ //when the _root.creaPoints variable's amount is bigger than 2000
_root.creativity = 4; // set the _root.creativity variable to 4
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x += 5;
}
if (Key.isDown(Key.LEFT)) {
this._x -= 5;
}
if (Key.isDown(Key.UP)) {
this._y -= 5;
}
if (Key.isDown(Key.DOWN)) {
this._y += 5;
}
}


Next we will need to create a dynamic text box to display the _root.creativity variable.
draw a text box anywhere you like, and set it to a Dynamic textbox. Make sure the VAR for this textbox is 'creativity'.

To actually change the creaPoints variable we will need to draw an object that will be used for the painting and convert it to a movieClip. Enter the movieClip you just created, and add a second frame to its timeline. On the second frame, place a dynamic text box (above the object itself) that will display the amount of the _root.creaPoints variable, and make sure its VAR reads '_root.creaPoints'. Now go back to the main frame, select the painting object you just created and add the following syntax to it:

onClipEvent (enterFrame) {
if (_root.man.hitTest(this)) { //when the character touches this object
this.gotoAndStop(2); //make this object go to its second frame
_root.creaPoints += 0.5; //and increase the creaPoints variable with 0,5.
} else { //otherwise
this.gotoAndStop(1); //make this object go back to its first frame
}
}

Again hit CTRL+ENTER to test your game, because we are finished for real this time!

I will upload mine later.
Back to top Go down
https://pro-flash-beat.darkbb.com
Maaron
Newbie
Maaron


Posts : 3
Join date : 2008-08-08
Location : Somewhere you don't know

Game-Life simulation Empty
PostSubject: Re: Game-Life simulation   Game-Life simulation Icon_minitimeFri Aug 08, 2008 5:23 pm

Hey, nice tutorial but would like to know how you made the banner in your signature
Back to top Go down
Demon
Newbie
Demon


Posts : 3
Join date : 2008-09-09
Location : Somewhere in time

Game-Life simulation Empty
PostSubject: Re: Game-Life simulation   Game-Life simulation Icon_minitimeTue Sep 16, 2008 9:01 am

yeah which banner (top or bottom)
Back to top Go down
http://hell-wave.darkbb.com/
Revan
Admin
Revan


Posts : 22
Join date : 2008-06-18
Age : 30
Location : In your head messing with your thoughts!

Game-Life simulation Empty
PostSubject: Re: Game-Life simulation   Game-Life simulation Icon_minitimeTue Sep 16, 2008 9:17 am

he wrote what he wanted. then he inserted another layer, inserted a pic, then he made that layer a screen. then he move the text around till he got it where he wanted.
Back to top Go down
https://pro-flash-beat.darkbb.com/
Demon
Newbie
Demon


Posts : 3
Join date : 2008-09-09
Location : Somewhere in time

Game-Life simulation Empty
PostSubject: Re: Game-Life simulation   Game-Life simulation Icon_minitimeWed Sep 17, 2008 8:08 am

how do you know he was not asking about the lower one
Back to top Go down
http://hell-wave.darkbb.com/
Revan
Admin
Revan


Posts : 22
Join date : 2008-06-18
Age : 30
Location : In your head messing with your thoughts!

Game-Life simulation Empty
PostSubject: Re: Game-Life simulation   Game-Life simulation Icon_minitimeThu Sep 18, 2008 12:30 pm

Demon wrote:
how do you know he was not asking about the lower one

Because thats not a banner...
Back to top Go down
https://pro-flash-beat.darkbb.com/
Sponsored content





Game-Life simulation Empty
PostSubject: Re: Game-Life simulation   Game-Life simulation Icon_minitime

Back to top Go down
 
Game-Life simulation
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Pro Flash Beat :: Animation :: Tutorials :: Flash-
Jump to: