Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
voodoo dog
Jun 6, 2001

Gun Saliva
Well, since this is a question I've been dealing with again and again, I thought I might as well post here. Basically, I have a very hard time deciding what language to do my game programming in. C# is what I'm most comfortable with, so XNA would be the natural choice, but I'd like at least the possibility to run the game on Linux as well.

Basically, it comes down to the fact that it is hard finding a decent library that does all I need. Especially, I'd like a solid UI library etc., so I always think of the days when I was doing stuff in C++ and ClanLib offered all I needed. Graphics, Sound, GUI, networking etc., so I am always tempted to move back to that. However, C++ is more of a hassle, so stuff in general takes longer to write.

I have even tried writing a SWIG wrapper around ClanLib, but their signal/slot-stuff was pretty much impossible to wrap and I gave up.

With all other languages and game libraries, there seems to be a lot of library-hunting involved. I just haven't found a combination that works for me yet, maybe it is indeed time to try out a few more python options.

Adbot
ADBOT LOVES YOU

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.
What about combining Ogre3d with something like Hikari? It allows you to design your GUI in Flash and the engine itself seems pretty robust as well.

tbradshaw
Jan 15, 2008

First one must nail at least two overdrive phrases and activate the tilt sensor to ROCK OUT!

Mithaldu posted:

You get hung up on the wrong things and completely ignore the obvious thing that i can also do this and negate all your arguments about "weird" syntax order:

I didn't ignore anything, except of course the things you didn't say. :P I also didn't suggest the changes you made because I recognize your original as very good Perl.

"Mithaldu posted:

Furthermore you ignore my original claim and act as if I'd said something else.

Then you go on to make a claim that my biggest point was completely wrong, only to go on to repeat my point with different words.

I did no such thing.

"Mithaldu posted:

I agree there is no point in going on here.

You know what, I also frequent the Python thread and I sort of got confused which one I was talking in. I definitely wouldn't have poo poo up the Game Dev thread with so much Perl vs. Python stuff if I would have realized earlier. Sorry, friends. :(

tbradshaw fucked around with this message at 17:40 on Nov 24, 2008

nihilocrat
Jun 8, 2004

all the hep cats jam to "cat /dev/hda1 > /dev/audio"

Morpheus posted:

Right, so I'm starting to add AI to my game (in C#), and I'm trying to figure out how. I mean, I know how to program an AI, it's about programming multiple variations of AI into a game, one for each type of enemy. At the moment I'm not entirely sure what to do, specifically from the coding perspective. I mean, I know how to program a single AI. That's easy. But I don't want to create a separate AI class for each type of enemy. I'm certain there's a way around this, possibly using delegates. Any tips? There was mention of finite-state-machines earlier, which sound pretty good, but it's all a question of implementation.

Create a dynamic / hybrid class.

Instead of explicitly coding a think() or whatever class, make it a function pointer and write callbacks which you plug into that function. Instead of having a bunch of class members, create a data dictionary (like an STL map or whatever) which you can plug values into at runtime. This is super-easy if you are using a higher-level language like Python.

Wuntvor posted:

I have even tried writing a SWIG wrapper around ClanLib, but their signal/slot-stuff was pretty much impossible to wrap and I gave up.

Please explain, I was thinking of making a wrapper as well. Perhaps I can shed some light on it (and more likely, not).

Panda3D is a good example of ClanLib for 3D: it is a one-stop-shop of sorts for most of what you need. The documentation is pretty bad, though, and it reeks of "this library was made for people who were being trained how to use it", so a lot of very simple stuff is not quite so obvious because the 'proper' way of doing it is undocumented.

Sagacity posted:

What about combining Ogre3d with something like Hikari? It allows you to design your GUI in Flash and the engine itself seems pretty robust as well.

It's a good suggestion, but that counts as "library hunting" :)

nihilocrat fucked around with this message at 21:18 on Nov 24, 2008

voodoo dog
Jun 6, 2001

Gun Saliva

nihilocrat posted:

Please explain, I was thinking of making a wrapper as well. Perhaps I can shed some light on it (and more likely, not).

