On the update script of your character paste this
if (this.y > project.height-(this.height/2)) {
this.y = project.height-this.height/2;
}
if (this.y < (this.height/2)) {
this.y = (this.height/2);
}
if (this.x < (this.height/2)) {
this.x = (this.height/2);
}
if (this.x > project.width-(this.height/2)) {
this.x = project.width-(this.height/2);
}