Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 831 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
I need some help please? :( #238842
11/30/08 17:14
11/30/08 17:14
Joined: Nov 2008
Posts: 25
M
MrTwiggy101 Offline OP
Newbie
MrTwiggy101  Offline OP
Newbie
M

Joined: Nov 2008
Posts: 25
Hey there! I recently started to learn Lite-C (2 days ago) and then I recently began to create a simple pong game for experience and practice (yesterday), I had run into some problems, and I tried to use the least amount of help, only using the workshops, and occasionally using prototype script for guidelines. I just finished it, but I have run into a problem. Look, I'll show you. This is my final code.

Code:
 #include <acknex.h>
#include <default.c>





/////////////////////////////////////These are the VARIABLES for the scores./////////////////////////
var top_score = 0;
var bottom_score = 0; 

///////////////////////////////////////These are the BMAP DEFINITIONS for the BMAPS./////////////////////
BMAP* left_border = "border_left.bmp";
BMAP* right_border = "border_right.bmp";
BMAP* center_line = "crossed_line.bmp";
BMAP* up_pong = "pong_up.bmp";
BMAP* down_pong = "pong_down.bmp";
BMAP* pongd_ball = "pong_ball.bmp";
/////////////////////////////////////These are PANELS for the BMAPS.////////////////////////////
PANEL* the_left_border =
{ // This is PANEL for Left Border
  pos_x = 0;              
  pos_y = 0;  
  layer = 2;
  digits(0, 0, 2, *, 1, top_score);
  bmap = left_border;
  flags = VISIBLE;
}
PANEL* border_right =
{ //This is a PANEL for Right Border
  pos_x = 620;
  pos_y = 0;
  layer = 2;
  digits(0, 0, 2, *, 1, bottom_score);
  bmap = right_border;
  flags = VISIBLE;
}
PANEL* crossed_line =
{//This is a PANEL for Center Line
  pos_x = 0;
  pos_y = 225;
  layer = 1;
  bmap = center_line;
  flags = VISIBLE;
}
PANEL* upper_pong =
{//This is a PANEL for Upper Pong
  pos_x = 225;
  pos_y = 20;
  layer = 6;
  bmap = up_pong;
  flags = VISIBLE;
}
PANEL* downed_pong =
{//This is a PANEL for Downed Pong
  pos_x = 225;
  pos_y = 430;
  layer = 6;
  bmap = down_pong;
  flags = VISIBLE;
}
PANEL* ponged_ball =
{//This is a PANEL for Pong Ball
pos_x = 300;
pos_y = 225;
layer = 6;
bmap = pongd_ball;
flags = VISIBLE;
}


      
      ////////////////////////////////////These are the SOUNDS for the effects./////////////////////////
SOUND* beep_1 = "beep.wav";
SOUND* goal = "score.wav";


////////////////////////////////////This defines the computer and user./////////////////////////

#define USER 1
#define COMPUTER 0

STRING* sTitle = "";
TEXT* tName = { string("computer", "user"); }

VECTOR* ball_speed;
var mode_top = COMPUTER;
var mode_bottom = COMPUTER;

////////////////////////////////////This updates the ball.//////////////////////////////
function update_ball()
{// This function updates ball
	pongd_ball.pos_x += 7*ball_speed.x*time_step;
	pongd_ball.pos_y += 7*ball_speed.y*time_step;
	
	/////////////////////////////////See if ball hit paddle/border.//////////////////////
	
	if (pongd_ball.pos_x < 0)  //If ball hits the left border on X axis
	{
		ball_speed.x = -3 - random(3);
		snd_play (beep_1, 50, 0);
	}
	else if (pongd_ball.pos_x > 620) //If ball hits the right border on X axis
	{
		ball_speed.x = +3 + random(3);
		snd_play (beep_1, 50, 0);
	}
	if (pongd_ball.pos_y < 0) //If ball hits the upper edge of the window on Y axis
	{
		ball_speed.y = -3 - random(3);
		snd_play (goal, 70, 0);
		top_score += 1;
		pongd_ball.pos_y = 0; 
	}
	else if (pongd_ball.pos_y > 450) //If ball hits the lower edge of the window on Y axis
{
	ball_speed.y = +3 + random(3);
	snd_play (goal, 70, 0);
	bottom_score += 1;
	pongd_ball.pos_y = 450;)
}

if ((pongd_ball.pos_y > 430) && (pongd_ball.pos_y < 440) && (pongd_ball.pos_x > down_pong.pos_x - 12) && (pongd_ball.pos_x < down_pong.pos_x + 90))
{//Bottom player has blocked the ball.
	snd_play (beep_1. 70. 0);
	ball_speed.x = 3 + random(3);
	ball_speed.y = 3 - random(3);
}
else if ((pongd_ball.pos_y < 20) && (pongd_ball.pos_y > 10) && (pongd_ball.pos_x > up_pong.pos_x - 12) && (pongd_ball.pos_x < up_pong.pos_x + 90))
{
	snd_play (beep_1, 70, 0);
	ball_speed.x = 3 - random(3);
	ball_speed.y = 3 + random(3);
}


////////////////////////////////This section updates the paddles.///////////////////
function update_paddle(var *paddle_pos,var paddle_mode,var key)
{
   if (COMPUTER == paddle_mode) {
		if ((ball_pan.pos_x > 10) && (ball_pan.pos_x < 600)) // Gives computer boundries.
			*paddle_pos = ball_pan.pos_y - 42;
	}
	else if (USER == paddle_mode) {
      *paddle_pos += 30*time_step*key;   	   
		*paddle_pos = clamp(*paddle_pos,35,470);
	}
	
}


///////////////////////////////////This is the function for the screen.//////////////////////////
function main()
{//This is the blue screen color
      screen_color.blue = 150;
      wait (1);
   
   randomize();
	ball_speed.x = 3 - 6 * (random(6) % 2); // -3 or 3, random ball direction at game start
	ball_speed.y = 3 - random(6); // -3...3, random vertical speed at game start
	
	while ((right_score != 10) && (left_score != 10))
	{
      if (key_esc) { sys_exit(NULL); }
      
//Switch to user mode if a paddle key is pressed      
      if (key_s || key_d) mode_top = USER;
      if (key_cul || key_cur) mode_bottom = USER;

// Update paddles and ball, and count scores
      update_ball();
      update_paddle(left_pan.pos_x,mode_top,key_s-key_d);
      update_paddle(right_pan.pos_x,mode_bottom,key_cul-key_cur);

// compose the sTitle string
      str_cpy(sTitle,"Pong Demo - ");
      str_cat(sTitle,(tName.pstring)[mode_top]);
      str_cat(sTitle," vs. ");
      str_cat(sTitle,(tName.pstring)[mode_bottom]);
      video_window(NULL,NULL,0,sTitle);

		wait (1);
	}
}


But on certain lines of code (quite of a few) I had to use the lines such as:

pong_ball.pos_y which is the position of my pong ball bmp, but, whenever I try to run it, it says that pos_y is not a bitmap? So, what should I do in this situation to ask the position of the paddle, or pong ball, in that same way up there, without the script engine mistaking the pos_y as a BMAP but more as a position on the Y axis?

Thanks a ton! laugh

Re: I need some help please? :( [Re: MrTwiggy101] #238845
11/30/08 17:38
11/30/08 17:38
Joined: Oct 2004
Posts: 150
Germany
T
tkunze Offline
Member
tkunze  Offline
Member
T

Joined: Oct 2004
Posts: 150
Germany
Your problem is that you try to move the bitmap itself instead of the panel you created. The panel structure does support .pos_x while the bitmap itselv does not.

Wrong:
Code:
	pongd_ball.pos_x += 7*ball_speed.x*time_step;
 


Correct:
Code:
	ponged_ball.pos_x += 7*ball_speed.x*time_step;
 


Re: I need some help please? :( [Re: tkunze] #238847
11/30/08 18:24
11/30/08 18:24
Joined: Nov 2008
Posts: 25
M
MrTwiggy101 Offline OP
Newbie
MrTwiggy101  Offline OP
Newbie
M

Joined: Nov 2008
Posts: 25
Thanks! It worked laugh Atleast I learned something. But I have another problem. This my code now, I changed a few things.

Code:
#include <acknex.h>
#include <default.c>





/////////////////////////////////////These are the VARIABLES for the scores./////////////////////////
var top_score = 0;
var bottom_score = 0; 

///////////////////////////////////////These are the BMAP DEFINITIONS for the BMAPS./////////////////////
BMAP* left_border = "border_left.bmp";
BMAP* right_border = "border_right.bmp";
BMAP* center_line = "crossed_line.bmp";
BMAP* up_pong = "pong_up.bmp";
BMAP* down_pong = "pong_down.bmp";
BMAP* pongd_ball = "pong_ball.bmp";
/////////////////////////////////////These are PANELS for the BMAPS.////////////////////////////
PANEL* the_left_border =
{ // This is PANEL for Left Border
  pos_x = 0;              
  pos_y = 0;  
  layer = 2;
  digits(0, 0, 2, *, 1, top_score);
  bmap = left_border;
  flags = VISIBLE;
}
PANEL* border_right =
{ //This is a PANEL for Right Border
  pos_x = 620;
  pos_y = 0;
  layer = 2;
  digits(0, 0, 2, *, 1, bottom_score);
  bmap = right_border;
  flags = VISIBLE;
}
PANEL* crossed_line =
{//This is a PANEL for Center Line
  pos_x = 0;
  pos_y = 225;
  layer = 1;
  bmap = center_line;
  flags = VISIBLE;
}
PANEL* upper_pong =
{//This is a PANEL for Upper Pong
  pos_x = 225;
  pos_y = 20;
  layer = 6;
  bmap = up_pong;
  flags = VISIBLE;
}
PANEL* downed_pong =
{//This is a PANEL for Downed Pong
  pos_x = 225;
  pos_y = 430;
  layer = 6;
  bmap = down_pong;
  flags = VISIBLE;
}
PANEL* ponged_ball =
{//This is a PANEL for Pong Ball
pos_x = 300;
pos_y = 225;
layer = 6;
bmap = pongd_ball;
flags = VISIBLE;
}


           ////////////////////////////////////These are the SOUNDS for the effects./////////////////////////
SOUND* beep_1 = "beep.wav";
SOUND* goal = "score.wav";


////////////////////////////////////This defines the computer and user./////////////////////////

#define USER 1
#define COMPUTER 0

STRING* sTitle = "";
TEXT* tName = { string("computer", "user"); }

VECTOR* ball_speed;
var mode_top = COMPUTER;
var mode_bottom = COMPUTER;

////////////////////////////////////This updates the ball.//////////////////////////////
function update_ball()
{// This function updates ball
	ponged_ball.pos_x += 7*ball_speed.x*time_step;
	ponged_ball.pos_y += 7*ball_speed.y*time_step;
	
	/////////////////////////////////See if ball hit paddle/border.//////////////////////
	
	if (ponged_ball.pos_x < 0)  //If ball hits the left border on X axis
	{
		ball_speed.x = -3 - random(3);
		snd_play (beep_1, 50, 0);
	}
	else if (ponged_ball.pos_x > 620) //If ball hits the right border on X axis
	{
		ball_speed.x = 3 - random(3);
		snd_play (beep_1, 70, 0);
	}
	if (ponged_ball.pos_y < 0) //If ball hits the upper edge of the window on Y axis
	{
		ball_speed.y = -3 - random(3);
		snd_play (goal, 70, 0);
		top_score += 1;
		ponged_ball.pos_y = 0; 
	}
	else if (ponged_ball.pos_y > 450) //If ball hits the lower edge of the window on Y axis
{
	ball_speed.y = 3 - random(3);
	snd_play (goal, 70, 0);
	bottom_score += 1;
	
}

if ((ponged_ball.pos_y > 430) && (ponged_ball.pos_y < 440) && (ponged_ball.pos_x > downed_pong.pos_x - 12) && (ponged_ball.pos_x < downed_pong.pos_x + 90))
{//Bottom player has blocked the ball.
	snd_play (beep_1, 70, 0);
	ball_speed.x = 3 + random(3);
	ball_speed.y = 3 - random(3);
}
else if ((ponged_ball.pos_y < 20) && (ponged_ball.pos_y > 10) && (ponged_ball.pos_x > upper_pong.pos_x - 12) && (ponged_ball.pos_x < upper_pong.pos_x + 90))
{
	snd_play (beep_1, 70, 0);
	ball_speed.x = 3 - random(3);
	ball_speed.y = 3 + random(3);
}


////////////////////////////////This section updates the paddles.///////////////////
function update_paddle(var paddle_pos,var paddle_mode,var key)
{
   if (COMPUTER == paddle_mode) 
   {
		if ((ponged_ball.pos_x > 10) && (ponged_ball.pos_x < 600)) // Gives computer boundries.
			*paddle_pos = ponged_ball.pos_y - 42;
	}
	else if (USER == paddle_mode) 
	{
      *paddle_pos += 30*time_step*key;   	   
		*paddle_pos = clamp(*paddle_pos,35,470);
	}
	
}


///////////////////////////////////This is the function for the screen.//////////////////////////
function main()
{//This is the blue screen color
      screen_color.blue = 150;
      wait (1);
   
   randomize();
	ball_speed.x = 3 - 6 * (random(6) % 2); // -3 or 3, random ball direction at game start
	ball_speed.y = 3 - random(6); // -3...3, random vertical speed at game start
	
	while ((bottom_score != 10) && (top_score != 10))
	{
      if (key_esc) { sys_exit(NULL); }
      
//Switch to user mode if a paddle key is pressed      
      if (key_s || key_d) mode_top = USER;
      if (key_cul || key_cur) mode_bottom = USER;

// Update paddles and ball, and count scores
      update_ball();
      update_paddle(upper_pong.pos_x,mode_top,key_s-key_d);
      update_paddle(downed_pong.pos_x,mode_bottom,key_cul-key_cur);

// compose the sTitle string
      str_cpy(sTitle,"Pong Demo - ");
      str_cat(sTitle,(tName.pstring)[mode_top]);
      str_cat(sTitle," vs. ");
      str_cat(sTitle,(tName.pstring)[mode_bottom]);
      video_window(NULL,NULL,0,sTitle);

		wait (1);
	}
}


But now, when I try to open it, it says this:

Error in 'MAIN' line 139: 'paddle_mode' undeclared identifier

< if (COMPUTER == paddle_mode) >
.
Can't compie PING_PONG_TEST2.C

And its saying it about these lines:

function update_paddle(var paddle_pos,var paddle_mode,var key)
{
if (COMPUTER == paddle_mode)
{
if ((ponged_ball.pos_x > 10) && (ponged_ball.pos_x < 600)) // Gives computer boundries.
*paddle_pos = ponged_ball.pos_y - 42;
}

Its saying that I havn't deined the var paddle_mode, but I did RIGHT above it? Whats wrong?

Re: I need some help please? :( [Re: MrTwiggy101] #238850
11/30/08 19:11
11/30/08 19:11
Joined: Oct 2004
Posts: 150
Germany
T
tkunze Offline
Member
tkunze  Offline
Member
T

Joined: Oct 2004
Posts: 150
Germany
You forgot a closing text in the function update_ball(). Just add } at the end of this function and it will work.

Re: I need some help please? :( [Re: tkunze] #238858
11/30/08 20:09
11/30/08 20:09
Joined: Nov 2008
Posts: 25
M
MrTwiggy101 Offline OP
Newbie
MrTwiggy101  Offline OP
Newbie
M

Joined: Nov 2008
Posts: 25
Originally Posted By: tkunze
You forgot a closing text in the function update_ball(). Just add } at the end of this function and it will work.
I dont understand?

Re: I need some help please? :( [Re: MrTwiggy101] #238859
11/30/08 20:17
11/30/08 20:17
Joined: Oct 2004
Posts: 150
Germany
T
tkunze Offline
Member
tkunze  Offline
Member
T

Joined: Oct 2004
Posts: 150
Germany
Your function update_ball() should look like this. At the moment the last } is missing.

Code:
 
function update_ball()
{// This function updates ball
	ponged_ball.pos_x += 7*ball_speed.x*time_step;
	ponged_ball.pos_y += 7*ball_speed.y*time_step;
	
	/////////////////////////////////See if ball hit paddle/border.//////////////////////
	
	if (ponged_ball.pos_x < 0)  //If ball hits the left border on X axis
	{
		ball_speed.x = -3 - random(3);
		snd_play (beep_1, 50, 0);
	}
	else if (ponged_ball.pos_x > 620) //If ball hits the right border on X axis
	{
		ball_speed.x = 3 - random(3);
		snd_play (beep_1, 70, 0);
	}
	if (ponged_ball.pos_y < 0) //If ball hits the upper edge of the window on Y axis
	{
		ball_speed.y = -3 - random(3);
		snd_play (goal, 70, 0);
		top_score += 1;
		ponged_ball.pos_y = 0; 
	}
	else if (ponged_ball.pos_y > 450) //If ball hits the lower edge of the window on Y axis
	{
		ball_speed.y = 3 - random(3);
		snd_play (goal, 70, 0);
		bottom_score += 1;
		
	}
	
	if ((ponged_ball.pos_y > 430) && (ponged_ball.pos_y < 440) && (ponged_ball.pos_x > downed_pong.pos_x - 12) && (ponged_ball.pos_x < downed_pong.pos_x + 90))
	{//Bottom player has blocked the ball.
		snd_play (beep_1, 70, 0);
		ball_speed.x = 3 + random(3);
		ball_speed.y = 3 - random(3);
	}
	else if ((ponged_ball.pos_y < 20) && (ponged_ball.pos_y > 10) && (ponged_ball.pos_x > upper_pong.pos_x - 12) && (ponged_ball.pos_x < upper_pong.pos_x + 90))
	{
		snd_play (beep_1, 70, 0);
		ball_speed.x = 3 - random(3);
		ball_speed.y = 3 + random(3);
	}
}


Re: I need some help please? :( [Re: MrTwiggy101] #238860
11/30/08 20:17
11/30/08 20:17
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
add a } after
else if ((ponged_ball.pos_y < 20) && (ponged_ball.pos_y > 10) && (ponged_ball.pos_x > upper_pong.pos_x - 12) && (ponged_ball.pos_x < upper_pong.pos_x + 90))
{
snd_play (beep_1, 70, 0);
ball_speed.x = 3 - random(3);
ball_speed.y = 3 + random(3);
}


3333333333
Re: I need some help please? :( [Re: Quad] #238864
11/30/08 20:59
11/30/08 20:59
Joined: Nov 2008
Posts: 25
M
MrTwiggy101 Offline OP
Newbie
MrTwiggy101  Offline OP
Newbie
M

Joined: Nov 2008
Posts: 25
OH! Thanks laugh!!! Now I have another one.

Its in this code:

function update_paddle(var paddle_pos,var paddle_mode,var key)
{
if (COMPUTER == paddle_mode)
{
if ((ponged_ball.pos_x > 10) && (ponged_ball.pos_x < 600)) // Gives computer boundries.
*paddle_pos = ponged_ball.pos_y - 42;
}
else if (USER == paddle_mode)
{
*paddle_pos += 30*time_step*key;
*paddle_pos = clamp(*paddle_pos,35,470);
}

}

And the error is this:

Error in 'MAIN' line 143: illegal indirection

< "padde_pos = ponged_ball.pos_y - 42; >
.
Can't compile PING_PONG_TEST2.C

Re: I need some help please? :( [Re: MrTwiggy101] #238948
12/01/08 11:47
12/01/08 11:47
Joined: Oct 2004
Posts: 150
Germany
T
tkunze Offline
Member
tkunze  Offline
Member
T

Joined: Oct 2004
Posts: 150
Germany
i did not worked much using pointer in lite-c. However the syntax of using
pointer in lite-c is different to ANSI-C.

There is no construct like *variable you would use to access a pointer. Regardless if a something is a variable or a pointer you access it always
with the variable name.

Wrong:
function update_paddle(var paddle_pos,var paddle_mode,var key)
*padde_pos = ponged_ball.pos_y - 42

Correct
function update_paddle(var* paddle_pos,var* paddle_mode,var* key)
padde_pos = ponged_ball.pos_y - 42

Re: I need some help please? :( [Re: tkunze] #238977
12/01/08 15:21
12/01/08 15:21
Joined: Nov 2008
Posts: 25
M
MrTwiggy101 Offline OP
Newbie
MrTwiggy101  Offline OP
Newbie
M

Joined: Nov 2008
Posts: 25
Hey guys! Thanks for the help! Everything helped that you guys said. But there is one more problem frown

Now, when I open it, it opens fine, no error nothing. Everything loads up fine, I can see the paddles in the middle where they are supposed to be, the borders are there, all the images are there, the ball is in the middle. But, its not doing anything? Its just sitting there. Could someone just take a quick look at my code and tell me, did I waste my time, and I created a code that just doesn't work? Or is there, like a few lines of code that are wrong and I can fix it?

Code:
#include <acknex.h>
#include <default.c>





/////////////////////////////////////These are the VARIABLES for the scores./////////////////////////
var top_score = 0;
var bottom_score = 0; 

///////////////////////////////////////These are the BMAP DEFINITIONS for the BMAPS./////////////////////
BMAP* left_border = "border_left.bmp";
BMAP* right_border = "border_right.bmp";
BMAP* center_line = "crossed_line.bmp";
BMAP* up_pong = "pong_up.bmp";
BMAP* down_pong = "pong_down.bmp";
BMAP* pongd_ball = "pong_ball.bmp";
/////////////////////////////////////These are PANELS for the BMAPS.////////////////////////////
PANEL* the_left_border =
{ // This is PANEL for Left Border
  pos_x = 0;              
  pos_y = 0;  
  layer = 2;
  digits(0, 0, 2, *, 1, top_score);
  bmap = left_border;
  flags = VISIBLE;
}
PANEL* border_right =
{ //This is a PANEL for Right Border
  pos_x = 620;
  pos_y = 0;
  layer = 2;
  digits(0, 0, 2, *, 1, bottom_score);
  bmap = right_border;
  flags = VISIBLE;
}
PANEL* crossed_line =
{//This is a PANEL for Center Line
  pos_x = 0;
  pos_y = 225;
  layer = 1;
  bmap = center_line;
  flags = VISIBLE;
}
PANEL* upper_pong =
{//This is a PANEL for Upper Pong
  pos_x = 225;
  pos_y = 20;
  layer = 6;
  bmap = up_pong;
  flags = VISIBLE;
}
PANEL* downed_pong =
{//This is a PANEL for Downed Pong
  pos_x = 225;
  pos_y = 430;
  layer = 6;
  bmap = down_pong;
  flags = VISIBLE;
}
PANEL* ponged_ball =
{//This is a PANEL for Pong Ball
pos_x = 300;
pos_y = 225;
layer = 6;
bmap = pongd_ball;
flags = VISIBLE;
}


           ////////////////////////////////////These are the SOUNDS for the effects./////////////////////////
SOUND* beep_1 = "beep.wav";
SOUND* goal = "score.wav";


////////////////////////////////////This defines the computer and user./////////////////////////

#define USER 1
#define COMPUTER 0

STRING* sTitle = "";
TEXT* tName = { string("computer", "user"); }

VECTOR* ball_speed;
var mode_top = COMPUTER;
var mode_bottom = COMPUTER;

////////////////////////////////////This updates the ball.//////////////////////////////
 
function update_ball()
{// This function updates ball
	ponged_ball.pos_x += 7*ball_speed.x*time_step;
	ponged_ball.pos_y += 7*ball_speed.y*time_step;
	
	/////////////////////////////////See if ball hit paddle/border.//////////////////////
	
	if (ponged_ball.pos_x < 0)  //If ball hits the left border on X axis
	{
		ball_speed.x = -3 - random(3);
		snd_play (beep_1, 50, 0);
	}
	else if (ponged_ball.pos_x > 620) //If ball hits the right border on X axis
	{
		ball_speed.x = 3 - random(3);
		snd_play (beep_1, 70, 0);
	}
	if (ponged_ball.pos_y < 0) //If ball hits the upper edge of the window on Y axis
	{
		ball_speed.y = -3 - random(3);
		snd_play (goal, 70, 0);
		top_score += 1;
		ponged_ball.pos_y = 0; 
	}
	else if (ponged_ball.pos_y > 450) //If ball hits the lower edge of the window on Y axis
	{
		ball_speed.y = 3 - random(3);
		snd_play (goal, 70, 0);
		bottom_score += 1;
		
	}
	
	if ((ponged_ball.pos_y > 430) && (ponged_ball.pos_y < 440) && (ponged_ball.pos_x > downed_pong.pos_x - 12) && (ponged_ball.pos_x < downed_pong.pos_x + 90))
	{//Bottom player has blocked the ball.
		snd_play (beep_1, 70, 0);
		ball_speed.x = 3 + random(3);
		ball_speed.y = 3 - random(3);
	}
	else if ((ponged_ball.pos_y < 20) && (ponged_ball.pos_y > 10) && (ponged_ball.pos_x > upper_pong.pos_x - 12) && (ponged_ball.pos_x < upper_pong.pos_x + 90))
	{
		snd_play (beep_1, 70, 0);
		ball_speed.x = 3 - random(3);
		ball_speed.y = 3 + random(3);
	}
}

////////////////////////////////This section updates the paddles.///////////////////
function update_paddle(var *paddle_pos,var paddle_mode,var key)
{
   if (COMPUTER == paddle_mode) 
   {
		if ((ponged_ball.pos_x > 100) && (ponged_ball.pos_x < 490)) // Gives computer boundries.
		*paddle_pos = ponged_ball.pos_x - 42;
	}
	else if (USER == paddle_mode) 
	{
      *paddle_pos += 30*time_step*key;   	   
		*paddle_pos = clamp(*paddle_pos,35,470);
	}
	
}


///////////////////////////////////This is the function for the screen.//////////////////////////
function main();
{//This is the blue screen color
      screen_color.blue = 150;
      wait (1);
   
   randomize();
	ball_speed.x = 3 - 6 * (random(6) % 2); // -3 or 3, random ball direction at game start
	ball_speed.y = 3 - random(6); // -3...3, random vertical speed at game start
	
	while ((bottom_score != 10) && (top_score != 10))
	{
      if (key_esc) { sys_exit(NULL); }
      
//Switch to user mode if a paddle key is pressed      
      if (key_s || key_d) mode_top = USER;
      if (key_cul || key_cur) mode_bottom = USER;

// Update paddles and ball, and count scores
      update_ball();
      update_paddle(upper_pong.pos_x,mode_top,key_s-key_d);
      update_paddle(downed_pong.pos_x,mode_bottom,key_cul-key_cur);

// compose the sTitle string
      str_cpy(sTitle,"Pong Demo - ");
      str_cat(sTitle,(tName.pstring)[mode_top]);
      str_cat(sTitle," vs. ");
      str_cat(sTitle,(tName.pstring)[mode_bottom]);
      video_window(NULL,NULL,0,sTitle);

		wait (1);
	}
}



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