Jump to content

  • Log In with Google      Sign In   
  • Create Account

thok

Member Since 23 Dec 2011
Offline Last Active Oct 14 2014 08:00 AM

#4985835 AABB Collision Detection

Posted by thok on 01 October 2012 - 01:23 PM

For various reasons, I need to hold tiles, objects and enemies in seperate managers - but what if I had a manager for all physical objects (that contained pointers to said objects) - did a quick broad phase test, then proceeded to run a more fine grain AABB check?


Sure, sounds reasonable. That's pretty much I'm doing with the GameState class, except there's no broad phase collision testing yet, and I don't plan to add it until I start seeing performance issues with many many many objects in play.

I say, stick with one manager. It would probably make sense to keep different kinds things (tiles, enemies, etc.) in separate lists/arrays, but this is kind of a trivial detail. Let the manager handle it's own internal state. Just do whatever works and keep it simple.


#4985753 I need help with structuring, really bad!

Posted by thok on 01 October 2012 - 08:08 AM

Figuring out what should be objects, what they should inherit from, Especially Reusable code, etc.


Code reusability != inheritance.

Nor does it really necessarily have anything to do with object oriented programming. There are design techniques you can apply (composition, inheritance, etc.) to achieve code reuse, but you can also get a lot of code reuse if you write in a somewhat functional style. Another way to put it: Try to move as much as code as you can into pure functions/methods. For example, you could write your physics, general math, and collision code as a collection of simple functions, then piece them together however you need. You don't need to worry about shared state as much and it makes your code easier to test. I would also argue that it makes managing the complexity (of games) much easier.

Neither OO nor functional programming are silver bullets, in my opinion. In my (limited) experience with writing game code, it seems that a balance between the two approaches is very nice. It depends on what type of component you're trying to build--"best tool for the job" and all that. =)

For reference, there's a nice blog post about functional programming written by John Carmack: http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/


#4985750 AABB Collision Detection

Posted by thok on 01 October 2012 - 07:56 AM

I have started working on a simple 2D tile based platformer (C++ & SFML), and I've made a reasonable start. At present, the character can walk around the map (loaded from a text file), jump and collide with solid tiles. The tiles are held in a two dimensional array, and accessed through a manager class, that can return pointers to individual tiles, render the tiles that are currently onscreen, and load a map from a text file.

Firstly, I was wondering if my method of collision detection was appropriate:

For each axis, I am moving the player according to its velocity, then checking if it collides with any solid tiles (Two tiles are checked per axis.) If a collision has occured, I move the player back by exactly the distance it has overstepped.

I feel that the code is a little heavy handed in places - e.g. passing the tile manager as an argument.

This is an example:

[source lang="cpp"]float cPlayer::collisionCheckX(cGraphicalObject A, cGraphicalObject B) { sf::FloatRect intersectionRect; if(A.returnBounds().intersects(B.returnBounds(), intersectionRect)) { return intersectionRect.width; } else { return 0; }}[/source]

