Page 439 - 완) I MDP 프로젝트 작품 보고서(전체과 1학년)1.6
P. 439
position = this.constants.LEFT_CUP_POSITION;
break;
case 1 /* Middle */:
position = this.constants.MIDDLE_CUP_POSITION;
break;
case 2 /* Right */:
position = this.constants.RIGHT_CUP_POSITION;
break;
default:
position = new ShellGame.Position(0, 0);
break;
}
this.hasBall = hasBall;
this.game = game;
var image = new Image(); //image객체 저장
image.src = imageUrl; //image의 URL
var self = this; //this를 다른 함수 안에서도 똑같이 사용하기 위해서
self변수에 저장
image.onload = function () { //이미지 속성값 지정 및 생성
var width = image.width * self.constants.SCALE_FACTOR;
var height = image.height * self.constants.SCALE_FACTOR;
var x = position.X - width / 2;
var y = position.Y - height / 2;
if (self.hasBall) { //공이 있는경우
var ballPosition = new ShellGame.Position(x + width / 2, y + height * 0.8);
self.ball = new ShellGame.Ball(self.constants.BALL_IMAGE_URL, self.game,
ballPosition);
}
self.kineticImage = new Kinetic.Image({
x: x,
y: y,
image: image,
width: width,
height: height
});
self.kineticImage.on("click", function () {
if (self.game.CanRaiseCups) {
self.selected = true;
self.game.guess(self.hasBall);
if (!self.raisedUp) {
- 432 -