Wednesday, November 30, 2016

marketing - Where to promote your indie game?





Possible Duplicate:
Where to advertise my game?



Let's say I have developed a game and I want to "get it out there". What I have in mind is open-source, non-commercial games.


What websites do you know of where you can promote your newly developed game, rather than simply posting it on your blog?



Answer



http://www.indiedb.com/ has just been created, and might be an excellent choice, in addition to David McGraw's recommendation.


http://www.igdb.com/indie Internet Game Database is a good place to add your indie game.



meaning - use of rather with noun and verb



Source


Rather a with a noun is more common in formal language than in informal language, particularly in writing:



  1. It was rather a surprise to find them in the house before me.


Rather + verb
We can use rather to emphasise verbs. We use it most commonly with verbs such as enjoy, hope, like.




  1. I was rather hoping you'd forgotten about that.





  2. He rather liked the idea of a well paid job in the japan. http://dictionary.cambridge.org/grammar/british-grammar/rather




No 1. says that we use rather a+noun in formal writiing.what's the meaning of rather when we use it in this way? Are there other adverbs or words to replace the use of "rather" in 'formal' writing and in informal (spoken) language?


No 2. says we use rather with verb to emphasize verb. What does this mean? Does rather still carry the meaning of "more than average" or "to some extent" when we use rather with verbs ?




word order - Reported speech (position of "was" in sentence)


I was wondering why in the following sentence "was" has to go at the end?



She asked the boy what his name was.





comparison - “energy saving” vs. “energy savings”


Assume that A and B are two systems. For example A consumes 3unit and B consumes 4unit of the energy. Now we know to A saves 0.25% in energy consumption than B.I want to draw a diagram and want to type on the y axis. I would like to which of these is correct:





  1. . . . the energy saving ratio of A to B . . .

  2. . . . the energy saving ratio of A than B . . .

  3. . . . the energy savings ratio of A to B . . .

  4. . . . the energy savings ratio of A than B . . .

  5. . . .. or?





modal verbs - How could it had happened vs How could it have happened


What is the difference between



How could it had happened



and



How could it have happened




It would be better if anyone can show its usage in some kind of situation.



Answer



John Lawler's comment provides a complete answer:



Could is a modal auxiliary and modal auxiliaries must be followed by an infinitive form of the next verb. Have is the next verb, and the infinitive form of have is have. Not had. That's all.



“How could it had happened” is therefore not a grammatical utterance.


Tuesday, November 29, 2016

How can I define items in my RPG like Java game?


I am casually working on an RPG type game in Java but I am having trouble figuring out how I can have items that can do many different things without creating a different class for every item.


As an example, how would I create an Axe that could chop trees and attack monsters?



If I extend either the chopping or the weapon class then I can't extend the other class.


If I have chopping and weapon be an interface then I will have a lot of duplicated code when a dagger can also attack monsters and a different axe can cut trees.


I am hoping there is a way to have a single Item class and load the items and their respective abilities from a file. If that is possible how can it be done? If it isn't then what is the best way to have items in a game?



Answer



Gregory Weir's answer is my favorite for how to structure the item instances in order to perform multiple roles.


To load from a file:


First, use YAML. YAML is a featureful data description language; it can be parsed relatively quickly, read and edited by humans, supports binary data, and libraries exist for most programming languages, including Java. This solves the "how do I get data from files into objects?"


Second, use the flyweight pattern. Most of the data you read from those files is static. It's not going to change per instance ("axe does 1d10 base damage and breaks wood but not stone" - that's true of all five axes a player has). What you actually read from the YAML files are these platonic definition, and your individual item instances have unowned (and constant) references to these, along with per-instance data like "How many swings before I break?", "Did the player give me a custom name?", and so on.


By sharing the cross-instance data in a single object, you preserve lots of memory, and make it easy to update items without persisted game state (save games or player database).


So your class structure looks something like:




  • class Item - One instance per item

    • Owns-a Weapon instance

    • Owns-a Tool instance

    • Has-a custom name, etc.



  • class Weapon - (Up to) one instance per item


    • Is-a ItemComponent

    • Refers-to WeaponDef

    • Has-a bonus enchantment level, etc.



  • class Tool - (Up to) one instance per item

    • Is-a ItemComponent

    • Refers-to ToolDef

    • Has-a durability, etc.




  • class WeaponDef - One instance per kind of weapon

    • Read from a file, fields should be constant.

    • Has-a base damage amount, 1 or 2 hands, etc.



  • class ToolDef - One instance per kind of tool


    • Read from a file, fields should be constant.

    • Has-a base durability, materials it can break, etc.




Where is the correct place to place adverbs in sentences?


I am always confused about where to put adverbs in sentences. For example, consider the questions below:




  1. Why did they target us specifically?

  2. Why did they target specifically us?

  3. Why did they specifically target us?




I believe all these sentences mean the same. Am I correct? I am always confused about where to put adverbs such as always and specifically, etc. Is there a particular grammar rule for this?


Funny, you see, I can even form the above sentence in different ways.




  1. I always confuse where to put this kind of adverb

  2. Always I confuse where to put this kind of adverb




Answer




Short answer:


You (almost) always put always before the verb because adverbs of frequency precede the main verb. There are always(!) exceptions that proves the rule.
Same applies to specifically. You'd usually put it precedent to the main verb but there are reasons to move it in end position which I will discuss shortly in the long answer.



I always confuse...


... they specifically target us...


... they target us specifically.





Long answer:



There are different kind of adverbs and there are different "rules" where to put them. Adverbs can take the initial, mid and end position.


Without going too deep into detail, here are some ideas on how to decide where to put the adverb. Let's start with adverbs (of manner) that modify a single word.


Broadly speaking, the adverb is preceding the word it's modifying. If the adverb modifies a verb, you place it before the verb. In the following sentence, for example, the adverb carefully modifies the verb to drive.



The man carefully drives the car.



If you want to put focus on how something is done, you can move the adverb to the end of the sentence.



The man drives the car carefully.




If the adverb modifies an adjective, you place it before the adjective. If the adverb modifies another adverb, you place it before the adverb. Those adverbs usually specify the certainty and degree of something. Here's an example for both:



The very old man drives the car extremely carefully.



The adverbs very and extremely modify the adjective old and the adverb carefully, respectively.
Adverbs of indefinite frequency (as always) are used likewise, i.e. they are in a mid position.



I always forget where to put the adverb.



Note, that an adverb is always after an auxiliary verb.




I have always been bad at remembering the position of adverbs.



Adverbs of place, time and definite frequency usually go in end position:



I learned English in school.


I saw her last week.



Again, in order to put emphasis on the adverb, you can move the adverb to the front.




The weather is still fine, but it will rain tomorrow.


The weather is still fine, but tomorrow it will rain.



Eventually, a linking adverb can take the initial position but also the position precedent to the verb. If you are unsure about this, simply take the initial position. Same applies to adverbs that have a commenting function or determine the viewpoint.



Officially, I am not allowed to tell that.


Generally speaking, learning English is fun.


However, this does not apply to me.



With this in my mind, a grammatical version of your sentence is




Why did they specifically target us?



Most natural in this situation, however, is to put the adverb at the end of the sentence as it put focus on that you care about "why us and not others".



Why did they target us specifically?



There is another alternative if you want to know the specific reason for targeting us:



Why, specifically, did they target us?




3D Ball Physics Theory: collision response on ground and against walls?


I'm really struggling to get a strong grasp on how I should be handling collision response in a game engine I'm building around a 3D ball physics concept. Think Monkey Ball as an example of the type of gameplay.


I am currently using sphere-to-sphere broad phase, then AABB to OBB testing (the final test I am using right now is one that checks if one of the 8 OBB points crosses the planes of the object it is testing against). This seems to work pretty well, and I am getting back:


