Jump to content
  • Advertisement

svenster

Member
  • Content Count

    12
  • Joined

  • Last visited

Community Reputation

124 Neutral

About svenster

  • Rank
    Member
  1. svenster

    Need An SDL Tutorial

    As well as the above, I've also found http://www.aaroncox.net/tutorials/ to be very useful. The site contains several walkthroughs on writing complete games in SDL, as well as more specific info. Hope this helps, Sven
  2. Quote:Original post by svenster Knowing me it'll be some silly & obvious little syntax error I've made somewhere! ...just as I said! Problem solved, cheers! :)
  3. Hi, Over the past week I've been trying to get my head around using classes in CPP. So far I've written a small SDL program to create a 2d starfield effect, which works fine- I create Star objects, which are then aggregated into a Starfield object so I can dial in as many stars as I might want. However, I've been attempting to add a class Ship, so I can have a little ship zooming around- and here's where Ive hit a bit of a snag. When I attempt to compile I get boatloads of compiler errors, and I'm not sure why as I'm doing it pretty much the same as with my other classes. I've noticed that when I comment out Ship's constructor it compiles, so this is where I presume the problem is. Find my classes.h file below, with the offending class commented. Knowing me it'll be some silly & obvious little syntax error I've made somewhere! By the way, I'm using VCPP EE. Here are my compiler errors: Error 1 error C2062: type 'int' unexpected c:\program files\seb\sdlprojects\shooter\ship\ship\ship\classes.h 70 Error 2 error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\seb\sdlprojects\shooter\ship\ship\ship\classes.h 70 Error 3 error C2143: syntax error : missing ')' before '}' c:\program files\seb\sdlprojects\shooter\ship\ship\ship\classes.h 72 Error 4 error C2143: syntax error : missing '}' before ')' c:\program files\seb\sdlprojects\shooter\ship\ship\ship\classes.h 72 (plus lots more, they're all syntax errors similar to this one) Here's my classes.h file. The problem is the Ship class, at the bottom: class Star { public: Star(int x = (rand() % WINDOW_WIDTH), float y = (rand() % WINDOW_HEIGHT), float brightness = (rand() % 255), float m_Speed = 0): m_XPos(x + 1), m_YPos(y), m_Brightness(brightness), m_Speed(brightness / 255) {} void UpdatePos() { if (m_YPos >= WINDOW_HEIGHT) { m_XPos = (rand() % WINDOW_WIDTH); m_YPos = 0; } else m_YPos += m_Speed; } void PlotStar(SDL_Surface* screen) { pixelRGBA (screen, m_XPos, (Sint16)m_YPos, (Uint8)m_Brightness, (Uint8)m_Brightness, (Uint8)m_Brightness, ALPHA); } private: int m_XPos; float m_YPos; float m_Brightness; float m_Speed; }; class Starfield { public: Starfield (int numStars = NUM_STARS) { m_StarVector.reserve(numStars); } void AddStars(Star& aStar) { m_StarVector.push_back(aStar); } void DrawStars(SDL_Surface* screen) { for(vector<Star>::iterator iter = m_StarVector.begin(); iter != m_StarVector.end(); ++iter) { iter->UpdatePos(); iter->PlotStar(screen); } } private: vector<Star> m_StarVector; }; class Ship { public: //problem constructor, if I comment this out it compiles Ship(int x = ((WINDOW_WIDTH / 2) - (SPRITE_SIZE / 2)), int y = (WINDOW_HEIGHT - SPRITE_SIZE): m_XPos(x), m_YPos(y) {} //NB variables in caps are all global constants private: int m_XPos; int m_YPos; }; If anyone can help then I'll be eternally in your debt! I can provide the rest of my project's code on request. Cheers! Sven
  4. svenster

    Whats a vector

    Just to clarify, the author is actually referring to iterators when he talks about putting post-it notes on pieces of data. An iterator is used to manipulate the elements held within a vector- read the chapter carefully for a full & concise explanation.
  5. Hi, Is it possible to initialise an array where all the elements contain a default value, or do I have to make do with using a for loop to insert my default value (example below)? Cheers, Sven int main() { string test[5]; for (int i = 0; i < 5; i++) { test = "Empty\n"; } for (int i = 0; i < 5; i++) { cout << test; } return 0; }
  6. svenster

    Simple VC++ IDE Question

    I find it stupid that an application as supposedly fully-featured as VC++ Express lacks something as simple as that, Dev-C++ has it after all... ah well, I'll live. Quote:Original post by xEricx Other than that, writing your own app wouldn't be that hard It would be for me- I'm atill right at the beginning of my studies, writing simple DOS console games alongside a little tinkering in SDL. I'm not sure I'd know where to begin with loading in & reading files, so if anyone would like to post any basic hints or links to help me get started then I'd be very appreciative of the challenge! Cheers for your responses, Sven
  7. svenster

    Random number generator

    #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(0)); //seed random number generator int randomNumber = rand(); //generate random number int die = ( randomNumber % 6 ) + 1; //get number between one & six cout << "You rolled " << die << endl; return 0 } The above simulates a dice roll, generating a number between one and six. It's lifted from Michael Dawson's book Beginning C++ Game Programming, which I can't recommend enough if you're just starting out like me. Rather than explaining it I recommend you test it, fiddle with it, google every command & generally get to understand every last little detail. Get a copy of a good book such as the one I mentioned. By the way, the "%" means "modulus" (google it!). Hope this helps, Sven
  8. How can I tell how many lines of code I've written in Visual C++ Express? Slightly pointless question I know, but I can't find how for the life of me and little things like this drive me crazy! Apologies if I've overlooked something totally obvious. Cheers in advance, Sven
  9. svenster

    SDL

    Are you using Visual C++ 2005 Express? I downloaded & set it up for the first time last night, using the "Setting Up SDL" page on Lazy Foo's indispensible tutorials section as guidance- check out http://lazyfooproductions.com/SDL_tutorials/lesson01/ (in fact, the entire series of tutorials is essential if you're getting stuck in with SDL). The instructions are for Visual Studio .NET 2003 but they still apply. Read the article thoroughly and you'll be rolling in no time. If you still have trouble then try downloading Bloodshed Dev-C++, you can get SDL installed very simply by downloading the SDL devpak & plugging it in. Hope this helps- if not, I'll leave it to someone a bit more knowledgable than myself :) Sven
  10. Lazy Foo: cheers for your surface rendering tip, that's so obvious I can't believe I didn't see it! I guess I'm not very used to SDL at present as I've only been doing it for a couple of days. Anyway, my memory problem is now solved. You're wicked-cool, as are your tutorials [cool] Everyone else: I'm currently working on injecting a little artificial intelligence (or rather, artificial stupidy) into my enemy bat so he's not totally unbeatable, but as soon as I'm done with that I'm going to take your suggestions on board and hopefully solve my scoreboard issue. The response has been absolutely wonderful- you all have my eternal gratitude, and with any luck I may well have a complete (if very simple) game to show you within a few days! By the way, if anyone wants to advise me on my SDL_mixer/sound library issues then I'll be your best friend [smile] Cheers, S
  11. Cheers for your prompt response, hadn't come across sprintf before so I'll look it up and do a bit of research. However, since then I've come across a much more serious problem. The section of code which writes the word "pong" at the top of the screen (which will display the score when I work out how to do it) causes the amount of memory my game uses to continuously go up by 2MB per second, according to Windows Task Manager. I know it's just this little section, as when commented out the bug goes away. I've got it towards the end of my while(gameRunning) loop, after the part where I use SDL_gfx to render the bat/ball etc and just before SDL_Flip(screen); //draw word pong at top score = TTF_RenderText_Blended (font, "PONG", textColor); SDL_Rect offset; //Get offsets offset.x = BOUNDARY_TOP_LEFT; offset.y = BOUNDARY_TOP_LEFT /2; SDL_BlitSurface( score, NULL, screen, &offset ); SDL_Flip(screen); How come it's using up so much memory, and what can I do?
  12. Hi, This is my first post on gamedev.net so please be gentle with me :) Apologies for the length of this post, I've tried to be as informative on my problems as possible. I'm a beginner C++ programmer who's decided to dive in and get his feet wet with SDL after reading about half of Michael Dawson's excellent book, Beginning C++ Game Programming. I'm using Dev-C++ as my compiler (running on Windows XP), and as well as C++ & SDL I'm using SDL_mixer, SDL_ttf & SDL_gfx. I've found it pretty hard going so far but have managed to get a quick & dirty simple Pong game going. However, I've hit upon a couple of snags which I need a little help with: 1: SDL_mixer problems- I'm using SDL_mixer to provide my background music and for sound effects when the ball bounces off the walls & paddles. I've got it all working and have set the music to loop infinitely, but when the music finishes and returns to the start I get a little gap. The music I'm using was written to loop perfectly and does so when I play it outside of my program, so how can I get rid of this? I'm guessing it might have something to do with the chunksize? When I initialise SDL_mixer the code I'm using is Mix_OpenAudio( 44100, AUDIO_S16, 2, 2048 ); and the music is .ogg format if that makes any difference. The command to play the music (Mix_PlayMusic( music, -1 );) is outside my while(gameRunning) main game loop. I've also got a minor problem with panning- I've set the sounds which play when the ball bounces off the left/right paddles to pan to the corresponding left & right. It works, but occasionally the panning glitches and momentarily (literally for milliseconds) plays the sound in the centre. I have all four sound effects I'm using set to different channels. Are these problems symptomatic of SDL_mixer itself or is it something I'm doing wrong, which is fixable? Should I try using a different sound library instead? 2. SDL_ttf problem- how do I go about using SDL_ttf to render my score integers? I have my scores as integer variables which increment when the ball goes off the side of the screen. I can get SDL_ttf to draw to the screen when it's got a const char* passed to TTF_RenderText_Solid(), but trying to get the int in there produces the compile error "invalid conversion from `int' to `const char*'". I'd guess I'd have to convert the int somehow but if it needs to be const, how can it be changed when the score updates? Sorry, I don't think I'm explaining myself very well so please bear in mind that I'm a beginner and this has me totally stumped. If anyone can help with either of the above then I would be very appreciative. I can provide some more info/code if necessary. Cheers!
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!