OSDN Git Service

stage scroll 実装
authorttwilb <ttwilb@users.sourceforge.jp>
Tue, 6 Aug 2013 04:52:41 +0000 (13:52 +0900)
committerttwilb <ttwilb@users.sourceforge.jp>
Tue, 6 Aug 2013 04:52:41 +0000 (13:52 +0900)
www/corelib/classes/BlockClass.js
www/corelib/classes/CharacterClass.js
www/corelib/classes/GameStageClass.js
www/corelib/classes/HorizonalScrollStageClass.js
www/corelib/classes/MainCharacterClass.js [new file with mode: 0644]
www/corelib/classes/MovableStageObjectClass.js
www/corelib/classes/OperatedCharacterClass.js
www/corelib/classes/StageObjectClass.js
www/corelib/header.js

index 7542b60..32a50d2 100644 (file)
@@ -6,7 +6,7 @@ var BlockClass = function(ownerStage, image)
        this.image = img;
        
 }.extend(StageObject, {
-       draw: function(){
-               this.stage.mainContext.drawImage(this.image, this.origin.x, this.origin.y, 32, 32);
+       draw: function(x, y){
+               this.stage.mainContext.drawImage(this.image, x, y, 32, 32);
        }
 });
\ No newline at end of file
index 960ae01..2bb88de 100644 (file)
@@ -1,12 +1,38 @@
 
-var CharacterClass = function(stage)
+//images \82É\82Í\8f\89\8aú\8fó\91Ô\82Å\95`\89æ\82µ\82½\82¢\89æ\91\9c\82Ì\83t\83@\83C\83\8b\96¼\82Ì\83\8a\83X\83g\81i\83A\83j\83\81\81[\83V\83\87\83\93\82³\82¹\82é\81j\82ð\8ew\92è
+var CharacterClass = function(stage, images /* , images2, ... */)
 {
        CharacterClass.base.apply(this, [stage]);
-       
        //\83L\83\83\83\89\93Æ\8e©\82Ì\8b@\94\\81i\82½\82Æ\82¦\82Î\8dU\8c\82\82â\91\8a\8eè\82ª\93\96\82½\82Á\82Ä\82«\82½\82Æ\82«\82Ì\82 \82½\82è\94»\92è\82È\82Ç)
        
+       this.interval = 30;
+       this.imageState = -1;
+       this.imageIndex = 0;
+       this.imageList = [];
+       for(var i = 1; i < arguments.length; i++)
+       {
+               var a = [];
+               for(var f in arguments[i])
+               {
+                       var img = document.createElement('img');
+                       img.src = "images/" + arguments[i][f];
+                       a.push(img);
+               }
+               this.imageList.push(a);
+       }
+       if(images != null)
+       {
+               this.imageState = 0;
+       }
+       
+       this.isFirst = true;
+       this.lastImage = null;
+       
 }.extend(MovableStageObjectClass, {
-       draw: function(){
+       draw: function(x, y){
+               this.stage.mainContext.drawImage(this.lastImage, x, y, 32, 32);
+
+               /*
                //\8cÊ\82Ì\95`\89æ
                this.stage.mainContext.save();
                this.stage.mainContext.fillStyle = "rgba(" + (((11*this.frame.size.x) & 0x7f) + 0x80) + "," + (((19*this.frame.size.x) & 0x7f) + 0x80) + "," + (((17*this.frame.size.x) & 0x7f) + 0x80) + ",0.5)";
@@ -14,10 +40,36 @@ var CharacterClass = function(stage)
                this.stage.mainContext.restore();
                //\8fÕ\93Ë\83}\83b\83v\82É\95`\89æ
                strokeRect(this.stage.collisionMapContext, this.origin.x + this.frame.origin.x, this.origin.y + this.frame.origin.y, this.frame.size.x, this.frame.size.y);
+               */
        },
        tick: function(){
                MovableStageObjectClass.prototype.tick.apply(this, []);
-
+               
+               if(this.stage.manager.tickCount % this.interval == 0 || this.isFirst)
+               {
+                       this.isFirst = false;
+                       if(this.imageState != -1)
+                       {
+                               if(this.imageList[this.imageState])
+                               {
+                                       if(this.imageList[this.imageState].length > 0)
+                                       {
+                                               if(this.imageIndex >= this.imageList[this.imageState].length) this.imageIndex = 0;
+                                               this.lastImage = this.imageList[this.imageState][this.imageIndex];
+                                               this.imageIndex ++;
+                                       }else
+                                       {
+                                               this.lastImage = null;
+                                       }
+                               }else
+                               {
+                                       this.lastImage = null;
+                               }
+                       }else
+                       {
+                               this.lastImage = null;
+                       }
+               }
        }
 });
 
index c2236a3..251a30d 100644 (file)
@@ -72,6 +72,7 @@ GameStage.prototype = {
        },
        draw: function(){
                this.drawBackground();
+
                this.drawAsPoint(0, 0);
        },
        drawAsPoint: function(x, y){
@@ -137,6 +138,11 @@ GameStage.prototype = {
                                f(stgobj);
                        }
                }
+       },
+       moveTo : function(obj, x, y){
+               //\96{\97\88\82Í\82±\82±\82É\93\96\82½\82è\94»\92è\8f\88\97\9d\82ð\93ü\82ê\82é
+               obj.origin.x = x;
+               obj.origin.y = y;
        }
 };
 
index d9eca9c..ef5e951 100644 (file)
@@ -5,7 +5,7 @@ var HorizonalScrollStageClass = function(opCharacter)
        
        //\8c»\8dÝ\91\80\8dì\91Î\8fÛ\82É\82È\82Á\82Ä\82¢\82é\83L\83\83\83\89\83N\83^\81[\81B
        this.operatingCharacter = opCharacter;
-       
+
        //\94w\8ci\82Ì\89æ\91\9c
        this.background = null;
        
@@ -14,15 +14,17 @@ var HorizonalScrollStageClass = function(opCharacter)
        
 }.extend(GameStage, {
        timerTick: function(){
-       //console.log(  HorizonalScrollStageClass.base);
+
                HorizonalScrollStageClass.base.prototype.timerTick.call(this);
-               if(this.operatingCharacter)     this.scrollX = this.operatingCharacter.origin.x;
+               if(this.operatingCharacter != null)     this.scrollX = this.operatingCharacter.origin.x - 320;
                if(this.scrollX > this.scrollMaxX) this.scrollX = this.scrollMaxX;
+               if(this.scrollX < 0) this.scrollX = 0;
        },
        draw: function()
        {
                this.drawBackground();
-               this.drawAsPoint(scrollX, 0);
+               
+               this.drawAsPoint(this.scrollX, 0);
        },
        drawBackground: function(){
                if(this.background)
diff --git a/www/corelib/classes/MainCharacterClass.js b/www/corelib/classes/MainCharacterClass.js
new file mode 100644 (file)
index 0000000..cb3a852
--- /dev/null
@@ -0,0 +1,30 @@
+//OperatedCharacterClass : \89½\8eÒ\82©\82É\82æ\82Á\82Ä\91\80\8fc\82³\82ê\82Ä\82¢\82é\83L\83\83\83\89(\93G\83L\83\83\83\89)
+//MainCharacter : \83L\81[\83{\81[\83h\82Ì\91\80\8dì\82ª\94½\89f\82³\82ê\82é\83\81\83C\83\93\83L\83\83\83\89
+
+var MainCharacterClass = function(stage, images){
+       MainCharacterClass.base.apply(this, arguments);
+       
+       this.upArrowDown = false;
+       
+}.extend(OperatedCharacterClass, {
+       tick : function()
+       {
+               MainCharacterClass.base.prototype.tick.apply(this);
+               
+               if(this.stage.manager.keyState.upArrow)
+               {
+                       if(this.upArrowDown == false)
+                       {
+                               this.jump();
+                               this.upArrowDown = true;
+                       }
+               }else
+               {
+                       this.upArrowDown = false;
+               }
+               
+               if(this.stage.manager.keyState.leftArrow) this.goLeft();
+               if(this.stage.manager.keyState.rightArrow) this.goRight();
+       }
+       
+});
index 706e8c8..0ab3a89 100644 (file)
@@ -1,18 +1,23 @@
 var MovableStageObjectClass = function(stage)
 {
        MovableStageObjectClass.base.apply(this, [stage]);
+
        this.movingSpeed = new Point2D(0, 0);
        //2 * hysteresis >= movingFriction\82Å\82 \82é\82±\82Æ\82ð\90\84\8f§\82·\82é\81B
        //\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
-       this.movingFriction = 90;
-       this.hysteresis = this.movingFriction / 2;
-       
+       this.movingFriction = 8000;
+       this.hysteresis = this.movingFriction / 50;
+       this.xMaxSpeed = 5;
+       this.yMaxSpeed = 5;
        
 }.extend(StageObject, {
        tick: function(){
-
-
-               //\96\80\8eC\8f\88\97\9d
+               if(this.movingSpeedX > this.xMaxSpeed) this.movingSpeedX = this.xMaxSpeed;
+               if(this.movingSpeedY > this.yMaxSpeed) this.movingSpeedY = this.yMaxSpeed;
+               if(this.movingSpeedX < -this.xMaxSpeed) this.movingSpeedX = -this.xMaxSpeed;
+               if(this.movingSpeedY < -this.yMaxSpeed) this.movingSpeedY = -this.yMaxSpeed;
+               
+               //\92ï\8dR\8f\88\97\9d
                if(this.movingSpeed.x < -this.hysteresis){
                        this.movingSpeed.x += this.movingFriction / this.stage.manager.tickPerSecond;
                } else if(this.movingSpeed.x > this.hysteresis){
@@ -29,8 +34,13 @@ var MovableStageObjectClass = function(stage)
                }
                
                //\89^\93®\8f\88\97\9d
-               this.origin.x += this.movingSpeed.x / this.stage.manager.tickPerSecond;
-               this.origin.y += this.movingSpeed.y / this.stage.manager.tickPerSecond;
+               this.moveTo(
+                       this.origin.x + (this.movingSpeed.x / this.stage.manager.tickPerSecond),
+                       this.origin.y + (this.movingSpeed.y / this.stage.manager.tickPerSecond)
+               );
+               
+               /*
+                       \82±\82ê\82Í\96{\97\88Stage\82ª\92S\93\96\82·\82é\82µ\82å\82è\81B
                
                //\95Ç\96Ê\92µ\82Ë\95Ô\82è\8f\88\97\9d
                if(this.origin.x < -this.frame.origin.x){
@@ -51,9 +61,13 @@ var MovableStageObjectClass = function(stage)
                        this.origin.y = this.stage.mainCanvas.height - (this.frame.origin.y + this.frame.size.y);
                        this.movingSpeed.y = -this.movingSpeed.y;
                }
+               */
 
        },
-       draw : function(){}
+       moveTo : function(x, y) {
+               //\93\96\82½\82è\94»\92è\82Ì\8eÀ\91\95
+               this.stage.moveTo(this, x, y);
+       }
 });
 
 //child : CharacterClass
index e69de29..777f09c 100644 (file)
@@ -0,0 +1,20 @@
+var OperatedCharacterClass = function(stage, images){
+       OperatedCharacterClass.base.apply(this, arguments);
+
+}.extend(CharacterClass, {
+       goLeft : function(){
+               this.movingSpeed.x -= 200;
+       },
+       goRight : function(){
+               this.movingSpeed.x += 200;
+       },
+       jump : function(){
+               this.movingSpeed.y -= 400;
+       },
+       tick : function(){
+               OperatedCharacterClass.base.prototype.tick.apply(this);
+       },
+       draw : function(x, y){
+               OperatedCharacterClass.base.prototype.draw.apply(this, [x, y]);
+       }
+});
index eb7298a..fc9d5c6 100644 (file)
@@ -3,6 +3,7 @@
 //
 
 function StageObject(ownerStage){
+
        this.stage = ownerStage;
        this.origin = new Point2D(10, 10);
        //origin\82ð\92\86\90S\82Æ\82µ\82½\8dÀ\95W\82Å\82Ì\83I\83u\83W\83F\83N\83g\82Ì\95`\89æ\96Ê\82Ì\83T\83C\83Y
index 1394553..33bf7c3 100644 (file)
@@ -8,4 +8,4 @@ document.write("<script type='text/javascript' src='corelib/classes/BlockClass.j
 document.write("<script type='text/javascript' src='corelib/classes/MovableStageObjectClass.js'></script>");
 document.write("<script type='text/javascript' src='corelib/classes/CharacterClass.js'></script>");
 document.write("<script type='text/javascript' src='corelib/classes/OperatedCharacterClass.js'></script>");
-
+document.write("<script type='text/javascript' src='corelib/classes/MainCharacterClass.js'></script>");