Skip to content

Instantly share code, notes, and snippets.

@Radnen
Last active September 6, 2016 00:15
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 Radnen/e7c11cc7fe187f634d0e7b9f0ab7873c to your computer and use it in GitHub Desktop.
Save Radnen/e7c11cc7fe187f634d0e7b9f0ab7873c to your computer and use it in GitHub Desktop.
/**
* Script: actor.js
* Written by: Radnen
* Updated: 5/10/2012
**/
function Actor(name)
{
this.name = name;
this.dx = 0;
this.dy = 0;
}
Actor.prototype = {
get angle() { return GetPersonAngle(this.name); },
set angle(val) { SetPersonAngle(this.name, val); },
get layer() { return GetPersonLayer(this.name); },
set layer(val) { SetPersonLayer(this.name, val); },
get x() { return GetPersonX(this.name); },
set x(val) { SetPersonX(this.name, val); },
get y() { return GetPersonY(this.name); },
set y(val) { SetPersonY(this.name, val); },
get speed() { return GetPersonSpeedX(this.name); },
set speed(val) { SetPersonSpeed(this.name, val); },
get direction() { return GetPersonDirection(this.name); },
set direction(val) {
SetPersonDirection(this.name, val);
this.dx = 0; this.dy = 0;
switch (val) {
case "north": this.dy = -1; break;
case "south": this.dy = 1; break;
case "west": this.dx = -1; break;
case "east": this.dx = 1; break;
}
},
get isQueueEmpty() { return IsCommandQueueEmpty(this.name); },
get exists() { return DoesPersonExist(this.name); },
get base() { return GetPersonBase(this.name); },
get baseWidth() { return this.base.x2 - this.base.x1; },
get baseHeight() { return this.base.y2 - this.base.y1; },
get visible() { return IsPersonVisible(this.name); },
set visible(val) { SetPersonVisible(this.name, val); },
get spriteset() { return GetPersonSpriteset(this.name); },
set spriteset(val) { SetPersonSpriteset(this.name, val); },
get frame() { return GetPersonFrame(this.name); },
set frame(val) { SetPersonFrame(this.name, val); },
get offsetX() { return GetPersonOffsetX(this.name); },
set offsetX(val) { SetPersonOffsetX(this.name, val); },
get offsetY() { return GetPersonOffsetY(this.name); },
set offsetY(val) { SetPersonOffsetY(this.name, val); },
get ignoreOthers() { return IsIgnoringPersonObstructions(this.name); },
set ignoreOthers(val) { IgnorePersonObstructions(this.name, val); },
get ignoreTiles() { return IsIgnoringTileObstructions(this.name); },
set ignoreTiles(val) { IgnoreTileObstructions(this.name, val); },
get width() { return GetPersonValue(this.name, "width"); },
get height() { return GetPersonValue(this.name, "height"); },
get frameRevert() { return GetPersonFrameRevert(this.name); },
set frameRevert(val) { SetPersonFrameRevert(this.name, val); },
get mask() { return GetPersonMask(this.name); },
set mask(val) { SetPersonMask(this.name, val); }
}
Actor.prototype.clearQueue = function() { ClearPersonCommands(this.name); }
Actor.prototype.destroy = function() { DestroyPerson(this.name); }
Actor.prototype.setXY = function(x, y) {
this.x = x;
this.y = y;
}
Actor.prototype.setOffsetXY = function(x, y) {
this.offsetX = x;
this.offsetY = y;
}
Actor.prototype.move = function(direction, tiles) {
tiles *= GetTileWidth();
while (tiles--) { this.queueCommand(direction, false); }
}
Actor.prototype.queueCommand = function(command, immediate) {
QueuePersonCommand(this.name, command, immediate);
}
Actor.prototype.create = function(spriteset, direction, x, y, layer) {
if (!this.exists) CreatePerson(this.name, spriteset, true);
if (layer != undefined) this.layer = layer;
if (direction != undefined) this.direction = direction;
if (x != undefined) this.x = x || 0;
if (y != undefined) this.y = y || 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment