OSDN Git Service

6f90580be2f38a775881463b0b4cfb67695bd841
[h58pcdgame/GameScriptCoreLibrary.git] / www / corelib / classes / FreeItemClass.js
1 // args[0] : \89æ\91\9c "xxx.png"
2 // args[1] : \83R\81[\83\8b\83o\83b\83N
3 // args[2] : \82±\82ê\82ðtrue\82É\82·\82é\82Æ\90Ú\90G\8fó\91Ô\82Å\8c\88\92è\83L\81[\82Ü\82½\82Í\89º\83L\81[\82ð\89\9f\82µ\82½\82Æ\82«\82Ì\82Ý\94½\89\9e(false, \8fÈ\97ª\82¾\82Æ\90Ú\90G\82µ\82½\8fu\8aÔ\94½\89\9e)
4
5 var FreeItemClass = function(stage, args){
6
7         FreeItemClass.base.apply(this, arguments);
8         if(args[0]){
9                 var img = document.createElement('img');
10                 img.src = "images/" + args[0];  //\89æ\91\9c\82Í\89¼
11                 this.image = img;
12         } else{
13                 this.image = null;
14         }
15         
16         //\83A\83C\83e\83\80\82ð\8eæ\93¾\82Å\82«\82é\89ñ\90\94\81B-1\82Å\96³\8cÀ
17         this.times = -1;
18         
19         //\83A\83C\83e\83\80\82ð\8eæ\93¾\82µ\82½\82Æ\82«\82É\8cÄ\82Î\82ê\82é\83R\81[\83\8b\83o\83b\83N\81B\88ø\90\94\82É\83A\83^\83b\83N\82µ\82Ä\82«\82½\83I\83u\83W\83F\83N\83g\82ª\8ew\92è\82³\82ê\82é
20         //null\82Å\89½\82à\82µ\82È\82¢\83A\83C\83e\83\80\82É\82È\82é
21         this.callback = args[1];
22         
23         //\8dÅ\8cã\82É\83L\83\83\83\89\82É\8fæ\82ç\82ê\82Ä\82¢\82é\8fó\91Ô\82Å\82È\82­\82È\82Á\82Ä\82©\82ç\89½tick\82Å\8dÄ\82Ñ\8eæ\93¾\82Å\82«\82é\82©\81B
24         this.touchInterval = 0;
25         this.lastTouchedTickCount = -9999;
26         
27         //\91I\91ð\83L\81[\89\9f\89º\8e\9e\82Ì\82Ý\83R\81[\83\8b\83o\83b\83N\82ð\94­\8ds
28         this.mustSelectKey = args[2] != undefined ? args[2] : false;
29         
30         this.isPhantom = true;
31         this.debugMode = false;
32         
33         this.isDisabled = false;
34         this.isTouching = false;
35         
36         this.selectKeyPushed = true;
37
38 }.extend(ItemClass, {
39         draw: function(x, y){
40                 if(this.image){
41                         this.ownerStage.mainContext.globalAlpha = this.opacity;
42                         this.ownerStage.mainContext.drawImage(this.image, x, y, 32, 32);
43                         this.ownerStage.mainContext.globalAlpha = 1.0;
44                 }
45                 if(this.debugMode && this.times > 0){
46                         //\8ec\82è\8eæ\93¾\89ñ\90\94\82ð\95\\8e¦
47                         this.ownerStage.mainContext.save();
48                         this.ownerStage.mainContext.fillStyle = "rgba(255,255,255,0.5)";
49                         this.ownerStage.mainContext.strokeStyle = "rgba(0, 0, 0, 1)";
50                         this.ownerStage.mainContext.font = "normal 12px sans-serif";
51                         drawText(this.ownerStage.mainContext, this.times, x, y - 20);
52                         this.ownerStage.mainContext.restore();
53                 }
54                 var tickCount = this.ownerStage.manager.tickCount;
55                 if(this.debugMode && ((tickCount - this.lastTouchedTickCount)< this.touchInterval)){
56                         //\8eæ\93¾\82Å\82«\82é\82æ\82¤\82É\82È\82é\82Ü\82Å\82Ì\8ec\82è\8e\9e\8aÔ\82ð\95\\8e¦
57                         this.ownerStage.mainContext.save();
58                         this.ownerStage.mainContext.fillStyle = "rgba(255,255,255,0.5)";
59                         this.ownerStage.mainContext.strokeStyle = "rgba(0, 0, 0, 1)";
60                         this.ownerStage.mainContext.font = "normal 12px sans-serif";
61                         drawText(this.ownerStage.mainContext, this.touchInterval - (tickCount - this.lastTouchedTickCount), x, y - 32);
62                         this.ownerStage.mainContext.restore();
63                 }
64         },
65         debugDraw: function(x, y){
66                 //\8fÕ\93Ë\83}\83b\83v\82É\95`\89æ
67                 this.ownerStage.collisionMapContext.save();
68                 this.ownerStage.collisionMapContext.strokeStyle='rgba(255, 255, 0, 0.5)';
69                 this.ownerStage.collisionMapContext.strokeRect(x, y, this.size.x, this.size.y);
70                 this.ownerStage.collisionMapContext.restore();
71         },
72         tick: function(){
73                 
74                 if(this.ownerStage.userControlledCharacter)
75                 {
76                         var main = this.ownerStage.userControlledCharacter;
77                         if(this.isOverlappedWithLocatedObject(main, main.origin.x, main.origin.y))
78                         {
79                                 var tickCount = this.ownerStage.manager.tickCount;
80                                 if(!this.isDisabled && tickCount - this.lastTouchedTickCount >= this.touchInterval)
81                                 {
82                                         if((!this.mustSelectKey && !this.isTouching) || (!this.selectKeyPushed && (this.ownerStage.manager.UIManager.keyState.select || this.ownerStage.manager.UIManager.keyState.cursorDown)))
83                                         {
84                                                 if(this.callback)
85                                                 {
86                                                         this.callback(main,0,0);
87                                                 }
88                                                 
89                                                 if(this.times > 0)
90                                                 {
91                                                         this.times--;
92                                                         if(this.times == 0)
93                                                         {
94                                                                 this.ownerStage.removeStageObject(this);
95                                                                 this.isDisabled = true;
96                                                         }
97                                                 }
98                                                 //\8dÅ\8cã\82É\90G\82ç\82ê\82½\8e\9e\8aÔ\82ð\8bL\98^
99                                                 this.lastTouchedTickCount = tickCount;
100                                         }
101                                 }
102                                 this.selectKeyPushed = this.ownerStage.manager.UIManager.keyState.select || this.ownerStage.manager.UIManager.keyState.cursorDown;
103                                 this.isTouching = true;
104                         } else{
105                                 this.isTouching = false;
106                         }
107                 }
108         },
109
110 });
111 FreeItemClass.tick = function(){return false;};