/* A breakout style demo :) you've got a paddle you can move with the arrows, a ball and some bricks you can destroy you can make a new ball with control (A on the gp32) the collision of the ball with the blocks is not perfect, but can be a pretty tricky thing, it's pretty good now, and very simple :) */ Program breakout; global blocksleft;//will count the amount of bricks there still are private i;//just 2 variables for the for loops j; begin SET_MODE(320,240,8);//set the graphics mode :) load_fpg("breakout.fpg");//load the fpg paddle(160,220);//create a paddle at that position ball(160,80);//create a ball at that position for(i=0;i<10;i++)//we'll create an array of blocks, 10 blocks wide for(j=0;j<3;j++)//3 blocks high blocksleft++;//we create a block, so it has to be added to the counter block(i*32+16,j*16+8);//and we place the block itself :) end end write(0,180,230,5,"Blocks left: ");//write some text (the 5 is centre alignment vertical, aligned to the left horizontal) write_int(0,180,230,3,&blocksleft);//write the amount of blocks, aligned right, so they're right next to eachother :) loop frame;//and loop frames, you could also kill this process if(key(_control))//now you can make an extra ball at any time, just press a :) while(key(_control))frame;end//wait until the key is released :) ball(160,80); end; end; end; process paddle(x,y)//a paddle :) (didn't expect that hé :p ) begin graph=3;//select the graph loop if(key(_left))x-=5;end//let it move if(key(_right))x+=5;end if(x<15)x=15;end//and check the boundries if(x>305)x=305;end frame;//and draw it ofcourse end; end; process ball(x,y)//a ball private vx=0;//with a speed in the x and y direction vy=5; paddle;//and a paddle/block it can collide with block; begin graph=1; loop paddle=COLLISION(type paddle);//check the collisions block=COLLISION(type block); if(block!=0)//we hit a block if(abs(block.y-y+vy)>8)//we hit the top or bottom :) vy=-vy; end if(abs(block.x-x+vx)>16)//we hit the left/rgiht vx=-vx; end while(block!=0)//we don't necessarily hit 1 block blocksleft--;//we hit this block signal(block,s_kill);//and remove it block=COLLISION(type block);//and see if there's another block we collide with (every time you call collission, it gives the next item it collides with, and whenever you do a frame;, you start at the first one again) end end if(x<=2 or x>=318)vx=-vx;end//let the ball bounce of the walls if(y<=2)vy=-vy;end if(paddle!=0)vy=-vy;vx+=(x-paddle.x)/2;end//if we hit a paddle, the horizontal speed will be altered dependent on where we hit the paddle :) if(vx>20)vx=20;end//limit the horizontal speed a bit :) x+=vx;//and don't forget to move.... y+=vy; if(y>260)return;end//if we loose the ball, kill the process :) frame;//....and draw the ball :) end; end; process block(x,y);//a block (shocking, isn't it) begin; graph=2;//select the graphics file loop frame;//and draw it! (damn fenix is complicated) end end