first_dominator
YaBB Newbies
Offline
Posts: 3
Re: Im not able to get an animated SpaceInvader shot
Reply #2 - Mar 30th , 2010, 9:44am
Thx but I'm having another problem now.. so if I press the left or right arrow to move the ship, it moves everything is ok but as soon as I touch another key, for exemple the spacebar to shot, it stops the moving platform... I have to release it and reclick... is there a fix to that? And also is there a way making my shot appear only when the key is released so that it doesn't pop out is I have the key down. Ship mothership; Enemy creature1; Fire shot; void setup() { size(350,800); smooth(); mothership=new Ship(width/2,height-10,40,10); creature1=new Enemy(width/2,200,20,20); shot=new Fire(width/2,10,10); noStroke(); } void draw() { background(0); shot.drawShot(); mothership.displayMothership(); creature1.displayCreature1(); } class Enemy { float posXCreature1; float posYCreature1; float wCreature1; float hCreature1; Enemy(float posXCreature1, float posYCreature1, float wCreature1, float hCreature1) { this.posXCreature1=posXCreature1; this.posYCreature1=posYCreature1; this.wCreature1=wCreature1; this.hCreature1=hCreature1; } void displayCreature1() { fill(255); rectMode(CENTER); rect(posXCreature1,posYCreature1,wCreature1,hCreature1); } } int shottimer; int counter; class Fire { boolean finishLine; float posXShot; float posYShot; float sizeShot; Fire (float posXShot, float posYShot, float sizeShot){ this.posXShot=posXShot; this.posYShot=posYShot; this.sizeShot=sizeShot; } void drawShot(){ shottimer++; if (keyPressed && key == 32 && shottimer > 85){ counter ++; println(counter); shottimer = 0; posXShot = mothership.posXMothership; posYShot = mothership.posYMothership; } if( posYShot > -30 && !finishLine){ posYShot-=10; fill(255); ellipse(posXShot,posYShot,sizeShot,sizeShot); } println(shottimer); } } class Ship { float posXMothership; float posYMothership; float rectWMothership; float rectHMothership; Ship(float posXMothership,float posYMothership, float rectWMothership, float rectHMothership) { this.posXMothership=posXMothership; this.posYMothership=posYMothership; this.rectWMothership=rectWMothership; this.rectHMothership=rectHMothership; } void displayMothership() { fill(255); rectMode(CENTER); rect(posXMothership,posYMothership,rectWMothership,rectHMothership); if(keyPressed){ if(keyCode==LEFT && posXMothership>rectWMothership-rectWMothership/2){ posXMothership--; } if(keyCode==RIGHT && posXMothership<width-rectWMothership/2){ posXMothership++; } } } }