Fenix Breakout Help Needed!


mots

Member
Joined
Oct 24, 2005
Messages
257
so, please help me in my first trys in Fenix. What I want to add to my game is:show graphic for board; make that a block gets removed on collision with a ball; spawn some blocks; If life<0 -> don't show anything but gameover.

Would be nice, if someone would explain me how to make this.

Code:
program BREAKOUT; 

global 
score[1]; 
life; 

//Graphics: 
gr_ball; 
gr_bat; 
gr_block; 


//GP Keys 
__A = _control; 
__B = _alt; 
__SELECT = _space; 
__START = _enter; 
__R = _tab; 
__L = _backspace; 

begin 
//initialize screen: 
set_title("Breakout by B4C|</"); 
full_screen = false; 
set_mode(m320x240); 

//Create graphics 
gr_ball = new_map(5,5,<img src=http://www.flamingbird.com/public_html/images/smiles/icon_cool.gif BORDER="0">; 
map_clear(0,gr_ball,300); 

gr_bat = NEW_MAP(30,5,<img src=http://www.flamingbird.com/public_html/images/smiles/icon_cool.gif BORDER="0">; 
map_clear(0,gr_bat,50); 

gr_block = NEW_MAP(15,8,<img src=http://www.flamingbird.com/public_html/images/smiles/icon_cool.gif BORDER="0">; 
map_clear(0,gr_block,25); 

//Create a ball process 
ball(); 

//Create a bat process 
bat(20,_left,_right); 

//Create some blocks 
block(160,120); 


//Write the current score on screen 
write(0,80,20,4,"Score:"); 
write_int(0,110,20,4,&score[1]); 
write (0,150,20,4,"Lifes:"); 
WRITE_INT (0,180,20,4, &life); 


loop 
  //If key start is pressed quit the game 
  if(key(_esc)) 
    exit("",0); 
  end 

  frame; 
end 

end 

 
Process ball(); 

private 
//Speed of the ball 
speedo; 

//Holds the bat's process identification number in case it collides with one 
bat_id; 

begin 

//Initialize start values for most variables 
//*position 
x = 160; 
y = 200; 
life = 3; 
//*angle 
angle = rand(0,360) * 1000; 
//*ball speed 
speedo = 500; 
//*graphic of the process 
graph = gr_ball; 



loop 
  //Makes it bounce off the top and bottom of the screen(0 and 240, but giving 
  //the ball a 5 pixel radius) 
  if(x>319 or x<1) 
    //Incoming angle is outgoing angle! 
    angle = -angle + 180000; 
  end 
  if(y<5) 
  angle=-angle; 
  end 

  //if off the screen on the left(point for player with score[0] 
  if(y>320) 
    //Add one to the score 
    life--; 
    //Reset speed to standard 
    speedo = 500; 
    //reset Position 
    y = 120; 
    x = 220; 
  end 


  //If it hits a bat 
  if(bat_id = collision(type bat)) 
    angle = -angle; 
    advance(3); 
  end 

  //Slowly increase the speed 
  speedo+=3; 
  //Move the ball in it's current direction 
  advance(speedo/100); 

  frame; 
end 

end 

/* 
A typical bat in a Pong game. It can move up and down with the keys 
specified in the keyup and keydown parameters. x specifies the horizontal position on 
screen. 

*/ 
Process bat(x,keyup,keydown,); 

begin 

//Start in the middle of the screen 
y = 235; 
x = 160; 



//use the graphic made for the bat 
graph = gr_bat; 

loop 
  //Move the bat vertically if buttons are pressed 
  if(key(keyup)) 
    x -= 12; 
  end 
  
  if(key(keydown)) 
    x += 12; 
  end 

  //Limit the bat movement on the edges of the screen 
  if(x < 0) 
    x=10; 
  end 
  
  if(x > 320) 
    x=310; 
  end 
  
  frame; 
end 

end 

process block(x,y); 
private 
ball_id; 
begin 
  if (ball_id = collision(type ball)) 
  score+=100; 
  end 
end 
  
process life(); 
begin 
if(life<0) 
let_me_alone(); 
Write(0,160,120,4,"GAME OVER"); 
end 
  
end
</pre>
 
first recommendation: go to the fenix on fire website and download the fully documented source of a very basic breakout game i made :)

secondly, i'll help you on some of your errors :)

1: just make an fpg containing the graphics, i don't know what you're doing with that new map command there, might work, but why on earth make it so hard? just make a little fpg :) (search for fpg edit on either google or the gp32 file archive)
2: the y value of your ball (to detect you lost it) is wrong, it should be 240, not 320 :), and looking at the comment you copied the code from some pong game :)
3: check your code for little errors, i see brackets not closed, or a "," too many (Process bat(x,keyup,keydown,); ),....

also, work in parts, i think you just programmed the entire thing, and then saw it didn't work and came for help, very bad idea, certainly if you're just beginning with fenix.

start with simple things, like for example making a bat move around. then add a ball that bounces around, then make it so that you can reflect the ball with the bat, then try drawing the blocks, then make the ball hit the blocks and reflect properly :)
if you try it all at once you're just making it harder to find errors, and harder to learn the language too :)

*edit, you used the example of moogle's pong ^^, scroll a bit lower and you'll find my breakout ^^
or for your convenience:
http://fenixonfire.gp32x.de/sources/breakout.prg
http://fenixonfire.gp32x.de/sources/breakout.fpg
the prg and fpg file (an fpg file contains graphics :) )

and even if you have an example, use it to learn things with, instead of trying to hack the code to do what you want it to do, use it to write your own program :)

try and do it in the steps i earlier mentioned, if you don't know how to do something, look it up in the examples!

also, make sure you're using a good IDE (integrated development envirenoment, lets you more easily write and compile code, try to set up flamebird2 or so, then, it'll give you a lot of feedback of small errors in the code :) )

i think that's about all i can say about this right now :), if you need more help, just ask :)

and one tiny last thing: there's a fenix forum, you better post and check there :)
 
thank you for your reply.
i found out the 1. thing some time ago
and i'm already using FB2, but I didn't know where to find such stuff.
In the fenix forum, noone is active...
 
thank you for your reply.
i found out the 1. thing some time ago
and i'm already using FB2, but I didn't know where to find such stuff.
In the fenix forum, noone is active...
there aren't so many fenix coders atm, but you can be sure that if you'd ask your question there you'd get an answer just as fast ^^ (or even faster, perhaps some fenix coders don't check this forum)
 
Last edited by a moderator:
Back
Top