Plane that object is colliding against (with a point on the plane, the plane's normal, and the exact point of intersection.


I've tried what feels like dozens of different high-level strategies for handling these collisions, without any real success. I think my biggest problem is understanding how to handle collisions against walls in the x-y axes (left/right, front/back), which I want to have elasticity, and the ground (z-axis) where I want an elastic reaction if the ball drops down, but then for it to eventually normalize and be kept "on the ground" (not go into the ground, but also not continue bouncing). Without kluging something together, I'm positive there is a good way to handle this, my theories just aren't getting me all the way there.


For physics modeling and movement, I am trying to use a Euler based setup with each object maintaining a position (and destination position prior to collision detection), a velocity (which is added onto the position to determine the destination position), and an acceleration (which I use to store any player input being put on the ball, as well as gravity in the z coord).


Starting from when I detect a collision, what is a good way to approach the response to get the expected behavior in all cases?


Thanks in advance to anyone taking the time to assist... I am grateful for any pointers, and happy to post any additional info or code if it is useful.


UPDATE


Based on Steve H's and eBusiness' responses below, I have adapted my collision response to what makes a lot more sense now. It was close to right before, but I didn't have all the right pieces together at the right time! I have one problem left to solve, and that is what is causing the floor collision to hit every frame. Here's the collision response code I have now for the ball, then I'll describe the last bit I'm still struggling to understand.



// if we are moving in the direction of the plane (against the normal)...
if (m_velocity.dot(intersection.plane.normal) <= 0.0f)
{
float dampeningForce = 1.8f; // eventually create this value based on mass and acceleration

// Calculate the projection velocity
PVRTVec3 actingVelocity = m_velocity.project(intersection.plane.normal);

m_velocity -= actingVelocity * dampeningForce;
}

// Clamp z-velocity to zero if we are within a certain threshold
// -- NOTE: this was an experimental idea I had to solve the "jitter" bug I'll describe below
float diff = 0.2f - abs(m_velocity.z);
if (diff > 0.0f && diff <= 0.2f)
{
m_velocity.z = 0.0f;
}

// Take this object to its new destination position based on...
// -- our pre-collision position + vector to the collision point + our new velocity after collision * time

// -- remaining after the collision to finish the movement
m_destPosition = m_position + intersection.diff + (m_velocity * intersection.tRemaining * GAMESTATE->dt);

The above snippet is run after a collision is detected on the ball (collider) with a collidee (floor in this case). With a dampening force of 1.8f, the ball's reflected "upward" velocity will eventually be overcome by gravity, so the ball will essentially be stuck on the floor. THIS is the problem I have now... the collision code is running every frame (since the ball's z-velocity is constantly pushing it a collision with the floor below it). The ball is not technically stuck, I can move it around still, but the movement is really goofy because the velocity and position keep getting affected adversely by the above snippet.


I was experimenting with an idea to clamp the z-velocity to zero if it was "close to zero", but this didn't do what I think... probably because the very next frame the ball gets a new gravity acceleration applied to its velocity regardless (which I think is good, right?).


Collisions with walls are as they used to be and work very well. It's just this last bit of "stickiness" to deal with. The camera is constantly jittering up and down by extremely small fractions too when the ball is "at rest".


I'll keep playing with it... I like puzzles like this, especially when I think I'm close. Any final ideas on what I could be doing wrong here?


UPDATE 2


Good news - I discovered I should be subtracting the intersection.diff from the m_position (position prior to collision). The intersection.diff is my calculation of the difference in the vector of position to destPosition from the intersection point to the position. In this case, adding it was causing my ball to always go "up" just a little bit, causing the jitter. By subtracting it, and moving that clamper for the velocity.z when close to zero to being above the dot product (and changing the test from <= 0 to < 0), I now have the following:


// Clamp z-velocity to zero if we are within a certain threshold

float diff = 0.2f - abs(m_velocity.z);
if (diff > 0.0f && diff <= 0.2f)
{
m_velocity.z = 0.0f;
}

// if we are moving in the direction of the plane (against the normal)...
float dotprod = m_velocity.dot(intersection.plane.normal);
if (dotprod < 0.0f)
{

float dampeningForce = 1.8f; // eventually create this value based on mass and acceleration?

// Calculate the projection velocity
PVRTVec3 actingVelocity = m_velocity.project(intersection.plane.normal);

m_velocity -= actingVelocity * dampeningForce;
}

// Take this object to its new destination position based on...
// -- our pre-collision position + vector to the collision point + our new velocity after collision * time

// -- remaining after the collision to finish the movement
m_destPosition = m_position - intersection.diff + (m_velocity * intersection.tRemaining * GAMESTATE->dt);
UpdateWorldMatrix(m_destWorldMatrix, m_destOBB, m_destPosition, false);

This is MUCH better. No jitter, and the ball now "rests" at the floor, while still bouncing off the floor and walls. The ONLY thing left is that the ball is now virtually "stuck". He can move but at a much slower rate, likely because the else of my dot product test is only letting the ball move at a rate multiplied against the tRemaining... I think this is a better solution than I had previously, but still somehow not the right idea. BTW, I'm trying to journal my progress through this problem for anyone else with a similar situation - hopefully it will serve as some help, as many similar posts have for me over the years.



Answer




I think my biggest problem is understanding how to handle collisions against walls in the x-y axes (left/right, front/back), which I want to have elasticity, and the ground (z-axis) where I want an elastic reaction if the ball drops down...



I think you should handle the walls exactly the same as the ground. Create a method that takes as parameters the surface normal & the ball's velocity and returns a reflected velocity vector. If you need a short snippet for that, we can show that to. The elastic factor of a ball is the same whether it bounces from the wall or floor. I think you may be needing to factor in gravity so your ball's motion appears more natural.



In a game where you are roughly trying to approximate real life physics, you will most likely have a gravity vector which influences (add to) the ball's velocity vector each frame. The effect of the gravity will appear to influence the ball differently if the ball is bouncing from the floor vs. the walls because the gravity is aligned with the floor and has the most pronounce effect on ball speed changes (magnitude of the velocity vector), so there is where the difference you are expecting may come from.



Starting from when I detect a collision, what is a good way to approach the response to get the expected behavior in all cases?




  1. Determine the ball's position at point of contact. Determine what percentage of the frame's time slice The ball will travel in the reflected direction.

  2. Run the surface normal & the ball's velocity vector through the reflection method above. It will return the ball's new velocity vector.

  3. Transform the point representing the ball's position at the time of contact by the new velocity vector multiplied by the remainder of the frame's time slice. Factor in the gravity influence on this point.


phrase usage - I am/have been a fan?


When you say you are a fan of someone, do you say "I am a fan" or "I've been a fan"?


Please see my example below:




A: Why did you buy this CD? It's full of crappy tracks!


Me: I bought it because I am a fan of this band.



Or is it more correct to say that you are a fan by using present perfect continuous?



Me: I bought it because I've been a long-time fan of this band.




Answer



Both statements seem grammatically correct and convey the same emotion except timeline mentioned in later statement. Later statement is slightly different because you have mentioned 'a long-time fan'.



modal verbs - "I would have liked to come" and "I would like to have come" - difference?


Please read the following:



  1. I would like to come with you.


  2. I would have liked to come with you.

  3. I would like to have come with you.


Another example:



  1. I would prefer to drink coffee.

  2. I would have preferred to drink coffee.

  3. I would prefer to have drunk coffee.


I perfectly understand the first sentence in both the groups. What I would like to know is the difference between second and third sentences. Could you please explain that?





Monday, November 28, 2016

subject verb agreement - Does "culture and languages" agree with "is"?


I have been writing and rewriting a text which now contains the following sentence:


"I have mainly studied Economics, but culture and languages is something I really enjoy; Today I fluently speak Spanish, Italian, French and I have good knowledge of English."


At the same time that, for some reason, it sounds right to me; because of "culture and languages" not agreeing with "is", it makes me believe that this sentence is wrong. It it right or wrong? Why is it so?




Passive construction of infinitive verb


Example #1:



Active voice: India expected to win the match.


Passive (book answer): It was expected by India that they would win the match.


My answer: India expected the match to be won.



Example #2:




Active: I expect her to finish the task.


Passive (book answer): I expect the task to be finished by her.



For the first example (#1), the book shows only one answer but I think my answer is also correct. I just changed the sentence into passive voice in the same way as the book changed the second example (#2) into a passive.


Is my answer for #1 correct? Is my answer to #1 grammatically the same as the book's answer to #1?



Answer




1#


Active voice: India expected to win the match.




I think the easiest way to read this sentence is to add one simple verb to act as a copulative:



India (is/was) expected to win the match.



Note that this sentence (or the original headline!) does not in any way indicate who expected India to win! It could be the press, the public at large, the writer of the article or some sports expert that said this in an interview.



Passive voice( book answer): It was expected by India that they would win the match.



Information is added that was not there in the original headline! The headline does not say that India expected to win, it say that India was expected to win. Nothing indicates who expected it!




My answer : India expected the match to be won.



That is an interesting expectation. It is equivalent to:



India did not expect a draw.



The original headline clearly states that expectations exist that India would win the match, your version states that India expect somebody will win.


Both the book and your version are introducing India as the party that expects something, but the headline does not have that information. In my view, both versions are incorrect.


Sentence 2 is more straightforward and I agree with the book version. The original sentence is also a complete sentence, not a headline.





I just realized that the original sentence does not have to be a (newspaper) headline. The answer above is obviously reading it as if the sentence appeared as a headline, but of course India also simply be the subject in a normal active sentence. In that case, yes, India or the India team are indeed the subject, and they do expect to win the match.


The book answer is completely correct in that case, of course.


Your version still leaves the main verb in the sentence (expects) in the active voice. The main idea of the original sentence is India expects something. You have change something into an (almost) meaningless passive construct and you changed the meaning of the sentence!


The original sentence India expected (to win the match) should be changed into the passive as It was expected by India (that they would win the match).


You version does use a passive construction for (to win the match), but normally in these exercises you are expected (pun intended) to change the voice of the main clause of the sentence.


Apart from the fact that you do not change the main clause of the sentence, you also have removed the important information about who was expected to win the match! In your version, if India's opponent won, that would still be according to the expectation.


ai - Pattern for performing game actions


Is there a generally accepted pattern for performing various actions within a game? A way a player can perform actions and also that an AI might perform actions, such as move, attack, self-destruct, etc.


I currently have an abstract BaseAction which uses .NET generics to specify the different objects that get returned by the various actions. This is all implemented in a pattern similar to the Command, where each action is responsible for itself and does all that it needs.


My reasoning for being abstract is so that I may have a single ActionHandler, and AI can just queue up different action implementing the baseAction. And the reason it is generic is so that the different actions can return result information relevant to the action (as different actions can have totally different outcomes in the game), along with some common beforeAction and afterAction implementations.


So... is there a more accepted way of doing this, or does this sound alright?



Answer



I don't think there's one accepted way of implementing this concept, but I'd really like to share how I usually deal with this in my games. It's a bit of a combination of the Command design pattern and the Composite design pattern.


I have an abstract base class for actions which is nothing more than a wrapper around an Update method that gets called each frame, and a Finished flag to indicate when the action has finished running.


abstract class Action

{
abstract void Update(float elapsed);
bool Finished;
}

I also use the composite design pattern to create a type of actions that is capable of hosting and executing other actions. This too is an abstract class. Boils down to:


abstract class CompositeAction : Action
{
void Add(Action action) { Actions.Add(action); }
List Actions;

}

Then I have two implementations of composite actions, one for parallel execution and one for sequential execution. But the beauty is that since parallel and sequence are actions themselves, they can be combined in order to create more complex execution flows.


class Parallel : CompositeAction
{
override void Update(float elapsed)
{
Actions.ForEach(a=> a.Update(elapsed));
Actions.RemoveAll(a => a.Finished);
Finished = Actions.Count == 0;

}
}

And the one that governs sequential actions.


class Sequence : CompositeAction
{
override void Update(float elapsed)
{
if (Actions.Count > 0)
{

Actions[0].Update(elapsed);
if (Actions[0].Finished)
Actions.RemoveAt(0);
}
Finished = Actions.Count == 0;
}
}

With this in place it's simply a matter of creating concrete action implementations, and using the Parallel and Sequence actions to control the flow of execution. I'll end with an example:


// Create a parallel action to work as an action manager

Parallel actionManager = new Parallel();

// Send character1 to destination
Sequence actionGroup1 = new Sequence();
actionGroup1.Add(new MoveAction(character1, destination));
actionGroup1.Add(new TalkAction(character1, "Arrived at destination!"));
actionManager.Add(actionGroup1);

// Make character2 use a potion on himself
Sequence actionGroup2 = new Sequence();

actionGroup2.Add(new RemoveItemAction(character2, ItemType.Potion));
actionGroup2.Add(new SetHealthAction(character2, character2.MaxHealth));
actionGroup2.Add(new TalkAction(character2, "I feel better now!"));
actionManager.Add(actionGroup2);

// Every frame update the action manager
actionManager.Update(elapsed);

I have successfully used this system to drive all of the gameplay in a graphic adventure before, but it should probably work for pretty much anything. It was also simple enough to add other types of composite actions, which were used for creating execution loops and conditionals.




Are there existing FOSS component-based frameworks?



The component based game programming paradigm is becoming much more popular. I was wondering, are there any projects out there that offer a reusable component framework? In any language, I guess I don't care about that. It's not for my own project, I'm just curious.


Specifically I mean are there projects that include a base Entity class, a base Component class, and maybe some standard components? It would then be much easier starting a game if you didn't want to reinvent the wheel, or maybe you want a GraphicsComponent that does sprites with Direct3D, but you figure it's already been done a dozen times.


A quick Googling turns up Rusher. Has anyone heard of this / does anyone use it? If there are no popular ones, then why not? Is it too difficult to make something like this reusable, and they need heavy customization? In my own implementation I found a lot of boilerplate that could be shoved into a framework.



Answer




If there are no popular ones, then why not?




Because there is nothing resembling a consensus on how such a framework would operate.


On a thread on Gamedev.net I determined that when people talk about component-based game systems there are actually at least 8 possible permutations of how they expect them to work, based on 3 different factors:


Inboard vs. outboard - should components be aggregated into an entity, or should they be part of a subsystem and only associated by an entity ID?


Static vs. dynamic composition - should entities consist of a known set of components (eg. 1 Physics, 1 Animation, 1 AI, etc) that can communicate in code via well-known interfaces, or can entities have arbitrary quantities of components added to them (with associated strategies for locating other components of interest)


Data on component vs data on entity - Should data be held by the component that primarily operates upon it? Or should data be stored on the entity in a shared space, accessible by all components?


Beyond that there are further questions over how the components should communicate (via the shared data? Via function pointers? Via signals/slots? Or not at all?), how they should update (in a fixed order based on component type? a per-entity order defined at creation time? based on a topological sort of component interdependencies?), etc.


Each of these choices are completely arbitrary, and anything you can do with one system can be done with the other. But the way in which you have to code it is quite different in each case. And people seem to have strong opinions over which way works best for them.


Right now people are still too caught up in the idea that components are somehow a replacement for object orientation (which they're not) and also imagining that they're a massive change from how games were traditionally made (which again, they were not - people have factored out the various subsystems in their entities for ages), so there's a lot of hyperbole and not much agreement. Maybe in a few years things will have settled down and people will settle on one or two fairly standard approaches.


grammar - Most of something is plural or singular?


I am writing a literature review. My question is which sentence is correct?



  1. Most of the existing work focus on...

  2. Most of the existing work focuses on ...

  3. Most of the existing studies focus on ...



Thanks



Answer



If the object after "most" is singular then the verb is singular too, else if the object after "most" is plural then the verb is plural:



  • Most of his ideas are silly. (ideas - plural, are - plural)

  • Most of his money is spent on PC games. (money - singular (uncountable), is - singular)


Your second and third sentences are correct. The first one is incorrect.


android - Saving player's progress in a Unity game


I am making a game using the Unity game engine. I want to save the player's progress including level, experience points, chosen character, etc. Presently I am using playerprefs but I want to know whether this will work for gamers who will run this game on their mobile devices (Android/iOS) as well as desktops (OSX/PCs)? If not, then how should I save this information? I want to auto-save player progress after clearing each stage.



Answer



PlayerPrefs will work cross-platform, but it's not recommended for gameplay progress save files because it's insecure. As a plaintext file, a player can easily open it up and change the contents to cheat, or make your game behave unpredictably. It's also not guaranteed to stay around.


PlayerPrefs is intended for non-essential preference information, like control mapping or music/sfx settings - things the player can freely change anyway, and wouldn't miss terribly if they were to (on Windows for example) use a system restore point and lose some of their registry information. If this lost their high scores or campaign progress, players would be justifiably upset!


Instead, it's recommended to save gameplay progress in your own file (usually binary, possibly encrypted or signed if you want to make it harder to modify, but see Philipp's comment below on this).


You can use Application.persistentDataPath to get a reliable save location on each platform. This is typically in a user data folder that won't be wiped out in cases like the example above.


Once you have a path to save to, you can use the regular C# IO methods to create, write, and read your file. The details will vary a lot depending on your save file format and structure, so if you run into trouble, it's best to ask a new question detailing what you're trying to do and where you're stuck.


Sunday, November 27, 2016

xbox360 - Is XNA good for professional development for the Xbox 360?


I want to start off developing for my Xbox 360, and I've heard of the XNA framework that can target both the PC and Xbox. This sounds like an attractive option since my clients can use the game/app on normal computers as well.


However I'm very new to the Xbox scene. Is XNA only for hobbyist development, and is it not recommended for semi-professional or corporate application development? Does XNA lack the capabilities of a C++ developed solution, or dos it badly reduce performance of a game/app running on the Xbox?


Is it possible to target the Xbox using C#, and without XNA? What are the advantages?


Low-level programming would be in C++ directly working with DirectX. What are the advantages?



Answer




The short answer: Yes.


XNA is just a tool. It is suitable for all but the most processor- and graphically-intensive games. If you are considering XNA for an Xbox 360 game, here's what you will miss out on:



  • Access to the SIMD/Vector unit for doing really, really fast CPU floating point maths

  • Ability to use native language code that will probably be a little bit faster than C#

  • Ability to be a little bit lazier with how you allocate memory

  • XBLIG games have access to only 4 of the 6 cores (but we still get all 3 CPUs, and they're not full cores either, so we don't miss out on much) - not sure if this applies to non-XBLIG XNA games

  • Full DirectX access for doing really obscure graphical trickery


There might be more - this is off the top of my head.



(Speculation: if you are a professional developer (as in: have a devkit), I think that you can use XNA with native code, same as P/Invoke on Windows. Best of both worlds. You'd have to ask Microsoft. See also XDK.)


The bottom line is that an XNA game is almost as fast as a native game and can do almost as much stuff. I'd suggest you use it unless you find a compelling reason not to.


I do not know if there is any kind of managed DirectX for the 360. Perhaps SlimDX is a good place to start.


Objective-C or C++ for iOS games?


I'm pretty confident programming in Objective-C and C++, but I find Objective-C to be somewhat easier to use and more flexible and dynamic in nature.


What would be the pros and cons when using C++ instead of Obj-C for writing games in iOS? Or rather, are there any known problems with using Obj-C as compared to C++?


For instance, I suspect there might be performance issues with Obj-C compared to code written in C/C++.




software engineering - Where can I find a programmer/game developer to team up with?



I'm a pixel artist looking for an ametuer programmer/game developer to team up with, But I'm not sure where to start!


I'm not particularly worried about profit, I'm only interested in making the game as a hobby. Where can I find potential partners?



Answer



Show What You Can Do


When looking to start or join a team online, people are always interested in seeing what work you've produced beforehand. The work doesn't necessarily have to be done in a game, but it should showcase your ability to create game quality assets.


Talk About What You Want To Do


If you're looking to recruit people for a team, talk about the project you're wanting to work on. You don't have to have all the details fleshed out, but it is important that potential applicants understand the scale and scope of work you're wanting to accomplish. As an example, there is a big difference in the programming skill and amount of effort required to produce an Astroids clone and a Bullet Hell style game with online networking capabilities.



Read and Follow The Rules


A lot of communities that have job/recruitment boards have specific rules about posting in them. In many cases, they require you to fill out a template when posting, to help ensure you hit on all the major pitch points. Be sure to read the rules for each site before you post.


Resources


Here are links to a few communities you may find useful for recruiting game developer talent:



Saturday, November 26, 2016

phrase usage - due to versus as a result of


According to the answer key of a SAT preparation book I'm studying, there is an error in the sentence




By the time the bank guard closed the doors, a riot had erupted due to the long lines and shortage of tellers.



and it should be changed to



By the time the bank guard closed the doors, a riot had erupted as a result of the long lines and shortage of tellers.



I disagree with this. Why is the first sentence unacceptable?



Answer



19th-century stylists held that due is an adjective and that due to X phrases should be employed only as




  • a postposed modifier, as in A riot due to long lines erupted, or

  • a predicate adjective, as in The riot was due to long lines.


Actual on-the-ground usage has long since transformed due to into a preposition equivalent to because of, and you may safely ignore this ‘rule’ in all circumstances except one:



When you're taking a test of your knowledge of English, assume your examiner follows the old rule: use due only as an adjective, and treat any other use as incorrect.



It’s stupid, but it’s a fact. As the poet Schiller wrote:



Against stupidity the gods themselves struggle in vain.




architecture - How to manage all the NPC/AI objects on the server?


I'm writing a simple MMO, and currently have the the server-client architecture in place for multiple users to see each other and be able to move around together...now its time to add enemies.


Was wondering if anyone had links to articles that discussed how to best handle the hundreds of NPC objects that need to be managed in the world. I've done some searching and couldn't find much info about how this is typically done.


The two methods of structuring the implementation I can think of:




  1. Holding all the instantiated NPC objects in a list, and having an NPC Thread loop through them sequentially and see if each has any logic that needs to be processed and perform necessary actions. I'm not sure if the performance of this design would be sufficient?

  2. Event based system. Create a method in the NPC class that processes AI/Logic on it, have this method be called when an associated event is signaled, either on a timer for non interacted AI functionality (such as wandering), or signal the event externally from the packet handler (player moving nearby, or player attacking within range).


Is either of these approaches the correct way? What other methods of doing this exist?



Answer



As always, architecture depends on your requirements. How many mobs are you going to have? How complex is their AI? What does it react to? How often does it change its state? Answer these questions, and you'll have a much better understanding of what you want and how to get that.


Generally, you'd want to have at least some kind of event system. AI is usually defined in terms of events: "When A happens, do B"; and if you don't have events in actual code, you'd have to somehow translate these definitions.


In my experience, you can get away with a simple loop implementation when you have few and really simple mobs (contrary to what the other answer seems to suggest). For example, in our current game we have hundreds of small instances with each having 10 mobs at most. And these mobs are dead-stupid; AI of 99% of them can be described in one sentence: "Am I attacking anyone? If not, attack closest player." In this case a simple loop is more than enough - twice a second we check for a new target (and a few other things for the rare "smart" mobs), and that does it.


However, when you have more and/or smarter mobs, naive approach stops working. For AI to react to some stimulus, you'd have to write code that detects it inside your AI loop. For example: suppose your mob should do something "when hit by a player". With a loop approach, there's no easy way to determine the mob was hit. When the AI is running, you can check that mob's health diminished since last tick, or that the mob is currently targeted by someone. But you cannot detect actual hits without resorting to hacks, like saving each hit info somewhere for AI to access it later.



Secondly, a naive loop always runs, no matter what happens. When you have lots of mobs, you want the AI to run as fast as possible.. and the fastest code is the code that never runs at all. If you have mobs that are not active, you want them to not run AI, or only run it sporadically (as in, wandering mob AI should only run when it decides where to go next).


With event-based approach, you can have you other subsystems send AI events whenever convenient, eliminating problem of "detecting hits". Of course, some events would still require detecting code: most notorious example is the "approach" event. And when you don't run your AI routine in a loop when nothing happens, you gain performance.


You can also use a hybrid approach. Instead of handling AI events immediately, you can stuff them into some kind of queue. Then, when AI routine runs (in a loop), it removes events from this queue and handles them one by one. With this architecture, AI performance might be a bit slower, but it is more predictable; also, you can guarantee that all AI runs on a single thread (which might be tricky otherwise). This kind of loop can also be easily throttled by skipping some events (for example, each AI iteration only handles three most recent events, discarding the rest). Or events might be prioritized, and less-important ones discarded if AI is found to be lagging.


Overall, the "loop with events queue" approach is probably the most flexible. But I want to reiterate: don't just choose it blindly as "the best". Think about your requirements first, and some simpler approach may turn out to be better.


unity - How can I prevent seams from showing up on objects using lower mipmap levels?


Disclaimer: kindly right click on the images and open them separately so that they're at full size, as there are fine details which don't show up otherwise. Thank you.


I made a simple Blender model, it's a cylinder with the top cap removed:


enter image description here


I've exported the UVs:


enter image description here


Then imported them into Photoshop, and painted the inner area in yellow and the outer area in red. I made sure I cover well the UV lines:


enter image description here



I then save the image and load it as texture on the model in Blender. Actually, I just reload it as the image where the UVs are exported, and change the viewport view mode to textured. When I look at the mesh up-close, there's yellow everywhere, everything seems fine:


enter image description here


However, if I start zooming out, I start seeing red (literally and metaphorically) where the texture edges are:


enter image description here


And the more I zoom, the more I see it:


enter image description here


Same thing happends in Unity, though the effect seems less pronounced. Up close is fine and yellow:


enter image description here


Zoom out and you see red at the seams:


enter image description here



Now, obviously, for this simple example a workaround is to spread the yellow well outside the UV margins, and its fine from all distances. However this is an issue when you try making a complex texture that should tile seamlessly at the edges. In this situation I either make a few lines of pixels overlap (in which case it looks bad from upclose and ok from far away), or I leave them seamless and then I have those seams when seeing it from far away.


So my question is, is there something I'm missing, or some extra thing I must do to have my texture look seamless from all distances?



Answer



You can't.


All right, that was a bit harsh. Let me illustrate this with two examples.




  1. Let's get outside of the computer graphics world. Suppose you are given a piece of paper with the texture you gave us printed on it. There's a faintly printed millimeter grid in the paper as well.


    Now you get some scissors and some paste, and your task is to make a cylinder out of the piece of paper, but you can only cut exactly through the millimeter grid. No problem! the printed paper was originally created in such a way the yellow and red parts fall exactly on the millimeter grid, so you make your cylinder with no problem.


    Now your task is to make a cylinder half the size. To do this, you get a piece of paper half the size with everything printed half the size. This is where your problems start. Some of the yellow-red borders will fall on the millimeter grid, but others won't. And for those that don't, you can either cut on the yellow or the red parts. Which one is more correct? It depends. Sometimes it's the yellow one, sometimes it's the red one, sometimes it's neither...





  2. So let's get back into the computer graphics world. Let's try to do what you're asking the GPU to do when you're asking it to create mipmaps. Take your large texture and resize it into a texture exactly half the size of the original one. What happens at the yellow-red borders? Well, it depends. It depends on the filtering algorithm you use when scaling your texture down.


    If you use "Nearest neighbor", you will preserve your abrupt yellow-red changes, but some borders (to be precise, those that fall in an odd coordinate in the original texture) will be forced to either side of the pixel grid, and the texture coordinates you originally carefully chose will no longer match the yellow-red border.


    If you use "Bilinear filtering", things are not really better. When the yellow-red border doesn't fall in the pixel grid as before (once again, when the border lies on an odd coordinate in the original texture), the resulting pixel will neither be red or yellow. It will be more like orange! Is this acceptable? I don't know.




You will notice that the problem is limited to the yellow-red borders that fall in odd coordinates. You can say "no problem!" and make sure all the yellow-red borders fall in even coordinates, and problem solved! Or is it?


Actually not. The problem will be solved when creating the first mip level. But when you create the next mip level, which is a texture one quarter of the size of the original, you will experience the same problem with the yellow-red borders that don't fall in an even coordinate in the half-size texture, which happen to be those that don't fall in a multiple of 4 coordinate in the original texture.


So even if you fix it for the second mip level, you will never solve the entire problem. You will just be taking it to a lower mip level.



As you can see this is not a problem with the game engine you're using. It's a problem with mipmapping in general. So does this mean that mipmapping is useless and should be disabled? Actually no. Mipmapping is very useful. You're just using it wrong. Actually, you said the answer yourself:



spread the yellow well outside the UV margins, and its fine from all distances



It seems like an ugly hack, but it's actually not. However, I have a more general solution I hereby call the "First Panda Pajama Rule of 3D skinning".



Don't map abrupt UV coordinate changes to abrupt texture changes.



You're experiencing this problem because you're matching an abrupt texture change (yellow to red) to an abrupt texture coordinate change (the change between the cylinder and the void (or the cap, when you close the cylinder). You want to avoid this when skinning, precisely to avoid the problem you're describing.


Corollary:




If you must make an abrupt UV coordinate change, don't put an abrupt texture change (like your proposed solution of spreading the yellow). If you must make an abrupt texture change, make it so it doesn't require an abrupt UV coordinate change (you should usually prefer doing this)



You can take advantage of the fact that, unlike when you're making models out of paper and paste, the shape of your texture does not have to match the shape of your model. When making the texture for the cap of your cylinder, you don't have to make it round. In fact, I'd make it rectangular so I can match it to the texture of the sides of the cylinder precisely to avoid abrupt UV coordinate changes between the sides and the caps (look for "Filters->Distort->Polar Coordinates" in Photoshop).


I'd also align the left and right borders of the cylinder texture to the left and right borders of the texture, and set the texture mapping to wrap, so the texture wraps nicely around the cylinder.


c# - Unity new UI - Dynamically change the functions called by GUI elements


Looking to dynamically change the value in the button OnClick and slider On Value Changed example 1 example 2.


If I had to guess on how this was done, get a reference to the button/gui element. Next get the Button script component and access that list of function calls. However I'm not sure how to modify that list. Anyone have any ideas?


More Details that might help:




  • The function being called is apart of a custom script component

  • Using the 'dynamic' variable option for the sliders

  • Could be used to create dynamic buttons



Answer



There's a super simple way to change events:


EDIT


See my other answer for the quick and easy way to add an event for the OnClick event only. For other events, like OnDrag see below.





Additionally, if you need more than just the events provided by default, I'd suggest instead attaching a EventTrigger to your game object. This gives us access to the BaseEventData object returned from the event, telling us stuff like the object that created the event. Then you can do something like:


//Create an event delegate that will be used for creating methods that respond to events
public delegate void EventDelegate(UnityEngine.EventSystems.BaseEventData baseEvent);

Then we can create a method for handling events, the signature must match that of our delegate. So, it needs to return void and accept BaseEventData as its first and only parameter:


public void DropEventMethod(UnityEngine.EventSystems.BaseEventData baseEvent) {
Debug.Log(baseEvent.selectedObject.name + " triggered an event!");
//baseEvent.selectedObject is the GameObject that triggered the event,
// so we can access its components, destroy it, or do whatever.
}


Finally, to dynamically add the event:


//Get the event trigger attached to the UI object
EventTrigger eventTrigger = buttonObject.GetComponent();

//Create a new entry. This entry will describe the kind of event we're looking for
// and how to respond to it
EventTrigger.Entry entry = new EventTrigger.Entry();

//This event will respond to a drop event

entry.eventID = EventTriggerType.Drop;

//Create a new trigger to hold our callback methods
entry.callback = new EventTrigger.TriggerEvent();

//Create a new UnityAction, it contains our DropEventMethod delegate to respond to events
UnityEngine.Events.UnityAction callback =
new UnityEngine.Events.UnityAction(DropEventMethod);

//Add our callback to the listeners

entry.callback.AddListener(callback);

//Add the EventTrigger entry to the event trigger component
eventTrigger.delegates.Add(entry);

If you're using version 5.3.3 or above, use this line instead instead of the last line above, delegates is depreciated:


eventTrigger.triggers.Add(entry); 

Friday, November 25, 2016

tense - Why is it not OK to use the Present Perfect here?


Michael Swan, in his grammar book, says that in this context the Present Perfect tense is not to be used.



1) Why are you crying? – Tony hit me.


2) This picture looks great. Did you paint it yourself?



I don't understand why the following are wrong, in his opinion. Could you shed some light on the factor I am missing?


These are apparently wrong. Why?



3) Why are you crying? – Tony has hit me.



