Skip to content

Instantly share code, notes, and snippets.

@jaytaph
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaytaph/9157928 to your computer and use it in GitHub Desktop.
Save jaytaph/9157928 to your computer and use it in GitHub Desktop.
game framework
How do we create a game?
Could it be (simply) javascript like system? In such a way that we can interact with a game engine where we add our stuff?
something like (don't mind the horrible JS code) :
game = new Game.Game("my game name", {
boxed_game : true
playing_field : [ 51.5, -0.9, 51.6, -0.6 ],
});
var blue_team = new Game.Team("the blue team", { max_players : 10 } );
game.addTeam(blue_team);
var red_team = new Game.Team("the red team", { max_players : 10 } );
game.addTeam(red_team);
for (i=0; i!=10; i++) {
Game.addPlayer("Player "+i, { ai: true, team : red_team });
}
red_flag = Game.Object("red team flag", { coords: game.getRandomCoordinate(); }, weight : -1).onPickup(function(entity, distance) {
if entity.team == red_team {
this.drop(); // Flag from the team cannot be moved by a team member
}
if entity.team == blue_team {
entity.score = 1000; // Since no other place will add scores, this player and thus team, will win
Game.Won();
});
blue_flag = Game.Object("blue team flag", { coords: game.getRandomCoordinate(); }, weight : -1).onPickup(function(entity, distance) {
if entity.team == blue_team {
this.drop(); // Flag from the team cannot be moved by a team member
}
if entity.team == red_team {
entity.score = 1000; // Since no other place will add scores, this player and thus team, will win
Game.Won();
}
});
// When a player comes into range of another player
Game.Player.onRange(entity) {
if (entity.team != this.team) { // player from another team
Game.pushNotification(entity, "Oh noes! Seems that " + entity.name + " has found you. Duck and cover!");
Game.pushNotification(this, "You are in range of player " + entity.name + ". Fire at will!");
}
}
Player.hit(entity, distance) {
if (Game.angleBetween(this, entity) == 180) {
Game.pushNotification(this, "Aargh! " + entity.name + " has struck you from the south!\nYou loose " + hitpoints + "XP");
// this.life takes care of 0 or negative values
this.life -= hitpoints;
hitpoints = (100 / Game.Random(0, distance));
}
}
Player.onDie() {
Game.pushNotification("You are killed in action. Over 2 minutes you will be able to enter the game");
Game.respawn(this, 120); // User is automatically respawned after 2 minutes
}

Game Components

Game

A game holds everything needed to play actual games. They have certain properties, like marked area's (players will be alerted when they leave the playing field), start and/or end on certain times, etc. Games are in two different flavours:

  • Continuous games
    Will continue forever, people can enter and leave at will. The game however continues.

  • Boxed games
    Game can be limited to a certain time range. Players can also be limited to either registered players, or a fixed number of players.

Losing a game

Somehow, it must be defined how to fail the game. These constraints could be any of a player properties (for instance: lifepoints <= 0, or time-in-game > 5minutes etc). When a game is lost, either a player can respawn, or not.

Winning a game

A game must define how it can be won. If it's a timeboxed game, this could be the player with MAX(objects.value), or player with MAX(distance).

It could also be a player arriving at a certain position, or having finished a list of criteria (visit X number of places) etc.

Either a game can continue when won, or be stopped.

For instance, a timeboxed game could have a winning-criteria of player with MAX(objects.value), but has a timebox of 30 minutes. This means that after 30 minutes, the game stops, and the winning criteria will be matched.

Other winning game types, could be the last player standing, most distance covered, most kills, most objects etc.

Objects

Inanimated objects that by itself cannot be moved, but can interact with other objects. They can be moved when being picked up by an animated object such as entities.

Objects have certain properties like values, weight, range and certain statistical properties.

Question: Could an object interact with another object (either implictly or explicitly)? For instance, when a user picks up two objects and merge them together into a new object?

Entities

Animated objects (probably not extended from object itself). Entities are either real life players, moving around with a mobile device, or A.I. players, that are being controlled by the game server.

Entities are able to move around by updates of their coordinates. Entities have certain proprerties like a lifespan (lifepoints), a search-range (how far away can you spot objects or other entities). Entities can interact with either other entities (depending on their range) and can interact with other objects (pick up, drop). Entities are only capable of dropping objects that are currently in posession by that entity . You can only pick up objects that are within a certain range of that object. When an object has a certain weight, it's possible that entities by itself cannot pickup that object unless their strength > weight object + (combined weight of all picked up objects). Thus either dropping other objects until the condition is met, or using other type of objects onto itself that can either increase the holding capacity of the entity, or decrease the weight of the object.

Teams

An entity can be part of a team. It's up to the game itself to check the players team, and act accordingly.

Properties and methods

These are the properties and methods for a given object. They are maintained by the game engine, and used by a game to create your own game.

Object properties

  • visibility_range
    What is the range in which entities will "see" this object. 0 for invisible objects, -1 for always visibile. Invisible objects can be usefull for "storage". Only when a entity hits the same coordinates of the object, it will be able to detect the object (there is always a certain range available to counteract GPS accuracy).
  • Weight
    How "heavy" is an object. Depending on the user, it can or cannot be picked up. 0 for no weight, -1 for not being able to be picked up.
  • Value
    The value of the object. 0 for no value.
  • Location
    Lat/Long position of the current object.
  • Keeper
    the entity currently in posession of the object. Location will be updated together with the entity's location. null when object is not in posession of an entity.
  • Distance
    distance moved by this object
  • Keepers
    number of (unique) entities that picked up the object
  • Pickup_cnt
    number of times the object has been picked up
  • Drop_cnt
    number of times the object has been dropped
  • Ranged
    number of times the object was in the vincity of an entity. This number will be 0 when the object has a visibility_range of 0 or -1
  • Line_of_sight
    the objects and/or entities that are in a CLEAR LINE OF SIGHT of the object (for instance, you could be 20 meters away from an object, but there is a building blocking it).
  • Spells (todo: find a better name) A list of spells that are attached to this object. A spell can either add, mutate or destroy existing spells that are linked to this object.

object methods

  • inRangeObject(object, distance)
    Called when an object has been brought in range of another object. Will be called on every update as long the object is in range, until this function acknowledge the object (for instance, when you have a range of 100 meters, but only want to respond unless you are in direct line of sight, and closer than 50 mtrs).
  • inRangeEntity(entity, distance) Called when an entity is in range of an object. Will be called on every update as long as the entity is in range, until this function acknowledge the object.
  • outRangeEntity(entity) Called when an entity has left the range of the object. TODO: add hysteresis?
  • outRangeObject(entity) Called when an object has left the range of the object. TODO: add hysteresis?

Entity methods:

  • is_AI
    Is this a virtual player? 0 = no, 1 = yes
  • Name
    Name of the player.
  • Account
    Possibly some kind of account linked to this player (null when it's an AI player). Got things like name, email, etc
  • The players team

Team properties

  • Team name The name of the team
  • Players A list of all players on the team
  • Rank The current position of the team (if available)

Spell properties

  • uses How many times can this spell be used. 1 for only once, -1 for unlimited number of times

Spell methods

  • canInteractObject(object) Can this spell interact with the (kind of)object. Maybe only at certain times, at certain points, or for certain players (only one team, for instance).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment