Jump to content

  • Log In with Google      Sign In   
  • Create Account

sednihp

Member Since 24 Apr 2012
Offline Last Active Oct 04 2013 04:37 AM

#5022547 Game doesnt work on other pc

Posted by sednihp on 17 January 2013 - 09:51 AM

The allegro-md.dll should be somewhere on your machine (c:/windows/system32 probably). When you find it, copy it into your distribution and then it won't be missing when people go to play your game




#5022541 using shared_ptr

Posted by sednihp on 17 January 2013 - 09:40 AM

When I want to put something on the screen I do something like this...


std::shared_ptr button1(new GUIButton(g_width/2-125,g_height/2-125,0,250,100,"(L)oad Default Scenario",updatestate));
button1->SetShortCut(ALLEGRO_KEY_L);
button1->SetZOrder(1);
UIelements.push_back(button1);

Now I may do that 2000 times on a single screen for all the various elements on the map (which worked fine as "raw" pointers)

In my main game loop I have this...
Instead of using new, use std::make_shared<T> instead, i.e.

std::shared_ptr button1 = std::make_shared<GUIButton>(g_width/2-125, g_height/2-125, 0, 250, 100, "(L)oad Default Scenario", updatestate);
Make_shared is exception safe and uses the same call to allocate the memory for the reference counting block and the resource itself, reducing construction overhead (and hey, if you're doing something 2000 times you want to do it the most efficient way possible)

For more advice on how to use shared_ptr I found the MSDN article excellent (there are equivalent articles on unique_ptr, weak_ptr and general smart pointers as well)

If you didn't have to call setShortCut() and setZOrder() I would have recommended emplace_back as well,

UIElements.emplace_back(std::make_shared<GUIButton>(g_width/2-125, g_height/2-125, 0, 250, 100, "(L)oad Default Scenario", updatestate));
Which constructs the element in place in the vector


#5018208 Question about using "Game States"

Posted by sednihp on 06 January 2013 - 09:18 AM

I like LazyFoo's state machines article myself:

http://lazyfoo.net/articles/article06/index.php


#5017307 Good habits for game development

Posted by sednihp on 03 January 2013 - 05:44 PM

For C++, I'd recommend reading C++ Coding Standards by Sutter and Alexandrescu. The table of contents by itself is helpful, but the full book contains discussion like reasoning and exceptions to the general rules. The only problem is that it predates C++11.

 

I just came across this the other day. Scott Meyers' range of Effective C++ books are also a great read on best practices




#5013736 Programming a Game...

Posted by sednihp on 23 December 2012 - 01:19 PM

I'll be honest I still hack away and make something work first, then go back and improve the flow, break it up into functions, look for areas where I can cut out repetitions. It's much more fun to have something working and playable that's badly coded then the most amazing looking code that does nothing.


#5011393 Intimidated, not sure where to start.

Posted by sednihp on 16 December 2012 - 05:05 PM

To answer q2, there is no other way to learn a programming language without actually programming in it. If you wanted to learn to play the piano, would you try and do it without actually playing the piano?

If you want to learn, start with a language like Python, which is a powerful language but is a lot easier to understand for a beginner. Then once you feel confident in that, move on to a language like C#, combined with XNA, to build yourself some more powerful games (that you can run on your 360 if you have one). After a while you might want to move over to C++, but it's not recommended for a beginner, in much the same way that learning Mozart straight away is not the best way to learn the piano.


#4989612 Is this a case for smart pointer usage or is my design wrong,help needed.

Posted by sednihp on 12 October 2012 - 05:39 PM

Don't create a particle every time it moves, no, but you could create one randomly on movement. The particle then controls it's own movement and animates itself (if so called for) until it's lifetime expires, at which time it is destroyed. All of this management should be done in the particle manager class, with a check done to see if a particle is still alive and needs to be removed in the game's code, i.e.

[source lang="cpp"]for(auto particle : particles){ if( particle.isDead() ) //erase particle code here else particle.update();}[/source]


#4956491 [First SDL game] Care to give some feedback ?

Posted by sednihp on 06 July 2012 - 03:49 PM

To set a time limit, whenever the main level starts, assign SDL_GetTicks() to a variable, then at the end of each frame, check if the current time minus the start time is bigger than the time limit. i.e.

[source lang="cpp"]const int levelTimeLimit = 30000 //30s time limitint startTime = SDL_GetTicks()while(game is running){ //insert game loop code here if(SDL_GetTicks() - startTime > levelTimeLimit) //check the current time vs the time limit { //exit level code goes here }}[/source]


The game seemed to work perfectly well from my quick trial, I like the idea behind it and the animations were pretty nice, but trying to read the code gave me a headache. Try to format your code nicely with proper indenting (like my example code above) to make it easier to read and understand for others. You might want to look into object oriented code as well, it'll make things easier for you in the long run when your games get bigger. If you want an idea I've got a few SDL games and their sourcecode at the link in my signature.


#4955031 Start with SFML or SDL?

Posted by sednihp on 02 July 2012 - 02:22 PM

I've used SDL for a few games and found it easy enough to get along with. After picking up C++ again, I was building SDL games in a matter of weeks thanks to Lazy Foo. I've posted a few articles over at my blog about some different things I've come across whilst developing my SDL apps, which might come in helpful, along with the sourcecode to the games to download as well if you want to have a look at what kind of code SDL produces.

I've found it remarkably easy to use SDL, the only thing I've come across that it doesn't do (so far) is rotation. I'm sure if I played around with the OpenGL side though I could nail that down. Lazy Foo has a tutorial for everything that you could need and each one has working sourcecode that you can run and see working and interrogate to make changes and see how they impact the output. I really can't praise the man enough.


#4955018 Learning SDL, need help to draw an object on screen between classes

Posted by sednihp on 02 July 2012 - 01:59 PM

The problem with that post is that since then, as with all code, the ImageCache has undergone even more refactoring in other projects that I'm working on, so it's out of date now! But it gets the important ideas across and will hopefully help you and others to build one of your own. :)


#4954658 Learning SDL, need help to draw an object on screen between classes

Posted by sednihp on 01 July 2012 - 03:28 PM

If you want to see an example of an Imagge loading class built in SDL, I've put an explanation of how I built my own ImageCache class up on my blog at http://sednihp.wordpress.com/2012/06/02/111/

It deals with loading and storing images so that theyre only loaded once per game, and also works with text using sdl_ttf.


#4949232 Open source code for a beginner

Posted by sednihp on 14 June 2012 - 12:32 PM

I've put up some of my games over on my blog if you want some small SDL games to look at. They're nothing amazing (Pong, breakout, space invaders, bomber run clones) but they might give you something to peruse...

I will say, I've only been at this for 4-5 months so I'm no expert, but I'm pretty happy with my code.


#4949229 Starting off

Posted by sednihp on 14 June 2012 - 12:25 PM

If you want to learn SDL and 2d programming use Lazy Foo's website. His tutorials are the best I've seen on the net, they explain how to get everything up and running perfectly. The way he breaks up his tutorials makes it really easy to understand how each bit works. They're not particularly well coded (globals everywhere and all in one file) but they get the idea across.


#4939417 Is getting an image to the screen in SDL an accomplishment?

Posted by sednihp on 11 May 2012 - 03:22 PM

For SDL, use the Lazy Foo tutorials. They're my SDL bible, I've used them to help create my own pong game, as well as breakout and tic tac toe clones.


PARTNERS