OSDN Git Service

TeleportMachine 鋳型
[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         this.size.x = 32;
33         this.size.y = 32;
34         
35         this.isDisabled = false;
36         this.isTouching = false;
37         
38         this.selectKeyPushed = true;
39
40 }.extend(ItemClass, {
41         draw: function(x, y){
42                 if(this.image){
43                         this.ownerStage.mainContext.globalAlpha = this.opacity;
44                         this.ownerStage.mainContext.drawImage(this.image, x, y, this.size.x, this.size.y);
45                         this.ownerStage.mainContext.globalAlpha = 1.0;
46                 }
47                 if(this.debugMode && this.times > 0){
48                         //\8ec\82è\8eæ\93¾\89ñ\90\94\82ð\95\\8e¦
49                         this.ownerStage.mainContext.save();
50                         this.ownerStage.mainContext.fillStyle = "rgba(255,255,255,0.5)";
51                         this.ownerStage.mainContext.strokeStyle = "rgba(0, 0, 0, 1)";
52                         this.ownerStage.mainContext.font = "normal 12px sans-serif";
53                         drawText(this.ownerStage.mainContext, this.times, x, y - 20);
54                         this.ownerStage.mainContext.restore();
55                 }
56                 var tickCount = this.ownerStage.manager.tickCount;
57                 if(this.debugMode && ((tickCount - this.lastTouchedTickCount)< this.touchInterval)){
58                         //\8eæ\93¾\82Å\82«\82é\82æ\82¤\82É\82È\82é\82Ü\82Å\82Ì\8ec\82è\8e\9e\8aÔ\82ð\95\\8e¦
59                         this.ownerStage.mainContext.save();
60                         this.ownerStage.mainContext.fillStyle = "rgba(255,255,255,0.5)";
61                         this.ownerStage.mainContext.strokeStyle = "rgba(0, 0, 0, 1)";
62                         this.ownerStage.mainContext.font = "normal 12px sans-serif";
63                         drawText(this.ownerStage.mainContext, this.touchInterval - (tickCount - this.lastTouchedTickCount), x, y - 32);
64                         this.ownerStage.mainContext.restore();
65                 }
66         },
67         debugDraw: function(x, y){
68                 //\8fÕ\93Ë\83}\83b\83v\82É\95`\89æ
69                 this.ownerStage.collisionMapContext.save();
70                 this.ownerStage.collisionMapContext.strokeStyle='rgba(255, 255, 0, 0.5)';
71                 this.ownerStage.collisionMapContext.strokeRect(x, y, this.size.x, this.size.y);
72                 this.ownerStage.collisionMapContext.restore();
73         },
74         tick: function(){
75                 
76                 if(this.ownerStage.userControlledCharacter)
77                 {
78                         var main = this.ownerStage.userControlledCharacter;
79                         if(this.isOverlappedWithLocatedObject(main, main.origin.x, main.origin.y))
80                         {
81                                 var tickCount = this.ownerStage.manager.tickCount;
82                                 if(!this.isDisabled && tickCount - this.lastTouchedTickCount >= this.touchInterval)
83                                 {
84                                         if((!this.mustSelectKey && !this.isTouching) || (!this.selectKeyPushed && (this.ownerStage.manager.UIManager.keyState.select || this.ownerStage.manager.UIManager.keyState.cursorDown)))
85                                         {
86                                                 if(this.callback)
87                                                 {
88                                                         this.callback(main,0,0);
89                                                 }
90                                                 
91                                                 if(this.times > 0)
92                                                 {
93                                                         this.times--;
94                                                         if(this.times == 0)
95                                                         {
96                                                                 this.ownerStage.removeStageObject(this);
97                                                                 this.isDisabled = true;
98                                                         }
99                                                 }
100                                                 //\8dÅ\8cã\82É\90G\82ç\82ê\82½\8e\9e\8aÔ\82ð\8bL\98^
101                                                 this.lastTouchedTickCount = tickCount;
102                                         }
103                                 }
104                                 this.selectKeyPushed = this.ownerStage.manager.UIManager.keyState.select || this.ownerStage.manager.UIManager.keyState.cursorDown;
105                                 this.isTouching = true;
106                         } else{
107                                 this.isTouching = false;
108                         }
109                 }
110         },
111
112 });
113 FreeItemClass.tick = function(){return false;};