• What Do You Need Help With? V6
    7,544 replies, posted
Why are you involving the player position in there at all? surely it's irrelevant to how the bullet should push the enemy?
[QUOTE=Tommyx50;46482396]Why are you involving the player position in there at all? surely it's irrelevant to how the bullet should push the enemy?[/QUOTE] It is, but I need it to get the bullet to travel at the right angle.
The player position should have NOTHING to do with the bullets angle. Honestly this code is absolute nonsense to me. [code] public void update(float dt) { Vector2f d = new Vector2f(GameScreen.getCurrentPlayer().getPos().x - x, GameScreen.getCurrentPlayer().getPos().y - y); // So you're getting a vector from the player, splitting it apart, then combining it into a new vector? Why?? float length = (float)Math.sqrt(d.x*d.x + d.y*d.y); normX = d.x/length; normY = d.y/length; // Normalize without any division of zero error checking. float vx = velocity; // Set the enemy's velocity to his *SPEED* (velocity and speed are different concepts), thus completely ignoring the direction the enemy is currently travelling in float vy = velocity; // Now the vx and vx jsut point to the bottom right. // intersectsWithBullet() modifies the class variable pushBackVelocity, which is immediately used afterwards and has nothing to do with the enemy's actual state // Why not just return that vector?? if (intersectsWithBullet()) { vx += pushBackVelocity.x; // pushBackVelocity is the bullet velocity. You add this to the already meaningless vx and vy vy -= pushBackVelocity.y; } // Now you have normX/Y. Which are created using player position, and has literally NOTHING to do with how a bullet should push the enemy. // Why should the players current position change how an enemy is pushed? // Then you multiply it by the completely meaningless vx and vy, which do nothing but add a bias for the enemy to be pushed towards the bottom-right. x += normX * vx * dt; y += normY * vy * dt; enemySprite.setPosition(x, y); // Not much more I can say, except... what? } [/code]
Alright, sorry. You don't have to be rude, but thanks for your input. The first line gets the distance between the enemy and the player as a vector. How would I change vx and vy to reflect the angle of the enemy? [editline]13th November 2014[/editline] How would I get pushBackVelocity() without using that method?
[QUOTE=NixNax123;46482711]Alright, sorry. You don't have to be rude, but thanks for your input. The first line gets the distance between the enemy and the player as a vector. How would I change vx and vy to reflect the angle of the enemy? [editline]13th November 2014[/editline] How would I get pushBackVelocity() without using that method?[/QUOTE] Sorry about any rudeness. I'm just a bit annoyed by your earlier insistence of not using vectors and the general confusion surrounding this issue. The distance between the enemy and the player is 100% irrelevant. it's the bullet hitting the enemy, not the player. YOu ought to completely remove that part. You shouldn't be setting vx and vy to velocity at all. You should just remove that part and set it to the bullet's x and y (pushBackVelocity) about pushBackVelocity - just return it through intersectsWithBullet(). Really, and ideally, you should have a separate function handling collision [I]detection[/I] and collision [I]response[/I]. Currently, you have one function doing both. This might be slightly outside the scope of the discussion, though.
[QUOTE=Tommyx50;46482947]Sorry about any rudeness. I'm just a bit annoyed by your earlier insistence of not using vectors and the general confusion surrounding this issue. The distance between the enemy and the player is 100% irrelevant. it's the bullet hitting the enemy, not the player. YOu ought to completely remove that part. [/QUOTE] The enemy tracks the player based on where the player is! I need that. [quote]about pushBackVelocity - just return it through intersectsWithBullet(). Really, and ideally, you should have a separate function handling collision detection and collision response. Currently, you have one function doing both. This might be slightly outside the scope of the discussion, though.[/quote] I would be interested in this (as it's something I can learn and make future projects nicer). I have uni class right now though so I'll talk to you later, thanks for all your help!
[QUOTE=NixNax123;46483006]The enemy tracks the player based on where the player is! I need that. I would be interested in this (as it's something I can learn and make future projects nicer). I have uni class right now though so I'll talk to you later, thanks for all your help![/QUOTE] So why are you multiplying it with vx/vy, instead of adding it? Try adding it instead.
So how should classes be handled in C++? Should you keep them in separate files and compile them separately, or is it still considered good practice to have just one .cpp file full of different classes?
[QUOTE=proboardslol;46483530]So how should classes be handled in C++? Should you keep them in separate files and compile them separately, or is it still considered good practice to have just one .cpp file full of different classes?[/QUOTE] Still? You should keep them in separate files.
[QUOTE=proboardslol;46483530]So how should classes be handled in C++? Should you keep them in separate files and compile them separately, or is it still considered good practice to have just one .cpp file full of different classes?[/QUOTE] Most common is one class per cpp file. You could argue that if you have a small class its kinda annoying to put it in cpp file, but in most cases you'll ruin discoverability of the class if you don't. Like the only time i do see multiple classes in the same CPP file is when they a headerless classes.
[QUOTE=proboardslol;46483530]So how should classes be handled in C++? Should you keep them in separate files and compile them separately, or is it still considered good practice to have just one .cpp file full of different classes?[/QUOTE] For the most part I tend to put each class in its own file except for small utility classes and the like, which go wherever they're needed. [editline]13th November 2014[/editline] There's also the weird half option of having a common header, but separate implementations.
[QUOTE=ECrownofFire;46483743]For the most part I tend to put each class in its own file except for small utility classes and the like, which go wherever they're needed. [editline]13th November 2014[/editline] There's also the weird half option of having a common header, but separate implementations.[/QUOTE] How do you handle headers? one header for each class, and then one "master header" to be imported into your main class? Ahh I figured it out :D
[QUOTE=proboardslol;46484197]How do you handle headers? one header for each class, and then one "master header" to be imported into your main class? Ahh I figured it out :D[/QUOTE] Its generally best to keep header files local, and not abuse them by creating a single header file that includes every single header file in your project.
[QUOTE=Tommyx50;46483147]So why are you multiplying it with vx/vy, instead of adding it? Try adding it instead.[/QUOTE] That works perfectly! Now I just have to vary speed based on the size of the enemy, and I'm good to go! Does this code give you less of an aneurysm? [code] Vector2f d = new Vector2f(GameScreen.getCurrentPlayer().getPos().x - x, GameScreen.getCurrentPlayer().getPos().y - y); float length = (float)Math.sqrt(d.x*d.x + d.y*d.y); if (length > 0) { norm = Vector2f.div(d, length); } if (intersectsWithPlayer()) { handlePlayerIntersection(); } if (intersectsWithBullet()) { handleBulletIntersection(collidingBullet); } x += norm.x + v.x * dt; y += norm.y + v.y * dt; enemySprite.setPosition(x, y); [/code] (:
[QUOTE=NixNax123;46484397]That works perfectly! Now I just have to vary speed based on the size of the enemy, and I'm good to go! Does this code give you less of an aneurysm? [code] Vector2f d = new Vector2f(GameScreen.getCurrentPlayer().getPos().x - x, GameScreen.getCurrentPlayer().getPos().y - y); float length = (float)Math.sqrt(d.x*d.x + d.y*d.y); if (length > 0) { norm = Vector2f.div(d, length); } if (intersectsWithPlayer()) { handlePlayerIntersection(); } if (intersectsWithBullet()) { handleBulletIntersection(collidingBullet); } x += norm.x + v.x * dt; y += norm.y + v.y * dt; enemySprite.setPosition(x, y); [/code] (:[/QUOTE] That's great, a lot cleaner! Congratulations on getting this far, the game looks pretty fun.
So whenever I try to run this: [code]#include <stdio.h> #include <string.h> int main() { char largelocker[5][3] = {"1L", "2L", "3L", "4L", "5L"}; printf("%s", largelocker[0][0]); getchar(); return 0; } [/code] I get access violation reading location error on Visual C Express 2010 and it points to this, in output.c: [code] text.sz = __nullstring; p = text.sz; while (i-- && *p) /* <-- points to this specifically */ ++p; textlen = (int)(p - text.sz); /* length of the string */ } [/code] How do I fix this?
[QUOTE=Cold;46484307]Its generally best to keep header files local, and not abuse them by creating a single header file that includes every single header file in your project.[/QUOTE] I agree. If one wants to have a single header file, make an amalgamation or die.
[QUOTE=frdrckk;46485985]So whenever I try to run this: [code]#include <stdio.h> #include <string.h> int main() { char largelocker[5][3] = {"1L", "2L", "3L", "4L", "5L"}; printf("%s", largelocker[0][0]); getchar(); return 0; } [/code] I get access violation reading location error on Visual C Express 2010 and it points to this, in output.c: [code] text.sz = __nullstring; p = text.sz; while (i-- && *p) /* <-- points to this specifically */ ++p; textlen = (int)(p - text.sz); /* length of the string */ } [/code] How do I fix this?[/QUOTE] You haven't null terminated your strings. Add "\0" on to the end of each (it counts as 1 char), otherwise the third char in your arrays are just garbage data. EDIT: Whoops, sorry, I'm wrong! string literals are automatically null terminated. Don't listen to me.
[QUOTE=frdrckk;46485985]So whenever I try to run this: [code]#include <stdio.h> #include <string.h> int main() { char largelocker[5][3] = {"1L", "2L", "3L", "4L", "5L"}; printf("%s", largelocker[0][0]); getchar(); return 0; } [/code] I get access violation reading location error on Visual C Express 2010 and it points to this, in output.c: [code] text.sz = __nullstring; p = text.sz; while (i-- && *p) /* <-- points to this specifically */ ++p; textlen = (int)(p - text.sz); /* length of the string */ } [/code] How do I fix this?[/QUOTE] largelocker[0][0] dereferences a character, not a string, but you are telling printf to treat it as a string (%s). So it should either be %c to print a single char, or largelocker[0] to print the first full string. [QUOTE=Tommyx50;46487243]You haven't null terminated your strings. Add "\0" on to the end of each (it counts as 1 char), otherwise the third char in your arrays are just garbage data.[/QUOTE] The strings in the array are null-terminated, that's not the issue.
I'm trying to find a way to decompile portal 2's client.dll so I can sift around and possibly extract some code, but I have no idea what I should use to decompile it. What software should I use? People are probably thinking that I should know know what to use if I'm posting on the programming section, but I've been learning Java for a few years and want to get into C++, which I'm totally new to.
[QUOTE=Dienes;46487268]The strings in the array are null-terminated, that's not the issue.[/QUOTE] I realised and slapped myself on the forehead just before you replied! String literals are automatically terminated... I'm dumb sometimes. [editline]14th November 2014[/editline] [QUOTE=x8BitRain;46487293]I'm trying to find a way to decompile portal 2's client.dll so I can sift around and possibly extract some code, but I have no idea what I should use to decompile it. What software should I use? People are probably thinking that I should know know what to use if I'm posting on the programming section, but I've been learning Java for a few years and want to get into C++, which I'm totally new to.[/QUOTE] Decompilation is both: 1. in a legal grey area and 2. gives very messy, ugly code (assuming it even works). I don't think it's the best thing to do to start learning C++, either way.
[QUOTE=x8BitRain;46487293]I'm trying to find a way to decompile portal 2's client.dll so I can sift around and possibly extract some code, but I have no idea what I should use to decompile it. What software should I use? People are probably thinking that I should know know what to use if I'm posting on the programming section, but I've been learning Java for a few years and want to get into C++, which I'm totally new to.[/QUOTE] If you can work with assembler, use ollydbg, there is nothing that can decompile native code back to C++. [editline]14th November 2014[/editline] You're new to C++, what you're trying to do is a complex subject. [editline]14th November 2014[/editline] Very.
For C++, what is a traditional way of structuring classes for a simple 2D game? So far I can think of the following things that need to be accounted for: Controllers (input, keyboard, joystick, etc.) class Graphics (sprites, textures) class Window Driver (creating windows, which then calls the graphics class, I think). How do [b]you[/b] partition the various things that need to be done in a game? I also want to have a scripting engine. Should that run actively, constantly updating, or is it something that only needs to be called whenever a script is read? I'm just looking for some precedence on how games are organized in OOP. Should the game loop be in the main method?
I've been informed that it's not possible and that I should do it via plugin_load or Dll injection, thanks anyway.
[QUOTE=Dienes;46487268]largelocker[0][0] dereferences a character, not a string, but you are telling printf to treat it as a string (%s). So it should either be %c to print a single char, or largelocker[0] to print the first full string.[/QUOTE] But if I use %c, will it print out the 1 in 1L?
[QUOTE=proboardslol;46487422]For C++, what is a traditional way of structuring classes for a simple 2D game? So far I can think of the following things that need to be accounted for: Controllers (input, keyboard, joystick, etc.) class Graphics (sprites, textures) class Window Driver (creating windows, which then calls the graphics class, I think). How do [b]you[/b] partition the various things that need to be done in a game? I also want to have a scripting engine. Should that run actively, constantly updating, or is it something that only needs to be called whenever a script is read? I'm just looking for some precedence on how games are organized in OOP. Should the game loop be in the main method?[/QUOTE] Thats a pretty big question. There is no "correct" way to do it, but something simple/generic would look something like this. So lets start at the core and our work our way out. So lets say you have a Goomba, this goomba has a unique texture and maybe some unique behaviour, it derives from a base NPC class, which has some of this NPC functionality in it, that will on its own derive from something like an Object/Entity class, which for example has some collision functionality and the rendering code in it. So to manage all these objects, most games have something thats often referred too as the "scene" or in small things something like a "game", which is basically a class that manages a list of entities and calls their various update/render functions. Then all other classes can be abstracted to "interfaces" basically a utility class that's mainly only called by functionality on the entities, stuff like Drawing Input Physics (Window) are good examples of these kind of classes. For example an draw loop would look something like: 1. CDrawing->Predraw() // Clear buffers, prepare some other stuff. 2. CScene->Draw() // Make a call to every object in our object list to draw. 3.Goomba->Draw() // Virtual function could be overwritten by the class if they want to do a custom draw or do something before/after they draw. An example of what the parent function of Object/NPC would look like be simple like this Object->Draw() { this.shader->Draw(this.texture, this.x, this.y); } If you're doing things in something like SDL Or SFML this could also be the place where you simply invoke SDL/SFML functions, and you don't need to abstract things into a shader. 4. CDrawing->PostDraw() // Swap buffers, do some other post draw stuff. The integration of a scripting language, generally just means that when an relevant class(Object or System) is instanced, you'll create the matching object in your scripting language, And then when a function on the object is called by CScene, the object can pass the call to the scripting language, and then the scripting language can call the functions exposed to the scripting language on the systems to do various tasks. EDIT: Like integrating a scripting language can be a lot of work, and you need quite a lot of scriptable content for it to be worth the work, you should consider that.
[QUOTE=frdrckk;46487699]But if I use %c, will it print out the 1 in 1L?[/QUOTE] Well, try it, but yes, it does. It extracts the first character of the string "1L" which is '1'.
-snip-
[QUOTE=frdrckk;46487699]But if I use %c, will it print out the 1 in 1L?[/QUOTE] Have you encountered pointers? A string is simply an array of characters, and an array is simply a pointer to the memory location of various characters. So if you want an array of strings (an array of arrays, or a pointer to more pointers), you want: [code] char *a[2]; [/code] and you can reference them like any other array [code] a[0] = "test"; printf("%s",a[0]); [/code] the output would therefore be "test". Alternatively, for a simpler output, if you only want to output a single string, you can also use [code] puts(a[0]); [/code] which outputs "test" with a newline automatically added
[QUOTE=frdrckk;46485985]So whenever I try to run this: [code]#include <stdio.h> #include <string.h> int main() { char largelocker[5][3] = {"1L", "2L", "3L", "4L", "5L"}; printf("%s", largelocker[0][0]); getchar(); return 0; } [/code] I get access violation reading location error on Visual C Express 2010 and it points to this, in output.c: [code] text.sz = __nullstring; p = text.sz; while (i-- && *p) /* <-- points to this specifically */ ++p; textlen = (int)(p - text.sz); /* length of the string */ } [/code] How do I fix this?[/QUOTE] What you want is this: [code] #include <stdio.h> #include <string.h> int main( int argc, char **argv ) { char largelocker[5][3] = {"1L", "2L", "3L", "4L", "5L" }; printf( "%s\n", largelocker[0] ); getchar(); return 0; } [/code] What you were doing was accessing a single character, but you really want to print each string in the string array. char string is a single character. char string[] is an array of characters (a string). char string[][] is an array of strings (an array of arrays of characters).
Sorry, you need to Log In to post a reply to this thread.