Panda3D is a good example of ClanLib for 3D: it is a one-stop-shop of sorts for most of what you need. The documentation is pretty bad, though, and it reeks of "this library was made for people who were being trained how to use it", so a lot of very simple stuff is not quite so obvious because the 'proper' way of doing it is undocumented.
The first issue I had was with a crash when initializing, but that turned out to be because they called CoInitialize (for DirectInput) with the wrong threading-model (doesn't work inside the .NET framework) and was easy to fix.

I don't quite remember at what point I gave up, I know I was able to at least call a few simple functions. I haven't really done a lot with function pointers, so maybe that's why I didn't see a way to wrap the signals/slots code. In theory, all you have to do is to convert a managed function pointer to a "normal" one (I think the Marshalling-class has a method for this), but I could never get it to work somehow.

Writing about this, I really want to give it another try..

voodoo dog fucked around with this message at 21:12 on Nov 24, 2008

nihilocrat
Jun 8, 2004

all the hep cats jam to "cat /dev/hda1 > /dev/audio"

Wuntvor posted:

blah blah .NET blah blah managed

Wait, are you talking about wrapping good old C++ ClanLib with good old CPython? I have also discovered Py++ in the interim. Python-Ogre uses it, so perhaps it actually works well. I think a ClanLib wrapper would be great for the Python game development world. We've already got a large number of graphics libraries, but nothing that is a one-stop-shop.

I hand-coded a ctypes wrapper around a C function that took function pointers a few years ago, and didn't have any issues. I was actually pretty amazed.

I am also sort of having trouble finding a good engine/set of libraries and I'm feeling like I might want to roll my own. Of course, whenever I decide I might want to do something big I have to throw in a bunch of other requirements or froofy features. My idea was to use Ogre3D on top of a sort of "game OS" written in Stackless Python, where every process or game entity gets its own tasklet, following the MVC model to have clear seperation between presentation, control, and data throughout the entire engine.

voodoo dog
Jun 6, 2001

Gun Saliva

nihilocrat posted:

Wait, are you talking about wrapping good old C++ ClanLib with good old CPython? I have also discovered Py++ in the interim. Python-Ogre uses it, so perhaps it actually works well. I think a ClanLib wrapper would be great for the Python game development world. We've already got a large number of graphics libraries, but nothing that is a one-stop-shop.

I hand-coded a ctypes wrapper around a C function that took function pointers a few years ago, and didn't have any issues. I was actually pretty amazed.

I am also sort of having trouble finding a good engine/set of libraries and I'm feeling like I might want to roll my own. Of course, whenever I decide I might want to do something big I have to throw in a bunch of other requirements or froofy features. My idea was to use Ogre3D on top of a sort of "game OS" written in Stackless Python, where every process or game entity gets its own tasklet, following the MVC model to have clear seperation between presentation, control, and data throughout the entire engine.
Oh, I was actually talking about wrapping it for C#/.NET.. ;-) Well, once you've got the SWIG code written, it should as far as I know also work with python, but that doesn't seem to be what you are talking about either.

EDIT: Just tested it with what I've got from last time, and it does indeed seem to be working in Python as well.

voodoo dog fucked around with this message at 21:56 on Nov 24, 2008

nihilocrat
Jun 8, 2004

all the hep cats jam to "cat /dev/hda1 > /dev/audio"
Oh. Yeah. For some reason I thought you mentioned Python in the post, it tells you how much tunnel vision I've gotten in the past year from 90% of my code being in Python.

A managed C# wrapper would probably still be pretty cool.

Did you do anything special for the SWIG wrapper, or can I just create an interface file that references all the headers (the "truly lazy" way according to the tutorials)?

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.

nihilocrat posted:

It's a good suggestion, but that counts as "library hunting" :)
True :) But they should provide a good 'all-in-one' solution. Oh well.

a slime
Apr 11, 2005

I just started using Psyco in my little pyglet/rabbyt sprite game and it doubled my fps :aaaaa:

tripwire
Nov 19, 2004

        ghost flow

not a dinosaur posted:

I just started using Psyco in my little pyglet/rabbyt sprite game and it doubled my fps :aaaaa:

While its not that great yet, pypy is hopefully going to knock that door off its hinges by letting you translate your python code down to C, LLVM or CIL code.

I'm not sure if theres any issues with rabbyt but pypy already works with pyglet and should give you greater speed benefits than psyco while allowing you to target 64 bit architectures as well.

There's also pyrex which lets you mix c and python data types and compiles down to a c extension which it calls from python, this should give you greater speedups than psyco as well.

Benji the Blade
Jun 22, 2004
Plate of shrimp.

tripwire posted:

While its not that great yet, pypy is hopefully going to knock that door off its hinges by letting you translate your python code down to C, LLVM or CIL code.

I'm not sure if theres any issues with rabbyt but pypy already works with pyglet and should give you greater speed benefits than psyco while allowing you to target 64 bit architectures as well.

There's also pyrex which lets you mix c and python data types and compiles down to a c extension which it calls from python, this should give you greater speedups than psyco as well.

I'll try to keep this brief, since this isn't the Python thread. First off, I'm no PyPy expert, so feel free to correct me where I'm wrong. This is just gathered from some small amount of experience with it, and a bunch of reading.

PyPy has a lot of promise, but PyPy is not particularly fast yet (unless that's changed really recently). PyPy can't translate normal Python into C, nor into any particularly fast form of LLVM, CIL, or anything else. What it can do is translate RPython, a subset of Python, into these things. The hope is, in the future, that it'll have a good JIT compiler/optimizer that will be able to do the same sorts of thing that the RPython translator does, but by generating the code needed on the fly, rather than using constraints to limit the needed permutations.

Now, you could code your project in RPython, but (perhaps unwisely) the PyPy people didn't design RPython to be used outside of PyPy, and thus it doesn't really have a spec, and it apparently can be pretty cryptic and crash-prone, and it just isn't designed to be used outside of PyPy. You can use it, it just isn't recommended.

I like Python a lot, and I think PyPy has a lot of promise, but I wouldn't encourage anyone to build games on top of it yet, and in general, I'm worried by the lack of real, immediately useful results from PyPy.

However, the good news is that Pyrex/Cython is a really excellent way to generate C extensions for Python using something that feels like a pretty natural extension of Python. And there are lots of other good ways to call into C extensions, like Ctypes and SWIG, depending on your needs.

Morpheus
Apr 18, 2008

My favourite little monsters

Mithaldu posted:

I think it would help if you'd drop a few words about what input the AI gets, what outputs it can form from that and maybe a rough sketch of how you would implement a base AI.

Er, right.

Basically, this is a platformer. We're not talking tactical shooter here, so all the AI needs to know is the player's location and the area around him. Then I need to know if the enemy wants to 1) move and 2) attack. For the most part, attacking will be done by shooting little bullets, probably directly at the player, or in a couple cases trying to collide with the player, either by dive-bombing, increasing speed, simple stuff.

A friend of mine suggested using a parameter list with a few variables that essentially tell the AI how to react to certain situations. Say, for example, there was a parameter MOVEMENT="Flying". I call enemy.move(), which says "Okay, are you a flying enemy?" and runs the "flyingMove()" function which, of course, doesn't take into account gravity. I'm not certain how well this would work, and I'd rather not code it all out just to find that it's a pain in the rear end and not extensible.

SlightlyMadman
Jan 14, 2005

It doesn't sound like you need anything that complex, Morpheus, so I'd suggest going with your first instinct approach, and seeing how it works. You probably won't understand the more complicated approaches until you figure out the deficiencies in the simpler approaches first hand, anyways.

I'd suggest giving each actor a state (fleeing, attacking, waiting, etc.), and creating a base enemy class that defines their behavior in each state, and a simple check which allows them to change state. Juts make sure you break it out into functions logically, so you can extend the base class when needed. For example, your flying guy, instead of having a parameter, could just override the move() function.

Really though, just start writing something and see if it works. You can always refactor it later.

UraniumAnchor
May 21, 2006

Not a walrus.
I get the feeling this is a relatively simple physics question but it's the kind of thing you might not be able to figure out yourself.

Given one object's current position and velocity (the 'target'), and another object's position (the 'shooter'), and a constant speed of a particular 'projectile', how would you figure out the angle necessary to aim the projectile to perfectly strike the target?

code:
   --X
T-- /
   /
  /
 /
S

T is moving in a certain direction at a certain speed, P can be shot in any direction but only at a given speed, how do I determine the direction necessary so that P and T meet at X at the same time?

schnarf
Jun 1, 2002
I WIN.

UraniumAnchor posted:

I get the feeling this is a relatively simple physics question but it's the kind of thing you might not be able to figure out yourself.

Given one object's current position and velocity (the 'target'), and another object's position (the 'shooter'), and a constant speed of a particular 'projectile', how would you figure out the angle necessary to aim the projectile to perfectly strike the target?

code:
   --X
T-- /
   /
  /
 /
S

T is moving in a certain direction at a certain speed, P can be shot in any direction but only at a given speed, how do I determine the direction necessary so that P and T meet at X at the same time?
Edit: This first way is a little too complicated. Look down a bit for what I think is a better way of thinking about it.

Parametrize the path of T with respect to the variable for time. Then parametrize the motion of P, with speed known, but direction unknown, set them equal, and solve for the direction (a vector).

I.e. for T at position P(x0, y0, z0) at t = 0, V(a, b, c)
T = P + Vt
Or alternatively (you shouldn't need to use this formulation, you can just do vector math, but this might be a little easier to understand?)
x(t) = x0 + at
y(t) = y0 + bt
z(t) = z0 + ct

Then say that you know the position of P, say it's P2, and its speed is S. One way you can do this is parametrize it in terms of the angles so that the velocity's magnitude equals S. Use Theta and Phi as the angles.
|V_p| = S
V_p = (S cos Theta sin Phi, S sin Theta sin Phi, S cos Phi)

Then say P2 + Vp * t = P + Vt, and choose a time t when you want them to intersect, if you want to simplify the solution. If not you'll get a relation between t and the angles which will let you choose any time, I believe.

Edit: Here's another way to think about it. This is really a 2-D problem. First, take a vector pointing from P to T, and the velocity vector of T. Take their cross product and use the position of P to have a normal and a point, so you have a plane, and the trajectory that P must take will lie in that plane, in fact, such that the direction will be somewhere between pointing at T's position at t=0, and pointing in the direction of T's velocity vector. Ever done those problems in calc class where you have a river going at some velocity, and want to travel along some vector so that you hit a point on the other end of the river? This is basically that problem. You can just do a similar parametrization to what I did above, but you only need to use one angle.

I haven't done the math out, but intuitively I think the angle should work out as a function of the ratio between the speeds of T and P. P should point directly at T when the ratio of the speed of T to P is zero, and P should approach pointing parallel to T's velocity as the ratio of the speed of T to P is infinite. Like I said I haven't done the math but I believe the angle should be equal to arcsin(|T|/|P|), where an angle of 0 represents pointing at T and an angle of 90 represents pointing parallel to T's velocity.

schnarf fucked around with this message at 05:24 on Nov 28, 2008

a slime
Apr 11, 2005

I'm driving myself crazy doing low-res pixel art graphics. Drawing sprites between pixel boundaries (ie. floating point coordinates) results in awful display artifacts, obviously- so for each sprite I maintain internal coordinates in floating point, and every time they are updated I do:

code:
display_x += int(real_x - display_x)
display_y += int(real_y - display_y)
Basically adding the integral component of any change in position to the "display coordinates." This avoids annoying problems with integer casting direction.

This worked great at first, but seems to haunt me at every corner. The biggest problem right now is if a sprite starts moving diagonally from non-integer coordinates, display_x and display_y will jump in an alternating fashion. This means instead of smooth diagonal movement, the sprite vibrates along its path.

The obvious solution is to reset the real coordinates to display coordinates whenever an object changes direction. Again, worked well for a while, until I starting implementing physics. Basically, objects can be caused to "change direction" every step of gameplay, and using the above solution means that objects never move. gently caress.

I feel pretty stuck at the moment. Am I missing something really obvious? Does anyone have any ideas at all?

schnarf
Jun 1, 2002
I WIN.

not a dinosaur posted:

I feel pretty stuck at the moment. Am I missing something really obvious? Does anyone have any ideas at all?
How about you store the coordinates (display_x and display_y) as floating-point, and don't cast to int when you update them. The way you're doing it, even though the data type is floating point, the actual value will always be integral. Then when you call the draw routine, you call it with rounded values -- by the way, casting to int doesn't round, it truncates. You might want to try roundf(number) or floor(number + 0.5f).

schnarf fucked around with this message at 20:43 on Nov 28, 2008

a slime
Apr 11, 2005

^^^^^^

I just read your edit. Again, I'll explain a bit better.

Two different sets of coordinates are maintained for each object. The floating point coordinates, "real_x" and "real_y", and the integral coordinates, "display_x" and "display_y." The update_position code looks something like this:

code:
def update_position(self, dt):
    self.real_x += self.velocity_x * dt
    self.real_y += self.velocity_y * dt
    self.display_x += int(self.display_x - self.real_x)
    self.display_y += int(self.display_y - self.real_y)
This way, the display coordinates lag behind the real coordinates- kind of a "directional" int cast. They are equal to the last integral value the real coordinates passed.

schnarf posted:

How about you store the coordinates (display_x and display_y) as floating-point, and when you call the draw routine, you call it with rounded values -- by the way, casting to int doesn't round, it truncates. You might want to try floor(number + 0.5f).

This has the same problem. Maybe I should describe it in more detail - let's say the player is at coordinates (5.4, 5.9). Every timestep, the player's movement vector, (-0.5, -0.5) is added to his current position. Note that the player would currently be displayed at (int(5.4), int(5.9)) = (5.0, 5.0). Now, execute the next timestep- the player's new position is (4.9, 5.4). He will be displayed at (int(4.9), int(5.4)) = (4.0, 5.0).

This is what I meant before- he has jumped in the x direction and not in the y direction. Next step, he'll do the alternate. The result is that instead of smooth diagonal movement, he vibrates in a diagonal direction.

a slime fucked around with this message at 21:48 on Nov 28, 2008

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
You're going to get "vibration" to some extent no matter how you do it if you're rounding float coordinates off to integers. If not when it's going "perfectly" diagonally, then when it's moving at some other angle. i.e. even if it looks OK going completely diagonally, what happens when it's moving, for example, twice as fast down as it is to the side?

One thing you could try is allowing sprites to use subpixel positions while in motion and snap them to pixel boundaries when they stop or slow down enough. Also, try experimenting with filtering modes, NEAREST filtering may wind up looking better if you're shooting for an "old school" look.

a slime
Apr 11, 2005

OneEightHundred posted:

You're going to get "vibration" to some extent no matter how you do it if you're rounding float coordinates off to integers. If not when it's going "perfectly" diagonally, then when it's moving at some other angle. i.e. even if it looks OK going completely diagonally, what happens when it's moving, for example, twice as fast down as it is to the side?

One thing you could try is allowing sprites to use subpixel positions while in motion and snap them to pixel boundaries when they stop or slow down enough. Also, try experimenting with filtering modes, NEAREST filtering may wind up looking better if you're shooting for an "old school" look.

Good point. Although, I think at angles other than 45 degrees the effect would be less noticeable.

That's a good idea. Unfortunately the snapping effect would be more obvious the slower an object is moving... But maybe with tuning it wouldn't be too bad. Thanks!

I am already using NEAREST :)