4) This picture looks great. Have you painted it yourself?





opengl - lighting for landscape


I've got a landscape(created in Photoshop .raw file) and a .tga texture for it. I read .raw file and read .tga file like this


LoadRawFile("landscape.Raw", MapSize * MapSize, &HeightMap[0][0]);


Texture landscape;
if (LoadTGA(&landscape, "landscape.tga")) {

glGenTextures(1, &landscape.texID);
glBindTexture(GL_TEXTURE_2D, landscape.texID);
glTexImage2D(GL_TEXTURE_2D,
0,
landscape.bpp / 8,
landscape.width,

landscape.height,
0,
landscape.type,
GL_UNSIGNED_BYTE,
landscape.imageData);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

if (landscape.imageData) free(landscape.imageData);

} else {
cout<<"Cannot load texture"<}

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer (3, GL_FLOAT, 0, VertexMap);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, TextureMap);


for (int Row=0; Row < MapSize*2; Row++)
{
Indices[Row] = Row;
}

I render landscape like this(method renderLandscape)


int x, y, i, j;
int Index = 0;

for (i = 0; i < MapSize-1; i++)

{
Index = 0;
for (j = 0;j < MapSize-1; j++)
{
x = j * Zoom;
y = i * Zoom;

TextureMap[Index+0][0]= j * TextureBit;
TextureMap[Index+0][1]= i * TextureBit;
TextureMap[Index+1][0]= j * TextureBit;

TextureMap[Index+1][2]= (i+1) * TextureBit;

VertexMap[Index+0][2] = HeightMap[j][i];
VertexMap[Index+1][2] = HeightMap[j][i+1];

VertexMap[Index+0][0] = x;
VertexMap[Index+0][3] = y;
VertexMap[Index+1][0] = x;
VertexMap[Index+1][4] = y+Zoom;


Index += 2;
}

glDrawElements(GL_TRIANGLE_STRIP, Index, GL_UNSIGNED_INT, Indices);
}

