1 2 function ball(x, y, traj, speed, atk, imageorsize, color){ 3 this.x = x; 4 this.y = y; 5 this.atk = atk; 6 this.traj = traj; 7 this.speed = speed; 8 this.size; 9 this.image; 10 this.lockedtopaddle = false; 11 if(typeof imageorsize ==='string'){ 12 this.image = LoadSurface(imageorsize); 13 this.size = this.image.width; 14 } 15 else{ 16 this.image = CreateSurface(imageorsize, imageorsize, CreateColor(0,0,0,0)); 17 this.image.filledCircle(imageorsize/2, imageorsize/2, imageorsize/2, color, false); 18 this.size = imageorsize; 19 } 20 this.unstoppable = false; 21 this.blit = function(){this.image.blit(this.x-(this.size/2),this.y-(this.size/2)); if (this.unstoppable){OutlinedCircle(this.x,this.y, (this.size/2)+1, Yellow, true)}} 22 this.move = function(){ 23 if(!this.lockedtopaddle){ 24 this.x+=Math.cos(this.traj)*this.speed;this.y+=Math.sin(this.traj)*this.speed; 25 } 26 else{this.x=paddles[0].x+(paddles[0].size/2); this.y=paddles[0].y 27 this.traj = 3*Math.PI/2+(paddles[0].traj/10) 28 if(IsKeyPressed(KEY_SPACE)){this.lockedtopaddle=false} 29 } 30 } 31 } 32 33 function processBalls(){ 34 var i = 0; 35 36 if(balls.length==0){ 37 if(lives>0){ 38 lives--; 39 reload(); 40 } 41 } 42 43 while(i<balls.length){ 44 if(IsKeyPressed(KEY_R)&&(randcd<1000)){randcd=1000; balls[i].traj = Math.random()*Math.PI*2} 45 balls[i].blit(); 46 balls[i].move(); 47 while(balls[i].traj>Math.PI*2){balls[i].traj-=Math.PI*2} 48 while(balls[i].traj<0){balls[i].traj+=Math.PI*2} 49 var goingdown = (balls[i].traj<Math.PI) 50 //check for collision with the sides of the screen. 51 if((balls[i].x-(balls[i].size/2)<0)||(balls[i].x+(balls[i].size/2)>GetScreenWidth())){ 52 balls[i].traj=-(balls[i].traj-Math.PI) 53 } 54 var destroy = false 55 if(balls[i].y+(balls[i].size/2)>GetScreenHeight()){ 56 destroy = true; 57 } 58 59 if(((balls[i].y-(balls[i].size/2)<32)&&!goingdown)||((balls[i].y+(balls[i].size/2)>GetScreenHeight())&&goingdown)){ 60 balls[i].traj=-(balls[i].traj) 61 balls[i].unstoppable = false; 62 } 63 if(((balls[i].y+(balls[i].size/2)>GetScreenHeight()-26)||(balls[i].y>GetScreenHeight()-26))&&goingdown){ 64 for(var e = 0; e<paddles.length; e++){ 65 if((balls[i].x>paddles[e].x)&&(balls[i].x<paddles[e].x+paddles[e].size)) 66 balls[i].traj=-((1.1*balls[i].traj)-(balls[i].traj*(paddles[e].gettrajmod(balls[i])/2))) 67 S_bounce.play(); 68 lasttrajmod = paddles[e].gettrajmod(balls[i]) 69 } 70 } 71 if(destroy){balls.splice(i, 1); S_break.play();} 72 i++ 73 } 74 }