Oh, I see, yeah Alpha123, that would be what he'll need, if he goes his route. He's drawing bullets on the render script (screen coordinates) which will need converting to the map coords for collision detection. But there's a simpler way.
What he'll want to do (to use Sphere's collision system) is to create the bullet as an entity rather than on screen, and use the Set/GetPersonX/Y() functions I showed him. SetPersonX/Y() ignores collision which is ideal when moving the bullet through terrain. In fact you can turn off terrain collision by setting
SetPersonTileObstructions("name", false); Then when you call
IsPersonObstructed("name", x, y), it'll only trigger when the bullet comes in contact with another person rather than a tile.
So that means to not use a render script and screen coordinates, and forego them for just using the map coordinates and setting a bullet with the SetPersonX/Y() functions as it moves.
I'd create an off-map representation of the bullet:
function Bullet(name, start_x, start_y, vel_x, vel_y)
{
this.name = name;
this.xVelocity = vel_x;
this.yVelocity = vel_y;
this.speed = 1;
CreatePerson(name, "bullet.rss", true); // name of this bullet;
SetPersonX(name, start_x);
SetPersonY(name, start_y);
IgnoreTileObstructions(name);
}
Bullet.prototype.update = function() {
SetPersonX(this.name, GetPersonX(this.name) + this.xVelocity * this.speed);
SetPersonY(this.name, GetPersonY(this.name) + this.yVelocity * this.speed);
}
Then when your hero creates a bullet you can do something like:
var bullets = [];
var bullet_num = 0;
function CreateBullet(hero)
{
var d = GetPersonDirection(hero);
var x = 0, y = 0;
switch(d) {
case "north": y = -1; break;
case "south": y = 1; break;
case "west": x = -1; break;
case "east": x = 1; break;
}
bullets.push(new Bullet("bullet: " + bullet_num, GetPersonX(hero) + x*16, GetPersonY(hero) + y*16, x, y);
}
function UpdateBullets()
{
for (var i = 0; i < bullets.length; ++i) bullets[i].update();
}
And then to attach it to the map engine:
function Update()
{
// your update script stuff
UpdateBullets();
}
function game() {
// your game code
SetUpdateScript("Update()");
MapEngine("map.rmp", 60);
}
Then you can also add collision detection to the update portion of the bullet:
Bullet.prototype.update = function() {
var x = GetPersonX(this.name) + this.xVelocity * this.speed;
var y = GetPersonY(this.name) + this.yVelocity * this.speed;
SetPersonX(this.name, x);
SetPersonY(this.name, y);
if (IsPersonObstructedAt(x, y)) {
this.dead = true;
}
}
function UpdateBullets()
{
for (var i = 0; i < bullets.length; ++i) {
bullets[i].update();
if (bullets[i].dead) { bullets.splice(i, 1); i--; }
}
}
Then if you want to get the name of the entity the bullet collided with (to do damage) you can use the GetObstructingPerson()
Bullet.prototype.update = function() {
var x = GetPersonX(this.name) + this.xVelocity * this.speed;
var y = GetPersonY(this.name) + this.yVelocity * this.speed;
SetPersonX(this.name, x);
SetPersonY(this.name, y);
if (IsPersonObstructedAt(x, y)) {
this.dead = true;
var name = GetObstructingPerson(this.name, x, y);
if (name != "") {
// here we have an obstructing entity..
}
}
}
edit: fixed code tags