draw method


glPushMatrix();
glTranslatef(-20, 0, 0);
glScalef(0.01, 0.01, 0.01);

glRotatef(90, 1, 0, 0);
landscape.RenderLandscape();
glPopMatrix();

So by default(without lighting) it looks like this enter image description here


But when I enable lighting(add this lines to my opengl init function)


GLfloat light_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };


glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

The result landscape looks like this enter image description here



I don't need any special or difficult lighting. So it seems I need to calculate normales(I am new in opengl and usually create .obj models where vn precalculated). What is the best way to calculate normales in my case?



Answer



This is how you calculate normals for a mesh. This methods averages vertex normals that is shared by multiple faces.


void CalculateNormals()
{
size_t vertexCount = m_triangles.size();

m_normals.reserve( m_vertices.size() );

for( int i = 0; i < vertexCount; i += 3 )

{
// get the three vertices that make the faces
glm::vec3 p0 = m_vertices[m_triangles[i+0]];
glm::vec3 p1 = m_vertices[m_triangles[i+1]];
glm::vec3 p2 = m_vertices[m_triangles[i+2]];

glm::vec3 e1 = p1 - p0;
glm::vec3 e2 = p2 - p0;
glm::vec3 normal = glm::cross( e1, e2 );
normal = glm::normalize(normal);


// Store the face's normal for each of the vertices that make up the face.
m_normals[m_triangles[i+0]] += normal ;
m_normals[m_triangles[i+1]] += normal ;
m_normals[m_triangles[i+2]] += normal ;
}


// Now loop through each vertex vector, and avarage out all the normals stored.
for( int i = 0; i < m_normals.size(); ++i )

{
m_normals[i] = glm::normalize(m_normals[i]);
}
}

How are sound effects made?



My friend and I are finishing up our first game right now and I have just discovered that even though he can make some decent music tracks, he has no idea how to make a sound effect. An explosion, for example.


How are sound effects made?



Answer




Do some research on what a Foley Artist does:


http://en.wikipedia.org/wiki/Foley_artist


word choice - Since and Because


Is there any difference between since and because?


Example:



Bob gave him a candy because he was nice.


Bob gave him a candy since he was nice.



Note: If someone has a better example, please post it in the comments




Answer



I knew one English professor who was fond of saying that we should never use since instead of because. We all thought he was an idiot for saying so, but perhaps purist would be a better word than idiot. To be fair, he also said this in the context of a technical writing course, so perhaps he'd even relax his own standards in the context of casual conversation.


I found this snippet on a discussion board:



This is "purist" territory. Purists will tell you that since refers to time – specifically, the amount of time that has elapsed from a starting point. Since I started work today, I've received 57 e-mails. And they will tell you that only because (not since) shows causation. So Since I started my new job today, I'm no longer looking for employment is where you should use "because."



So, back to your two examples:



Bob gave him a candy because he was nice.




Here, the candy is a reward for the lad's nice behavior. However, this sentence:



Bob gave him a candy since he was nice.



could be construed to mean that Bob gave a candy after – not necessarily because – the boy was nice.


Practically speaking, I think the difference is trivial in your example. So long as there were no pedants in the room, you could probably get away with using the two words interchangeably. Yet there are contexts where you'd want to be more careful:



Since the industrial era began, the earth has begun warming.
Because the industrial era began, the earth has begun warming.




Those two sentences have very different meanings – in the first sentence, the temperature rise might have coincided with the dawn of the industrial age by chance. The second sentence unequivocally asserts that one caused the other.


Guidance for building a proper in game economy


I'm seriously thinking of building a space opera game which would share some of Machiavelli The Prince aspects regarding commerce: each player will be able to extract/build/buy/sell/donate a wide range of products (from ore to spaceships roughly).


However, I'm struggling with the economy aspect of it. Should the game define the prices once and for all? Should each player be able to determine his own buy/sell prices, and if so, how? How can I avoid over engineering this game economy mechanism, while still making it attractive for users?


Edit: thanks to your very nice input, some more information about the setup:



  • it's a "player only game," with no "computer managed player."

  • players start with a planet and some resources/units and then (try to) expand

  • players can be of multiple "species" with no proper relationship apart from the one they might make up => no possible notion of "central bank" or similar in the first place

  • consequently, I would prefer "not magic" on the economy, by that I mean a standard currency whose value would be determined by the system. However then I don't see how trading would be appealing, since bartering would be the only way, which feels a bit clumsy for the players. I was thinking of having some rare metal as the standard exchange medium, but then I wonder how would to include other basic economic attributes, such as the population's wealth...



Hopefully it doesn't look too daunting...




phrase usage - What does "What's up?" mean?



I usually hear people ask others "What's up?" when they first meet each other. But what does this sentence mean? Does it mean "How are you?" or "What are you doing?' And if asked with such phrase, how should I answer?




Thursday, November 24, 2016

grammar - Does one use a or an in this case?


I'm a bit confused in regards to a and an and I hope to clear that confusion. I've the following sentence:



was incomplete or a nonaborting error occured



The "a" there is where I'm confused. Normally from what I remember it is so that "an" is only used if the next word begins with a,e,i,o,u so from what I remember "a" would be correct there but my gut tells me "an" should be there as the "a" refers to error and not nonaborting.



So my question there is am I correct there or is my gutfeeling correct and if so why?




Can we add "more" with an adjective to convert it into comparative degree?



We say "more beautiful" to refer to someone's beauty as being greater than another person's or other people's beauty. Here we use more because beautiful has no comparative form. When we deal with the words that have a comparative form, we use the comparative, e.g., "he looks happier today"; here we are using happier because happy has a comparative form.


But even if an adjective has a comparative form, can we use more to compare with others? Do sentences such as "John is more tall than Jack", instead of "John is taller than Jack" sound odd?




android - per pixel based collision detection


I was wondering if anyone had any ideas on how to get per pixel collision detection for the android. I saw that the andEngine has great collision detection on rotation as well but couldn't see where the actual detection happened per pixel. Also noticed a couple solutions for java, could these be replicated for use with the Android SDK?


Maybe someone here has a clean piece of code I could look at to help understand what is going on with per pixel detection and also why when rotating it is a different process.


EDIT: Here is something I am working with right now.


public void getBitmapData(Bitmap bitmap1, Bitmap bitmap2){
int[] bitmap1Pixels;
int[] bitmap2Pixels;


int bitmap1Height = bitmap1.getHeight();
int bitmap1Width = bitmap1.getWidth();
int bitmap2Height = bitmap2.getHeight();
int bitmap2Width = bitmap2.getWidth();
bitmap1Pixels = new int[bitmap1Height * bitmap1Width];
bitmap2Pixels = new int[bitmap2Height * bitmap2Width];

bitmap1.getPixels(bitmap1Pixels, 0, bitmap1Width, 1, 1, bitmap1Width - 1, bitmap1Height - 1);
bitmap2.getPixels(bitmap2Pixels, 0, bitmap2Width, 1, 1, bitmap2Width - 1, bitmap2Height - 1);


}




reasoning - Pick out the word in each of the following that is different (Odd One Out)


