Skip to main content
GameDev.net gamedev.net
🔒 Locked

Worms Engine

Started by Funkymunky Dec 19, 2004 at 3:53 PM 14 replies 3k views
Original Post
Funkymunky
Funkymunky
Hi I am interested in making a 2d Worms style engine with DirectX. I figured I'd ask all my questions ahead of time to save myself any stress. Basically, what I want to do then, as i've gathered so far, is render a list of D3DPT_LINELISTs. I can set a regular texture for these and it will be filled in. Say I wanted to have grass on the top of the lines, would that just be a separate line list with a grass texture? Will doing it this way allow me to have fast speeds even when the full screen is full of lines, and is being traversed quickly? Especially if I have a separate image in the background scrolling by as well? Also, anyone know of any tutorials or anything like that for this sort of thing?
vajuras
vajuras
Have you taken a look at ID3DXSprite? It's very useful for blitting textures directly to the screen. All you need to use them is the Begin, End, Draw functions.
doynax
doynax
Do you have a good reason for wanting to do it this way?
Rendering the landscape as actual polygons will be a lot harder (and almost certainly slower) than simply using a bitmap (as Worms did), especially if it needs to be dynamic.
Maybe you could prerender everything? Then you wouldn't have to worry about performance or being able to blast it to pieces.
Funkymunky
Funkymunky
Look basically all I want is to have a landscape like the worms landscape, hell it doesn't even have to have floating sections like they did, it really just needs to have a ground that isn't tiled platforms, it needs hills and slopes and whatnot. So I thought the worms style looked good. Isn't that done with a line list? Wouldn't that be a D3DPT_LINELIST as far as DirectX is concerned? Please don't ask me questions about how to do it, that's why i posted...i want input from people who have a good idea about worms style engines.
doynax
doynax
Worms never even touched 3d polygons (well, except worms 3d).
Everything is just a big (often hand-drawn) bitmap. For collision detection you eighter use the transparent color to identify air or make a separate palettized image where each color represents different landscape types (i.e. earth, air, lava, ice).
I'm writing a worms-style game myself, so I should know.
Funkymunky
Funkymunky
Ok i wasnt asking about 3d, directx can do 2d too. So you guys think I should just have one big bitmap, with a mask on it for the worms-like destructions? not a list of lines? if that's the case how can i build like an editor, or at least a generator of sorts?
doynax
doynax
Quote:
Original post by Funkymunky
If that's the case how can i build like an editor, or at least a generator of sorts?
The whole beauty of this approach is that you don't have to use a custom editor. You could draw your levels in paint if you wanted to.
You could ofcourse try to generate the bitmap automatically to save space. Look at the editor in Worms 2 for a good example, there everything is generated from a monochrome bitmap that gets textured with the background style of choice.

I wouldn't worry too much about the file sizes though. Our levels generally get a compression ratio somewhere between 30:1 and 100:1.
Funkymunky
Funkymunky
How do you texture that kind of thing though? How do you render it in DX as a bitmap that gets a specific texture? And say I want it to be rendered with a dirt texture, with grass along the top...how do i specify those kind of distinctions?

Also i have my doubts about doing it as a bitmap because I want HUGE levels, like bigger than 1024 wide, bigger than 2048 wide....etc. HUGE
doynax
doynax
Quote:
Original post by Funkymunky
How do you texture that kind of thing though? How do you render it in DX as a bitmap that gets a specific texture? And say I want it to be rendered with a dirt texture, with grass along the top...how do i specify those kind of distinctions?

Well.. That's the hard part, and there's a million and one ways of doing it.
The easiest would probably be to use a pre-rendered tilemap.
Another way of doing it would be to blend multiple textures according to an alpha map (i.e. the level itself) where ranges between 0 and 63 interpolates between the grass and earth texture, 63-128 between the earth and lava, and so on. This kind of generation would almost be easiest to do manually, without involving the GPU.
My advice is that if you decide to use bitmaps then wait with implementing the "generator" system, it's not exactly essential during development anyway.

