OSDN Git Service

main.jsが動作しないバグ修正
[h58pcdgame/GameScriptCoreLibrary.git] / www / corelib / classes / MovableStageObjectClass.js
1 var MovableStageObjectClass = function(stage)
2 {
3         MovableStageObjectClass.base.apply(this, [stage]);
4         this.movingSpeed = new Point2D(0, 0);
5         //2 * hysteresis >= movingFriction\82Å\82 \82é\82±\82Æ\82ð\90\84\8f§\82·\82é\81B
6         //\82»\82¤\82Å\82È\82¢\8fê\8d\87\81A\96\80\8eC\82Å\82Ì\8c¸\91¬\8cã\82É\8a®\91S\82É\92â\8e~\82Å\82«\82È\82¢\89Â\94\\90«\82ª\82 \82é\81B
7         this.movingFriction = 90;
8         this.hysteresis = this.movingFriction / 2;
9         
10         
11 }.extend(StageObject, {
12         tick: function(){
13
14
15                 //\96\80\8eC\8f\88\97\9d
16                 if(this.movingSpeed.x < -this.hysteresis){
17                         this.movingSpeed.x += this.movingFriction / this.stage.manager.tickPerSecond;
18                 } else if(this.movingSpeed.x > this.hysteresis){
19                         this.movingSpeed.x -= this.movingFriction / this.stage.manager.tickPerSecond;
20                 } else{
21                         this.movingSpeed.x = 0;
22                 }
23                 if(this.movingSpeed.y < -this.hysteresis){
24                         this.movingSpeed.y += this.movingFriction / this.stage.manager.tickPerSecond;
25                 } else if(this.movingSpeed.y > this.hysteresis){
26                         this.movingSpeed.y -= this.movingFriction / this.stage.manager.tickPerSecond;
27                 } else{
28                         this.movingSpeed.y = 0;
29                 }
30                 
31                 //\89^\93®\8f\88\97\9d
32                 this.origin.x += this.movingSpeed.x / this.stage.manager.tickPerSecond;
33                 this.origin.y += this.movingSpeed.y / this.stage.manager.tickPerSecond;
34                 
35                 //\95Ç\96Ê\92µ\82Ë\95Ô\82è\8f\88\97\9d
36                 if(this.origin.x < -this.frame.origin.x){
37                         //\8d\95Ç\96Ê
38                         this.origin.x = -this.frame.origin.x;
39                         this.movingSpeed.x = -this.movingSpeed.x;
40                 } else if(this.origin.x > this.stage.mainCanvas.width - (this.frame.origin.x + this.frame.size.x)){
41                         //\89E\95Ç\96Ê
42                         this.origin.x = this.stage.mainCanvas.width - (this.frame.origin.x + this.frame.size.x);
43                         this.movingSpeed.x = -this.movingSpeed.x;
44                 }
45                 if(this.origin.y < -this.frame.origin.y){
46                         //\8fã\95Ç\96Ê
47                         this.origin.y = -this.frame.origin.y;
48                         this.movingSpeed.y = -this.movingSpeed.y;
49                 } else if(this.origin.y > this.stage.mainCanvas.height - (this.frame.origin.y + this.frame.size.y)){
50                         //\89º\95Ç\96Ê
51                         this.origin.y = this.stage.mainCanvas.height - (this.frame.origin.y + this.frame.size.y);
52                         this.movingSpeed.y = -this.movingSpeed.y;
53                 }
54
55         }
56 });
57
58 //child : CharacterClass
59
60