var bullets = [];var bullet_num = 0; // how many bullets where shotvar bullet_distance = 32; //distance of bullets journey in pixelsvar bullet_sprite = "bullet.rss"//Bullet is an Object with argumentsfunction Bullet(name, start_x, start_y, vel_x, vel_y){ this.name = name; this.startX = start_x; this.startY = start_y; this.xVelocity = vel_x; this.yVelocity = vel_y; this.speed = 1; //general speed of bullet CreatePerson(name, bullet_sprite, true); // name of this bullet; SetPersonX(name, start_x); SetPersonY(name, start_y); switch(direction) { case direction: SetPersonDirection(name,direction);break; //north -y }}//creates and positions bullet according to player directionfunction CreateBullet(player){ var x = 0, y = 0; switch(direction) { case "north": y = -1;break; //north -y case "south": y = 1;break; //south +y case "west": x = -1;break; //west -x case "east": x = 1;break; //east x } bullet_num++; //creat a new instance for Bullet(name, start_x, start_y, vel_x, vel_y) and store inside bullets array bullets.push(new Bullet("bullet: " + bullet_num, GetPersonX(player) + x * 32, GetPersonY(player) + y * 32, x, y));}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); QueuePersonCommand(this.name,COMMAND_ANIMATE,true); // pythagoras theorem a^2 + b^2 = c^2 var dx = x - this.startX; var dy = y - this.startY; var dist = Math.sqrt(dx*dx + dy*dy); if (dist >= bullet_distance) { this.dead = true; var obstruction = GetObstructingPerson(this.name, x, y); if (obstruction != "") { bullet_sprite = GetPersonSpriteset(obstruction); SetPersonSpriteset(this.name,bullet_sprite) } }}function UpdateBullets(){ for (var i = 0; i < bullets.length; ++i) { bullets[i].update(); if (bullets[i].dead) { DestroyPerson(bullets[i].name); bullets.splice(i, 1); i--; } }}
CreatePerson(name, bullet_sprite, true);
function Bullet(name, start_x, start_y, vel_x, vel_y, direction){ this.name = name; this.startX = start_x; this.startY = start_y; this.xVelocity = vel_x; this.yVelocity = vel_y; this.speed = 1; //general speed of bullet CreatePerson(name, 'bullet.rss', true); // name of this bullet; SetPersonSpriteset(name, bullet_sprite); SetPersonX(name, start_x); SetPersonY(name, start_y); SetPersonDirection(name, direction);}function CreateBullet(player){ var x = 0, y = 0; switch(direction) { case "north": y = -1;break; //north -y case "south": y = 1;break; //south +y case "west": x = -1;break; //west -x case "east": x = 1;break; //east x } bullet_num++; //creat a new instance for Bullet(name, start_x, start_y, vel_x, vel_y) and store inside bullets array bullets.push(new Bullet("bullet: " + bullet_num, GetPersonX(player) + x * 32, GetPersonY(player) + y * 32, x, y, direction));}
if (dist >= bullet_distance) { this.dead = true; var obstruction = GetObstructingPerson(this.name, x, y); if (obstruction != "") { bullet_sprite = GetPersonSpriteset(obstruction); SetPersonSpriteset(this.name, bullet_sprite); } }
if (dist >= bullet_distance) { this.dead = true; var obstruction = GetObstructingPerson(this.name, x, y); if (obstruction != "") { bullet_sprite = obstruction + ".rss" } }}
if (obstruction != "" && obstruction != this.name)
if (obstruction != "" && obstruction != "bullet:"+bullet_num)
if (obstruction != "" && obstruction != "bullet:"+bullet_num++)
if (obstruction != "" && obstruction != "bullet:"+bullet_num--)
if (obstruction != "" && obstruction.indexOf("bullet:") < 0)
var name = string.substring(0, 5); // if the name is expected to have 5 characters in it before numbers start.
var bullets = [];var bullet_num = 0; // how many bullets where shotvar bullet_distance = 32; //distance of bullets journey in pixelsvar bullet_sprite = "ghost1.rss"//Bullet is an Object with argumentsfunction Bullet(name, start_x, start_y, vel_x, vel_y){ this.name = name; this.startX = start_x; this.startY = start_y; this.xVelocity = vel_x; this.yVelocity = vel_y; this.speed = 1; CreatePerson(name,bullet_sprite, true); SetPersonX(name, start_x); SetPersonY(name, start_y); SetPersonDirection(name,direction); }//creates and positions bullet according to player directionfunction CreateBullet(player){ var x = 0, y = 0; switch(direction) { case "north": y = -1;break; //north -y case "south": y = 1;break; //south +y case "west": x = -1;break; //west -x case "east": x = 1;break; //east x } bullet_num++; //creat a new instance for Bullet(name, start_x, start_y, vel_x, vel_y) and store inside bullets array bullets.push(new Bullet("shot"+bullet_num, GetPersonX(player) + x * 32, GetPersonY(player) + y * 32, x, y));}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); QueuePersonCommand(this.name,COMMAND_ANIMATE,true); // pythagoras theorem a^2 + b^2 = c^2 var dx = x - this.startX; var dy = y - this.startY; var dist = Math.sqrt(dx*dx + dy*dy); if (dist >= bullet_distance) { this.dead = true; var obstruction = GetObstructingPerson(this.name, x, y); if (obstruction != "" && obstruction.indexOf("shot") < 0){ bullet_sprite = obstruction + ".rss" } }}function UpdateBullets(){ for (var i = 0; i < bullets.length; ++i) { bullets[i].update(); if (bullets[i].dead) { DestroyPerson(bullets[i].name); bullets.splice(i, 1); i--; } }}
if (dist >= bullet_distance) this.dead = true; else { var obstruction = GetObstructingPerson(this.name, x, y); if (obstruction != "" && obstruction.indexOf("shot") < 0) { bullet_sprite = obstruction + ".rss" } }