• ### Popular Now

• 14
• 12
• 9
• 10
• 9

#### Archived

This topic is now archived and is closed to further replies.

# a football game withdirect draw

This topic is 5849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hello, I would like to create a speedball like game(kind of football game). Here is my problem: a have a pitch of 960 pixels(composed from two bitmaps). The scrolling on this pitch is vertical. the pitch has the following dimension : 640*960. I can only see a part of the pitch. my clipping screen has the following dimensions (640*480). here is a schema :
-----------------------------   0 (vertical position)
|                           |
|                           |
|                           |
|                           |
|                           |
|                           |
|...........................|  scrollpos
|.                         .|
|.                         .|
|.    clipping screen      .|
|.    (640*480)            .|
|.                         .|
|.                         .|
|...........................|
|                           |
|                           |
|                           |
|                           |
-----------------------------   960

I am able to display the pitch correctly with the respect to scrollpos variable. My problem is to compute the position of the ball. I would like that the value of the scrollpos variable be computed with respect to the value of the postion of the ball. In other word, the position of the ball changes -> the value of the scrollpos changes. Is someone could help me? thank you!!! [Edit: Formatted diagram] Edited by - Oluseyi on March 17, 2002 5:48:26 PM

##### Share on other sites
World and screen coordinates.

Your field may be described in world coordinates, so the ball is positioned at a certan (x, y) on the field. The screen, however, uses it''s own set of coordinates, so you need to convert world coordinates to screen coordinates. How? Using the viewport coordinates, which are in world coords.

  COORD viewport;         // center of viewportlong v_width, v_height; // viewport dimensions (e.g 640x480)COORD ball;             // //COORD World2Screen(const COORD & w){  COORD s;//  // compute absolue coords  s.X = w.X - (v_width * 0.5f);  s.Y = w.Y - (v_height * 0.5f);//  // keep coords within screenspace  s.X = (s.X < 0) ? 0 : ( (s.X > v_width) ? v_width : s.X );  s.Y = (s.Y < 0) ? 0 : ( (s.Y > v_height) ? v_height : s.Y );//  return s;}

Now plug your viewport coordinates (or ball coordinates) into World2Screen and you get a new pair of screen coordinates. You can then add the value of this coordinate pair to the world position of all elements (ie, use it as an offset).

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

##### Share on other sites
hi,

first, thank you to answer so quickly. I use your code and it is a very good starting. But I still have a problem. I would like to see the goal before the ball reach it.
if in world space the ball =240, then I should be able to see the goal.
In the same way, if in world space the ball =720 we can see the goal.
any idea?

I am looking for a web site where I could find the different step to build a game, and where I could find general algorithm.

what is the general algotithm. Here is the beginning (I guess)

while (true)
if message
loopmessage
else
gameMain()
......... what next?

how to use the time, how to detect collision? I don''t know where I have to put this process and how to do it. If you know a place where I could find this kind of information, Please tell me.

thank you
zip7000

##### Share on other sites
Here's a screenshot from my DirectDraw Football game:

CHECK IT OUT!

But I got tired. It was ment to be a commercial game. But making a football game, how boring is that!

Maybe I'll continue on it. The code was pretty nice this far, but there were just too many

The cool this was that everything worked in pure 2D(with 32x32 tiles), although it draws it isomertic.

And the GFX's are a pain too

Although I have my texture -> IsoGround/IsoWall converter

/MindWipe

"If it doesn't fit, force it; if it breaks, it needed replacement anyway."

[edited by - MindWipe on March 18, 2002 8:09:10 AM]

##### Share on other sites
hi MindWipe,

I looked at your screen shot football game. Isometric view increases the complexity of the game, no? My project is to create a football game with top view. I am a beginner in direct draw and games programming. So I don''t want to create something complex. It would be great if you could advice me on the way to do a such game. Your experience could help me. For instance, how could I find out the position of the ball if I want to consider the velocity, collision...

thank you!!

##### Share on other sites
quote:
Original post by zip7000
But I still have a problem. I would like to see the goal before the ball reach it.

To look ahead of the ball, set your viewport to be a few spots ahead. This can take a little work to get right.

What you want to do is to "predict" where ball is going to be (using simple Newtonian physics equations). If the ball''s velocity is v and it''s position is s (both vectors, or COORDs in this case), then the ball''s position at time t, provided nothing interrupts it, is s'' = s + vt. So try using a value of t that places your viewport just enough ahead of the ball.

quote:

I am looking for a web site where I could find the different step to build a game, and where I could find general algorithm.

Have you actually looked around this site, specifically here?

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

##### Share on other sites
I really didn''t get that far, so I don''t have the answers you need - sorry.

I only got so far that you could draw the map with x,y in the center and move a player around the field

/MindWipe

"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."