Map format in 2d racing game - c#

I have little experience in writing a simple games on XNA, but now i dont have knowns to solve my problem.
So, i want to write simple racing 2d-arcade, and i dont know how i can do maps for this game.
I decided do this so:
I draw a picture-map in mspaint. Black - its grass, white color -
its road, red color - road markings, blue - water, green - forest,
etc.;
After the image is loaded, I override textures in XNA - on white
color i place texture of road, on black color i place texture of
grass and etc.
So i have 2 questions.
I think in the right direction?
How i can to know color in desired pixel and how i can pour all white color, not each pixel separately? Second question not required, because i can just do second image with normal textures, and place this on second layer, right?
Sorry for really bad english. And thanks for answers advance.

In MSDN forums, man with the nickname Mad Martin adviced do so:
Draw the final picture in paint with the mixture of textures like you
want it on the screen. Draw this texture directly. Now you'r game
logic needs to know where the road is in that texture. There are two
ways i can think of:
Make the road a spline and calculate the exact layout of the game. Probably a bit steep for beginners, but the most powerful.
Make a separate texture like yours with just two colors(black no road, white road). You can then check via the coordinates of the cars
whether you are on the road or not. You can do this either on the CPU,
by readign the texture into an array with Texture2D.GetData, or you
can do this on the GPU. Either way needs a little fiddling around, so
your cars dont hang on the edges of the road.
i think that it's quite useful answer, so i close question.

Related

Is there a way to apply a single gradient across game objects in Unity?

Part 1: Forgive me if the question itself is unclear. I am learning how to use Unity and script in C#, and I want to know if there's a way to apply a gradient of color (or an image) utilizing the game objects that already exist as the places where the gradient will show up.
Say I have a group of these circles that randomly grow and change size during the game run.
Example image of circles
I am not sure of the correct terminology, but a couple of words come to mind, i.e. shader/mask. My goal is to display the gradient/image only within where the game objects exist. So instead of white circles, it's circles display parts of the one singular image/gradient.
Part 2:
To take a it a step further, I'd like to know how to have the gradient continuously run through its spectrum so one can see the colors shift across the circles.
Again, still very new to this kind of stuff, but would anyone know what steps I would need to take to get there.
Thanks!

How to make adjacent tiles combine seamlessly ?(2D)

Ok ill get straight to the point, here is an image of what i want to achieve:
And here is an Image of what my game looks like:
What I'm referring to is how the tiles seamlessly "connect". As you can see, on the first image there is a slight fade from one tile to the next one, for example where the sand and grass meet. On the second image, my game, there is not fade and no transition and it looks very bad. Like when the grass changes colors, there is no fade/filtering.
I assume this is a fairly common problem, so is there any assets from the asset store that solve this problem, or any built in solution within Unity? (Without writing own own custom script, of course) If there isnt any, how do I go about creating this filtering/transition between the tiles?
I suggest you to draw them on your own in some software and then importing it in Unity, other way to do it is to make them overlay where the transition is and put 50% opacity on both layers just where they are overlaping, this will give you small effect of transition.

How to render specific edges of a cube different from filling in XNA? (Monogame)

I am working with C#, Monogame and XNA 4.0. In my scene I have a lot of cubes. Some are connected, some are not. I would like to render the edges of the cube with another shader than the filling. Besides that, I would like to render the outer edges of connected cubes in another color (or thicker) than the edges within the cube-object. Here is a small painting to make clear what I want to do (sorry for my bad painting skills, but I think you will get it).
I know how to render a cube with a specific shader and I am also able to render the wireframe but I was not able to connect both methods. Besids that, the outer lines can not be rendered differently with this approach.
I tried it with post-effects like the edgefinding of comic shaders but in this approach I am not able render only specific edges. Besides that if two cubes are next to each other the shader does not recognize the edges.
I am not searching for a ready-to-use solution from you but I would be glad to get some tips/approaches/tutorials/similar projects/etc on how to achieve my goal. Are there some shader experts out there? I am at my wit's end.
(If you however would like to post a ready to use solution I would not be miffy :D)
It is a shame you're not using deferred shading, this would be pretty straight forward to implement if you were.
If you can access the normal and material for each pixel on screen through a texture lookup you can easily post-process this. You could use a 3x3 filter kernel and search for sufficiently large normal discontinuities (this would catch silhouette edges) and also search for pixels that lie on the transition between material IDs (this would catch the edges between blue and orange cubes). If your filter neighborhood satisfied either of these two conditions, then draw a black pixel to form the outline.
You should be able to do this if you use MRT rendering when you draw your cubes, and encode the normal + material ID into an RGBA texture (x,y,z,material).
The basic theory is described in this paper (pp. 13). In this case instead of using the depth as the secondary characteristic for outlining, you would use the material (or object ID, if you want EVERY cube to have an outline).

isometric tile engine

I am making an RPG game using an isometric tile engine that I found here:
http://xnaresources.com/default.asp?page=TUTORIALS
However after completing the tutorial I found myself wanting to do some things with the camera that I am not sure how to do.
Firstly I would like to zoom the camera in more so that it is displaying a 1 to 1 pixel ratio.
Secondly, would it be possible to make this game 2.5d in the way that when the camera moves, the sprite trees and things alike, move properly. By this I mean that the bottom of the sprite is planted while the top moves against the background, making a very 3d like experience. This effect can best be seen in games like diablo 2.
Here is the source code off their website:
http://www.xnaresources.com/downloads/tileengineseries9.zip
Any help would be great, Thanks
Games like Diablo or Sims 1, 2, SimCity 1-3, X-Com 1,2 etc. were actually just 2D games. The 2.5D effect requires that tiles further away are exactly the same size as tiles nearby. Your rotation around these games are restricted to 90 degrees.
How they draw is basically painters algorithm. Drawing what is furthest away first and overdrawing things that are nearer. Diablo is actually pretty simple, it didn't introduce layers or height differences as far as I remember. Just a flat map. So you draw the floor tiles first (in this case back to front isn't too necessary since they are all on the same elevation.) Then drawing back to front the walls, characters effects etc.
Everything in these games were rendered to bitmaps and rendered as bitmaps. Even though their source may have been a 3D textured model.
If you want to add perspective or free rotation then you need everything to be a 3D model. Your rendering will be simpler because depth or render order isn't as critical as you would use z-buffering to solve your issues. The only main issue is to properly render transparent bits in the right order or else you may end up with some odd results. However even if your rendering is simpler, your animation or in memory storage is a bit more difficult. You need to animate 3D models instead of just having an array of bitmaps to do the animation. Selection of items on the screen requires a little more work since position and size of the elements are no longer consistent or easily predictable.
So it depends on which features you want that will dictate which sort of solution you can use. Either way has it's plusses and minuses.

Restrict movement on reaching map border or any objects

I'm totally new in game-dev and would like to know the best practice about above question.
Let me explain more.
I want to create 2D game with top-down view and with free movement (without snapping to the grid) just like any Zelda game on GameBoy.
How should I store map bounds? Is there a way to do this automatically? For example I have a texture with background and texture with foreground where black color should appear transparent and should allow to move in space of it.
Thanks in advance.
For easy 2D collision detection, you'll probably implement bounding boxes.
Basically you will create a rectangle that represents every Game Object. The coordinates and size of the rectangle will be the same as the Texture2D (it is common to make this a property on the given class). Every time you update the position of your Texture, you update the position of your bounding box.
Now to check for collision, just loop through your game objects and see if any of the bounding boxes intersect.
Once you get the idea, you'll see that its very easy to implement. XNA also provides some math helpers to abstract the math (though its simple addition and subtraction).
Try this link for a more in depth explanation with code examples: http://www.dreamincode.net/forums/topic/180069-xna-2d-bounding-box-collision-detection/

Categories