I want to make the bullet change its spriteset to the obtruding person's spriteset so you "steal" that entity's 'soul'. I could swear my codding was right but I'm getting an error message. I don't understand whats wrong. The error message is attached.
var bullets = [];
var bullet_num = 0; // how many bullets where shot
var bullet_distance = 32; //distance of bullets journey in pixels
var bullet_sprite = "bullet.rss"
//Bullet is an Object with arguments
function 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 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));
}
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--; }
}
}
Line 22
CreatePerson(name, bullet_sprite, true);