a slime
Apr 11, 2005

Are there any fancy ways to find the first intersection of a curve with an axis-aligned bounding box?

I was previously using a modified version of the Liang-Barsky line-clipping algorithm (along with Minkowski differences) to determine if objects collided. Now I've added acceleration and things are no longer linear- this isn't enough any more. Instead of the relative positions of two possibly colliding objects being simply "move_vec_a - move_vec_b", it is vel_a * t + 0.5 * accel_a * t^2 - vel_b * t + 0.5 * accel_b * t^2... Ugh.

I'm hoping there's something better than straight up solving for the points where the curve intersects with each line segment of the AABB, but nothing is showing up on :google:

edit: details, details

edit 2: fuuuck now determining moving AABBs means calculating local extrema for each moving object

a slime fucked around with this message at 14:46 on Nov 29, 2008

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

not a dinosaur posted:

Good point. Although, I think at angles other than 45 degrees the effect would be less noticeable.

That's a good idea. Unfortunately the snapping effect would be more obvious the slower an object is moving... But maybe with tuning it wouldn't be too bad. Thanks!

I am already using NEAREST :)
Well, you could also try NOT using NEAREST and using LINEAR. You could also try for higher-resolution artwork with low-res styling, i.e. Paper Mario. Key is to keep trying variations on poo poo until you find something that works. :)

not a dinosaur posted:

Are there any fancy ways to find the first intersection of a curve with an axis-aligned bounding box?
For each plane of the box, intersect the curve with it and then see if either of the impact points are behind all of the other box planes (that is, that the point is on the box surface and not out in space). If the point is in front of any other box planes, then the collision missed. The algebra of this depends on how the curve is being calculated, but it shouldn't really be that difficult.

If you're trying to do it with moving objects, you're opening up a major :can: that even well-established major physics engines don't attempt to solve (they just let objects penetrate, generate contact constraints, then run a few more solver iterations). The easiest way to do non-penetrating physics is to iterate each object separately, which doesn't work well for groups of connected or contacting bodies, but is extremely stable.

OneEightHundred fucked around with this message at 12:11 on Nov 30, 2008

t_rf
Nov 24, 2006
Re: the python/psyco/pypy discussion

I think it is worth pointing out (bragging) that haXe has a C++ target in testing now:
http://gamehaxe.com/2008/10/28/c-backend-for-haxe/
and
http://gamehaxe.com/2008/11/10/hxcpp-02-huge-performance-increase/

If that gets more stable and optimized, it'll be feasible to write number-crunch-heavy software in haXe. I used Python for a very long time but have switched over to this in the last year - nice language, the multiplatformness rules, and it's much, much more promising than PyPy if you're looking for speed. The main downside is that library support is limited and probably will continue to be for years to come.

