Hi to all,
this is the last project i made for Egolab, it is a long time i do not update my portfolio online.
It is a funny drag and drop game, in which you have to reinterpret recipes on the base of the Slowfood association principles, that are biodiversity and the right of any nation to grow and use its own tastes.
For this project i worked with Marco Fresta, creative designer, Rita Petruccioli, character and background designer, Alessandro Balasco, php/mysql designer & developer and Federico Panella, character animator.
Have a try and discover what kind of cook is inside you!

Homepage

Nation select

Game screen

Your recipe
Enjoy :)
Welcome back!
We are going on in programming a simple money money clone, here. It is very simple. If you lost the previous lesson, please read it in the previous posts. Anyway, shortly it is a game in which you control a character in the lower part of the screen with your mouse to catch objects falling from the ceiling (or to avoid objects, of course).
I left you with some main concept about the object dispatcher. Now we are going to make it in actionscript.
Up to now, we have in our library two objects exported via the linkage name of “coin” and “hammer”. We only have to attach them dynamically to the stage and let them fall.
We have to decide where to attach movies from the library. For this example, we are going to attach them to the root timeline, but in some cases it is useful to attach them to a container movieclip.
At the same moment we start playing this game, the objects must be started to fall down too. So we are going to add something similar to the code below to the main action layer.
nint = setInterval(crObject, 1000, this);
curr++;
score_txt.text = String(score
energy_txt.text = String(energy);
This lines will be useful to initialize the event dispatcher (1), increasing the number of the current object, and displaying initialized values for score and energy.
The setInterval function takes three parameters, the function to be called at the specified interval, the interval and one or more parameters to pass to the variable. So we are telling the actionscript compiler to call the crObject function each 1000 milliseconds (1 second), passing the address of the current timeline as a parameter (for reference).
Of course, we have to initialize some variables in the context of our game. We can add at the very beginning of the code, this code that initializes the variables needed in the game.
var curr:Number = 0;
var energy:Number = 100;
var score:Number = 0;
var nint:Number;
This code initializes the variables for object number (curr), energy and score and a variable (nint) that represents the interval at which calling the function to create objects.
Now we need the last function to make it all work. I will leave the architecture open, so you are going to use this code for games like this one. I prefer to comment in the code, hoping this will be more clear.
function crObject(root:MovieClip) {
// casual object, the number will be interpreted later
tipo = Math.round(Math.random()*1);
// increase the current object number,
// so objects will not replace themselves at any creation.
curr++;
// this will decide if coin or hammer from the tipo number.
tipo_mc = (tipo == 0) ? "coin" : "hammer";
// the object is now created, attached to the root timeline,
// and it get the name of objectN where N is curr and placed
// at level 1024 + curr.
objmc = root.attachMovie(tipo_mc, "object"+curr, 1024+curr);
// defines the starting position of objects.
objmc._x = Math.round(Math.random()*340)+30;
objmc._y = -20;
// defines falling rate of the object
objmc.fstep = 2;
// stores the type of the object in the object.
objmc.tipo = tipo;
// randomize the scale of the object
objmc._xscale = objmc._yscale=Math.round(Math.random()*50)+50;
// this code is executed during the fall of the object
objmc.onEnterFrame = function() {
// falling
this._y += this.fstep;
// increase falling rate
this.fstep += 0.2;
// increase rotation of the object
this._rotation += 5;
// when the object collides with the main char
if (this.hitTest(root.char) == true) {
// depending on tipo acts in a different way
switch (this.tipo) {
case 0 :
// if type is coin, increase the score
score += 10;
break;
case 1 :
// if type is hammer, lose energy.
// If energy falls under 0, go to GameOver frame.
energy -= 10;
if (energy <= 0) {
clearInterval(nint);
root.gotoAndStop("gameover");
}
break;
}
// updates score and energy
score_txt.text = String(score);
energy_txt.text = String(energy);
// remove this clip
this.removeMovieClip();
}
// if, instead, objects falls under
// the lower limit of the stage, simply remove it.
if (this._y>450) {
this.removeMovieClip();
}
};
}
The game is done. You should test it and try to understand each single piece of code. This is very simple, next time we are going to see how to develop a more complex game. This was just to put you in the right mood.
Now create a home for your game, a game over frame and you are ready to go online.
If something went wrong, please download the complete fla from here.
See you soon!
Hey
Welcome to the new and awaited lesson about flash gamemaking! I know you all have been awaiting for the real stuff to begin, that’s it!
First of all, you have learned to control your main sprite with mouse and keyboard. So you are going to program a little application that will:
- Control your main character
- Create and control enemies
- Check general collisions - i.e. the events that happen when some char on the screen is hit by something else, like projectiles, enemies themselves, bonus or game screen bounds.
- Decrease or increase several variables attributed to some values. For example, score, energy, ammunition number.
- Check every now and then for special events to happen, like death of the main character, enemy destroyed, game over, game exit or anything.
This is the skeleton of your game.
Now we are focusing on a simple game for this lesson. We are programming something like Money Money, a game from a old (but very dear) site I worked on, the site was Naive.it. The game sees a piggy bank, that is a money box shaped like a pig, chasing money to increase its points, and trying to avoid hammers falling from the sky, that will make you loose energy. When energy is over, you are over. Otherwise it will go on forever. Let’s start doing something like this. We prefer using mouse controls for this game. This will leave the player the possibility to make the main char move faster than what we could achieve with keyboard.
Create a new fla document. Set the stage dimensions to 400×400 pixels at 30fps.
Start creating your character. We are not loosing time on making graphics first, so we are going to use a simple square for the main character. We are using the code for mouse control for it, so we are going to use onEnterFrame to check on every frame for the mouse position, and changing the sprite position as well. We can use a simple square movieclip, with pivot point set to its center, and we can give it the instance name “charâ€.
Place the char onto the stage, leaving it in the bottom part at the center. I will leave some pixels as the bottom margin.
Now, in the timeline, add a new layer, name it “actionsâ€, block it and then add this code to control the char sprite.
stop();
char.onEnterFrame = function () {
dx = this._x - _xmouse;
this._x -= dx/10;
}
Please test your game, you will see your square moving right and left as you move your mouse. You can notice two things.
- The square does not move vertically. This is because for this game, the sprite does not have to move but horizontally.
- If you drag your mouse out of the stage, the square follows it and get out of the stage. So we are going to implement some limiting in the horizontal movement.
We can change the code this way:
char.onEnterFrame = function () {
dx = this._x - _xmouse;
this._x -= dx/10;
if (this._x > 370) {
this._x = 370;
}
if (this._x < 30) {
this._x = 30;
}
}
So now, if we test the swf, we can see that the square will still follow the mouse, but it will stop at the right and left limits of the stage.
That’s almost all for the main char movement.
Now we are going to create the object dispatcher.
What is the object dispatcher? Well, it is just a fantasy name for the movieclip that will handle coin creation. This time it will summon a coin to fall from the ceiling every n milliseconds. In other kind of games, maybe this will help creating an enemy dispatcher, that will serve your game with enemy created infinitively.
Anyway. The method is quite easy. Making it actionscript, it more difficult but still not impossible.
We must create a symbol in library, with linkage name “coinâ€. Every n milliseconds, the dispatcher will create a clone of “coin†and attach it to the stage. After attaching it, each coin should fall, so we are going to create the code for each coin to make it move. Moreover, we should evaluate collisions of coins with the character, to increase the score.
But the dispatcher has an evil side too. It will create not only coins, but even hammers, that can damage you, if they hit.
So, let’s start. Create a simple star using the polystar tool (or by hand). Create a blue star and a red star. We are going to use the blue one as a coin, and the red one as a hammer. So please make them movieclips and give them the linkage name of “coin†and “hammerâ€. Now you can delete them from the stage, they are not needed anymore.
Ops. Time has finished :D
Next time we are going to see how to implement the mechanic we discuss about the dispatcher in actionscript. Prepare yourself, next one will be a tough one!
See you and experiment by yourself!
Do you want to learn how to control your characters using the Keyboard? Learn how in this very simple tutorial, that build the basis of advanced game programming that will come in the next lessons!
Sit down, lesson is up, here!
Enjoy!