Pick out the word in each of the following that is different (Odd One Out)


Intuitive, initiative, talkative, quantitative


The answer is - initiative.


PS - I just want to know the reason or the logic used here to pick 'initiative' the odd one out.


Meanings:



Intuitive : when one feels something to be true without conscious reasoning. Initiative : ability to initiate and assess things, to take charge before others do. Talkative : one who talks a lot. quantitative : ample quantity



Answer



"Initiative" is the only noun. (The definitions aren't the most helpful, because they make it sound like 3 and 4 are also nouns. They're adjectives.)


as answered by @LukeSawczak


Wednesday, November 23, 2016

2d - Which axis-aligned line does an AABB collide with first?


I am making the collision resolution system for my 2d top-down game, and I managed to find a solution where I query which surfaces of other AABBs the current entity can collide with in the next frame.


To resolve the new location of the player however, I need to find which surface the entity collides with first.


I have a list of lines, which is LinkedList collidedLines. a line is {x1,y1,x2,y1}, however in this case, they are axis-aligned, so either x1==x2 or y1==y2.


I also have the entity, which has the following properties:


int posX
int posY
int speedX // The amount to move in the
int speedY // next step of the game.
int size // The halfwidth of the square AABB.


How can I find the first line the entity collides with? Thanks for your help!



Answer



You can also achieve this with the following steps:




  • 1/ Find the intersection points between the infinite lines passing though the four sides of the AABB and the infinite line passing through the entity position (pre-collision) which use the entity speed vector as slop. (You can either find a collision point or an undefined number, which corresponds to parallels or overlapping lines)




  • 2/ Once you know the intersection points (if they exist) you can search for those that are into the segment bounds.





  • 3/ Finally, if there is still multiple points on the list (the velocity vector can pass through multiple sides), you can search for the closest point from the entity origin using the magnitudes of the vector from the intersection to the entity origin.






More details:




  • 1/ Find intersections





    • a / Determine the implicit lines ( Ax + Bx = D ) using their parametric forms ( P(t) = Po + tD ).



      Point origin: Po = [posX, posY]
      Direction vector: D = [speedX, speedY]

      A = D.y = speedY
      B = -D.x = -speedX
      D = (Po.x * D.y) - (Po.y * D.x) = (posX*speedY) - (posY*speedX)

      Ax + By = D <====> (speedY*x) + (-speedX*y) = (posX*speedY) - (posY*speedX)



      I used the entity point values to illustrate the method, but this is exactly the same method to determine the 4 side implicit lines (Use Po = [x1,y1] and D = [ x2-x1 ; y2-y1 ] instead).





    • b / Next, to find the intersection of two implicit lines we can solve the following system:



      A1x + B1x = D1 <== Line passing through the entity point with the speed vector as slop.
      A2x + B2x = D2 <== One of the lines passing through the AABB sides.



      which yields the following coordinates for the interception:



      Interception x = ((B2*D1) - (B1*D2)) / ((A1*B2) - (A2*B1))

      Interception y = ((A1*D2) - (A2*D1)) / ((A1*B2) - (A2*B1))



      If the denominator ((A1*B2) - (A2*B1)) equals zero, then the both lines are parallels or overlapping, otherwise you should find an intersection.






  • 2/ Test for the segment bounds. As this is straightforward to verify, there is no needs for more details.





  • 3/ Search for the closest point. If there is still multiple points on the list, we can find which side is the closest to the entity origin point.




    • a / Determine the vector going from the intersection point to the entity origin point



      V = Po - Int = [Po.x - Int.x ; Po.y - Int.y ]





    • b / Compute the vector magnitude




      ||V|| = sqrt( V.x² + V.y² )




    • c / find the smallest one.






Note: this is probably not the most efficient way to do it, but as it still can helps some people i think it worth to be added.



Tuesday, November 22, 2016

passive voice - "is said to" causes ambiguity



P1: She is said to work 16 hours a day.


P2: It is said that she works 16 hours a day.



The Murphy's grammar says that passive P1 is equivalent to passive P2.


But let's transform these passive statements to their active forms:




A1: Somebody says to her to work 16 hours a day.


A2: Somebody says that she works 16 hours a day.



How can P1 be equivalent to P2 if their active forms have different meanings? In other words P1 may mean either A1 or A2. Should not it cause ambiguity?



Answer



She is said to work 16 hours a day


This is in fact a difficult construction for learners because actually the construction is not grammatical. But it is complicated to show what has happened here. There are several things to explain.



a) The neighbour saw the boy break the window of the house across the street.




Here "to break" is followed by an accusative (object case) + bare infinitive. English can turn such a sentence into passive: The boy was seen to break the window.



b) The officer ordered the soldiers to attack.



Even if in other languages "the soldiers" would be seen as a dative object (indirect object) and other languages would keep the dative object in a passive sentence English does not say:



To the soldiers (it) was ordered to attack.



English shifted the dative to a nominative and says:




The soldiers were ordered to attack.



A passive that in other languages (e.g. German) is not possible. German would maintain the dative in the passive sentence.


This shift of case in passive sentences is a peculiarity of English, simply because dative (without "to") and accusative have the same form. And English does not care whether such a construction is a-grammatical or not.


So if you have a pasive sentence like



She is said to work 16 hours a day (1)



the "she" is a shifted case. Actually is should be




"Of her it is said" to work 16 hours a day.



So you can't turn a sentence such as (1) into an active sentence according to normal rules. Your assumption that the active is



A1: Somebody says to her to work 16 hours a day.



is simply wrong. That isn't the sense of the passive sentence.


The sense is:



People say of her that she works 16 hours a day.




I hope you won't get lost with my explanation. It is the first time that I try to explain such a complicated thing such as passive sentences with shift of case. And it is possible the native speakers don't agree with my view. And I might guess that a lot of native speakers have lost the feeling for the fact that this passive contains a shift of case.


word choice - "aged X" vs. "age X"


Should it be "aged 85" or "age 85", when you want to indicate someone's age?



Answer



It is aged, such as in the following sentence:



They have two children aged six and nine.



You could also use aged as in "volunteers aged between 25 and 40."


Notice that aged in phrases like my aged aunt or the aged means very old/very old people.



determiners - much - very much, many - very many?


In case of uncountables, the large amount expressed by much like in



much water, much money, much sand



can be increased by prepending very like in



very much water, very much money, very much sand



But in case of countables, the large amount expressed by many like in




many trees, many people, many children



can not be increased by prepending very? So, the following is wrong?



very many trees, very many people, very many children



Is there a comprehensible explanation for this difference?


And what is/are the correct expression(s) to increase many?




plural forms - Why "was" not "were" in "Nearly £20 was taken from my bank account"


I've always said "$100 were taken" not "$100 was taken" because I thought $100 is plural. Could you explain why "was" not "were"? Any other helpful notes about the issue would be appreciated.



Nearly £20 was taken from my bank account




Answer



Because phrases that indicate the amount of sum, time, distance, weight, temperature, etc. are treated as singular:



10 million pounds is a lot of money.




= This sum is a lot of of money.



50 liters of petrol fills my car.



= This quantity fills my car.



Five kilometers is a long way to walk.



= This distance is a long way to walk.




Fifty degrees is a very high temperature.



= This temperature is a very high temperature.


And so on.


software engineering - Time critical events based on framerate


Problem Description


Basically, I've made a "programming game" in which I've made my own scripting language. It is a completely standard Lunar Lander game, though instead of directly controlling the lander using keyboard input, it instead fires a sequence of commands you have provided through the scripting language I made. This all works, and I've hit a critical problem.


So essentially, using the scripting language, you specify something like After 5 seconds, activate thrust for 10 seconds, and then after 2 seconds, rotate the lander for 4 seconds. The goal is then to chain together a sequence of commands which will get you to land the lander safely.


Of course, this comes with one problem. If you repeat the sequence of commands, each command will have to be fired at exactly the same spot in the level, that is, after x amount of seconds, but also with the lander being in the exact same spot. If you did not use timer-based movement, sure you could indicate that a command should activate after 5 seconds, but the lander moving at 60 FPS would have moved way further than a lander moving at 30 FPS.


Why of course, I thought I would simple just make the lander use timer-based movement so it is independent of FPS (I am using the very standard approach of taking the amount of time passed last frame, and multiplying it to a constant move speed). Then I would count seconds using the system clock. So the after x amount of seconds, the lander would be in the same spot in the level when the command activates.


