I'm trying to have a bullet collide with a shape drawn with beginShape(); and endShape();. All of my points are stored as PVectors in an array. How can I test if a point is inside of the shape?
I'm working on an Asteroids clone, but I'm having trouble when it comes to movement. I got the player to move properly, but then I realized that in Asteroids, when you stop moving forwards, you drift in the same direction, and can turn on the spot without moving in a different direction (hopefully you understand this). Can anybody help me with this?
Relevant class files:
Player player;
Factory factory = new Factory();
ArrayList enemies = new ArrayList();
boolean upReleased = true;
int score;
boolean show;
boolean keys[] = new boolean[512];
void setup() {
size(screen.width-300, screen.height);
smooth();
player = new Player();
factory.newEnemy();
}
void draw() {
background(0);
text("Score: "+score, 0, 10);
player.update();
if (keys[' ']) player.fire();
updateEnemies();
if (keys[81]) factory.newEnemy();
println(upReleased);
}
void keyPressed() {
keys[keyCode] = true;
}
void keyReleased() {
keys[keyCode] = false;
}
void updateEnemies() {
//if (frameCount % 120 == 0) factory.newEnemy();
for (int i = 0; i < enemies.size(); i++) {
Enemy e =(Enemy) enemies.get(i);
e.update();
if (e.destroyed) {
enemies.remove(i);
factory.split(e, i);
if (enemies.size() == 0) {
show = true;
}
}
}
}
class Player {
float ang, moveang, speed, x, y;
boolean canshoot = true;
ArrayList bullets;
Player() {
bullets = new ArrayList();
ang = PI+HALF_PI;
moveang = PI+HALF_PI;
speed = 0;
x = width/2;
y = height/2;
}
void update() {
if (frameCount % 45 == 0) canshoot = true;
pushMatrix();
translate(x, y);
rotate(ang);
fill(255);
rect(-20, -7.5, 40, 15); // Center the rect
translate(20, 0); // Translate to default Polar Coordinate 0 radians
I'm trying to make a character controlled by arrow keys, and I want it to move in any direction. when I hit left and right, i would like it to turn, and up and down should be forwards and backwards. I have something that kinda works, but it only rotates around the screen corner, and is technically only sliding on the x axis. Can anybody help?
Once again, I'm modifying my paint program. This time, i'll be adding a fill bucket.
<sarcasm> Oh, joy! </sarcasm>.
I found this paint bucket function on the internet, and I modified slightly to suit my needs. The only problem is that when I implement it into my paint program, it gives me a NullPointer exception.
I made a paint program a while back, and it works fine, however I decided to add a few things. I can now save my images, and I was working on getting a circe to appear above where you are about to paint, as it does in MS Paint. I experimented with PGraphics, but the P2D renderer messes with my shapes, and turns them into weird lines, and I can't get the mouse image to clear from the screen. Help anybody?
I'm trying to make Rush Hour, and it's working fine, but the blocks don't reset for each level. I've tried using the arrraylist.remove command, but it keeps drawing them. Help?
I'm trying to make a program where I can type something in binary, and it will convert it into letters for me. I came up with this simple program, but it's telling me the "[" in the third line is unexpected. What did I do wrong?
So for my first real project in processing, I decided to go simple, and make paint. I have already finished and moved on, but there are still some things I would like to work out. The main thing I want to add is an "eyedropper" tool. I've tried many different codes that work in my mind, but I just can't seem to get it to run properly. I've already tried storing the color to a variable. I'm using controlP5 for the color picker.