As a side project, I'm trying to create a scrolling shooter. I'm currently having a problem with moving the player ship, and was wondering if anyone could assist me. Please don't post criticism of how I code as I'm still getting to grips with this type of jQuery development (more accustomed to standard website features). If it's of use to anyone answering my questions, I'm using jQuery 1.4.2.
Problem 1: After having problems using arrows for ship movement, I've decided to go with mouse-based movement. I can't seem to limit the mouse movement to the left and right edges of my centered container, however. Is there an adjustment I can make to the following code so that the user cannot drag the mouse outside of the container unless they click an escape key (any, I can change it later)?
var x, y;
$("#game_container").mousemove(function(e){
$("#player_ship").fadeIn();
x = e.pageX - this.offsetLeft;
y = e.pageY - this.offsetTop;
$("#player_ship").css({"top": (y - 43) + "px"}); // Move ship to coordinate minus half ship height.
$("#player_ship").css({"left": (x - 42) + "px"}); // Move ship to coordinate minus half ship width.