Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 16 Oct 2013
Online Last Active Today, 09:44 AM

#5155892 Why does game GUI have to be rectangles?

Posted by Lactose! on 25 May 2014 - 11:22 AM

Buttons don't have to be rectangular, but it's generally easier to implement/create a framework for buttons which have a nice geometrical/symmetrical shape.

If you want, you can create buttons which are whatever shape you can think of.


Edit: Being a ninja.

#5155865 Bounding Box Collision Glitching Problem (Pygame)

Posted by Lactose! on 25 May 2014 - 07:48 AM

Keep in mind that if you do that, with large velocities, you can end up with never being able to get very close to a wall. E.g. if there's a 20 unit gap, and your movement speed is 25 units, moving towards the collision thing will make you stay at that 20 gap distance, instead of closing the gap and touching the wall.


Other than that, I agree with splitting input handling and movement logic.

#5154500 What good OpenGL book do you recommend for beginners?

Posted by Lactose! on 18 May 2014 - 03:33 PM

I would suggest the following link. It's online, free and related to current (shader based) OpenGL.


#5152863 graphics

Posted by Lactose! on 11 May 2014 - 08:43 AM

Your question is too broad to answer easily. I'm going to assume you're new to programming in general.


The FAQ has some pointers on where to being with programming:



Additionally, I'm going to copy something written by jbadams, which might also help you on your journey - a more step-by-step guide. What follows is the advice he gave to a different user, but a lot of it should be relevant to you as well. Good luck!


  1. Download SFML and follow the getting started tutorial for your development environment (from here) to install it and get set up.  Get help if you have problems, and do not give up until you have it set up properly.
  2. Follow the tutorial to open a window. Get help if you have problems, and do not give up until you have a window open.
  3. Follow the tutorials on "drawing 2d stuff" and "sprites and textures" to draw a single sprite (make it a space ship if you like!) in your window.  Get help if you have problems, and do not give up until you have a sprite drawn in your window.
  4. Follow the tutorial on "keyboard, mouse and joysticks" to make your sprite move in response to the arrow keys on your keyboard.  Get help if you have problems, and do not give up until your sprite is moving around the screen in response to input.
  5. Referring back to the drawing tutorials (from step #3) and the input tutorial (from step #4), make a second sprite (make it a bullet if you like!) appear in your window when the space-bar is pressed.  Don't worry about putting it in the right place yet (just put in in the middle of the window), and don't worry about making it move.  Get help if you have problems, and do not give up until your second sprite appears in response to pressing the space-bar.
  6. Make it so that your second sprite (bullet) moves constantly until it goes off the screen.  Don't worry about making it go the correct way, just make it go up for now.  Get help if you have problems, and do not give up until it moves up and disappears off the top of the screen after you press the space bar.
  7. Make it so that if your bullet moves off of the screen it will be removed.  Get help if you have problems, and do not give up until it's working.
  8. Make it so that instead of appearing in the middle of the screen your bullet appears in front of the space-ship.  Get help if you have problems, and do not give up until it's working.
  9. If it doesn't already, make sure that you can spawn additional bullets by pressing the space bar again.  Get help if you have problems, and do not give up until it's working.
  10. Continue to make very small additions to your program, and at each stage get help if you're stuck and do not give up till it works.  Continue until you have a complete asteroids game including a simple menu, scores, and a proper "game over", with no obvious bugs.
  11. Make a slightly more complicated game using the same technique of breaking it down into small steps.  Each time you finish a game you can make something more complicated next.

For all of the above steps (except the test program from step #1) actually type out the code, don't just copy and paste from the tutorials.

#5152774 opengl question

Posted by Lactose! on 10 May 2014 - 06:40 PM

I have to admit I'm interested in seeing where this goes...


As far as I can tell, the forums are (still!) open for people asking questions. Keep in mind that, as L. Spiro (and probably others) has mentioned before, there are good/effective ways to ask questions, and there are bad/ineffective ways. This has all been said before, so I won't repeat it here.


If you have a simple question I would encourage you to ask it. If it's something which can be answered in a sensible manner, I'm sure people will answer.


Regardless, good luck with whatever you're trying to accomplish, even though I don't personally really see the point in making a thread to ask whether you can ask something.

#5152664 question regarding game developer

Posted by Lactose! on 10 May 2014 - 06:15 AM

Just reading book(s) will probably not get you hired. I guess potentially a junior position, or some interning type job (with a potential for advancement) might be the only realistic options.


What I see suggested most often is just... make something.

If you've got something you've made, e.g. a prototype or a mod or anything, it's vastly more interesting for future employers than just having a "I read this book" on a CV/resume. It shows you can actually produce and work with stuff that's a lot more tangible/real than just "I have some knowledge which might apply here".


Note that, by trying to make something and learning from it, you will almost invariably have to read and research a ton of stuff you don't know. Making something doesn't replace reading books, it adds to it.


If you prefer books over sources (or vice versa) is probably only a personal preference. Some people prefer to read and spend time on their own, others gain more from having someone give a lecture and being able to ask directly. I don't think there's a 1 true answer there.

#5151940 How much time do you need to finish a beginners book?

Posted by Lactose! on 06 May 2014 - 05:43 PM

The gang of four's design pattern book is great example of such a book but there are many others. Once you're comfortable with the syntax of your chosen language, I would suggest reading the gang of four's design pattern book. It will really help you with managing complexity, which is an absolutely critical skill if you want to move beyond textbook examples and onto writing non-trivial code.

A related link, discussing various game programming patterns. Free, online.


#5151830 2D Platform Movement [Solved]

Posted by Lactose! on 06 May 2014 - 10:10 AM

And welcome to software, where as soon as you walk away, post the question, get in the shower, or start driving, you figure out the answer.

You forgot the part where you bang your head against a problem for hours, then go to bed feeling exhausted. Then, right before you fall asleep, you realize the problem, and now have to decide whether to get out of bed to fix it1, or try to sleep2 and fix it the next day3.


But even with all of that, it's still fun :)



1 ...and forget to go to bed again because of continued programming.

2 ...which often takes ages, because you're thinking through the solution and wanting to implement it.

3 ...hoping that you still remember the solution instead of just remembering the fact that you had a solution.

#5151669 What is your opinion and how would you do a structure that has multyple funct...

Posted by Lactose! on 05 May 2014 - 01:00 PM

For some reason following line was not allowed by the compiler i had error. I hope it was a mistake on my part.
objFarm = SFStorage | SFRest; //Add two flags together.
That is why you see in the following i used ampersand i couldn't get it to compile. I will try to write it again and see what i got.

This works if objFarm is an int. I'm not quite sure what you're wanting to achieve with your holder struct, but you add an "int type" field or something, and then do

objFarm.type = SFStorage | SFRest;

#5151207 Should I use NeHe tutorials?

Posted by Lactose! on 03 May 2014 - 10:05 AM

Kaptein already linked a more modern 3D/OpenGL related tutorial in your other thread, which is what you're asking for now.


What you're not asking for, but which I suggest you do regardless, is put all that aside for a little while on focus on the basics.

Learn about variables, functions, etc. You'll have a much much better chance at learning 3D programming if you know some basic programming things first. While I guess it's possible to learn it all by jumping into the most difficult stuff first, I would really advise you not to.


This might even include learning a more beginner-friendly language at first. A lot of the concepts translate over from language to language, which would make future things easier for you.


At this rate, you'll be finding/reading some advanced programming and math topics, and you'll be lost on almost every little detail.

#5151015 How much time do you need to finish a beginners book?

Posted by Lactose! on 02 May 2014 - 05:10 PM

std::string str("This is a string");

std::cout << "The length of this string is" << str.length() << " characters."

#5148434 Trying to get a zelda style textbox going

Posted by Lactose! on 20 April 2014 - 06:05 PM

Are you basing this code off something else? You're repeating some earlier mistakes we've already pointed out, which leads me to think you don't fully understand what you're posting here.
Notably: You're still doing stuff where you declare & define a variable at the start (assumption: assigned to same value), and seem surprised that the position is the same throughout.
I'll be guessing a bit here, based on your description of what happens.
1. You're calling this function every update, with the same input every time (full text string you want to be printed sequentially, positionX and positionY). I'm assuming this because you say the behavior/output changes. Keep doing this. Note that I'm assuming this despite you not mentioning whether or not the sound plays correctly. I am guessing the sound plays repeatedly, far too frequently.
2. When you're testing this, you are starting the text drawing at startup. I'm assuming this based on guessing that al_get_time() returns seconds since the application was started, and because you say the text prints each individual letter from start to finish. This will hide a future problem, but I'll get to that.
3. px is supposed to be the current character's x position, while the int x parameter is the start x position.
Things that go wrong with your approach:
1. You only every print one character.
2. You play a sound every time you call the function.
3. You never advance the text cursor -- you always print in the same location. This is linked to only printing one character every time you call the function.
4. The timer you're using will only work immediately upon starting the game.
5. If left running, text[timeElapsed] will try to access garbage data (timeElapsed will surpass the number of characters in the text string).
Things you need to do:
1. Figure out how many characters to print. This involves being able to tell how much time has passed from when the text printing began. This also involves never trying to print more characters than are in the given text string.
2. Print the correct amount of characters, using the information above.
3. Figure out a way to tell if you should play a sound (this could be based on time, or based on more characters printed now than previous function call, or something else).
I'm slightly hesitant in terms of just posting a suggested solution (and honestly, somewhat tired again!). I'd suggest trying to solve the issues above on your own, and posting again if you run into problems, or if you've just got questions.
Hopefully that helps, both in accomplishing your goals and possibly increasing your programming abilities smile.png
Also, as a minor note to Satharis: int i is actually not redeclared/ghosted in the for loop. The for loop just uses the already declared i. As I mentioned in my first post, though, there is no reason to declare the variable before the loop in this case.
EDIT: I typed all of this up before your edit. Most of the issues I listed are still relevant.

#5147792 Trying to get a zelda style textbox going

Posted by Lactose! on 17 April 2014 - 08:28 PM

The timecounter variable is created and set to 0 every time the function is called.

I'm thinking unless you pass in a text string which is at least 100 characters long, nothing will ever display.

Setting it to static might work, but you don't want to increment it within the for loop. You want to increment it before the for loop occurs.

Imagine delay was = 3. Updating timecounter inside the for loop would make every 4th character be written.

(char0, timecounter = 1, char1, timecounter = 2, char2, timecounter = 3, char3, timecounter = 4 --> greater than delay, print char3)


An alternative to setting timecounter to static would be to calculate the amount of characters to print outside of the drawtext2 function and pass it through as a new parameter to drawtext2, e.g. as int numCharsToPrint.

In either case (static or gotten from from parameter), the for loop would then just loop through (for int i = 0; i < numCharsToPrint; i++) //print;


Do you really intend to print the character + a newline using cout? I'm guessing this is for debugging purposes.


I don't see a reason for declaring int i outside of the for loop.


A lot of games have it so the text prints more quickly if a specific button is held down. You could do this by not resetting timecounter everytime you print.

You'd then do something like...

timecounter += buttonPressed ? 50 : 1;

if (timecounter > (delay * i + 1))



Sorry if the post is somewhat jumbled, quite tired.

#5147198 Triangle and rectangle intersect find position points of rectangle that inter...

Posted by Lactose! on 15 April 2014 - 03:17 PM

Putting words into dejaime's mouth/hands:

A triangle has 3 lines.

You can split the "Triangle vs Box" intersection problem into 3x "Line Segment vs Box" intersection problems, 1 per line of the triangle.


There might be more efficient ways of doing it, but it should give you a starting point.



I haven't used this reference personally, but it might be of some assistance:


#5146714 AI is harder than I thought

Posted by Lactose! on 13 April 2014 - 09:28 AM

Here is a case and point. I once played the highest difficulty on the chessmaster PC game. I knew the computer would play optimally, and that it was taught the best move in every case. But in some cases, it would play the best move provided I play the best move. So I played an off-the-wall move. The next move, the computer made a blunder.

Then the computer did not play optimally. You might have discovered a bug in the AI code for the chess program, or it might have been completely unrelated to what you were doing, and just triggered a different bug.

This is actually a concept you hear quite often if you follow chess a bit -- "well, just play something completely random/unexpected and you'll circumvent the logic behind the other person's moves, and you'll beat a grand champion even if you're a noob".

A good chess player will crush you instantly if you make any "silly" moves like that -- they are silly for a reason. If using them was a good tactic, then the good chess players would use that sort of thinking.


That said, I don't necessarily agree with every Tic-Tac-Toe player being able to play it flawlessly, but I don't see Tic-Tac-Toe AI as being a fuzzy logic shaped problem.