Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Series of generic computer programming questions (theory)
Index -> General Discussion
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
isaiahk9




PostPosted: Sun Nov 16, 2008 9:42 am   Post subject: Series of generic computer programming questions (theory)

Hey, I was just wondering that if I posted a dozen questions, any one of them would be answered. So, I?m looking for an answer that could be used in nearly all programming languages, based off universal controls like variables, arrays, etc. I?m not looking for answers, just theory (although answers are fine too. . . ). It?s a little bit of a contest, I?ll reward anyone who can answer a question with my personal thanx, awe and bits. So, here they are :

1. If there is a game that is a fighter with modern firearms, certain firearms will automatically lock-onto opponents positions to enable easier shots. As well, the lock-on would be a little slow - it would not be able to keep up to an enemy running at full speed. Theoretically, the coding would be like the computer finds the nearest enemy, and then it would find its position from one previous run of the loop. However, I?m wondering if anybody has a better answer than that.

2. If there is a game that is a side-scroller, then as the player nears the edge of the screen, the map will scroll so that the character is always on the screen. How would this be done?

3. If there was a program to simulate a destructible environment, how would that be done? Say that there are 50 items in the environment that are breakable. Would that mean an array of the 50items, with variables of whether they are broken or not? Is there any other way that is more efficient than an if check for every time the player presses the ?Break? key?

4. If there was a game that was a shooter, then from wherever the player is to wherever their cursor is, they would shoot bullets from the two positions. Say that there are 60 different angles the player can shoot from. Is there a better way of figuring out this slope of bullet programming than having a massive if loop of the character?s position and cursor?s position, that changes the picture for the bullet and its direction that the bullet travels in depending on what the difference is between the characters (x, y) and cursor?s (x,y)?

5. If there was a game that was a spy game, and the player had a weapon called ?trip mine? (an explosive that can be set down, and will blow up when its laser is broken), how would the computer sense if the laser is broken, if the laser can start at any wall, and stop at any obstacle?

6. If there was a game that was a shooter, then depending on where the target is shot, they would take varying amounts of damage (like how headshots are almost always instant kills, and the player can take several shots to the leg)? Is there a better way than an if checking every time a gun is fired, where the bullets hit and change the amount of life? Also related is if the target has varying sizes (certain people are taller, so they have a larger hittable area).

7. If there was a program simulating cloning, how could the computer keep track of how all the clones are behaving, when there can be different numbers of them? In this instance, the user can switch between the different clones. I?m guessing an array, but I?m unsure.

8. If the game was a puzzler, where the user collects scrap metal from the environment to make things, how could the computer test where there is scrap metal and whether it has been used or not?

9. Suppose there is a game that was a fighter. Your character has a flame-thrower. Unlike the generic, ordinary flame-thrower, this flame-thrower operates like real flame-throwers. Instead of shooting out flames, the player has a key to spray gas on targets or in the air, and then a key to spark any gas near it. How would the computer check for where there is gas, as it would be the only thing that can be lit on fire? And how would the computer know that the flames should only go across the gas, and not any farther?

10. Suppose there is a game that is a fighter. Your character has a shield. Said shield can deflect any projectiles shot at them. How could this shield be coded without having an if loop every time a projectile is near the foe?

11. Suppose there is a game that is a spy game. In it, your character can take over or ?jack? enemies. How in the world would this be done?

12. Suppose the game is a puzzler. How would one make gravity? And more so, suppose that in this puzzler, your ability is to effect gravity. You could send out shockwaves, make black-holes, or use a tractor-beam. How would that be done. Moreso, linking to the destructible environment question, how could one make every single item on the map effected by gravity (so that it could be sent flying)? And, how could one code so that some high-speed item flying at you could damage you?

13. Final question : suppose the game is a fighter. In it, your character has the ability to make infinite amounts of missiles to shoot at foes. Could arrays be used so that missiles could A) be shot like a machine-gun, and B) be shot like a machine-gun with homing bullets? How would that be done?

This thread probably won?t get any responses, but oh well. Some of these problem are extremely difficult, while others may seem simplistic. But I?m wondering if you have the theory/pseudo code to solve them.
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Sun Nov 16, 2008 1:16 pm   Post subject: Re: Series of generic computer programming questions (theory)

isaiahk9 @ 2008-11-16, 9:42 am wrote:
Hey, I was just wondering that if I posted a dozen questions, any one of them would be answered. So, I?m looking for an answer that could be used in nearly all programming languages, based off universal controls like variables, arrays, etc. I?m not looking for answers, just theory (although answers are fine too. . . ). It?s a little bit of a contest, I?ll reward anyone who can answer a question with my personal thanx, awe and bits. So, here they are :

1. If there is a game that is a fighter with modern firearms, certain firearms will automatically lock-onto opponents positions to enable easier shots. As well, the lock-on would be a little slow - it would not be able to keep up to an enemy running at full speed. Theoretically, the coding would be like the computer finds the nearest enemy, and then it would find its position from one previous run of the loop. However, I?m wondering if anybody has a better answer than that.

enemies current position - enemies velocity vector should be close enough. Or 2x the velocity vector if you want it to be even less accurate.

isaiahk9 @ 2008-11-16, 9:42 am wrote:
2. If there is a game that is a side-scroller, then as the player nears the edge of the screen, the map will scroll so that the character is always on the screen. How would this be done?

You have an offset for the screen; when you do your drawing you only draw things that would be in a box the size of the screen when the box is offset. Then you increase the screen offset when the character gets close to the edge of the screen, as well as the players position.

isaiahk9 @ 2008-11-16, 9:42 am wrote:
3. If there was a program to simulate a destructible environment, how would that be done? Say that there are 50 items in the environment that are breakable. Would that mean an array of the 50items, with variables of whether they are broken or not? Is there any other way that is more efficient than an if check for every time the player presses the ?Break? key?

You have a list of all objects somewhere anyways (if you are writing this in the correct manner); all you need is to either modify their models (image, 3d model, whatever) and properties when they are broken.

isaiahk9 @ 2008-11-16, 9:42 am wrote:
4. If there was a game that was a shooter, then from wherever the player is to wherever their cursor is, they would shoot bullets from the two positions. Say that there are 60 different angles the player can shoot from. Is there a better way of figuring out this slope of bullet programming than having a massive if loop of the character?s position and cursor?s position, that changes the picture for the bullet and its direction that the bullet travels in depending on what the difference is between the characters (x, y) and cursor?s (x,y)?
Assuming this is a top-down shooter, the vector is as simple as subtracting the player position from the mouse position (in game space). The mouse position would usually be screen position + screen offset.

isaiahk9 @ 2008-11-16, 9:42 am wrote:
5. If there was a game that was a spy game, and the player had a weapon called ?trip mine? (an explosive that can be set down, and will blow up when its laser is broken), how would the computer sense if the laser is broken, if the laser can start at any wall, and stop at any obstacle?
you would check to see if something started on one side of the tripwire vector and finished on the other. Basically you find out if the vector from the mine to hte wall crosses the vector from the players starting position to the players starting position + his velocity vector.

isaiahk9 @ 2008-11-16, 9:42 am wrote:
6. If there was a game that was a shooter, then depending on where the target is shot, they would take varying amounts of damage (like how headshots are almost always instant kills, and the player can take several shots to the leg)? Is there a better way than an if checking every time a gun is fired, where the bullets hit and change the amount of life? Also related is if the target has varying sizes (certain people are taller, so they have a larger hittable area).
You use hit boxes; and no. you need to check each hit box. But you only need to check if the bullet hits the players hitbox (which encompases all of him)

isaiahk9 @ 2008-11-16, 9:42 am wrote:
7. If there was a program simulating cloning, how could the computer keep track of how all the clones are behaving, when there can be different numbers of them? In this instance, the user can switch between the different clones. I?m guessing an array, but I?m unsure.
You generally use arrays or linked lists or trees, depending on how you use them. This is more a general keeping track of objects thing.

isaiahk9 @ 2008-11-16, 9:42 am wrote:
8. If the game was a puzzler, where the user collects scrap metal from the environment to make things, how could the computer test where there is scrap metal and whether it has been used or not?
You have scrap metal objects, the player can pick them up.

