• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=NixNax123;46475349]I'm trying to add a particle effect when an enemy dies: [code] public boolean toBeRemoved() { if (health == 0 || intersectsWithPlayer()) { // Sprite t = enemySprite; // ParticleEntity deathParticle = new ParticleEntity(t); // deathParticle.setPos((int)t.getPosition().x, (int)t.getPosition().y); // deathParticle.setRotation(t.getRotation()); // GameScreen.addEntity(deathParticle); Audio.playSound("enemydeath.wav", 1/size); return true; } else { return false; } }[/code] I draw the entities and check for removal here: [code] public void show() { ... // iterate through entities for (Iterator<Entity> it = entities.iterator(); it.hasNext(); ) { Entity e = it.next(); e.draw(); e.update(dt); if (e.toBeRemoved()) { it.remove(); } } ...[/code] However, this (obviously) returns a concurrent modification exception. How can I avoid this?[/QUOTE] Make a list of dead entities and then after your update/draw loop, run a loop run through the remove list if it's got entries and remove them from the main list, and spawn any special effects when you detect it's dead but before you get to the removal loop.
[QUOTE=Fantym420;46475623]Make a list of dead entities and then after your update/draw loop, run a loop run through the remove list if it's got entries and remove them from the main list, and spawn any special effects when you detect it's dead but before you get to the removal loop.[/QUOTE] Thank you so much! That worked perfectly! [editline]12th November 2014[/editline] Now I need help on making bullets knock the enemy back, but smoothly. This is what I have now: [code] if (intersectsWithBullet()) { x += normX * BulletEntity.getForce() * dt; y += normX * BulletEntity.getForce() * dt; } [/code] Where normX/Y is the vector the enemy is traveling on. I know I should actually be using the vector that the bullet is traveling on (I'm working on figuring that out, should be simple (since I already got the bullet to travel in the direction I need it to, but for some reason I'm having a huge mind block here). However, how would I get the the enemy to get knocked back in a smooth way? Right now, it just flashes back a little.
[QUOTE=NixNax123;46475975]Thank you so much! That worked perfectly! [editline]12th November 2014[/editline] Now I need help on making bullets knock the enemy back, but smoothly. This is what I have now: [code] if (intersectsWithBullet()) { x += normX * BulletEntity.getForce() * dt; y += normX * BulletEntity.getForce() * dt; } [/code] Where normX/Y is the vector the enemy is traveling on. I know I should actually be using the vector that the bullet is traveling on (I'm working on figuring that out, should be simple (since I already got the bullet to travel in the direction I need it to, but for some reason I'm having a huge mind block here). However, how would I get the the enemy to get knocked back in a smooth way? Right now, it just flashes back a little.[/QUOTE] If you want the enemy to smoothly be knocked back, add to the velocity vector of the enemy instead of directly affecting it's position. However, I'd argue that the quick "snap" backwards is meatier than a smooth push.
[QUOTE=Tommyx50;46476328]If you want the enemy to smoothly be knocked back, add to the velocity vector of the enemy instead of directly affecting it's position. However, I'd argue that the quick "snap" backwards is meatier than a smooth push.[/QUOTE] You've got a point! Now I just need to figure out how make the enemy be pushed back by the direction of the bullet, which is proving harder than I thought it would be... I have the bullet's velocity and position, why is something so simple escaping my mind?
[QUOTE=ECrownofFire;46475614]In disable_if<T>, if T::value is true (template helpers such as is_same and such have a member called value) then disable_if<T>::type does not exist and so attempting to assign to a variable of type disable_if<T>::type will result in a compiler error. By default disable_if<T>::type is void. I guess they use type* instead because you can't assign to void. Basically the syntax is such that the template has 3 parameters, but the last 2 are actually template value parameters instead of just types or classes. The last 2 are also defaulted to 0 and are of type boost::disable_if<T>::type*, which is void*.[/QUOTE] SFINAE with a weird syntax, in other words? Gotta read up more on templates.
'Ello, for a university project, my teammate and I are creating the board game Stratego in Java. We're using JavaFX8. Photoshop render of desired end-product: [url]http://i.imgur.com/aUoVR7H.png[/url] Current JavaFX scene: [url]http://i.imgur.com/JimTjOY.png[/url] ImageConstants class, imported and know it works for "Stratego" logo image: [img]http://i.imgur.com/i4cfsLG.png[/img] Gridpane/Hashmap code: [img]http://i.imgur.com/bvgs1CW.png[/img] ( [url]http://pastebin.com/reK0u6rB[/url] - text for accessibility) Our current thinking is it might have something to do with how the temp images are created and then out of scope disappearing even though they were placed in a hashmap? We're stumped and have been for hours on how to do this, I appreciate your help, thanks!
I think you forgot to explain what the problem is, friend. From what I can see, it seems like you're well on your way to recreating the render. I don't see anything inherently wrong, just some missing content.
Oh, sorry, the images simply do not show up. I debugged line 94 where it gets the image from the hashmap from the image constant class and the file name is right but when I tried printing out the image itself when it should return a reference to the image it prints NULL. But we know the image works, when we use the ImageConstants.BLUE_02 for example it works, but not the hashmap "BLUE_02" key. We were wondering if it can't be done inline like this was our guess
Shouldn't temp_nums be {... SPY, BACK, BOMB, FLAG} instead of {... BOMB, SPY, FLAG} ? [editline]13th November 2014[/editline] I also suggest that you check if tempImage is not null, and throw an exception / write to debug output. Will save you time in the long run looking for errors if you do this. [editline]13th November 2014[/editline] I also think you're using your brace initialzation wrong, shouldn't it be this [code]public final static HashMap<String, ImageView> PIECE_MAP = new HashMap<>(24) static { ... } [/code] I might just be being stupid, though.
Good catch on the temp_nums, thank you, that would've been a problem later. I forgot my teammember added that in there, I moved it to the end so it won't affect us later. TempImage is not NULL, I've checked the string key and the ImageView, both are returning references. As I was writing this post I checked the third thing and it appears to have worked! Haha, cheers! Such a silly little thing.
[QUOTE=NixNax123;46476472]You've got a point! Now I just need to figure out how make the enemy be pushed back by the direction of the bullet, which is proving harder than I thought it would be... I have the bullet's velocity and position, why is something so simple escaping my mind?[/QUOTE] Try adding a portion of the bullet's velocity onto the enemy's velocity.
[QUOTE=NixNax123;46476472]You've got a point! Now I just need to figure out how make the enemy be pushed back by the direction of the bullet, which is proving harder than I thought it would be... I have the bullet's velocity and position, why is something so simple escaping my mind?[/QUOTE] You really ought to get a simple vector mathematics class together - reasoning about vectors is a lot easier than reasoning about separate x, y values. Anyways, as said above add a portion of the bullet's velocity onto the enemies position directly (for snappy movement) or onto their velocity (for smoother movement).
If I have unhashed words, and then the hashed version of the words. How can I find out how they are being hashed? Like what type etc?
[QUOTE=AnonTakesOver;46478199]If I have unhashed words, and then the hashed version of the words. How can I find out how they are being hashed? Like what type etc?[/QUOTE] What exactly do you mean by, "Find out how they're being hashed; like what type?" And what language? Do you think you can provide, like, an example of what you're trying to do, and the context in which you'd be doing this?
[QUOTE=Gmod4ever;46478293]What exactly do you mean by, "Find out how they're being hashed; like what type?" And what language? Do you think you can provide, like, an example of what you're trying to do, and the context in which you'd be doing this?[/QUOTE] Sorry, I'm trying to make a youtube to mp3 converter on my phone, I'm attempting this by using a website and just going to leech off of it. [url]http://www.listentoyoutube.com/index.php[/url] when you enter the youtube link, I can view the requests and there is a hash that is in the download link, the hash is always the same to the link, so I assume it is converting the link or the ID into a hash. I'm wondering if there is anyway I can construct my own hash, which means I need to work out how it is making the hash.
[QUOTE=AnonTakesOver;46478334]Sorry, I'm trying to make a youtube to mp3 converter on my phone, I'm attempting this by using a website and just going to leech off of it. [url]http://www.listentoyoutube.com/index.php[/url] when you enter the youtube link, I can view the requests and there is a hash that is in the download link, the hash is always the same to the link, so I assume it is converting the link or the ID into a hash. I'm wondering if there is anyway I can construct my own hash, which means I need to work out how it is making the hash.[/QUOTE] So you want to reverse-engineer the hashing function the site is using, basically? Well, if you're lucky, they're using some standard hashing function. Unfortunately, even trivial hash functions, such as something like (psuedocode) [code]int function hash(string str, int hashSize) { int r = 0 for chr in string do { r += byteCode(chr) + SOME_CONSTANT_PRIME % hashSize } return r }[/code] can be difficult to determine, due to the sheer amount of values that could be hashSize or SOME_CONSTANT_PRIME. And then if you get into [url=http://en.wikipedia.org/wiki/Hash_function#Hash_function_algorithms]more complex hashing methods[/url], it becomes even more difficult. I'm not saying it isn't impossible to reverse-engineer the hash function. Just that it won't be trivially easy, unless they're using a stock hash function you can get your hands on.
[QUOTE=Gmod4ever;46478420]So you want to reverse-engineer the hashing function the site is using, basically? Well, if you're lucky, they're using some standard hashing function. Unfortunately, even trivial hash functions, such as something like (psuedocode) [code]int function hash(string str, int hashSize) { int r = 0 for chr in string do { r += byteCode(chr) + SOME_CONSTANT_PRIME % hashSize } return r }[/code] can be difficult to determine, due to the sheer amount of values that could be hashSize or SOME_CONSTANT_PRIME. And then if you get into [url=http://en.wikipedia.org/wiki/Hash_function#Hash_function_algorithms]more complex hashing methods[/url], it becomes even more difficult. I'm not saying it isn't impossible to reverse-engineer the hash function. Just that it won't be trivially easy, unless they're using a stock hash function you can get your hands on.[/QUOTE] Hmmm, I guess I'll make my own converter then, instead of leeching from a site :v:.
They probably aren't hashing any video (meta)data, it's more likely they store their extracted/converted MP3 under a (random) GUID and write a video ID -> MP3 GUID relationship to the database. So whenever someone inputs a video, they check whether that video ID has already been converted before.
[QUOTE=Tommyx50;46478102]You really ought to get a simple vector mathematics class together - reasoning about vectors is a lot easier than reasoning about separate x, y values. Anyways, as said above add a portion of the bullet's velocity onto the enemies position directly (for snappy movement) or onto their velocity (for smoother movement).[/QUOTE] I have taken them, and I completely understand vectors. That solution is simple, and I was just having a mind block. Thank you
You guys probably get this question all the time, but what books do you recommend for learning C++? Or programming games in C++? I have classes on C#, and knowing C++ would be a plus. Plusplus.
[QUOTE=Tommyx50;46478102]You really ought to get a simple vector mathematics class together - reasoning about vectors is a lot easier than reasoning about separate x, y values. Anyways, as said above add a portion of the bullet's velocity onto the enemies position directly (for snappy movement) or onto their velocity (for smoother movement).[/QUOTE] So this is what I'm using now. The vx and vy for bullet is like this: [code] vx = (float) (300 * Math.sin(Math.toRadians(GameScreen.getCurrentPlayer().getAngle()))); vy = (float) (300 * Math.cos(Math.toRadians(GameScreen.getCurrentPlayer().getAngle())));[/code] And I use those like this [code] public void update(float dt) { x += vx * dt; x += vx * dt; y -= vy * dt; bulletSprite.setPosition(x, y); }[/code] [code]public Vector2f getVelocity() { return new Vector2f(vx, vy); }[/code] But I'm doing my hits like this [code]...float vx = velocity; float vy = velocity; if (intersectsWithBullet()) { vx += pushBackVelocity.x / 4; vy += pushBackVelocity.y / 4; } x += normX * vx * dt; y += normY * vy * dt; enemySprite.setPosition(x, y);[/code] Which results in the enemies being push back at the wrong angle sometimes (when the bullet is traveling right, the enemies get pushed to the left). Why does this happen?
I made a quick program that read a file and puts the characters in it into an array. The array is one dimensional, but it handles new line characters so If I print it out, I get a perfectly formatted output with tabs and returns. However, if I wanted to make the array 2-dimensional, and to switch down to the next row in the array whenever it hit a new line character \n, what would be the best way of doing that? I know how to do it different ways, but what would be the BEST way to do it? Also, how should I malloc the array to handle any file input as best as possible? For example, not having a maximum width limit for a single line? the code: [code] #include <stdio.h> int main(){ FILE* fp; char currentCh; //cursor char dungeonMap[200]; //buffer to be fed into int finalchar; //last significant place in the dungeonMap[] array fp = fopen("dungeon.txt","r"); while( currentCh != '!' ){ //exit on '!' currentCh = getc(fp); if(currentCh == '!'){ //set the last significant place to current cursor position if '!'. finalchar = ftell(fp); } dungeonMap[ftell(fp)-1] = currentCh; } //please rewind your tapes before //returning them to blockbuster. rewind(fp); fclose(fp); for(int i = 0; i < finalchar; i++){ //print up until last significant character. printf("%c",dungeonMap[i]); } } [/code] edit: oh also this is for C
[QUOTE=NixNax123;46479606]I have taken them, and I completely understand vectors. That solution is simple, and I was just having a mind block. Thank you[/QUOTE] That's not the point. Coding is 90% reading code, and 10% writing it, and not using vectors dramatically increases the time for both. When you have to do: [CODE] vecLength = sqrt((x*x) + (y*y)); if (vecLength > 0) { newX = x / vecLength; newY = y / vecLength; } [/CODE] instead of: [CODE] newVec = vec.normalized(); [/CODE] You are wasting a lot of space, and limiting the reusability and readability of your code. For example, if you (for whatever reason) decide to turn your game 3d, you'd need to go over dozens of places in your codebase and change that every time, as opposed to just changing it once! When you are writing more code, you are more likely to write bugs, when you are reading more code, you are less likely to find them. [editline]13th November 2014[/editline] [QUOTE=NixNax123;46480737]So this is what I'm using now. The vx and vy for bullet is like this: [code] vx = (float) (300 * Math.sin(Math.toRadians(GameScreen.getCurrentPlayer().getAngle()))); vy = (float) (300 * Math.cos(Math.toRadians(GameScreen.getCurrentPlayer().getAngle())));[/code] [/QUOTE] Took a while to figure out what you were doing here, but you've got the sine and cosine mixed up. cos is used for x, and sin used for y - also, you should really turn the 300 into a bulletSpeed variable. Magic numbers are horrific! Anyways, this is EXACTLY the sort of thing that having a vector class would've made easier...
[QUOTE=Tommyx50;46481628] Took a while to figure out what you were doing here, but you've got the sine and cosine mixed up. cos is used for x, and sin used for y[/QUOTE] That's not the problem. I shoot bullets fine. If I change that, it comes out 45 degress clockwise of where I'm facing. Also, using a vector for that would have made things more complex for me.
[QUOTE=NixNax123;46481828]That's not the problem. I shoot bullets fine. If I change that, it comes out 45 degress clockwise of where I'm facing. Also, using a vector for that would have made things more complex for me.[/QUOTE] No it wouldn't have. It would've changed the code into: [code] velocity = vec(bulletSpeed, 0) velocity.setAngle(GameScreen.getCurrentPlayer().getAngle()) [/code] Much easier. Sure, it's still 2 lines, but now you know WHAT they are doing. Your not needing to mentally decode it and realize "ah", "I'm converting polar to cartesian!"
For me, that's making things hard to read and understand what exactly is going on. Anyways, that's not my issue. I just need bullets to knock enemies back in the direction they were shot at.
[QUOTE=NixNax123;46481892]For me, that's making things hard to read and understand what exactly is going on. Anyways, that's not my issue.[/QUOTE] Look, my point is, your code is going to become completely unmaintainable when you are needing to write out these huge vector functions constantly and repeatedly. I don't see how it's harder to see what's going on, it's practically bare English - "set the angle of the bullet to the angle of the player", compared to "convert the bullet's x velocity to the sine of the radians of the player's angle, and the y to the cosine". That's meaningless without context. Anyways, can you elaborate on this code snippet?: [code] float vx = velocity; float vy = velocity; if (intersectsWithBullet()) { vx += pushBackVelocity.x / 4; vy += pushBackVelocity.y / 4; } x += normX * vx * dt; y += normY * vy * dt; enemySprite.setPosition(x, y); [/code] What is velocity? Is vx and vy the velocity of the bullet or the enemy? what is normX and normY, and X and Y - are they the enemy positions or bullet ones? This doesn't tell me very much.
Velocity is the inverse of the size of the sprite times 250. [quote]Where normX/Y is the vector the enemy is traveling on.[/quote] [editline]13th November 2014[/editline] It's harder to read your code for me, sorry.
[QUOTE=NixNax123;46481952]Velocity is the inverse of the size of the sprite times 250.[/QUOTE] What? Why? And the size of WHAT sprite? I don't have the full knowledge and access to your codebase, this is entirely meaningless without context.
The size of the enemy sprite. The larger it is, the slower it moves. [url]https://github.com/Tetramputechture/Corraticca/[/url]
Sorry, you need to Log In to post a reply to this thread.