| |

Playing around with Javascript and impact.js

The Invisible Developer had commented that I write an awful lot about SAS and maybe I should write about some other language. For Christmas last year, someone gave me an impact.js license so I made a little game where players drop snares to catch rabbits and collect berries. This doesn’t have much educational value,  I was just playing around. I thought it would be amusing to have the food items they collect in the game be equal in value to the number of calories in that item.

If you have impact and wanted to do this yourself, here is what you would do.

1. Basic stuff – include game.entities.berry, game.entities.rabbit and any other food item in your main.js script. It goes right at the beginning with any other entities you require

 

ig.module(
‘game.main’
)
.requires(
‘game.entities.berry’,
‘game.entities.rabbit’,

— more stuff —

)

2. Create the score in your game info function that stores information

GameInfo = new function(){
this.food = 0;
— other stuff you want to initialize
}

 

3. When you extend the game to add your own cool stuff include an addFood function

MyGame = ig.Game.extend({

— init and other functions

addFood: function(amt){
//pickup item
GameInfo.food += amt; //add caloric value to the food score
}
,

— draw and other functions

 

4. To each entity script, add a function that defines how the player gets the food. Here are two examples.

Collecting berries

In the case of the berries, the player will just walk by the bushes and collect the berries. Think Pac Man!

In your berry.js file add a check function like this

EntityBerry = ig.Entity.extend({

— other stuff

check: function(other){
if (other.name == “player”){
ig.game.addFood(5);
this.kill();
}}
})

So …. it is about 5 calories per berry. When the player walks by a bush and comes into contact with a berry (picks the berry), the berry disappears and the player’s food count goes up by 5.

Snaring rabbits

Here is a second example. In this one, they drop snares around the virtual woods and when they snare a rabbit they get 1,000 points which is the approximate calorie content of a dressed rabbit, according to the USDA Nutrient database . I assumed this yielded an average of 2 pounds of meat.

For my rabbit I have extended the rabbit.js script as follows

EntityRabbit = ig.Entity.extend({

— other stuff

kill: function(other){
ig.game.addFood(1000);
this.parent();
}
})

But what is going to kill my rabbits? The snares, of course, so I added this into my snare.js script

EntitySnare = ig.Entity.extend({

— other stuff

check: function(other){
if (other.name == “rabbit”){
other.receiveDamage(100,this) ;
ig.game.addFood(1000);

}}
})

Since the rabbit only has 100 health points, that kills it off so your rabbit disappears and your food value goes up by 1,000.

As you can see, you could easily add shooting deer, buffalo and other food in the same way.

——————————————–

After I had played around with this for a bit, I thought it was a waste to just trash it so I put it into our upcoming game, Fish Lake, in between levels. When they finish Level 3, they play this game and then go on to Level 4. Our main game is 3-d, this is just a little interlude. I like to throw surprises into the game so kids like it and keep playing.

—————————————-

Someone in Los Angeles was very upset by our Spirit Lake game where players shoot wolves and buffalo. She said she just could not kill animals. (The Invisible Developer asked me if she was aware that they were virtual animals and not real.) I told her that our games are based on Native American history and history is what happened, not what you think should have happened or wanted to happen. In fact, there is a very touching story in Fish Lake narrated by Debbie Gourneau of the Turtle Mountain reservation on how many people died of starvation and how many more would have died were it not for the jackrabbits.

——————————

buffalo in the snowClick here to get Spirit Lake: The Game for $9.99

 

P. S. The amount of information produced by USDA is nothing short of amazing, and I don’t say that just because they funded are grant. They really are incredible.

 

 

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *