• What do you need help with? V. 3.0
    4,884 replies, posted
Ok I see what you mean now. Yeah, it makes more sense [editline]30th December 2011[/editline] Well, now I know why I used it. shipimage is private.
Can you post your code? It'll make life much easier.
header: [url]http://pastebin.com/dUz81uV2[/url] source: [url]http://pastebin.com/9KJXvaY7[/url] main: [url]http://pastebin.com/q8HbAmh3[/url]
First, I don't recommend loading an image every time a certain key is pressed. Second, I recommend changing "shipimage" to "ShipSprite" for clarity. I was confused earlier. in your main: [code] ship1.SetShipAccel(ship1.GetShipImage().GetRotation(), ship1.GetThrust(), ship1.GetMass()); [/code] change to: [code] ship1.SetShipAccel(ship1.GetRotation(), ship1.GetThrust(), ship1.GetMass()); [/code] I recommend reading up on C++ Classes again. [url]http://en.wikipedia.org/wiki/C++_classes#Declaration_and_usage[/url] EDIT: [code] ship1.SetShipRotation(ship1.GetShipRotation()); [/code] Not trying to be rude, but please reread your code.
[QUOTE=Parad0x0217;33967526]First, I don't recommend loading an image every time a certain key is pressed. [/QUOTE]How else can I change the image when a key is pressed? [editline]30th December 2011[/editline] [QUOTE=Parad0x0217;33967526] make a member function to return rotation in your ship class. [/QUOTE]I did [editline]30th December 2011[/editline] [QUOTE=Parad0x0217;33967526] Not trying to be rude, but please reread your code.[/QUOTE]Well you kind of made me change a lot of things, and I didn't get a chance to rewrite the code yet. Also, what? What was that function for?
[QUOTE=Meatpuppet;33967551]How else can I change the image when a key is pressed? [/QUOTE] Load up the images into sf::Image and then when you press a key, use Sprite.SetImage(Image);
[QUOTE=Parad0x0217;33967609]Load up the images into sf::Image and then when you press a key, use Sprite.SetImage(Image);[/QUOTE] got it [editline]30th December 2011[/editline] [QUOTE=Parad0x0217;33967609]Load up the images into sf::Image and then when you press a key, use Sprite.SetImage(Image);[/QUOTE] How do I set the image? Typing the filename doesn't work. I have [cpp]ship1.GetShipImage().SetImage("spaceship1_thrusting.png")[/cpp]
[QUOTE=Meatpuppet;33967551] Well you kind of made me change a lot of things, and I didn't get a chance to rewrite the code yet. Also, what? What was that function for?[/QUOTE] You were setting the ships rotation to itself. EDIT: You have to make sf::Image for each of them. [code] sf::Image First; sf::Image Second; sf::Image Third; //and so on if(!First.LoadFromFile("WHEREVER") || !Second.LoadFromFile("WHEREVER") || !Third.LoadFromFile("WHEREVER") || ) { return EXIT_FAILURE; } // then when you want to press a key.. if (keypressed) ShipSprite.setImage(First); //or other image [/code]
[QUOTE=Parad0x0217;33967665]You were setting the ships rotation to itself.[/QUOTE] How else would I change the rotation?
[QUOTE=Meatpuppet;33967675]How else would I change the rotation?[/QUOTE] In the class itself. It would be good to have an Update() member function as well as a Draw() member function. Also, make your variables in your class private. When you need to access them, write a getVariable() function and a setVariable() function. (Obviously replace Variable with the name of the variable.)
[QUOTE=Parad0x0217;33967809]In the class itself. It would be good to have an Update() member function as well as a Draw() member function. Also, make your variables in your class private. When you need to access them, write a getVariable() function and a setVariable() function. (Obviously replace Variable with the name of the variable.)[/QUOTE] That's what I did for every variable except Thrusting. I wrote that late night, and I wasn't going to bother. And thanks. Even though I don't know how to do that, haha. I wish I was working on something easier, like a tile game. I just don't want to disappoint my dad
A tile game may not necessarily be easier. For the Update and Draw functions, I usually do something like: in the header: [code] void Update(sf::RenderWindow* window); void Draw(sf::RenderWindow* window); [/code] in the source: [code] void Spaceship::Update(sf::RenderWindow* window) { if (sf::Keyboard::IsKeyPressed(sf::Keyboard::W)) //check if keys are pressed { } //update things like rotation here. } void Spaceship::Draw(sf::RenderWindow* window) { window->Draw(sprite); } [/code] and in the main: [code] Spaceship ss; //declare new spaceship //in main loop ss.Update(window); //update space ship, and pass in a pointer to the SFML window //after you clear the screen // Clear screen for new stuff to be drawn window->Clear(sf::Color(0, 0, 0)); ss.Draw(window); // Display things on screen window->Display(); [/code] EDIT: I also want to say, if you keep at it, you'll succeed.
Okay. Thanks [editline]30th December 2011[/editline] I'll probably start a new project and put this one away, because I have no idea how to implement what you just said. That and the sf::Image thing.
[QUOTE=Meatpuppet;33968021]Okay. Thanks [editline]30th December 2011[/editline] I'll probably start a new project and put this one away, because I have no idea how to implement what you just said. That and the sf::Image thing.[/QUOTE] Make sure you don't do that too often. Changing projects frequently makes you think you never get anything done. Update() and Draw()? I gave you code examples. You could almost copy and paste. For the sf::Image thing, you could always go back later and improve it. Keep it how you have it now, and eventually you'll figure out on your own how to do things better. That is true with all programming.
[QUOTE=Parad0x0217;33968187]Make sure you don't do that too often. Changing projects frequently makes you think you never get anything done. Update() and Draw()? I gave you code examples. You could almost copy and paste. For the sf::Image thing, you could always go back later and improve it. Keep it how you have it now, and eventually you'll figure out on your own how to do things better. That is true with all programming.[/QUOTE] If I just copy and paste, I won't learn anything. Ok.
When using pointers and references do you guys prefer this: [cpp] RandomClass *randomPointer RandomClass &randomReference [/cpp] or [cpp] RandomClass* randomPointer RandomClass& randomReference [/cpp] [editline]30th December 2011[/editline] I usually go with the first.
The first makes more sense when you examine what the syntax actually means, but the second makes more sense to me as to me a "int-pointer" is just as much of a type as an "int" is.
First is clearer in cases where you define multiple variables: [cpp]int *a, b; //or int* a, b;[/cpp] Both actually define a as a pointer to int and b as int, but from first it's more understandable and less error prone.
I prefer "int* p_num;" but when creating multiple pointers: "int * p_num, * p_num2;"
How do I do all these cool bindings people are doing? Like say if I wanted to bind lua functions to Java to print stuff in the terminal how would I go about doing that?
Can you somehow compare a lets say string_temp to every vector<string> a(10) values at once and if any of them is true I could use the one it equaled true to. C++ is the language.
[QUOTE=Armandur;33941471]What is the simplest way to generate a tone using C++? I know about outputting \a but I need to be able to generate tones of different lengths. Any ideas?[/QUOTE] [QUOTE=ief014;33941506]I know in windows you can do this: [code] #include <windows.h> int main() { DWORD freq = 300, dur = 100; Beep(freq, dur); return 0; } [/code][/QUOTE] Finished it :) [IMG]http://dl.dropbox.com/u/5342745/Morse.png[/IMG] Only works on Windows since it uses Beep() and Sleep() from windows.h (Couldn't be bothered to use a sound library and a timer class) [url]http://dl.dropbox.com/u/5342745/Morse.exe[/url]
[QUOTE=handler;33971207]Can you somehow compare a lets say string_temp to every vector<string> a(10) values at once and if any of them is true I could use the one it equaled true to. C++ is the language.[/QUOTE] If you mean checking equality with comparing then there is a simple way. All you have to do is search vector<string> for the string you want to compare. To do that you first must include <algorithm> to get access to the find function. Then you do so: [cpp]vector<string>::iterator it = find(a.begin(), a.end(), string_temp); if (it != a.end()) // if string_temp was found in a { string &str = *it; //make found string modifiable through str // or if you want to know the index of found string int i = it - a.begin(); } [/cpp] It might seem quite complex at a glance, but if you learn more about STL then you see it's a really powerful tool.
I'm programming a little game using OpenGL in C++. For my previous projects I used GLUT, because it made everything simple, but now I faced the downside of that library: I cannot make my own window. All I have is window that GLUT gives me with its own styles and icon(I suppose I can track down the goddamn window and force it to update styles and icon, but that is a dirty workaround). I want to make my own window that can render stuff via OpenGL. Can anyone tell me how it's done?
[QUOTE=krassell;33977622]I'm programming a little game using OpenGL in C++. For my previous projects I used GLUT, because it made everything simple, but now I faced the downside of that library: I cannot make my own window. All I have is window that GLUT gives me with its own styles and icon(I suppose I can track down the goddamn window and force it to update styles and icon, but that is a dirty workaround). I want to make my own window that can render stuff via OpenGL. Can anyone tell me how it's done?[/QUOTE] [cpp] void ClientWindow::CreateAppWindow(HINSTANCE hInstance) { m_hWindowInstance = hInstance; WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = MWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = m_hWindowInstance; wc.hIcon = LoadIcon(0, IDI_APPLICATION); wc.hCursor = LoadCursor(0, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = L"WindowClass"; //If we can't register for some reason... if(!RegisterClass(&wc)) return; //Window-border flags UINT borderFlags = 0; borderFlags |= WS_OVERLAPPED; //Compute some sizes... (If there's a border, we end up with a bigger-width window...) RECT R = {0, 0, m_iClientWindowWidth, m_iClientWindowHeight}; AdjustWindowRect(&R, borderFlags, false); //Compute the X/Y position on the screen given their desktop size and the window size. RECT desktopRect; GetWindowRect(GetDesktopWindow(), &desktopRect); //Since we adjusted the width of our window to match the borders, //these may not match the m_iClientWindowWidth. So, go local! int width = R.right - R.left; int height = R.bottom - R.top; int posX = (int)((desktopRect.right - desktopRect.left) / 2) - (width / 2); int posY = (int)((desktopRect.bottom - desktopRect.top) / 2) - (height / 2); //Create our window finally m_hWindowHandle = CreateWindow(L"WindowClass", m_wsWindowTitle.c_str(), borderFlags, posX, posY, width, height, 0, 0, m_hWindowInstance, this); if(!m_hWindowHandle) return; ShowWindow(m_hWindowHandle, SW_SHOW); UpdateWindow(m_hWindowHandle); } [/cpp] That'll get you a window on Windows (I snipped out some irrelevent code, so it might be a bit confusing/hard to compile. :v:) Then you need to pass your window-handle to OpenGL and initialize it - I've only done it in DirectX so you're on your own there.
[url]http://www.opengl.org/wiki/Creating_an_OpenGL_Context[/url]
need help making a new type of iterator in python that if you have a 3 long list that you can slice to 4 and get whatever... nvm you can just % the len
C++ question. Maybe I should state my goals to make it clearer: I'm trying to get a Lisp embedded in C++, but for it to be of any use other than a toy, it has to be able to call C++ functions. So I implemented a function, findLookupTable, that takes two mandatory arguments and a variable number of arguments of any type. The first argument is the lookup table code, which means "Which table has the function you want to call?" (A global table would be too slow). This value is put through a switch() statement that finds the correct table, then passes the second argument and the rest to a findLookupFunction function for the corresponding table. This second argument is the code that identifies the function that must be called within a particular lookup table. Here's my code: [CODE]#include <iostream> #include <boost/algorithm/string.hpp> template <typename ... Ts> void table1_findLookupFunction(int functionCode, Ts ... ts) { switch(functionCode) { case 1: std::cout << "Table 1. Function code: " << functionCode << std::endl; std::cout << "Function: Boost string to uppercase" << std::endl; //boost::to_upper(ts ...); break; default: std::cout << "Couldn't find function :(" << std::endl; } } template <typename ... Ts> void table2_findLookupFunction(int functionCode, Ts ... ts) { std::cout << "Table 2. Function code: " << functionCode << std::endl; } template <typename ... Ts> void findLookupTable(int tableCode, int functionCode, Ts ... ts) { switch(tableCode) { case 1: std::cout << "Table: " << tableCode << std::endl; table1_findLookupFunction(functionCode, ts...); break; case 2: std::cout << "Table: " << tableCode << std::endl; table2_findLookupFunction(functionCode, ts...); break; default: std::cout << "Couldn't find lookup table :(" << std::endl; } } int main() { findLookupTable(1,1,"derpcar",1,'d',2.6); return 0; }[/CODE] The call in main() correctly identifies the table and the function to call within the table. But I'm wondering, how do I 'expand' these arguments and give them to the function (In this case the boost function to uppercase a string). Something like: boost::to_upper(Ts ... ts); That would expand at runtime to the arguments I passed: boost::to_upper("derpcar",1,'d',2.6); EDIT: Already tried "boost::to_upper(Ts ... ts);", returns: [CODE]eudoxia@desktop:~$ g++ cpp_var_args.cpp -std=gnu++0x cpp_var_args.cpp: In function &#8216;void table1_findLookupFunction(int, Ts ...)&#8217;: cpp_var_args.cpp:12:23: error: expected primary-expression before &#8216;...&#8217; token eudoxia@desktop:~$ [/CODE] EDIT II: Tried calling findlookTable like this: [CODE] findLookupTable(1,1,"derpcar");[/CODE] And modifying the function call so it's like this: [CODE]boost::to_upper(ts ...);[/CODE] Now it gives this error: [CODE]eudoxia@desktop:~$ g++ cpp_var_args.cpp -std=gnu++0x In file included from /usr/include/c++/4.5/algorithm:63:0, from /usr/include/c++/4.5/ext/slist:48, from /usr/include/boost/algorithm/string/std/slist_traits.hpp:16, from /usr/include/boost/algorithm/string/std_containers_traits.hpp:23, from /usr/include/boost/algorithm/string.hpp:18, from cpp_var_args.cpp:2: /usr/include/c++/4.5/bits/stl_algo.h: In function &#8216;_OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation) [with _IIter = const char*, _OIter = const char*, _UnaryOperation = boost::algorithm::detail::to_upperF<char>]&#8217;: /usr/include/boost/algorithm/string/detail/case_conv.hpp:95:17: instantiated from &#8216;void boost::algorithm::detail::transform_range(const RangeT&, FunctorT) [with RangeT = boost::iterator_range<const char*>, FunctorT = boost::algorithm::detail::to_upperF<char>]&#8217; /usr/include/boost/algorithm/string/case_conv.hpp:160:13: instantiated from &#8216;void boost::algorithm::to_upper(WritableRangeT&, const std::locale&) [with WritableRangeT = const char*]&#8217; cpp_var_args.cpp:12:4: instantiated from &#8216;void table1_findLookupFunction(int, Ts ...) [with Ts = {const char*}]&#8217; cpp_var_args.cpp:32:4: instantiated from &#8216;void findLookupTable(int, int, Ts ...) [with Ts = {const char*}]&#8217; cpp_var_args.cpp:45:31: instantiated from here /usr/include/c++/4.5/bits/stl_algo.h:4688:2: error: assignment of read-only location &#8216;* __result&#8217; eudoxia@desktop:~$ [/CODE] EDIT: Gentlemen, I'VE DONE IT!
Been wondering this for a while; how would one add control over the Steam Overlay to an application? Like, controlling which processes get the overlay applied and such? If it matters, I'm working with C# here.
Im having problems sorting textures in XNA during the drawing. This whole drawing code is in a DrawableGameComponent that is created during the first game initialization. [code]sprite.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend); sprite.DrawString(guifont, "FPS: " + Math.Round(fps, 2), new Vector2(10, 10), Color.White); sprite.DrawString(guifont, "Player's world position: " + terrain.playerVirtualPos, new Vector2(10, 30), Color.White); sprite.DrawString(guifont, "Player's tile: " + terrain.playerTile, new Vector2(10, 50), Color.White); sprite.DrawString(smallfont, player.brasskeys.ToString(), new Vector2(175, 847), Color.Black); sprite.DrawString(smallfont, player.silverkeys.ToString(), new Vector2(175, 880), Color.Black); sprite.DrawString(guifont, player.health + "/" + player.maxhealth, new Vector2(55, 900), Color.Red, 0f, Vector2.Zero, 1.2f, SpriteEffects.None, 1); sprite.Draw(guitex, new Rectangle(0, 840, guitex.Width, guitex.Height), null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 1); foreach (ItemButton ibtn in itemButtons) { ibtn.Draw(gameTime, sprite); if (ibtn.currentItem != null) { if (ibtn.currentItem.count > 1) { sprite.DrawString(smallfont, ibtn.currentItem.count.ToString(), ibtn.position, Color.Black, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1); } } } health.Draw(sprite); player.Draw(gameTime, sprite); sprite.End();[/code] The health bar has two sprites that both have to drawn, and the second has to be drawn behind the another. At first, all the GUI objects are drawn correctly, but when one of the ibtns have to draw something more, the health bar draws incorrectly as the sprite behind is drawn on the front. Halp mee!
Sorry, you need to Log In to post a reply to this thread.