
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 1.73 KB | hits: 7 | expires: Never
//Many of these throughout the rule section of the game.
//They are loosely connected by the parameters.
public static void RatCollision(GameLevel level, Collision<Hero,Rat> impact)
{
impact.First.HP--;
impact.Second.Movement.bounce();
level.Sounds.Play(Sounds.RatSqueal);
}
// The engine will take all rules and build the game loop itself. They are not manually connected.
// Generated at compile time:
foreach(var collision in collisionList)
{
CollisionType1 = Typeof(collision.First);
CollisionType2 = Typeof(collision.First);
If (CollisionType1 == Hero && CollisionType2 == Rat)
{
HeroCollisions.RatImpact(level, new Collision(collision.First, collision.Second));
}
else if (CollisionType1 == Rat && CollisionType2 == Hero)
{
HeroCollisions.RatImpact(level, new Collision(collision.Second, collision.First));
}
//Many more collision type checks and calls.
}
//A game of tag in pseudocode.
class gameObject<T>
{
T Movement
int x
int y
int width
int height
move()
render()
}
class Hero : gameObject<Player8WayMovement>
{
}
class Opponent : gameObject<ComputerAvoidance8WayMovement>
{
avoid(gameObject)
}
//Level:
main
{
var hero = new Hero()
Add(hero)
var opponent = new Opponent()
opponent.avoid(hero)
Add(opponent)
}
//rules:
public static function win(Collision<Hero,Opponent> impact, gameLevel level)
{
impact.Second.Destroy()
level.ShowMessage("You caught him!")
level.Sound.Play(Sounds.Fanfair)
}
public static function mockingSound(GameLevel level)
{
RestrictBySeconds(10)
level.Sound.Play(Sounds.OpponentMocking)
}
public static function addObstacle(GameLevel level)
{
RestrictBySeconds(14)
var pointBetweenPlayerAndOpponent = point(5,5) //for example
level.CreateObject<obstacle>(point)
}