Quote:
Original post by Funkymunky
Also i have my doubts about doing it as a bitmap because I want HUGE levels, like bigger than 1024 wide, bigger than 2048 wide....etc. HUGE

Exactly how big do they need to be, and what's your target hardware? They are essentially only limited by your system memory since there's really no need to keep more than a small cache in video memory (slightly larger than the screen so you don't have to updated it each frame, you could even make it "circular" to avoid updating more than a few kilobytes every few dozen frames).

Sure, there's a limit. But a level needs to be truly huge to reach it.
So lets say you're running in 1024x768 and the level needs to be 6x2 screens big, in 16 bpp. That's 6*2*1024*768*2 bytes = 18 mB, not much of a problem even if you're targetting 64 mB machines.
Worms levels might seem big but they're really quite small, usually somewhere between 2x2 and 3x2 screens.

[Edited by - doynax on December 19, 2004 8:08:07 PM]
Asheh
Asheh
What about the issue of randomly generated terrain? How would you go about that ? :P
doynax
doynax
Quote:
Original post by Asheh
What about the issue of randomly generated terrain? How would you go about that ? :P
Generating a decent random landscape is a whole other issue. And would be as bad, if not worse in a vector world.
The solution also varies a lot depending on the game, so lets just say that trial and error is your friend.
Or you could study Worms and try to copy whatever they do..
bit64
bit64
I would do the following:

create 3 quads each the size of the screen, one for the back ground,one for the middle ground and one for the foreground.

texture these, each with their own texture, make sure to have alpha blending enabled.

On your foreground texture and middle ground texture, you would simply create a tga file where the alpha of the terrain is full and everything else is zero.

when you explode a bomb or other such thing into the terrain, you simply grab the surface and draw a circle onto the alpha layer of the img, making it transparent. this would show the middle ground texture behind it, which should look like dirt and stones (or whatever you would like).


also: make sure that lighting is disabled.
Don't be afraid to be yourself. Nobody else ever will be.
Funkymunky
Funkymunky
Ok so my train of thought has led me to this way of doing it. Since I really only need lines from the bottom (IE only ground, nothing floating) a list of heights is the smallest way to store the biggest level (so i'd be using lines). So I figured, I should just have a 256x256 texture, render 256 single color lines to it using line lists with directx, then use this texture as the mask to add the bitmap texturing to!

So I tried, and i can't render the lines to the texture. here's what i'm trying:

IDirect3DSurface9 *pRenderTarget;IDirect3DSurface9 *surf;GroundVert vs[512];  // 256 linesd->GetRenderTarget(0, &pRenderTarget);  // save the current Render TargetD3DXCreateTexture(d, 256, 256, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, &texture);texture->GetSurfaceLevel(0, &surf);  // get the surfaced->SetRenderTarget(0, surf);         // set it as the Render Target// fill in the vs line datad->DrawPrimitive(D3DPT_LINELIST, 0, 256);  //  render to the surf, of the texture, right?d->SetRenderTarget(0, pRenderTarget);  // and reset the original Render Target



Then I just make a simple quad and set this texture for it, and render, but all i get is black, no lines. ??
DBX
DBX
The way I did it (in OpenGL) was to split the level (a 2048x512 bitmap, or something like that) into 256x256 textures. Render the visible textures as quads. These textures could then be modified if something changed on them.
The background was done in a similar way, but it doesn't change.
Funkymunky
Funkymunky
Anonymous i think you should reread what I wrote, you're "acting a fool" as they say. I know that just because I render to a texture doesn't mean the texture is "at the screen."
Quote:

Then I just make a simple quad and set this texture for it, and render

Also I disagree with the comment about using sprites because that doesn't suite my needs, and plus I don't want to base an engine on the D3DX functions. Personal preference.

PS: here's the problem

D3DXCreateTexture(d, 256, 256, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, &texture);

nees to be

D3DXCreateTexture(d, 256, 256, 0, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.