We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello. My keyboard stops responding at random times when I play my game, and while it stops, any key-related booleans and functions stop working until a random amount of time, and then it will work again, but it eventually will stop responding again. My code is below. Everything related to the keys are either in draw or keyTyped().
PVector pos = new PVector(200,200);
PVector spd = new PVector(0,0);
PVector xppos = new PVector(500,500);
float xp = 1;
float diam = 0;
int atk = 0;
int agi = 0;
float wis = 0;
void setup() {
size(1600,900);
}
void draw() {
background(50,225,225);
stroke(2);
fill(100);
diam = 100 + atk * 2;
ellipse(pos.x, pos.y, diam,diam);
if (spd.y < 10) { //falling
spd.add(0,0.3);
} else {
spd.y = 10;
}
if (pos.x < diam/2 || pos.x > 1600 - diam/2) {
spd.x = spd.x * -1;
}
if (pos.y < diam/2 || pos.y > 900 - diam/2) {
spd.y = spd.y * -1;
}
spd.mult(0.999);
fill(255,255,0);
ellipse(xppos.x, xppos.y, 50, 50);
if (sqrt(sq(pos.x-xppos.x)+sq(pos.y-xppos.y)) <= diam/2 + 25) {
xp += wis/100+1;
xppos.x = random(50,width-50);
xppos.y = random(50,height-50);
}
if (keyPressed){ //control
if (key == 'w') {
spd.add(0,-0.5*((agi/100)+1));
}
if (key == 's') {
spd.add(0,0.5*((agi/100)+1));
}
if (key == 'a') {
spd.add(-0.5*((agi/100)+1),0);
}
if (key == 'd') {
spd.add(0.5*((agi/100)+1),0);
}
}
pos.x += spd.x;
pos.y += spd.y;
fill(0);
textSize(32);
text("Skill Points: " + floor(xp),50,50); //hud
text("Attack: " + atk,50,80);
text("Agility: " + agi,50,110);
text("Wisdom: " + floor(wis),50,140);
}
void keyTyped() {
if (key == 'r'){
spd.x = 0;
spd.y = 0;
pos.x = 200;
pos.y = 200;
}
if (xp >= 1) {
if (key == 'b'){
xp -= 1;
atk += 1;
}
if (key == 'n'){
xp -= 1;
agi += 1;
}
if (key == 'm'){
xp -= 1;
wis += 1;
}
}
}
Answers
I can't reproduce the problem. I got about 40 skill points. I can see a problem. My wisdom didn't go up at all. Am I the problem or is not yet implemented?
What OS are you using? When it gets stuck, is that for a long time? You can check responsiveness if you add this line in draw
if(frameCount%60==0) prinltn("Current frm="+frameCount+" Time[sec]="+millis()/1000.0);
And add this is line in keyTyped() but slightly modified:
prinltn("Current frm="+frameCount+" Key="+int(key));
So, if it gets stuck, do you get still a response from your keyboard and the messages from draw?
Kf