OSDN Git Service

当たり判定の修正と敵キャラクターを踏んでダメージを与える動作の実装
[h58pcdgame/GameScriptCoreLibrary.git] / www / corelib / classes / HorizonalScrollStageClass.js
1
2 var HorizonalScrollStageClass = function()
3 {
4         HorizonalScrollStageClass.base.apply(this, []);
5
6         this.scrollX = 0;
7         this.scrollMaxX =1280 - 640;    //\83X\83e\81[\83W\82Ì\89¡\82Ì\92·\82³-640
8         
9 }.extend(GameStage, {
10         className: "HorizonalScrollStageClass",
11         timerTick: function(){
12
13                 HorizonalScrollStageClass.base.prototype.timerTick.call(this);
14                 if(this.userControlledCharacter){
15                         //\83L\83\83\83\89\83N\83^\81[\82ð\92Ç\94ö\82·\82é
16                         this.scrollTo(this.getScrollLocation());
17                 }
18                 //this.eachStageObject(function(f){
19                 //      f.movingSpeedY -= 1;
20                 //      return true;
21                 //});
22         },
23         
24         // \8eq\83X\83e\81[\83W\82Å\81A\91\80\8dì\92\86\83L\83\83\83\89\88È\8aO\82ð\92\86\90S\82É\8e\9d\82Á\82Ä\82«\82½\82¢\82Æ\82«\82Í\82±\82Ì\8aÖ\90\94\82ð\83I\81[\83o\81[\83\89\83C\83h\82·\82é
25         getScrollLocation: function(){
26                 var pos = 0;
27                 if(this.userControlledCharacter){
28                         return this.userControlledCharacter.origin.x - 320;
29                 }
30                 
31                 return 0;
32         },
33         draw: function(){
34                 this.drawBackground();
35                 this.drawAsPoint(this.scrollX, 0);
36         },
37         drawBackground: function(){
38                 if(this.background){
39                         //\89æ\96Ê\88Ê\92u\82É\8d\87\82í\82¹\82Ä\89æ\91\9c\82ð\83X\83N\83\8d\81[\83\8b\95\\8e¦\82·\82é
40                         var width = this.background.width;
41                         var pos = -((this.scrollX / 2) % width);
42                         for(;pos < this.background.width; pos += width)
43                         {
44                                 this.mainContext.drawImage(this.background, pos, 0, this.background.width, this.background.height);
45                         }
46                 } else{
47                         //\83L\83\83\83\93\83o\83X\82ð\91S\8fÁ\8b\8e
48                         this.mainContext.clearRect(0, 0, this.mainCanvas.width, this.mainCanvas.height);
49                 }
50                 if(this.collisionMapContext){
51                         this.collisionMapContext.clearRect(0, 0, this.collisionMapCanvas.width, this.collisionMapCanvas.height);
52                 }
53         },
54         
55         //\83X\83N\83\8d\81[\83\8b\82µ\82½\82¢\82Æ\82«\82É\81Atick\96\88\82É\8cÄ\82Ô\81B
56         scrollTo: function(x){
57                 this.scrollX += (x - this.scrollX) / 7;
58                 if(this.scrollX > this.scrollMaxX){
59                         this.scrollX = this.scrollMaxX;
60                 }
61                 if(this.scrollX < 0){
62                         this.scrollX = 0;
63                 }
64         }
65 });
66