isaiahk9 @ 2008-11-16, 9:42 am wrote:
9. Suppose there is a game that was a fighter. Your character has a flame-thrower. Unlike the generic, ordinary flame-thrower, this flame-thrower operates like real flame-throwers. Instead of shooting out flames, the player has a key to spray gas on targets or in the air, and then a key to spark any gas near it. How would the computer check for where there is gas, as it would be the only thing that can be lit on fire? And how would the computer know that the flames should only go across the gas, and not any farther?
Math and bounding volumes.

isaiahk9 @ 2008-11-16, 9:42 am wrote:
10. Suppose there is a game that is a fighter. Your character has a shield. Said shield can deflect any projectiles shot at them. How could this shield be coded without having an if loop every time a projectile is near the foe?
If the vector from the gun to the player intersects the object representing the shield then reflect the bullet.

isaiahk9 @ 2008-11-16, 9:42 am wrote:
11. Suppose there is a game that is a spy game. In it, your character can take over or ?jack? enemies. How in the world would this be done?
Depends on entirely on your game engine

isaiahk9 @ 2008-11-16, 9:42 am wrote:
12. Suppose the game is a puzzler. How would one make gravity? And more so, suppose that in this puzzler, your ability is to effect gravity. You could send out shockwaves, make black-holes, or use a tractor-beam. How would that be done. Moreso, linking to the destructible environment question, how could one make every single item on the map effected by gravity (so that it could be sent flying)? And, how could one code so that some high-speed item flying at you could damage you?
Using math, gravity formulas, and probably special objects that have higher then normal mass.

isaiahk9 @ 2008-11-16, 9:42 am wrote:
13. Final question : suppose the game is a fighter. In it, your character has the ability to make infinite amounts of missiles to shoot at foes. Could arrays be used so that missiles could A) be shot like a machine-gun, and B) be shot like a machine-gun with homing bullets? How would that be done?
If you have infinite missles then you don't need to count anything. No need for arrays.

This thread probably won?t get any responses, but oh well. Some of these problem are extremely difficult, while others may seem simplistic. But I?m wondering if you have the theory/pseudo code to solve them.[/quote]
Vermette




PostPosted: Sun Nov 16, 2008 1:38 pm   Post subject: RE:Series of generic computer programming questions (theory)

12 would probably be implemented as a dynamic flow field

http://www.red3d.com/cwr/steer/FlowFollow.html
http://en.wikipedia.org/wiki/Vector_field

Plasma Pong is an example of a game that used flow fields for real-time fulid dynamics simluation. The core codebase was from a GDC paper running maybe 80 lines of C.
isaiahk9




PostPosted: Sun Nov 16, 2008 2:37 pm   Post subject: RE:Series of generic computer programming questions (theory)

@ Vermette : Okay, that sounds convenient. But how on earth is it done? You say "dynamic flow field" but not everybody is as wise in the ways of programming to know what that means.

@ md :
1. A much simpler way than what I was thinking. SOLVED. +bits (at the end)
2. Question : so when the player clicks the right arrow key, the screen moves sideways. So would I need to change the enemy's position based off that? And could the enemy then have a less than 0 or greater than maxx x position with the theory?
3. OK, from your theory + my brainstorming it was solved. Thanx. SOLVED +bits (at the end).
4. But the bullets don't instantaneously hit the enemy. They actually travel through space. So I was wondering about their slope of firing.
5. But that is still a problem. What if the trip mine's laser is hitting a box (destructible), and then the box is shot to pieces? Then the coding wouldn't work - the laser would stop at the box.
6. OK, thanx for the confirmation. SOLVED +bits (at the end).
7. OK, thanx for the confirmation. SOLVED +bits (at the end).
8. No, I mean that say there is a broken metal car. When it is shot up, it turns into scrap metal. If the scrap metal is collected, it disappears. But if the scrap is not collected, it does not disappear. How would I test to see if the character can pick up scrap, or not?
9. Not exactly what I was looking for. What do you mean "math and bounding values"? I mean, how does the computer know where there is gas and where there isn't, as well as how to get the computer to only light the gas on fire and nothing else.
10. So that would mean an If for every bullet fired towards him (so it would mean 20 ifs if there were 20 types of bullets, which there are)?
11. Hmmm. . . I guess that's all I'll be able to get. thanx anyways. SOLVED + bits (at the end).
12. I meant, where could I find gravity formulas? And I still can't see an answer for how high speed objects could hurt you.
13. But then how would it be done without arrays?

