Posts

Javascript Getter and Setters; jQuery .data() function

Image
For many kinds of games, a given character is likely to have a health level.  After taking enough damage, the character's health level falls to zero, at which point the character can be seen to run some kind of death animation and it's game over.  To track the health level of a given character, or to keep track of any other kind of character-relevant data for that matter (e.g. magic, experience, etc.), you can create arbitrary attributes to store data in the DOM element that represents a character.  jQuery offers the short-hand .data() function, which can be called on any jQuery element and which can double as a getter and a setter, depending on how many arguments are passed into the function. We'll see this in action by hammering out some simple code to simulate a character taking damage, either as result of being attacked by enemies or as a result of being hit by the player.  Check out the movie below, which features the by-now famous wingman character provided courte

Texture Animations

Image
Today, we're going to learn how to make a game character that can be used to develop full-fledge, interactive games.  A really nifty game character should have some basic functionality common to many games: ability to respond to collisions, ability to respond to user input, ability to run animations, etc.  The assets for this game character are from kenney.nl , and the final character should look like this in your web browser: For today, we'll focus on enabling our game character to run animations.  In a text editor, create a new html file and make sure to include the necessary <script> and <link> tags needed to include jQuery, jQuery UI, and Bootstrap.  For the animated game character, you will only really need jQuery, but I like to include jQuery UI and Boostrap as a matter of habit. Your custom css and javascript files are app.css and app.js , respectively, each of which should be located in dedicated folders ( css/ and js/ directories respectively).