[source lang="cpp"]void cPlayer::moveObject(cTileManager* TM) { getSprite()->move(_velocity.x, 0); if(_velocity.x > 0){ float a = collisionCheckX(*this, *TM->getTile((int)getPosition().y / 32, (int)getPosition().x / 32 + 1)); float b = collisionCheckX(*this, *TM->getTile((int)getPosition().y / 32 + 1, (int)getPosition().x / 32 + 1)); if( (a && TM->getTile((int)getPosition().y / 32, (int)getPosition().x / 32 + 1)->getSolidity() ) || ( b && TM->getTile((int)getPosition().y / 32 + 1, (int)getPosition().x / 32 + 1)->getSolidity() )) { //std::max is being used in case only one of the tiles is solid getSprite()->move(-std::max(a, b), 0); }}//...[/source]

Another issue that I need to resolve is animated sprites. Currently, I have the clipping of sprite sheets being handled by the movement functions in the player class (as a temporary measure) - could anyone reccomend a solid method of handling animations? I will need animations for most non-tile objects.


I can't answer your question about the animation, because this is something that I have yet to tackle my platformer project. But maybe I can help with the collision detection.

It seems fine to pass in the cTileManager; using dependency injection in this way should make things easy to mock and test. The alternative would be to just pass in the 2D array of your tiles, instead of the entire tile manager. But it probably doesn't matter for now.

From your post, I didn't really see any question about AABB collision, except for the worry about heavy-handedness, so you still have questions about the collision bit, please clarify. For reference, here is how I implemented AABB collision detection/response in my project. (It's Java, not C++, but maybe you'll find something useful in here.)

Collision.java - Contains utils for tracing the path an entity has taken during a given update (on both the X and Y axes), as well methods for calculating the correction delta when a collision/intersection occurs. It also covers the case where an entity is moving _so_ fast during a given update that it passes completely through a tile. Check it out: https://github.com/larsbutler/gamedemo/blob/opengl/src/com/larsbutler/gamedemo/math/Collision.java

These are used in the move() method, which is responsible for moving entities for the given tick and checking for/responding to collisions: https://github.com/larsbutler/gamedemo/blob/opengl/src/com/larsbutler/gamedemo/core/GameState.java#L94

Disclaimer: This code may be rather rough and inefficient (especially with a large number of tiles), but it works fine for small cases and it's reasonable well tested: https://github.com/larsbutler/gamedemo/blob/opengl/tests/com/larsbutler/gamedemo/math/CollisionTest.java


#4983759 Website for code library?

Posted by thok on 25 September 2012 - 03:56 PM

If you want to share code publicly, the proper place to do it is on something like github or bitbucket. And instead of saying "You're free to use it in any way with no strings attached and no guarantee of fitness/correctness", it would be better include a proper source code license file with your code.

Also, if you want your code to be "tested", you should actually write tests for it. If you don't know how, do some research on unit testing and NUnit. You can include the test code with your code above. Otherwise, I not consider this to be "tested" code, now matter how many manual tests you performed.

Hope that helps.


#4980911 New to this need some help

Posted by thok on 17 September 2012 - 09:40 AM

1) I have a level class that contains all the Arrays that hold my objects. One of the Arrays holds the bullets. Currently I have two different types of weapons the player can use. You start with a machine gun and can upgrade to a plasma missile (Ooooh!). Anywys I am usure of a good way of adding the weapons to the array in a clean manner. Right now each of my weapon types has a create method that will create a weapon of its type at the position of the owner and move in the direction the owner is facing. It seems bad to me to have a object have a create method that crates a copy of itslef.


This doesn't really make sense. You have an array which holds the bullets. Then you go on to talk about how you're trying to figure out "a good way of adding weapons to the array". What array? Is there an array for weapons as well?

If so, can't you just take the weapon the player has (referring to it by its BaseWeapon type) and add it to the array? There seems to be no reason to copy the weapon.


#4979676 Easy way to learn computer languages

Posted by thok on 13 September 2012 - 06:00 AM

First of all let me explain myself so that you can understand my situation well. My name is Eva and i’m 19. I’m dong job in local company as data entry opreator. It is my passion to become a good and professional software Developer. I don’t have any degree related to computer sceince or any other field. Now my plan is to take admission in BS in CS or IT online virtual university but i know that with just degree it is much hard to get job, experience is much necessary. So i have decided to do job and study at same time. So now i want to join any company as software developer in few months.

I have find so many jobs on newspapers and also on internet who doesn’t require any special degree their requirements are similar to these.

  • Must have a solid background in Microsoft Technologies (.NET Framework 2.0, 3.5 etc, ASP.NET, C#, VB.NET, ADO.NET, SQL Server) and databases
  • Microsoft Visualbasic
  • C#
  • Microsoft .NET
  • Microsoft SQL Server
  • ASP, CGI
  • ETC...
So now I’m confused that how to get command and full knowledge about these languages I have searched on internet like youtube but I’m confused that where to start learn, which language I should learn first and then second language I mean step by step. So here are some points on that i want to get advice.
  • How and where i should start learning these languages. Which language i should learn first and then next?? I don’t wanna pay any dollar to buy any language course so is it possible to learn through internet i mean youtube videos and other pdf books.
  • Which is most demanded and valuable language that will help me in my career?? ( well I’m hearing about .NET)
  • Is it necassary to know about background of language i mean all terminologies of relative language for making a complete application or it doesn’t matter we can make complete software without getting all infomation about language.
I shall be very thankful to you if you can give some advice.Thank you so much in advance.

Regards,
Eva


If you're completely new to programming, I would recommend "Learning Python the Hard Way", by Zed Shaw: http://learnpythonthehardway.org/book/. It's freely available online and it's extremely practical. This is not going to teach you Microsoft's stack, but for a beginner this is fine. Python is arguably one of the better languages to learn first and will give you the foundation to pick up other languages later on.

To address the MS-specific technologies, here is my (slightly biased, since I'm a developer using mostly Python/Linux in my day job) recommendation: Don't lock yourself into the Microsoft stack. I suggest that you stick with technologies that either are platform-agnostic or even tend to favor technologies centered around Linux/Unix.

As for which languages are the most in demand. it's hard to say, and I wouldn't worry about learning _the_ language which is in the highest demand. Instead, focus on learning _one_ of the in-demand languages. Python is one of them, so that's another reason to start with LPTHW.

Once you have a grasp of basic programming, you can start branching off into other things like databases. Zed Shaw, again, has a nice intro to SQL (all of his books are here http://learncodethehardway.org/).

Hope that helps.


#4979295 Hey, a couple general questions on how to get started making a game

Posted by thok on 12 September 2012 - 07:12 AM

A word of advice - if you're like me and learn a lot from reading tutorials & sites like GameDev.net then NEVER EVER copy and paste. But if you're going to copy - AT THE VERY LEAST type it out. Line-by-line and character-by-character.


This is very good advice. Building this kind of "muscle memory" is crucial to gaining programming skill.


#4979265 Opinion on new boston

Posted by thok on 12 September 2012 - 05:35 AM

lolx
well its not like that you can become a game developer in java coming out of blue and just start programming at the professional level you have to start from the basics both as the application developr and the game developer


I agree with you on that. But that wasn't my point. Whether the content is basic or not is irrelevant. My point is that the author appears to be lacking the proper comprehension of the subject matter to be teaching even at a basic level. The style of the tutorials is very "cargo cult", which is not good for anyone (especially beginners). There's a big difference between "simplifying" and "dumbing down". Explaining complex concepts using simple clear language is useful. Dumbing things down and overprotecting newbies from what is really going on is not useful. What's even worse is when the presenter doesn't actually explain things properly (as in, using incorrect terminology to describe concepts). An example:

In one of this Python tutorials, he explained how tuples can be passed to Python function and expanded into positional arguments. Here's the function, more or less:

def example(a, b, c):
  return a + b * c

He states that this function "returns a mathematical function". Well, no it does not. It returns the value of an expression (most likely a mathematical expression). It is certainly not a "mathematical function". I found this just by picking a video at random and watching a few random minutes. These poor explanations are all over the place in the tutorials. So while the author does appear to grasp some concepts (it quite clear, given that he can write some working programs), he does not appear to have clear enough understanding of the subject matter to be teaching it properly. That's my point.


#4979222 Want to join java project

Posted by thok on 12 September 2012 - 02:27 AM

Hmm, well one idea that comes to mind is to contribute to some open source project. Find something that interests you, and then:
  • Subscribe to the mailing list.
  • If possible, just use the software (hard to do if it's just a library). Become a power user.
  • Get your development environment set up so you can build and test the project. (This is a given, but the importance of this cannot be overstated.)
  • Find the bug/issue tracker site for the project.
  • Look at code submissions from the community. Read the code. Try to understand it. Ask questions about it.
  • Find some "low-hanging fruit" in the issue tracker. Write some code to address it. If you get stuck, ask questions on the mailing list/IRC/whatever.



#4978922 Getting started with OpenGL on OSX

Posted by thok on 11 September 2012 - 09:31 AM

I just started playing with OpenGL, with Java + lwjgl. So, even though I'm developing on OSX as well, there's nothing platform specific here. So that's the extent of my OpenGL experience.

Using a search engine I found this: http://developer.apple.com/library/mac/#documentation/graphicsimaging/conceptual/opengl-macprogguide/opengl_intro/opengl_intro.html#//apple_ref/doc/uid/TP40001987-CH207-TP9
I skimmed through this a bit and it looks promising. Just look at the table of contents and see what looks useful to you. There seem to be plenty of code samples. I'm assuming you're using Xcode, so getting your environment set up will be the only major challenge. developer.apple.com should have the info you need to get this set up.

Keep in mind, OpenGL itself is not platform specific. So, once you have a library which implements the OpenGL API, the API calls are pretty much the same, no matter what is language or platform. For example, this objective-c code is almost identical to what I would do in Java (using lwjgl) to draw a triangle:
static void drawAnObject ()
{
    glColor3f(1.0f, 0.85f, 0.35f);
    glBegin(GL_TRIANGLES);
    {
	    glVertex3f(  0.0,  0.6, 0.0);
	    glVertex3f( -0.2, -0.3, 0.0);
	    glVertex3f(  0.2, -0.3 ,0.0);
    }
    glEnd();
}

Again, once have a proper lib set up for your language/platform, you then just need to learn the OpenGL API.

The wikipedia article about OpenGL has a lot of good info, including history, concepts, and features: http://en.wikipedia.org/wiki/OpenGL

Hope that helps.


#4973780 Java: Looking for tips on Square to Square stationary collision response.

Posted by thok on 27 August 2012 - 07:45 AM

I'm not sure if I understanding entirely the game mechanics you are going for, so forgive me. It seems like you're struggling with basic concepts of movement and collision response, and I think there is a much simpler (and more stable) way of handling this. Below is what I've implemented in my simple 2D game project. It's pretty straightforward. It may not work so well in more complex physics simulations, but for simple stuff it's okay.
  • Instead of trying to prevent two objects from overlapping, let them. This overlap is your collision area. The area has a size and shape (which is, in this case, just another rectangle). I'll explain below how to deal with this.
  • When your ball moves through 2D space, it should have an X velocity and a Y velocity. These values indicate how far (in pixels, for example) your ball needs to move on a given axis per update. Various forces (gravity, user input, etc.) can change these values.
  • When you do a game update, move one axis at a time. Check for collisions on that axis, respond to any that occurred, and do the next axis. (It's doesn't really matter which axis you do first, except in some extreme cases. For now, don't worry about it.)
  • When you move on a given axis, the moving object has either a positive or negative velocity on that axis. The sign of this values tells you which direction the object is moving (up vs. down on the Y axis, left vs. right on the X axis).
  • For each object that your moving object could possibly collide with, check for an intersection. Hint: If you don't want to code this yourself, have a look at http://docs.oracle.com/javase/6/docs/api/java/awt/geom/Rectangle2D.Double.html#createIntersection(java.awt.geom.Rectangle2D).
  • As I mentioned before, each intersection has a size. This tells you how much your moving object is overlapping with the object it hit.
  • Given this size, you know exactly how far you need to move (in the opposite direction) to get out of the intersection. Again, the axis is relevant.
This method of responding to collisions (called "projection") is briefly mentioned in this article: http://www.metanetsoftware.com/technique/tutorialA.html#section0

Projection [Jakobsen] is one physically-plausible method for dealing with overlapping ("penetrating") objects. The basic idea is to move the objects out of penetration using the smallest possible displacement. Solving the collision then becomes equivalent to finding the vector v which moves the two objects out of penetration by the shortest distance possible.


Hope that helps.


#4972174 java libraries

Posted by thok on 22 August 2012 - 06:28 AM

Disclaimer: I do not have extensive experience with any game libs. I'm working on a 2D platformer also and I'm building almost everything from scratch as a side project--for learning and for fun.

My answer is: It depends on what you want, exactly.

If you want to learn how things really work, start writing it yourself, from scratch. That's what I did (and am still doing).

To make a platform game, you don't need any special libraries. The following is what it takes to get the basic platformer mechanics in place. All of this can reasonably be written from scratch.

- Create a window with some sort of canvas you can you can draw on
- Build a game loop to make update and render calls. For simplicity in your implementation, you can synchronize the update/render cycles and fix them to a particular framerate (60 frames per second, for example).
- Figure out how to draw primitive shapes, like different colored rectangles.
- Figure out how to draw rudimentary animations. For example: Draw a background and move a rectangle back and forth across the screen, or draw it at a random location each frame. The point is, you want to see _movement_. This will show you that your render loop is working.
- Figure out how to get keyboard input from the user -- arrow keys, for example.
- Figure out how to use the arrow key input to move the rectangle around.
- Now figure out how to make it smooth.
- Next, add platforms, jumping, and gravity, and start figuring out collision detection and response. This is where things start to get interesting.

For all of this, you only need the Java standard libs, including Swing and AWT for the graphics.

Building a decent game (event a simple one) takes a lot hard work. Don't expect immediate success. I started my platformer project over 2 years ago. I would work on it for a while, then I would let it sit for several months. The first prototype was pretty cool: I had gravity, level scrolling, jumping, blocks that you could push around, level switching, parallax background scrolling, basic character animation, little projectiles that the character would throw, and I was even working on ladders. I had a basic level editor too. And you know what happened? It turned out, I had made several major fundamental errors in the core design. It got really ugly and it was nearly impossible to make changes without breaking tons of stuff. So I started over from scratch with an attempt to do things right. This also means I'm unit testing my code religiously (before, I hardly tested anything).

Anyway, sorry for the speech. Just wanted to share my experiences. I hope it helps. Just start small and be prepared to learn.

Thok


#4963558 Preventing Chaos in your game code

Posted by thok on 27 July 2012 - 02:03 AM

As others have said, reading books and other resources about clean code, coding style, and design patterns are all very useful.

Here's my advice:
- Use static analysis tools to check for styling issues and possible bugs. For Java, there's Checkstyle and Findbugs. For Python, you have pep8, pylint, and pyflakes. There are equivalents for other languages; just check google.
- Check your code/test coverage. (You are writing unit tests, right?) I found this immensely helpful in pursuing game programming as a hobby. Before I started doing rigorous testing and coverage analysis, I was just kind of thrashing around and things just sort of worked. Now, when I implement a new feature, I check my test coverage. If there's a large body of code with no coverage, I stop coding and I test it. If it can't be tested easily, it probably needs to be refactored.
- Write as much as you can in a pure functional style. That doesn't mean you have to go crazy with functional programming concepts, but the fact is purely functional code is much easier to test. So if you can move a bunch of the complexity into small, easily testable functions, you'll that you'll have greater confidence in your code and that it's easier to make changes. (BTW, John Carmack has talked about the benefits of writing functional-style code: http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/)

That's my 2 cents.


#4963555 good code to read

Posted by thok on 27 July 2012 - 01:47 AM


When I find a good chess engine the code is always cluttered with the GUI, etc its using,

I just want to look at pure c++ code (console, ascii text)
I'm preferably looking for code that's for a chess game(with/or without AI), and a text RPG game

XoaX has a few samples of a chess and rpg text game but its not enough

Reading other people's completed programs usually doesn't help much. Their code usually doesn't help you understand the problem domain much, and it's usually full of bad habits you'll pick up, OR tricks that only make sense in the context of their own program.

The best code to read for anything is in articles and tutorials. That way, when you understand how everything works, you will know how to write that stuff off the top of your head, instead of trying to reverse engineer someone else's design.

(since you just got Chess links...) For a text RPG, you can try reading a lot of MUD articles, and all the stuff at ROGUE BASIN. They have great articles on random dungeon generation algorythms, and when you understand them, you can implement your own easily.

http://roguebasin.ro...x.php/Main_Page


On the contrary, reading other peoples' code is actually a really good way to learn. Reading a large body of code written by another person can give you some really interesting insights into style, design, architecture, and you may even pick up a few new tricks or idioms.

But I agree; for specific things (such as implementing a particular collision detection algorithm), tutorials and articles will probably be more useful.


#4963382 Whats wrong?

Posted by thok on 26 July 2012 - 11:48 AM

I want to get rid of the JVM completely


Why?

btw im really noob


Okay, so in that case you don't to get rid of the JVM. Just launch4j if you want to create an exe. Otherwise, you can still just execute .jar files (hell, I think Minecraft still works this way doesn't it?).




PARTNERS