duck monster
Dec 15, 2004

not a dinosaur posted:

I'm driving myself crazy doing low-res pixel art graphics. Drawing sprites between pixel boundaries (ie. floating point coordinates) results in awful display artifacts, obviously- so for each sprite I maintain internal coordinates in floating point, and every time they are updated I do:

code:
display_x += int(real_x - display_x)
display_y += int(real_y - display_y)
Basically adding the integral component of any change in position to the "display coordinates." This avoids annoying problems with integer casting direction.

This worked great at first, but seems to haunt me at every corner. The biggest problem right now is if a sprite starts moving diagonally from non-integer coordinates, display_x and display_y will jump in an alternating fashion. This means instead of smooth diagonal movement, the sprite vibrates along its path.

The obvious solution is to reset the real coordinates to display coordinates whenever an object changes direction. Again, worked well for a while, until I starting implementing physics. Basically, objects can be caused to "change direction" every step of gameplay, and using the above solution means that objects never move. gently caress.

I feel pretty stuck at the moment. Am I missing something really obvious? Does anyone have any ideas at all?

I'm having a similar problem to this, although using GL, which I've found GL_NEAREST seems to solve.

Kinda. This is an iphone though, so things are a bit whacky , being GL ES and all that.

a slime
Apr 11, 2005

duck monster posted:

I'm having a similar problem to this, although using GL, which I've found GL_NEAREST seems to solve.

Kinda. This is an iphone though, so things are a bit whacky , being GL ES and all that.

I'm also using GL with GL_NEAREST, not sure why you aren't having the same problem with scaling artifacts.

It doesn't happen at all float coordinates, only some. Lower image shows the ugliness.





VVVVVVVV and there it is, let me know if you find a solution

a slime fucked around with this message at 15:21 on Nov 30, 2008

duck monster
Dec 15, 2004

