class Player { public float x, y; public float dx, dy; float weight; float aim; float aimGoal; public boolean isFacingRight; public boolean isMoving; public boolean isShooting; int pWidth, pHeight; int shootCount; int maxShootCount = 5; Animation[] anims; AnimFrames[] animFrames; Player(float X, float Y) { x = X; y = Y; aim = 0; pWidth = 40; pHeight = 60; weight = 50; isFacingRight = true; isMoving = false; isShooting = false; shootCount = 0; anims = new Animation[7]; animFrames = new AnimFrames[7]; animFrames[0] = new AnimFrames("7player", "7player1.png"); animFrames[1] = new AnimFrames("6player", "6player1.png"); animFrames[2] = new AnimFrames("5player", "5player1.png"); animFrames[3] = new AnimFrames("4player", "4player1.png"); animFrames[4] = new AnimFrames("3player", "3player8.png"); animFrames[5] = new AnimFrames("2player", "2player11.png"); animFrames[6] = new AnimFrames("1player", "1player8.png"); anims[0] = new Animation(x, y, 0.45, animFrames[0]); anims[1] = new Animation(x, y, 0.5, animFrames[1]); anims[2] = new Animation(x, y, 0.5, animFrames[2]); anims[3] = new Animation(x, y, 0.5, animFrames[3]); anims[4] = new Animation(x, y, 0.5, animFrames[4]); anims[5] = new Animation(x, y, 0.5, animFrames[5]); anims[6] = new Animation(x, y, 0.5, animFrames[6]); } void hurt() { /*for(int i=0; i<4; i++) blobs.add(new Blob(x, y, random(1, 1.5), random(7, 10)));*/ weight += 0.25; checkWeight(); } void heal() { for(int i=0; i < 4; i++) blobs.add(new Blob(x, y, random(8, 12))); weight -= 0.25; checkWeight(); } void checkWeight() { if(weight < 10 && stage != 6) { switchStage(6); } else if(weight < 20 && weight > 12 && stage != 5) { switchStage(5); } else if(weight < 30 && weight > 22 && stage != 4) { switchStage(4); } else if(weight < 40 && weight > 32 && stage != 3) { switchStage(3); } else if(weight < 50 && weight > 42 && stage != 2) { switchStage(2); } else if(weight < 60 && weight > 52 && stage != 1) { switchStage(1); } else if(weight > 62 && stage != 0) { switchStage(0); } } void move() { if(isFacingRight) { dx += 15*(1 + (float)stage/2)/(weight); isFacingRight = true; } else { dx -= 15*(1 + (float)stage/2)/(weight); isFacingRight = false; } } void update() { // process input if(!isShooting) { if(keyDown[2] ^ keyDown[3]) { isFacingRight = keyDown[3]; isMoving = true; anims[stage].setIdle(false); move(); } if(isMoving && (!keyDown[2] && !isFacingRight) || (!keyDown[3] && isFacingRight) ) { isMoving = false; anims[stage].setIdle(true); } } else { if(keyDown[0]) { if(aim > 3*PI/2) aim -= (PI/2 - aim)*0.1; else aim += (PI/2 - aim)*0.1; } if(keyDown[1]) { if(aim < PI/2 && aim > 0) aim -= (3*PI/2 - aim)*0.1; else aim += (3*PI/2 - aim)*0.1; } if(keyDown[2]) aim += (PI - aim)*0.1; if(keyDown[3]) { if(aim > PI) aim += (2*PI - aim)*0.1; else aim += (0 - aim)*0.1; } shootCount--; if(shootCount <= 0) { float xAim = cos(aim); float yAim = -sin(aim); float speed = 8; beams.add(new Beam(x + 10*xAim, y + 10*yAim, speed*xAim, speed*yAim, atan2(yAim, xAim), true)); shootCount = maxShootCount; } } aim = (aim + 2*PI) % (2*PI); if(isMoving && !isShooting) move(); x += dx; dx *= 0.65; if(isShooting) { if(aim < PI/2 || aim > 3*PI/2) isFacingRight = true; else isFacingRight = false; } render(); } void release() { } void render() { if(isShooting) { stroke(255, 255, 100, 100); strokeWeight(1.5); line(x-cam+50*cos(aim), y-50*sin(aim), x-cam+70*cos(aim), y-70*sin(aim)); } pushMatrix(); if(!isFacingRight) { translate(x-cam, y); scale(-1.0, 1.0); translate(cam-x, -y); } anims[stage].update(x - cam - anims[stage].w/2, y - anims[stage].h/2); //image(sprite, x-cam-pWidth/2, y-pHeight/2, pWidth, pHeight); //noFill(); //rect(x-cam-pWidth/2, y-pHeight/2, pWidth, pHeight); popMatrix(); } }