Yam's For Gp2x - Need Advices...


GuZzO

Still Fresh
Joined
Jan 29, 2009
Messages
9
Hello,

I'm trying to learn how to programing in Fenix. I start a dice game : "yam's".
I think the code is a bit clumsy but it almost works as I want. I had a look in differents tutorials and game codes but I still have basics problems...

I try differents ways to exit the program but nothing works...
What do you advice to quit correctly the game?

In future developments, i would like to click on dices to keep them from the next draw.
Does the way i code the dices allow to check for a collision with the mouse pointer?

I post the code right here:



CODE

//------------------------------------------------------------------------------
// Yam version 0.1 30-01-2009
//------------------------------------------------------------------------------

Program yam;


global

//GP2X Keys
__A = _control;
__B = _alt;
__X = _x;
__Y = _y;
__SELECT = _space;
__R = _tab;
__L = _backspace;
__START = _enter;
//__VolP = _à définir;
//__VolM = _à définir;

//Loading stuff
hasard1;
map1;
hasard2;
map2;
hasard3;
Map3;
hasard4;
map4;
hasard5;
map5;

//Sprites & Fonts
fpg1;
fnt1;

//Counter
num_de;

begin

//Initialisation de l'écran
set_mode(320,240,16);
set_fps(30,0);

//Chargement des graphics
fpg1 = load_fpg("yam16bit.fpg");
fnt1 = load_fnt("big.fnt");
set_text_color(1);

//title
nettoyage_ecran ();



Loop;

//Exit if pressed escape
if(key(_esc))exit();end


While (!key(__B));
//Clean the screen
nettoyage_ecran ();

From num_de = 1 to 5 step 1
//Draw randomly 5 dices
dice(num_de);
End;

FRAME(250);
End;

display_dice ();

Repeat
FRAME;
Until (key(__A));

nettoyage_ecran ();

End;


End;


///////////////////////////////////////////////////////////////////////////////////////////////////
//PROCESSES
///////////////////////////////////////////////////////////////////////////////////////////////////

Process dice (Int number)
//Draw randomly 5 dices

Private
num_dice;

begin

num_dice = rand (1,6);
put(fpg1, num_dice, (40*number), 210);

if (number == 1)
hasard1 = num_dice;
End;

if (number == 2)
hasard2 = num_dice;
End;

if (number == 3)
hasard3 = num_dice;
End;

if (number == 4)
hasard4 = num_dice;
End;

if (number == 5)
hasard5 = num_dice;
End;

End;


///////////////////////////////////////////////////////////////////////////////////////////////////

Process display_dice ()
//Display the result

begin

write ( 0, 100, 80, 1, "Dice n°1 : " + hasard1);
write ( 0, 100, 90, 1, "Dice n°2 : " + hasard2);
write ( 0, 100, 100, 1, "Dice n°3 : " + hasard3);
write ( 0, 100, 110, 1, "Dice n°4 : " + hasard4);
write ( 0, 100, 120, 1, "Dice n°5 : " + hasard5);
write ( 0, 220, 90, 1, "A new draw?");
write ( 0, 220, 110, 1, "Press Ctrl");

End;


///////////////////////////////////////////////////////////////////////////////////////////////////

Process nettoyage_ecran ()
//Clean the screen and display the title

begin
delete_text(all_text);
PUT_SCREEN ( fpg1,7);
write ( 1, 160, 15, 1, "YAM'S par D&G");
Frame;
End;







the missing files are here:
SOURCES & FPG

I really appreciate any help or advice!!
Thanks in advance!

Guzzo
 
Ok, for exiting exit(); usually works, another way in your case could be to put the following in the main program loop

CODE
IF(key(_esc))
RETURN;
END


a Return in the main program loop should cause the main program function to complete which will terminate the whole program.

as for interaction with the mouse, if you make a graphic that you want to use as the cursor then you can make a process like so:

CODE
PROCESS cursor();
BEGIN
graph = 100; (or what ever number you cursor graphic is)
LOOP
x = mouse.x;
y = mouse.y;
FRAME;
END
END


Then you can interact with this process like so:

Inside the dice process you can use the collision function

CODE
IF(collision(TYPE cursor) AND mouse.left)
whatever action you want to take when you click on a dice with the left mouse button
END


Hope that helps.

P.S There's a dedicated forum for fenix help.
 
thanks!
may the admin move this topic in the right place?

I modified the code writing
if(key(_esc))exit();end
in every loop of the main process....
i don't know if it's a good choice but it's the only working one....


For the mouse pointer, what's the difference with this code:

CODE

PROCESS cursor();
BEGIN
dmap = new_map(10,10,8);
map_clear(0,dmap,rgb(150,150,150));
mouse.graph = dmap;
END




but the collision process doesn't work as i did...

CODE


Process display_dice ()
//Display the result

begin

write ( 0, 100, 80, 1, "Dice n°1 : " + hasard1);
write ( 0, 100, 90, 1, "Dice n°2 : " + hasard2);
write ( 0, 100, 100, 1, "Dice n°3 : " + hasard3);
write ( 0, 100, 110, 1, "Dice n°4 : " + hasard4);
write ( 0, 100, 120, 1, "Dice n°5 : " + hasard5);
write ( 0, 220, 90, 1, "A new draw?");
write ( 0, 220, 110, 1, "Press Ctrl");

