Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by Lapsa. 06/26/24 12:45
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Lapsa), 1,268 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Mino, squik, AemStones, LucasJoshua, Baklazhan
19061 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 4 1 2 3 4
Need some help =) #324691
05/22/10 17:39
05/22/10 17:39
Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
Minamato Offline OP
Junior Member
Minamato  Offline OP
Junior Member

Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
Hey guys!

I think two weeks ago I decided to create a little game. I wanted to do a "new" version of the old Arcade-classic "Pong". I wanted to integrate items into the game, like a bigger paddle, smaller paddle, fast ball and double ball.

So I made this little function - Which item appears should be random, so I used a variable called "itemhilfe" which should get attached to a random number (between 1 and 5). Depending on which number gets disgorged, different items should appear:

Quote:

function items() // function to create the items
{
while(itemsaktiv = 1)
{
itemhilfe = random(5); // itemhilfe becomes 1, 2, 3, 4 or 5
if (itemhilfe = 1) // if itemhilfe becomes 1, create the big paddle item
{
paddlebig_pan.flags = SHOW;
paddlebig_pan.pos_x += 4*time_step;
paddlebig_pan.pos_y += 2*time_step;
if ((paddlebig_pan.pos_x >= 931) | (paddlebig_pan.pos_y >= 664))
{
paddlebig_pan.flags = 0;
}
if ((paddlebig_pan.pos_y > right_pan.pos_y - 12) && (paddlebig_pan.pos_y < right_pan.pos_y + 96) && (paddlebig_pan.pos_x > 943) && (paddlebig_pan.pos_x < 955))
{
big_paddle();
paddlebig_pan.flags = 0;
}
}
else if (itemhilfe = 2) // if itemhilfe becomes 2, create speedball item
{
speedball_pan.flags = SHOW;
speedball_pan.pos_x += 4*time_step;
speedball_pan.pos_y += 1*time_step;
if ((speedball_pan.pos_x >= 931) | (speedball_pan.pos_y >= 664))
{
speedball_pan.flags = 0;
}
if ((speedball_pan.pos_y > right_pan.pos_y - 12) && (speedball_pan.pos_y < right_pan.pos_y + 96) && (speedball_pan.pos_x > 943) && (speedball_pan.pos_x < 955))
{
speedball_pan.flags = 0;
ball_speed.x = 3 - 6 * (random(50) % 2);
ball_speed.y = 3 - random(6);
}
}
else if (itemhilfe = 3) // if itemhilfe becomes 3, create small paddle item
{
paddlesmall_pan.flags = SHOW;
paddlesmall_pan.pos_x += 4*time_step;
paddlesmall_pan.pos_y += -1*time_step;
if ((paddlesmall_pan.pos_x >= 931) | (paddlesmall_pan.pos_y >= 664))
{
paddlesmall_pan.flags = 0;
}
if ((paddlesmall_pan.pos_y > right_pan.pos_y - 12) && (paddlesmall_pan.pos_y < right_pan.pos_y + 96) && (paddlesmall_pan.pos_x > 943) && (paddlesmall_pan.pos_x < 955))
{
small_paddle();
paddlesmall_pan.flags = 0;
}
}
else if (itemhilfe = 4) // if itemhilfe becomes 4, create double ball item
{
doubleball_pan.flags = SHOW;
doubleball_pan.pos_x += 4*time_step;
doubleball_pan.pos_y += -2*time_step;
if ((doubleball_pan.pos_x >= 931) | (doubleball_pan.pos_y >= 664))
{
doubleball_pan.flags = 0;
}
}
wait(1);
}
}


Now I included this function in the function which gets called when the game starts:

Quote:

function start_singleplayer()
{
wait (1);
mouse_mode = 0;
bg_pan.flags = SHOW; //set the flags of the background panel to SHOW
main_pan.flags = SHOW; //set the flags of the playing field panel to SHOW
left_pan.flags = SHOW | OVERLAY; //set the left paddle panel to SHOW and OVERLAY
right_pan.flags = SHOW | OVERLAY; //set the right paddle panel to SHOW and OVERLAY
ball_pan.flags = SHOW | OVERLAY; //set the ball panel to SHOW and OVERLAY
wait (1);

randomize();
ball_speed.x = 3 - 6 * (random(6) % 2); // -3 or 3, the direction in which the ball moves when the game starts
ball_speed.y = 3 - random(6); // -3...3, random vertical speed of the ball at the start of the game

wait(20);

items(); // create the items
while ((spielstand_rechts != 15) && (spielstand_links != 15)) // as long as the score of the left or right player has not reached 15
{
if (key_esc) { sys_exit(NULL);
}

// up or down for controlling the right paddle
if (key_cuu || key_cud) mode_right = USER;

// update the ball and both paddles
update_ball();
update_paddle(left_pan.pos_y,mode_left,key_s-key_w);
update_paddle(right_pan.pos_y,mode_right,key_cud-key_cuu);

// if the variable "big_use" is set to 1 (big paddle is active), use it to control the player
if (big_use = 1)
{
update_paddle(right_panbig.pos_y,mode_right,key_cud-key_cuu);
}

// if the variable "small_use" is set to 1 (small paddle is active), use it to control the player
if (small_use = 1)
{
update_paddle(right_pansmall.pos_y,mode_right,key_cud-key_cuu);
}

video_window(NULL,NULL,0,sTitle);

wait (1);
}

// if the score of the left or right player reached 15, shut down the game
if ((spielstand_rechts == 15) || (spielstand_links == 15))
{
sys_exit(NULL);
}
}


And those two function are used to create a big/small paddle:

Quote:

function big_paddle()
{
snd_play (click_wav, 20, 0);
big_use = 1; // set the variable "big_use" to 1, which means that the big paddle is used
right_pan.flags = 0; // hide the old paddle
right_panbig.flags = SHOW | OVERLAY; // show the bigger paddle
wait(-30); // wait 30 seconds
big_use = 0; // set all panels and variables to the normal condition ('cause big paddle is not used anymore)
right_pan.flags = SHOW | OVERLAY; // show the old paddle again
right_panbig.flags = 0; // hide the bigger paddle
}

function small_paddle()
{
snd_play (click_wav, 20, 0);
small_use = 1; // set the variable "small_use" to 1, which means that the small paddle is used
right_pan.flags = 0; // hide the old paddle
right_pansmall.flags = SHOW | OVERLAY; // show the smaller paddle
wait(-30); // wait 30 seconds
small_use = 0; // set all panels and variables to the normal condition ('cause big paddle is not used anymore)
right_pan.flags = SHOW | OVERLAY; // show the old paddle again
right_pansmall.flags = 0; // hide the bigger paddle
}


If I now start the game, an item appears - But just one time - I want, that the items appear every 1 minute (randomly chosen now!), plus it's everytime just the bigger paddle item...

Could anyone help me please? I hope you understand my problem =)

Greetz, Minamato

PS: all the names of the variables and function are german, sorry about that - but I translated the commentaries to English

Re: Need some help =) [Re: Minamato] #324719
05/22/10 20:36
05/22/10 20:36
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
itemhilfe = random(5); // itemhilfe becomes 1, 2, 3, 4 or 5
Wrong!! that gives you 0.000 till 4.999 in steps from 0.001. Read the manual !!!!!!!!
Use:
itemhilfe = integer(random(5) + 1);

if (big_use = 1)
Wrong!!
should be:
if (big_use == 1)


After that two things that is false at your code i stop searching for more. Better you make the Workshop

Last edited by Widi; 05/22/10 20:53.
Re: Need some help =) [Re: Widi] #324722
05/22/10 20:43
05/22/10 20:43
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
Also, it's better to not you hide and show panels like you do:
right_pan.flags = 0; // hide the old paddle
right_panbig.flags = SHOW | OVERLAY; // show the bigger paddle

Because setting the flags variable to 0 turns ALL flags off. This is bad if you want to keep other flags. Better do it like this:
right_pan.flags &= ~SHOW; // hide the old paddle
right_panbig.flags |= SHOW; // show the bigger paddle

If you do it like this, you have to set the OVERLAY flags only once and you don't have to set it each time again.

Re: Need some help =) [Re: Minamato] #324723
05/22/10 20:54
05/22/10 20:54
Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
Minamato Offline OP
Junior Member
Minamato  Offline OP
Junior Member

Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
thank you very much! =)

@Widi: Thanks, but you don't have to be so ignorant - I'm programming for nearly 1 year in C-Script/C-Lite and for over 4 years HTML/PHP/CSS - I know this "="/"==" mistake is very very very very stupid and I'm now really ashamed of it, but that doesn't has to make you laugh about me o.O But thanks for telling me this mistake - Have been too blind for that =)

Re: Need some help =) [Re: Minamato] #324727
05/22/10 21:09
05/22/10 21:09
Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
Minamato Offline OP
Junior Member
Minamato  Offline OP
Junior Member

Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
Another thank you to both of you - Changed my sourcecode. But now I have the problem that two items appear at the same time, instead of just one. Can you help me here, too?

Edit:

And the items appear, again, just one time and there doesn't want to come another one...is there any way to get it that way?

Last edited by Minamato; 05/22/10 21:16.
Re: Need some help =) [Re: Minamato] #324801
05/23/10 13:01
05/23/10 13:01
Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
Minamato Offline OP
Junior Member
Minamato  Offline OP
Junior Member

Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
just still need help^^...

Re: Need some help =) [Re: Minamato] #324804
05/23/10 13:30
05/23/10 13:30
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
Budapest
You should show all your changes, organized into understable form to the community. Do you think everybody is able here to read your thoughts?

Re: Need some help =) [Re: Minamato] #324820
05/23/10 15:13
05/23/10 15:13
Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
Minamato Offline OP
Junior Member
Minamato  Offline OP
Junior Member

Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
My item-function:

Quote:

function items() // function to create the items
{
while(itemsaktiv = 1)
{
itemhilfe = integer(random(5)+1); // itemhilfe becomes something between 1 and 6
if (itemhilfe == 1) // if itemhilfe becomes 1, create the big paddle item
{
paddlebig_pan.flags = SHOW;
paddlebig_pan.pos_x += 4*time_step;
paddlebig_pan.pos_y += 2*time_step;
if ((paddlebig_pan.pos_x >= 931) | (paddlebig_pan.pos_y >= 664))
{
paddlebig_pan.flags = 0;
}
if ((paddlebig_pan.pos_y > right_pan.pos_y - 12) && (paddlebig_pan.pos_y < right_pan.pos_y + 96) && (paddlebig_pan.pos_x > 943) && (paddlebig_pan.pos_x < 955))
{
big_paddle();
paddlebig_pan.flags = 0;
}
}
else if (itemhilfe == 2) // if itemhilfe becomes 2, create speedball item
{
speedball_pan.flags = SHOW;
speedball_pan.pos_x += 4*time_step;
speedball_pan.pos_y += 1*time_step;
if ((speedball_pan.pos_x >= 931) | (speedball_pan.pos_y >= 664))
{
speedball_pan.flags = 0;
}
if ((speedball_pan.pos_y > right_pan.pos_y - 12) && (speedball_pan.pos_y < right_pan.pos_y + 96) && (speedball_pan.pos_x > 943) && (speedball_pan.pos_x < 955))
{
speedball_pan.flags = 0;
ball_speed.x = 3 - 6 * (random(50) % 2);
ball_speed.y = 3 - random(6);
}
}
else if (itemhilfe == 3) // if itemhilfe becomes 3, create small paddle item
{
paddlesmall_pan.flags = SHOW;
paddlesmall_pan.pos_x += 4*time_step;
paddlesmall_pan.pos_y += -1*time_step;
if ((paddlesmall_pan.pos_x >= 931) | (paddlesmall_pan.pos_y >= 664))
{
paddlesmall_pan.flags = 0;
}
if ((paddlesmall_pan.pos_y > right_pan.pos_y - 12) && (paddlesmall_pan.pos_y < right_pan.pos_y + 96) && (paddlesmall_pan.pos_x > 943) && (paddlesmall_pan.pos_x < 955))
{
small_paddle();
paddlesmall_pan.flags = 0;
}
}
else if (itemhilfe == 4) // if itemhilfe becomes 4, create double ball item
{
doubleball_pan.flags = SHOW;
doubleball_pan.pos_x += 4*time_step;
doubleball_pan.pos_y += -2*time_step;
if ((doubleball_pan.pos_x >= 931) | (doubleball_pan.pos_y >= 664))
{
doubleball_pan.flags = 0;
}
}
wait(1);
}
}


Re: Need some help =) [Re: Minamato] #324824
05/23/10 15:41
05/23/10 15:41
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
Budapest
Your indentation is horrible.

Re: Need some help =) [Re: Aku_Aku] #324825
05/23/10 15:46
05/23/10 15:46
Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
Minamato Offline OP
Junior Member
Minamato  Offline OP
Junior Member

Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
my indentation? what do you mean with that?

EDIT:

Oh you mean the code? It's not my fault - quotations ignore the indentations. How can I show it with indentations?

Last edited by Minamato; 05/23/10 15:56.
Page 1 of 4 1 2 3 4

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1