AI for enemies (OSD – SC)

Here is a nifty code for your enemies, it’s pretty basic but you judge for yourself… don’t mind the Modulo symbol, you can change tht to add or multiply…

If you know your maths this will be a click in the head, you’ll figure out what it will exactly do, but if you ever need help you can always email :P (sway-emo@hotmail.com), but nuff said, her’s the code:

onClipEvent (enterFrame) {
 aX = _root.a._x;
 aY = _root.a._y;
 findX = (aX-_x)/(aX%aY-10);
 //change to findX = (aX-_x)/(aX%aY/2) for teleporting or simpler findX = (aX-_x)/(aX%aY-10)
 findY = (aY-_y)/(aY%aX+10);
 setProperty(”", _x, _x+findX);
 setProperty(”", _y, _y+findY);
 if (_x>aX-10) {
  _xscale = -100;
 }
 else if (_x<aX+10) {
  _xscale = 100;
 }
 if (this.mHit(”Y”, _root.a/2)) {
  gotoAndStop(1);
 } else {
  gotoAndStop(2);
 }
}
onClipEvent (enterFrame) {
 this.swapDepths(this._y);
}

Download link is

HERE

And optionally you can add this to your timeline:

MovieClip.prototype.mHit = function(w, ww) {
 //what with what
 switch (w) {
 case “:legs” :
  if (this.hitTest(ww._x, ww._y+(ww._height-ww._height/2), true)) {
   return true;
  } else {
   return false;
  }
  break;
 case “Y” :
  if (this.hitTest(ww._x, ww._y+9.75, true)) {
   return true;
  } else {
   return false;
  }
  break;
 case “X” :
  if (this.hitTest(ww._x, ww._y, true)) {
   return true;
  } else {
   return false;
  }
  break;
 case “:hands” :
  if (this.hitTest(ww._x+8, ww._y+9.75, true)) {
   return true;
  } else {
   return false;
  }
  break;
 }
};

 

Basics of A game

Tutorial

To succeed in creating a game, you will have to learn the basics, here is a directory chart showing how and why these they are needed in a game:

******MOVEMENT

_x: Horizintal view of movement(move from side to side), example: _x -= runSpeed/2;
_y: Vertical view of movement(move from up to down), example: _y += gravityForce;

******HITTING

_x: Position of the horizontal area where an instance is placed, example: _x = 350;
_y: Position of vertical area where an instance is placed, example: _y = 275;
hitTest(): Boolean(true/false), Determines if an instance has collided w/Something, example: character = character.hitTest(_root.enemy) ?: hp--: _x = normX;

******MATH

Math.ceil(): Rounds pronumeral/var/number defined to the highest whole number, example: Math.ceil(49);
Math.floor(): Rounds pronumeral/var/number defined to the lowest whole number, example: Math.floor(43);
Radians: An arc of a circle which is equal to the radius, or the angle measured by the arc, example: _rotation = Int(Math.PI/180*90);

List will get updated whenever I Have time…

Simple ball physics game

OPEN SOURCE(DOWNLOAD–>)

This was created some few days ago… it’s a simple one frame game… the four levels are in a movieclip container  it’s open source so if you like games which have gravity, friction and movement, then you can download it:

HERE

(PUBLISHING PROJECTS IS ONLY ALLOWED BY AUTHOR)