Unfortunately, this approach do not work. Every time I run a sequence of commands, they will be activated with, sometimes very slight, variations, making it impossible to actually get a consistent and reliable path for the lander.



My Question


So my question is, am I tackling this problem a completely wrong way? What exactly do you do when it is absolutely critical that timed events defined by the user will activate at exactly the same time and spot in a level? I seem to be quite stuck with this question.



Answer



The general solution to this problem is to have an update function with a completely fixed timestep. Unity calls this FixedUpdate, in physics engines you can run the simulation several times before updating the world, etc. but it's all the same concept.


While this fixed update function will always be slightly out of sync with everything else in your world, if you select a small enough timestep (1/60 or 1/30 or so), this will be unnoticable. Another thing to remember is that you only need to use this update function for things that need to be absolutely deterministic, so it doesn't hog your cpu even if you need to run it several times before updating the world. And if it's not completely obvious, this function should have absolutely nothing to do with your system clock - this runs on a "simulated" clock that you keep track of, and that never actually steps over the real system clock, but is otherwise independent.


Having said all this, in your case there may be simpler solutions. You can pre-calculate the path for your unit and interpolate on that path. The idea behind this solution is that you think of your unit's movement as a continous function instead of a physical simulation.


Alternatively you can try to "snap" your ship to the correct position after every movement, so the arithmetic error doesn't add up. However this may cause visual glitches if your fps is low or not constant.


Monday, November 21, 2016

physics - How can I convert a 2D bitmap (Used for terrain) to a 2D polygon mesh for collision?


So I'm making an artillery type game, sort of similar to Worms with all the usual stuff like destructible terrain etc... and while I could use per-pixel collision that doesn't give me collision normals or anything like that. Converting it all to a mesh would also mean I could use an existing physics library, which would be better than anything I can make by myself.


I've seen people mention doing this by using Marching Squares to get contours in the bitmap, but I can't find anything which mentions how to turn these into a mesh (Unless it refers to a 3D mesh with contour lines defining different heights, which is NOT what I want). At the moment I can get a basic Marching Squares contour which looks something like this (Where the grid-like lines in the background would be the Marching Squares 'cells'):


Marching Squares result


That needs to be interpolated to get a smoother, more accurate result but that's the general idea. I had a couple ideas for how to turn this into a mesh, but many of them wouldn't work in certain cases, and the one which I thought would work perfectly has turned out to be very slow and I've not even finished it yet! Ideally I'd like whatever I end up using to be fast enough to do every frame for cases such as rapidly-firing weapons, or digging tools.


I'm thinking there must be some kind of existing algorithm/technique for turning something like this into a mesh, but I can't seem to find anything. I've looked at some things like Delaunay Triangulation, but as far as I can tell that won't correctly handle concave shapes like the above example, and also wouldn't account for holes within the terrain.


I'll go through the technique I came up with for comparison and I guess I'll see if anyone has a better idea. First of all interpolate the Marching Squares contour lines, creating vertices from the line ends, and getting vertices where lines cross cell edges (Important). Then, for each cell containing vertices create polygons by using 2 vertices, and a cell corner as the 3rd vertex (Probably the closest corner).


enter image description here


Do this for each cell and I think you should have a mesh which accurately represents the original bitmap (Though there will only be polygons at the edges of the bitmap, and large filled in areas in between will be empty). The only problem with this is that it involves lopping through every pixel once for the initial Marching Squares, then looping through every cell (image height + 1 x image width + 1) at least twice, which ends up being really slow for any decently sized image...




Answer



I haven't worked with 2D physics engines before, I'm not sure exactly how the collision mesh is supposed to look.


If it's simply a set of 2D triangles, then you should look into triangulation methods. For example, constrained Delauney triangulation.



Delaunay triangulations maximize the minimum angle of all the angles of the triangles in the triangulation; they tend to avoid skinny triangles.



Which is a good thing when it comes to rendering these triangles at least, and may or may not be good for collision detection as well.


A constrained Delauny triangulation incorporates fixed edges, which would be your detected edges. This library may provide what you need


Sunday, November 20, 2016

sentence construction - usage of "all of the tasks" and "all the tasks"


which of the following sentences is the most common in English?



"all of the tasks were performed well." "all the tasks were performed well."




unity - Does interfacing not work as well when it comes to games development?


I'm currently at the start of a project, and I'm following the wisdoms of my day-to-day career as a C# developer for large web applications.


Currently I have set up a bunch of interfaces. Notable of these are IActor, IHuman, ISelectable, IUIAction & IHealth.



I also have a Person class. Person implements IHuman (which implements IActor), ISelectable and IHealth and also inherits from MonoBehaviour.


ISelectable has a property of IEnumerable Actions. Actions have a property of Action click. Im sure you can see where I am going with this...


The intended goal is that if a class inheriting from MonoBehaviour (person in this case) implements ISelectable and is attached to a GameObject that is clicked, a list of buttons representing ISelectable.Actions is displayed on the screen. If a class implements IHealth, a healthbar will be displayed on the screen etc etc...


Now, the problem I see is I'm going to end up with huge classes. The classes are going to need properties for their health, theyre going to need properties for their actions, theyre going to need properties for what the UI panels title should be when selected, and anything else that comes up as development progresses... My other thought is to remove the interfaces like IHealth from the class itself and have them be their own class, such that IHealth will only mean a class has a property that is of the class Health and Health has all the properties relating to an objects health levels... but this removes authority from the class as to what control it has over its health.


Whats the industry standard for this sort of thing, and how can I implement it effectively in my game?



Answer



Unity emphasizes a philosophy called Composition Over Inheritance.


The idea is that rather than thinking of what a particular entity "is":



A soldier is a unit which is selectable and which is damageable.




You think of the set of behaviours/features it "has":



A soldier has a selection behaviour and a taking-damage behaviour



So then, as you suggest in the question, you can break these responsibilities off into their own MonoBehaviour components:




  • Selectable (watch out for naming conflicts with UnityEngine.UI.Selectable) can respond to click events and hold information needed to draw a selection highlight.





  • Damageable can track the current health, resistances, and handle firing off low-health state change events or destruction animations.




etc.


Your "soldier" might not exist as a class anywhere in code - it's just a particular combination of components and parameter values that gives the set of behaviours you want, ie. an entity with both Selectable and Damageable components attached (among others).


This move from defining each entity in code to doing it in data gives us a number of outcomes that are useful in game development:




  • Non-programmers on the team can take a more active role in developing game behaviour. If your coders provide a good set of building-block components, the level designers can go to town experimenting & combining them in new ways, without waiting on a coder to write a class that glues-together all the bits they need in a new standalone class.





  • Occasionally you'll get new behaviour "for free" out of this combinatoric play. For example, take an enemy and remove the Damageable component - boom, now you have invulnerable enemies, without a coder creating a special mode or flag. ;)




  • We can create and modify these compound entities on the fly while the game is running, without recompiling code or relying on edit-and-continue functionality.




  • This style helps encourage small modular components, each easy to understand and modify on their own, rather than massive sprawling classes with many responsibilities as you describe - a common pitfall in game development, with player classes especially!





  • A more modular, data-driven architecture tends to have fewer bottlenecks for exclusive checkouts & merging when multiple developers are collaborating on a cluster of features.




  • This pattern can also make it easier to develop tools like level editors or support user generated content, since all the game entities are just data files that can be modified without code changes.




That's not to say you can't or shouldn't use interfaces - they're still a great tool to have in your toolbox, especially when you have some kind of well-defined need in your game and multiple ways you might want to serve that need.


For example, maybe your base AI movement logic knows it wants to move into firing range for whatever weapon it's using - but that weapon might vary from one unit archetype to another. You could introduce an IAttackBehaviour interface exposing methods to select a target, locate a good attack position for the movement behaviour to reach, and to execute an attack. Then you could implement this in concrete types likeMeleeAttackBehaviour, SniperAttackBehaviour, GrenadierAttackBehaviour, etc. Your movement behaviour just needs to know it "has" an IAttackBehaviour attached, but doesn't need to implement these details itself for every archetype flavour. This allows AI designers to mix & match components as they need, while maintaining a clear contract for how the movement & attack behaviours communicate.


Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...