Repeat
IF(collision(TYPE cursor) AND mouse.left)
put(fpg1, hasard1, 40, 180);
ELSE
put(fpg1, hasard1, 40, 210);
END;
Frame;
Until (key(__A));


End;




whatever i do, the dice appears upside, even if i don't click left....
11294541kv9.jpg


and another strange thing, the first dice disppears when i use the "Alt Gr" touch ?!?...
90080662iz2.jpg
 
Ok, im not quite sure exactly what it is your trying to do, but I think that your making a Yatzee game:

1. Roll 5 Dice
2. Select ones to keep ("hold")
3. Roll rest of dice

Here's how I would do it:

CODE
PROGRAM yam;
BEGIN
load_fpg("fpg_name");
cursor();
LOOP
IF(key(_control))
WHILE(key(_control)) FRAME; END //this makes it so you have to release control before the press does anything, stops accidental multiple presses.
signal(TYPE dice,s_kill); // this will kill off all the currently on-screen dice
dice(40,200,1);
dice(80,200,2);
dice(80,200,3);
dice(80,200,4);
dice(80,200,5);
dice(80,200,6); // adjust the first 2 values in each call to put the dice in the right place
END
FRAME;
END
END

PROCESS cursor();
BEGIN
graph = 100 (or whatever number)
LOOP
x = mouse.x;
y = mouse.y;
FRAME;
END

PROCESS dice(x,y,number);
PRIVATE
num_dice;
BEGIN
num_dice = rand(1,6);
graph = num_dice + offset; (have the images for the different dice faces numbered sequentially in your FPG, say 11,12,13,14,15,16 and offset would be 10)

SWITCH (number)
CASE 1:
hasard1 = num_dice;
END
CASE 2:
hasard2 = num_dice;
END
CASE 3:
hasard3 = num_dice;
END
CASE 4:
hasard4 = num_dice;
END
CASE 5:
hasard5 = num_dice;
END
CASE 6:
hasard6 = num_dice;
END
END

LOOP
FRAME;
END
END


Ok so, provided I haven't made any mistakes (i havent tested it) this should give you 5 dice which change everytime you press control.

I'll figure out the dice hold in a min.

P.S you'll need to put in your declarations of the hasard variables and the code to put the text on-screen.
 
Ok, think i've sorted out the holding of dice, change the code to:
CODE


PROGRAM yam;
GLOBAL
shake = 0;
BEGIN
load_fpg("fpg_name");
cursor();

dice(10,200,1);
dice(20,200,2);
dice(30,200,3);
dice(40,200,4);
dice(50,200,5);
dice(60,200,6);

LOOP
shake = 0;
IF(key(_control))
WHILE(key(_control)) FRAME; END //this makes it so you have to release control before the press does anything, stops accidental multiple presses.
shake = 1;
END
FRAME;
END
END

PROCESS cursor();
BEGIN
graph = 100 (or whatever number)
LOOP
x = mouse.x;
y = mouse.y;
FRAME;
END

PROCESS dice(x,y,number);
PRIVATE
num_dice;
hold = false;
BEGIN
num_dice = rand(1,6);
graph = num_dice + offset; (have the images for the different dice faces numbered sequentially in your FPG, say 11,12,13,14,15,16 and offset would be 10)

SWITCH (number)
CASE 1:
hasard1 = num_dice;
END
CASE 2:
hasard2 = num_dice;
END
CASE 3:
hasard3 = num_dice;
END
CASE 4:
hasard4 = num_dice;
END
CASE 5:
hasard5 = num_dice;
END
CASE 6:
hasard6 = num_dice;
END
END

LOOP
graph = num_dice + offset;
IF(collision(TYPE cursor) AND mouse.left)
IF(hold == false)
hold = true;
//do what you want to change the appearence of a held dice, id change the graph by changing the offset value
ELSEIF(hold == true);
hold = false;
//change offset value back here to make dice look regular (unheld)
END
END
IF(shake == 1 AND hold == false)
shake = 0;
num_dice = rand(1,6); //this should change the value of the dice, but leave it if it's being held
END
FRAME;
END
END
 
Thanks for the code, I understood many things with it !!
Even if i did it my own way, the main part of my program works! ^^

The only bad thing is I'm unable to use the touchscreen....
It works on my PC but "mouse.x" and "mouse.y" commands don't react on my GP2X. I have a F200 with "Homebrew Touchscreen enabler" patch installed.
 
No, idea how to use the touchsreen on the F200, as I only have an F100
 
Hi, do other programs on your F200 work with touchscreen if not it maybe just needs calibrating. If other programs work fine then it must be a code issue.
One other thing it could be - are you using the correct fenix runtime as the older versions didn't have touchscreen support You need beta 6 or Ufenix for touchscreen.
I sent sent you a pm with my MSN details if you want some help sorting out the problem.
 
I downloaded 3 differents runtime (beta5, v0.1 and v0.2) and i didn't use the good one..... what a shame! ^^
now i know the right version is 0.2. The stylus works fine!
 
QUOTE
Ok, i'm not quite sure exactly what it is your trying to do, but I think that your making a Yatzee game:


I didn't know this name, I knew only the french name... but yes indeed i try to make a Yatzee game. I finished the first part (roll dice, keep and roll again).

I have to develop how to calculate and store the score.... it's gonna be tougher i think!
 
Back
Top