thanx so far

when I say +bits at the end, I mean once we finish this conversation/thread.
md




PostPosted: Sun Nov 16, 2008 9:06 pm   Post subject: RE:Series of generic computer programming questions (theory)

First, I'm a mod so I don't get bits Wink

For 2, think of the screen as a window into a larger virtual world. Everything has a position in the virtual world, and in order to get the screen over them you have to subract the screens position from the virtual world position.

For 4, you can still use that vector as the basis for your bullet velocity. You just need to scale it; then treat your bullet like any other object and update it's position with each frame.

For 5, you know how long the vector from the mine to the box was. Then the box is destroyed. Now you measure the distance to whatever's behind the box. It's different so explode the mine.

For 8, car object gets shot up -> turns into scrap metal object. Player picks up scrap metal object -> no more scrap metal object on ground. Problem solved.

9 is more complex because you need to make new models and/or add flags to objects saying they are covered in gas. It's really more of an engine design thing and it's highly dependent on type of game and game engine.

For 10, you have objects in your game engine. Everything has a velocity vector, as well as a position vector. You can use these with some math (which you cna google or ask in another thread when you have more details about specifics) to find out if two objects intersected/collided. Then you can reflect your bullet - also using math and vectors.

For 12, hurt is subjective. How much force will hurt a human? How fast must something be going to impact with that much force? Now use the gravity formulas and vector math and you can figure it all out.

For 13, you have a list of objects. A bullet is an object. Since you have unlimited ammo you can just add more and more bullet objects to your list.
wtd




PostPosted: Sun Nov 16, 2008 10:11 pm   Post subject: RE:Series of generic computer programming questions (theory)

If it's a sharp object, then not much force is needed at all. About a pound of pressure will break human skin.
isaiahk9




PostPosted: Mon Nov 17, 2008 6:43 am   Post subject: RE:Series of generic computer programming questions (theory)

@wtd : I'll keep that in mind, thanx.
@ md : OK
2. I understand that - a guy I knew last year was making a platformer with that sort of idea. However, his enemies would always mess up (they would move when he would move, they would walk through walls and stop at empty space, etc.). So I was wondering if when the PC moves, does the NPC's variables need to be changed?
4. OK, thanx. SOLVED
5. But do you know how I could measure that? So that everytime the master loop is run through, I could check its length?
8. OK, I get the picture. SOLVED
9. I'm going to use a brutishly simple approach to this - split the screen into sections, and if sprayed, then the section is "covered" in gasoline, and if gasoline is lit on fire, then that section is lit and ones next to it covered in gas are also lit on fire. SOLVED
10. OK, I get the picture. SOLVED
12. But my main question was how do I make it so that gravity will affect everything without making the 5 or so variables for everything?
13. OK, I get the picture. SOLVED
thanx so far. Left unsolved are 2, 5, 12.
Vermette




PostPosted: Mon Nov 17, 2008 2:00 pm   Post subject: Re: RE:Series of generic computer programming questions (theory)

isaiahk9 @ November 16th 2008, 14:37 wrote:
@ Vermette : Okay, that sounds convenient. But how on earth is it done? You say "dynamic flow field" but not everybody is as wise in the ways of programming to know what that means.


Think of the field as a 2d or 3d array of vectors (heading+magnitude, I'm assuming you've already taken HS physics). Objects in your gamespace have the vector of whatever cell(s) they are on act as a force that moves them for that tick of the game clock. It's dynamic if the vectors themselves are modified over time, which would be the case in fluids which was the scope of the paper.

www.dgp.toronto.edu/people/stam/reality/Research/pdf/GDC03.pdf

That's the paper I mentioned that was used in the creation of Plasma Pong. It should be readable; don't worry about the details of Navier-Stokes equations or the code, the basic idea of a vector field could be adapted to simulate gravity fields with a little creativity.
Sponsor
Sponsor
Sponsor
sponsor
isaiahk9




PostPosted: Mon Nov 17, 2008 4:55 pm   Post subject: RE:Series of generic computer programming questions (theory)

@vermette : sweet, thanx. If I can, I'll use your way of making gravity fields. If that doesn't work out for me, I'll just have to use an array.
Display posts from previous:   
   Index -> General Discussion
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: