class Ship { float x; float y; float vx; float vy; float angle; boolean bulletShot; void update() { if (keyPressed) { if(keyCode == LEFT) { angle = angle - 0.1; } if(keyCode == RIGHT) { angle = angle + 0.1; } if(keyCode == UP) { vx = vx + cos(angle + 3.14/2) * 0.2; vy = vy + sin(angle + 3.14/2) * 0.2; } if(keyCode == CONTROL) { if (!bulletShot) { bullets[bulletsCount] = new BasicBullet(); bullets[bulletsCount].x = x; bullets[bulletsCount].y = y; //bullets[bulletsCount].svx = vx; // bullets[bulletsCount].svy = vy; bullets[bulletsCount].angle = angle; bulletsCount ++; bulletShot = true; } } else { bulletShot = false; } } else { bulletShot = false; } x = x + vx; y = y + vy; vx *= 0.99; vy *= 0.99; if (x > 500) x = 0; if (y > 400) y = 0; if (x < 0) x = 500; if (y < 0) y = 400; } void draw() { pushMatrix(); translate(x, y); rotate(angle); noFill(); rect(-5, -5, 10, 10); rect(-9, -4, 3, 3); rect(6, -4, 3, 3); popMatrix(); } }