回答編集履歴
1
思いっきり勘違いしてたので修正
test
CHANGED
@@ -64,160 +64,150 @@
|
|
64
64
|
|
65
65
|
//追加
|
66
66
|
|
67
|
+
enableEvents(AWTEvent.KEY_EVENT_MASK);
|
68
|
+
|
69
|
+
addMouseMotionListener(this);
|
70
|
+
|
67
|
-
add
|
71
|
+
addMouseListener(this);
|
72
|
+
|
68
|
-
|
73
|
+
alltimer = new Timer(1, this);
|
74
|
+
|
69
|
-
|
75
|
+
alltimer.start();
|
76
|
+
|
70
|
-
|
77
|
+
}
|
78
|
+
|
79
|
+
public void paint(Graphics g){
|
80
|
+
|
81
|
+
int BlockX = 50;
|
82
|
+
|
83
|
+
int BlockY = 450;
|
84
|
+
|
85
|
+
g.setColor(Color.red);
|
86
|
+
|
87
|
+
g.fillRect(PlayerX, PlayerY, 50, 100);
|
88
|
+
|
89
|
+
g.setColor(new Color(0, 255, 255));
|
90
|
+
|
91
|
+
g.fillRect(BlockX - 50, BlockY, 50, 50);
|
92
|
+
|
93
|
+
//ループしよう?
|
94
|
+
|
95
|
+
g.fillRect(BlockX * 1, BlockY, 50, 50);
|
96
|
+
|
97
|
+
g.fillRect(BlockX * 2, BlockY, 50, 50);
|
98
|
+
|
99
|
+
g.fillRect(BlockX * 3, BlockY, 50, 50);
|
100
|
+
|
101
|
+
g.fillRect(BlockX * 4, BlockY, 50, 50);
|
102
|
+
|
103
|
+
g.fillRect(BlockX * 5, BlockY, 50, 50);
|
104
|
+
|
105
|
+
g.fillRect(BlockX * 6, BlockY, 50, 50);
|
106
|
+
|
107
|
+
g.fillRect(BlockX * 7, BlockY, 50, 50);
|
108
|
+
|
109
|
+
g.fillRect(BlockX * 8, BlockY, 50, 50);
|
110
|
+
|
111
|
+
g.fillRect(BlockX * 9, BlockY, 50, 50);
|
112
|
+
|
113
|
+
g.fillRect(BlockX * 10, BlockY, 50, 50);
|
114
|
+
|
115
|
+
g.fillRect(BlockX * 11, BlockY, 50, 50);
|
116
|
+
|
117
|
+
g.fillRect(BlockX * 12, BlockY, 50, 50);
|
118
|
+
|
119
|
+
g.fillRect(BlockX * 13, BlockY, 50, 50);
|
120
|
+
|
121
|
+
g.fillRect(BlockX * 14, BlockY, 50, 50);
|
122
|
+
|
123
|
+
g.fillRect(BlockX * 15, BlockY, 50, 50);
|
124
|
+
|
125
|
+
g.fillRect(BlockX * 16, BlockY, 50, 50);
|
126
|
+
|
127
|
+
g.fillRect(BlockX * 17, BlockY, 50, 50);
|
128
|
+
|
129
|
+
g.fillRect(BlockX * 18, BlockY, 50, 50);
|
130
|
+
|
131
|
+
g.fillRect(BlockX * 19, BlockY - 50, 50, 50);
|
132
|
+
|
133
|
+
}
|
134
|
+
|
71
|
-
|
135
|
+
public void actionPerformed(ActionEvent e){
|
136
|
+
|
72
|
-
|
137
|
+
if(PlayerY >= 0 && PlayerY <= 350 && flyFlag == true){
|
138
|
+
|
139
|
+
PlayerY += 9;
|
140
|
+
|
73
|
-
|
141
|
+
repaint();
|
142
|
+
|
143
|
+
flyFlag = true;
|
144
|
+
|
145
|
+
}else if(PlayerY >= 350){
|
146
|
+
|
147
|
+
flyFlag = false;
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
if(UFlag == true && flyFlag == false){
|
152
|
+
|
153
|
+
PlayerY -= 50; repaint();
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
if(DFlag == true){
|
158
|
+
|
159
|
+
System.out.println(DFlag);
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
if(RFlag == true && PlayerX <= 850){
|
164
|
+
|
165
|
+
PlayerX += 10; repaint();
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
if(LFlag == true && PlayerX >= 50){
|
170
|
+
|
171
|
+
PlayerX -= 10; repaint();
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
protected void processKeyEvent(java.awt.event.KeyEvent e){//キーイベントの関数
|
178
|
+
|
179
|
+
if(e.getID() == java.awt.event.KeyEvent.KEY_PRESSED){
|
180
|
+
|
181
|
+
if(e.getKeyCode() == java.awt.event.KeyEvent.VK_UP){
|
182
|
+
|
183
|
+
UFlag = true;
|
184
|
+
|
185
|
+
}else{
|
186
|
+
|
187
|
+
UFlag = false;
|
74
188
|
|
75
189
|
}
|
76
190
|
|
77
|
-
});
|
78
|
-
|
79
|
-
addMouseMotionListener(this);
|
80
|
-
|
81
|
-
addMouseListener(this);
|
82
|
-
|
83
|
-
alltimer = new Timer(1, this);
|
84
|
-
|
85
|
-
alltimer.start();
|
86
|
-
|
87
|
-
}
|
88
|
-
|
89
|
-
public void paint(Graphics g){
|
90
|
-
|
91
|
-
int BlockX = 50;
|
92
|
-
|
93
|
-
int BlockY = 450;
|
94
|
-
|
95
|
-
g.setColor(Color.red);
|
96
|
-
|
97
|
-
g.fillRect(PlayerX, PlayerY, 50, 100);
|
98
|
-
|
99
|
-
g.setColor(new Color(0, 255, 255));
|
100
|
-
|
101
|
-
g.fillRect(BlockX - 50, BlockY, 50, 50);
|
102
|
-
|
103
|
-
//ループしよう?
|
104
|
-
|
105
|
-
g.fillRect(BlockX * 1, BlockY, 50, 50);
|
106
|
-
|
107
|
-
g.fillRect(BlockX * 2, BlockY, 50, 50);
|
108
|
-
|
109
|
-
g.fillRect(BlockX * 3, BlockY, 50, 50);
|
110
|
-
|
111
|
-
g.fillRect(BlockX * 4, BlockY, 50, 50);
|
112
|
-
|
113
|
-
g.fillRect(BlockX * 5, BlockY, 50, 50);
|
114
|
-
|
115
|
-
g.fillRect(BlockX * 6, BlockY, 50, 50);
|
116
|
-
|
117
|
-
g.fillRect(BlockX * 7, BlockY, 50, 50);
|
118
|
-
|
119
|
-
g.fillRect(BlockX * 8, BlockY, 50, 50);
|
120
|
-
|
121
|
-
g.fillRect(BlockX * 9, BlockY, 50, 50);
|
122
|
-
|
123
|
-
g.fillRect(BlockX * 10, BlockY, 50, 50);
|
124
|
-
|
125
|
-
g.fillRect(BlockX * 11, BlockY, 50, 50);
|
126
|
-
|
127
|
-
g.fillRect(BlockX * 12, BlockY, 50, 50);
|
128
|
-
|
129
|
-
g.fillRect(BlockX * 13, BlockY, 50, 50);
|
130
|
-
|
131
|
-
g.fillRect(BlockX * 14, BlockY, 50, 50);
|
132
|
-
|
133
|
-
g.fillRect(BlockX * 15, BlockY, 50, 50);
|
134
|
-
|
135
|
-
g.fillRect(BlockX * 16, BlockY, 50, 50);
|
136
|
-
|
137
|
-
g.fillRect(BlockX * 17, BlockY, 50, 50);
|
138
|
-
|
139
|
-
g.fillRect(BlockX * 18, BlockY, 50, 50);
|
140
|
-
|
141
|
-
g.fillRect(BlockX * 19, BlockY - 50, 50, 50);
|
142
|
-
|
143
|
-
}
|
144
|
-
|
145
|
-
public void actionPerformed(ActionEvent e){
|
146
|
-
|
147
|
-
if(PlayerY >= 0 && PlayerY <= 350 && flyFlag == true){
|
148
|
-
|
149
|
-
PlayerY += 9;
|
150
|
-
|
151
|
-
repaint();
|
152
|
-
|
153
|
-
flyFlag = true;
|
154
|
-
|
155
|
-
}else if(PlayerY >= 350){
|
156
|
-
|
157
|
-
flyFlag = false;
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
if(UFlag == true && flyFlag == false){
|
162
|
-
|
163
|
-
PlayerY -= 50; repaint();
|
164
|
-
|
165
|
-
}
|
166
|
-
|
167
|
-
if(DFlag == true){
|
168
|
-
|
169
|
-
System.out.println(DFlag);
|
170
|
-
|
171
|
-
}
|
172
|
-
|
173
|
-
if(RFlag == true && PlayerX <= 850){
|
174
|
-
|
175
|
-
PlayerX += 10; repaint();
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
if(LFlag == true && PlayerX >= 50){
|
180
|
-
|
181
|
-
PlayerX -= 10; repaint();
|
182
|
-
|
183
|
-
}
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
protected void processKeyEvent(java.awt.event.KeyEvent e){//キーイベントの関数
|
188
|
-
|
189
|
-
if(e.getID() == java.awt.event.KeyEvent.KEY_PRESSED){
|
190
|
-
|
191
|
-
if(e.getKeyCode() == java.awt.event.KeyEvent.VK_
|
191
|
+
if(e.getKeyCode() == java.awt.event.KeyEvent.VK_DOWN){
|
192
|
-
|
192
|
+
|
193
|
-
|
193
|
+
DFlag = true;
|
194
194
|
|
195
195
|
}else{
|
196
196
|
|
197
|
-
|
197
|
+
DFlag = false;
|
198
198
|
|
199
199
|
}
|
200
200
|
|
201
|
-
if(e.getKeyCode() == java.awt.event.KeyEvent.VK_
|
201
|
+
if(e.getKeyCode() == java.awt.event.KeyEvent.VK_RIGHT){
|
202
|
-
|
202
|
+
|
203
|
-
|
203
|
+
RFlag = true;
|
204
204
|
|
205
205
|
}else{
|
206
206
|
|
207
|
-
|
207
|
+
RFlag = false;
|
208
208
|
|
209
209
|
}
|
210
210
|
|
211
|
-
if(e.getKeyCode() == java.awt.event.KeyEvent.VK_RIGHT){
|
212
|
-
|
213
|
-
RFlag = true;
|
214
|
-
|
215
|
-
}else{
|
216
|
-
|
217
|
-
RFlag = false;
|
218
|
-
|
219
|
-
}
|
220
|
-
|
221
211
|
if(e.getKeyCode() == java.awt.event.KeyEvent.VK_LEFT){
|
222
212
|
|
223
213
|
LFlag = true;
|