Actually now I think about it, I am having some issues... But its really sporadic. Just a rip, here and there on the sheet :(

grilldos
Mar 27, 2004

BUST A LOAF
IN THIS
YEAST CONFECTION
Grimey Drawer
Me and this other dude are collaborating on a pygame project as our annual winter time-waste. At its core, it will incorporate some basic sidescroller elements with assorted minigames that I can only define shortly as sort of like rhythm games without a beat. We've spent two weeks scouring around looking for relevant tutorials on how to set up both aspects, and we either come up against really terrible ones or decently written but old as hell.

Does anyone have links to any pygame tutorials they recommend? Or even some nicely written open source games we can tear apart and learn how to structure our poo poo?

Thug Bonnet
Sep 22, 2004

anime tits ftw

Wuntvor posted:

Well, since this is a question I've been dealing with again and again, I thought I might as well post here. Basically, I have a very hard time deciding what language to do my game programming in. C# is what I'm most comfortable with, so XNA would be the natural choice, but I'd like at least the possibility to run the game on Linux as well.

Basically, it comes down to the fact that it is hard finding a decent library that does all I need. Especially, I'd like a solid UI library etc., so I always think of the days when I was doing stuff in C++ and ClanLib offered all I needed. Graphics, Sound, GUI, networking etc., so I am always tempted to move back to that. However, C++ is more of a hassle, so stuff in general takes longer to write.

I have even tried writing a SWIG wrapper around ClanLib, but their signal/slot-stuff was pretty much impossible to wrap and I gave up.

With all other languages and game libraries, there seems to be a lot of library-hunting involved. I just haven't found a combination that works for me yet, maybe it is indeed time to try out a few more python options.

You're going to have a hard time finding a single library that does it all and is completely cross platform. I don't know if I would recommend it but you could probably use C# for your Win32 gui code, use managed C++ for the core, and of course use something other than C# for the gui on other platforms. I think you'd be making life harder for yourself that way, though.

The other option is to mix and match your libs, say SDL (or whatever) for your video/input/sound, and something else (probably platform specific) for your gui lib. You could also write your own in SDL, too.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

not a dinosaur posted:

I'm also using GL with GL_NEAREST, not sure why you aren't having the same problem with scaling artifacts.

It doesn't happen at all float coordinates, only some. Lower image shows the ugliness.

You're probably getting floating-point error. Having textures with power-of-two coordinates helps, as does putting the textured quad in the middle of a pixel on the screen (i.e. if 1 unit = 1 pixel, your vertices should be some_int + 0.5).

voodoo dog
Jun 6, 2001

Gun Saliva

Thug Bonnet posted:

You're going to have a hard time finding a single library that does it all and is completely cross platform. I don't know if I would recommend it but you could probably use C# for your Win32 gui code, use managed C++ for the core, and of course use something other than C# for the gui on other platforms. I think you'd be making life harder for yourself that way, though.

The other option is to mix and match your libs, say SDL (or whatever) for your video/input/sound, and something else (probably platform specific) for your gui lib. You could also write your own in SDL, too.
I know it is probably expecting a bit too much, I am just spoiled by my C++ experiences, I guess. I am currently playing around with Crazy Eddie's GUI combined with SdlDotNet, which seems to be working pretty well. Documentation could be better, but for the most part things are done almost exactly the same way as in the C++ variant.
Plus, if performance at some point turns out to be subpar, I can still switch from SdlDotNet to OpenGL at some point.

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!
While we are on the subject of libraries, what do you guys use? I use:

SFML -- Handles Sound, Graphics, Input, and limited TCP. Very easy to set up and use. ( http://www.sfml-dev.org ) Demonstrably faster than SDl in the 2D department. Only a 2D library.

RakNet -- UDP networking library that is at once easy to use, and VERY powerful. This guy knows his stuff. ( http://www.jenkinssoftware.com ) Includes support for game lobbies, object replication, auto patching, logging, and a whole bunch on top of their basic UDP handling.

CEGUI -- Pretty decent GUI library. Scriptable with lua. ( http://www.cegui.org.uk )

Box2D -- 2D physics library. Never run into problems with it ( http://box2d.org ) As far as I know, it's still being actively developed.

With those four libraries, you should have everything you need to write your 2D networked game, without having to worry about the particulars.

Oh, and Boost. For things like shared pointers.

vanjalolz
Oct 31, 2006

Ha Ha Ha HaHa Ha

Pfhreak posted:

Box2D -- 2D physics library. Never run into problems with it ( http://box2d.org ) As far as I know, it's still being actively developed.

This thing got me so excited last year. Fascinating library, I'm sure its responsible for more than half of the physics inspired games available today.

What ever happened to that Crayon game?

vanjalolz
Oct 31, 2006

Ha Ha Ha HaHa Ha
edit: I suck.

vanjalolz fucked around with this message at 06:52 on Dec 2, 2008

Lifespan
Mar 5, 2002

vanjalolz posted:

What ever happened to that Crayon game?

It's up for preorder with a TBA date: http://www.crayonphysics.com/

nihilocrat
Jun 8, 2004

all the hep cats jam to "cat /dev/hda1 > /dev/audio"

t_rf posted:

Re: the python/psyco/pypy discussion

I think it is worth pointing out (bragging) that haXe has a C++ target in testing now:
http://gamehaxe.com/2008/10/28/c-backend-for-haxe/
and
http://gamehaxe.com/2008/11/10/hxcpp-02-huge-performance-increase/

If that gets more stable and optimized, it'll be feasible to write number-crunch-heavy software in haXe. I used Python for a very long time but have switched over to this in the last year - nice language, the multiplatformness rules, and it's much, much more promising than PyPy if you're looking for speed. The main downside is that library support is limited and probably will continue to be for years to come.

I'm hoping things will turn out as you suspect. Not having the huge library support that Python has is a bit limiting, but having a mature FFI would basically "solve" this, as lots of Python libraries are just ctypes/Py++ or other FFI wrappers.

It seems like haXe is basically looking at the strengths of the VM platforms (JVM and .NET) but trying to implement them in a different way. It seems promising, but I'm not sure how everything would actually turn out in practice. Being able to code the same game in flash and C++ simletaneously would be a huge boon to game development, though. Flash provides a great outlet for getting people interested in your game, while C++ is obviously quite fast.

whoknew
Sep 18, 2004


oh shit
im lit



Anyone else doing uDevGames this year? http://www.udevgames.com

I don't really have any ideas for what I'm going to do yet, but when I do, it will probably use SDL and have terrible art because I am terrible at art. They've got some really great prizes for the winners, too. 3 months seems reasonable to do something good but simple. I think I'm gonna spend the next few days brainstorming and another day or two writing up a design document so I can have a solid foundation to work from. As far as I know, at this point it's going to be 2D and sprite based, or if I have an idea that I think will benefit from it, 2.5D. I am bad enough at 2D art, 3D art will be impossible to get done in the amount of time I have.

ShinAli
May 2, 2003

The Kid better watch his step.

whoknew posted:

I don't really have any ideas for what I'm going to do yet, but when I do, it will probably use SDL and have terrible art because I am terrible at art. They've got some really great prizes for the winners, too. 3 months seems reasonable to do something good but simple. I think I'm gonna spend the next few days brainstorming and another day or two writing up a design document so I can have a solid foundation to work from. As far as I know, at this point it's going to be 2D and sprite based, or if I have an idea that I think will benefit from it, 2.5D. I am bad enough at 2D art, 3D art will be impossible to get done in the amount of time I have.

I wouldn't be too worried about art. Just design a game that uses a simple art style. Look at Darwinia, it obviously didn't have a huge art budget but the game still looks very pretty.

posting smiling
Jun 22, 2008
I'm sure something like this has been posted in this thread, but I sure can't find it so if this is a huge repeat just point me to where it was already posted.

I'm trying to develop a very simple platformer in Flash and I want to ask about physics. If I was making a physics reliant game I'd just import Box2D and be done with it, but I only want a really basic feature set (think Knytt) and I figure it will be a good learning experience to do it myself.

I'm only using static, rectangular, non-rotating hitboxes so collision detection is easy. My problems come from resolving those collisions. My basic idea was to decide from which side a platform was being hit (all objects are either platforms or not and this collision resolution code only runs for collisions between platforms and non-platforms) and then back the moving object up until it's on that side of the platform. This has worked to some extent and the more I tweak it the better it gets, but some problems just keep cropping up that make me think I'm doing something fundamentally wrong.

Here's the collision resolution code:

code:
public function resolveCollision(p:WorldObject, o:WorldObject):void {
	var y_diff_one:Number = o.y+o.height - p.y;	// Overlap between object and platform on y axis
	var y_diff_two:Number = p.y+p.height - o.y;
	var y_diff:Number;
	if (o.dy > 0) {	// If object is coming from the top
		y_diff = y_diff_one;
	} else if (o.dy < 0) {	// If object is coming from the bottom
		y_diff = y_diff_two;
	} else { // If object isn't moving in y axis choose the lesser one because if one of them is 0
			// that means that the object isn't moving towards the platform anymore, but it probably
			// was in the past so we'll just use that figure.
		y_diff_one < y_diff_two ? y_diff_one : y_diff_two;
	}
	
	var x_diff_one:Number = o.x+o.width - p.x; // Same deal with x axis
	var x_diff_two:Number = p.x+p.width - o.x;
	var x_diff:Number;
	if (o.dx > 0) {
		x_diff = x_diff_one;
	} else if (o.dx < 0) {
		x_diff = x_diff_two;
	} else {
		x_diff = x_diff_one < x_diff_two ? x_diff_one : x_diff_two;
	}
	
	// If a diff is 0 in an axis and the object isn't moving in that axis
	// then the object is just sliding along the side and we don't care about it
	if ((x_diff == 0 && o.dx == 0) || (y_diff == 0 && o.dy == 0)) {
		return;
	}
	
	// Out variables tell how many iterations it would take for the object to
	// get as far into the platform as it currently is.
	var x_out:Number = Number.POSITIVE_INFINITY; // If an object isn't travelling
	if (o.dx != 0) { // in an axis it will never leave the object in that axis.
		x_out = x_diff/o.dx;
	}
	
	var y_out:Number = Number.POSITIVE_INFINITY;
	if (o.dy != 0) {
		y_out = y_diff/o.dy;
	}
	
	// Whichever direction would take the least iterations is the direction
	// from which the object entered so move it back to where it was when it hit.
	// And only move it on the significant axis to keep it simple.
	o.state = WorldObject.FALLING;
	if (Math.abs(x_out) < Math.abs(y_out)) {
		if (o.dx > 0) // Reverse direction as needed to extricate object.
			o.x -= x_out*o.dx;
		else
			o.x += x_out*o.dx;
	} else {
		if (o.dy > 0)
			o.y -= y_out*o.dy;
		else
			o.y += y_out*o.dy;
	}
}
And here's the SWF so you can see what's going on. Controls are left/right arrow to move left and right and up to jump. Stuff works on a basic level, but try pushing up against a platform (the blue blocks) and then release the arrow key, you'll float to the top of the platform you're pushing against because you're only movement is down (from gravity) and it assumes that you must have collided with the platform from the top so it puts you back there. And jumping doesn't work at all and results in something returning NaN and sticking you at the top of the screen.

TL;DR – If anyone has any resources/example code for simple physics like this I'd love to see how it's usually done.

Adbot
ADBOT LOVES YOU

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Just use the dynamic separating axis theorem: http://realtimecollisiondetection.net/files/levine_swept_sat.txt

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply