|
3 registered members (TipmyPip, clint000, 1 invisible),
5,116
guests, and 0
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Need some help =)
#324691
05/22/10 17:39
05/22/10 17:39
|
Joined: Feb 2009
Posts: 80 STRING* location = "Germany";
Minamato
OP
Junior Member
|
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: 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: 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: 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
Serious User
|
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: Minamato]
#324727
05/22/10 21:09
05/22/10 21:09
|
Joined: Feb 2009
Posts: 80 STRING* location = "Germany";
Minamato
OP
Junior Member
|
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]
#324820
05/23/10 15:13
05/23/10 15:13
|
Joined: Feb 2009
Posts: 80 STRING* location = "Germany";
Minamato
OP
Junior Member
|
OP
Junior Member
Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
|
My item-function: 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: Aku_Aku]
#324825
05/23/10 15:46
05/23/10 15:46
|
Joined: Feb 2009
Posts: 80 STRING* location = "Germany";
Minamato
OP
Junior Member
|
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.
|
|
|
|