Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 20 May 2009
Offline Last Active Sep 11 2015 04:10 PM

#4953779 2D game, pursuit code Q's

Posted by on 28 June 2012 - 04:31 PM

I'm currently working on a rogueish/nethack text game, I'm somewhat stuck on how to implement the pursuit code (how a monster chases down your character). I somewhat took a stab at it and currently have the monster take your X,Y, and by using a series of subtractions/additions relative to it's own position, did manage to have it head towards your general direction quite consistently. But say it runs into a wall that's in it's way, should I code it somehow so that it knows it's looking at a wall and have it try to figure out how to walk around the wall to get to you? Or should I just make it cheat a little, and just record your keystrokes from the moment you start fleeing and just have the monster follow your footsteps exactly Posted Image ? Thanks for any info!

There are a couple ways this can be handled, depends on how you want to model your AI. If you want "perfect" AI, then you can use pathfinding (with A* or A-star being the common one).

If you want imperfect AI (or more realistic), you can try simulating tracking by scent and/or sound. There is an article here about this: http://roguebasin.roguelikedevelopment.org/index.php/Tracking_by_Scent_and_Sound

While I'm link roguebasin, here is another that might be relavent: http://roguebasin.roguelikedevelopment.org/index.php/The_Incredible_Power_of_Dijkstra_Maps

#4953315 When it comes to C# I am at a deadend when it comes to what to do.

Posted by on 27 June 2012 - 06:38 AM

Practice, practice, practice. Choose a goal project, get it done. If it is too overwhelming, downsize your goal until you can finish it. Reading books and completing small excercises is fine to a point, but doing only this will not teach you how these specific items really fit together. You need to develop the "engineering" side of things, get comfortable with the larger picture.

As you keep building projects, you will notice that you keep using the same patterns, refactoring the same set of code. Polymorphism theory and practice (for example) can be explained in a book, but until you use it, get comfortable with it, notice how it simplifies and leads to more elegant code, over and over again in 20 different projects, you will not really grasp it.

#4951406 Tile size in a 2D Map

Posted by on 21 June 2012 - 10:24 AM

This question gets asked alot, and there is no general good answer - it depends on a lot of factors. If you search for "tile size" on this site, you should get a number of good posts.

One suggestion I can put out there, though, is to design your tile engine to support any size of tile, so that if your art direction changes (and it probably will!), you can adjust accordingly without having to re-write a bunch of code.

#4949910 Collision detection, 2d environment with C#

Posted by on 16 June 2012 - 04:11 PM

That is pretty difficult to read, there is no way I would want to try and understand all that without a debugger.

This is how I usually tackle these things: get out a piece of graph paper, draw out a simple test case and write down what each variable value should be, then step through the code until there is a discrepancy between the graph paper test case and the watch variables.

#4948958 [C#] Game Saving Problems, Files are too large

Posted by on 13 June 2012 - 04:41 PM

I think you need to provide some more information in order to get meaningful replies.

What kind of objects are you saving? What exactly does a single "block" consist of? How are maps being stored in memory? How exactly are you serializing?

#4948952 Newbie: Questions about 2d game development.

Posted by on 13 June 2012 - 04:24 PM

Is it normal that I have to do a LOT of coding before I make a game or I need a proper UI to speed up the development?

Yes, games are a LOT of work - both on the coding side, and on the asset creation side. Note that even if you go with the Unity3D route, you will still need to do some coding (just a lot less), and you will still need to make all the assets. Also, Unity is a complex piece of software with it's own learning curve - but there appears to be a lot of support through forums and tutorials. Personally, I prefer working in XNA, but that is because I enjoy the programming side of things, where Unity3D always seemed more targeted for an artist-minded developer - your mileage may vary.

If you've got the basics of XNA and C# down, you could try out FlatRedBall which, last I checked, has some support for higher level game development tools. It is basically a 2d engine built on top of XNA.

There is also something called GameMaker that can be used to quickly create basic 2D games with minimal programming, if that is what you are looking for.

Of course, as you gain experience, coding gets much quicker (less backtracking, less refactoring, less research, and reusing pieces of code you have amassed).

Is there any other 2d engine that I should use instead of XNA (something more ideal for beginners)? If yes please mention some.

Although I have never used it, there is Python + Pygame (and there are likely other libraries for Python as well). I've heard it's "good for beginners", but again I've never gotten into Python much.

My personal opinion is that unless you are getting too discouraged, try and stick with one thing until you feel like you've got a fairly good grasp of it. If it's too hard, lower your goals abit - a completed "simple" project is more motivational than a complex one that never gets done.*

* P.S. for the record, although that is my advice, it is advice that I never seem to be able to practice ;)

#4948371 Virtual Machine/Scripting/Console in XNA using C#

Posted by on 11 June 2012 - 08:21 PM

Object[][] args2 = new object[1][] { new object[2] { ref camera.Position, ref camera.Target.Position } }; <----doesnt work.

Whats happening is the position isnt updating to match the true position of the camera. Its staying at whatever the position is at the time of creating the widget....

It's possible I'm still misunderstanding, but here is how I see it:

You want to reference the two Position values - however, Vectors are structs, thus value types, so they are being copied into your new object (just like any other value, such as an int).

What you need to do is copy a reference type that contains and exposes those values. In the above case, "camera" is (probably) a reference, so couldn't you just have your object keep a copy of the camera reference?

In general, when you want to hold on to a reference to a value type, you need to put it inside of a reference type.

#4947951 C# stop waiting on events

Posted by on 10 June 2012 - 10:46 AM

I believe what you are looking to do is discussed here: http://blogs.msdn.com/b/shawnhar/archive/2010/12/06/when-winforms-met-game-loop.aspx

It's targeted for XNA + Winforms, but should be applicable in straight Winforms applications that need animation timing as well.

#4947265 Efficient coding in C#

Posted by on 07 June 2012 - 09:31 PM

Profile, either the quick and dirty way with timers, or with some profiling tool. This should always be the first step of optimizing. Never assume you know where inefficiences are, even fairly experienced coders can be mistaken.

#4941896 Optimising Sprite Sheets

Posted by on 21 May 2012 - 06:33 AM

My experience has been to just trust SpriteBatch to sort all the sticky details out for you - it's been designed and optimized for general cases like this, and typically performs plenty fast.

I don't know the particular details inside SpriteBatch, but as long as all your drawing occurs between a Begin() End(), it likely sends the texture only as often as it has to (once in your case).

If you indeed are seeing a bottleneck in rendering sprites from a texture sheet (which I fine hard to believe on modern hardware), you will have to roll your own effect, AFAIK.

#4941823 What's the best C#(XNA) book/site

Posted by on 20 May 2012 - 11:13 PM

2. (dumb question) Can C# be used to develop iOS/android games?

I don't know much (if anything) about developing for those platforms, but I do know Unity3D supports them, and C# is one of the scripting languages supported by Unity - so yes.

#4939282 Mouse collision: new Rectangle or move Rectangle?

Posted by on 11 May 2012 - 06:58 AM

Doesn't Rectangle have a Contains() method? If so, it would be simpler to use that instead of creating a rectangle of size 1 every time.

#4936960 Checking for texture transparency with resize

Posted by on 02 May 2012 - 10:27 PM

There may be an easier way, maybe an XNA guru here will give a better answer, but personally I would try and tackle this by adjusting your sample coordinates (array index) of the original texture by the scale factor. This may be innacurate unless you reproduce the sampling method used by the shader, however (IIRC mip-mapping is enabled by default)

Or, you could render to a rendertarget and query that - this might be slower, but if you aren't scaling the texture every frame it may work fine.

#4934928 Weird simple CSharp math issue.

Posted by on 25 April 2012 - 06:44 PM

What are you expecting it to return? Are you thinking that ^ is a power operator (it's not)?

See here for c# operators: http://msdn.microsof...y/6a71f45d.aspx

#4928605 Best approach to loading and saving game data?

Posted by on 05 April 2012 - 04:08 PM

I looked into saving data into binary format but I'm not very familiar with it. Is there any way to convert values into binary format through an online application? I get things like ô SOH NUL NUL

Typically whatever language/framework you are programming in will have some sort of binary input/output library or routines available that interface with the operating system, and provide a way to directly read or write binary data to an from a disk file. The specifics of how this is accomplished varies widely, however. What exactly are you trying to do?