Tuesday, December 31, 2019

education - What are the fundamentals of game development?




I completely do not understand how a video game can be coded.


I'm a beginner programmer and only have experience writing console applications that do math and what not. I do not understand how these logical processes can make images move on the screen (video games). Obviously if I jumped into a game development book or something like that I would understand but I am currently still getting a grasp of the fundamentals of programming in general. Could anyone give a simple explanation, coding wise, on the jump between making a computer do simple math to making a computer produce amazing graphical programs such as video games? Maybe there are some introductory videos someone can point me to?



Answer



Assuming you're an absolute beginner in programming, and in order to base my example on something you might know, while writing a console application which has a menu where you want the user to choose among the available option, what will you do first?


If you thought about creating your menu, you got a point, but what if after the user pressed a key which is not part of the available option,



  1. will your application exit, or

  2. shall it continue until the user presses the "Exit" key?



My bet would be #2, the application shall continue until the user expressly press the key to exit from the console application.


A game is somehow the like! When do you want the game to exit? When the user chooses to, right? Hence, the action or the game menu has to last until the user wishes to exit. Then, you will have to create a loop that tells the program to continue until this very key to exit has been pressed.


You've just been introduced to the Game Loop. A game is just another program that runs until it is expressly exited by the user.


While in the game loop, when you're playing the game, the moves are images drawn on the screen at specific coordinates. When the user/player presses a directional key such as [Left], then you make your image refresh its coordinates while decrementing its X coordinate so that you give the impression for a motion toward the left direction. You got to get these inputs in order to get what action the player wants his character/ship to do next. Then, the Game Loop continues to loop until you can get another desired action from the player, until the game is exited.


Well, I'm afraid this answer begins to be fairly long enough, so allow me to point you to two other questions that might be of interest to you, I hope.



  1. Where to start writing games, any tutorials or the like?

  2. Moving my sprite in XNA using classes.


This third link is not about how to begin to write games, but about how to make a sprite move on the screen. Since you also asked about how to make the graphics move on screen, I thought this could interest you.



I hope this helps! =)


Monday, December 30, 2019

word choice - Do caves have "alleys" or "paths"?


Which one is the appropriate use for caves?


The evenness of bat species is influenced by the length of caves path (?)


The evenness of bat species is influenced by the length of caves alley (?)




meaning - What does "unplugged" mean or imply in this headline?


What does "unplugged" mean or imply in the headline



Trump unscripted and unplugged



screenshot of CNN international edition




algorithm - Creating non-rectangular hotspots and detecting clicks


Say for a game with irregular hotspots (say Risk, or a strategy game like Paradox's Hearts of Iron or Crusader Kings), how do you





  1. Define a non-rectangular hotspot of irregular shape (much like a territory on a map?), in code?




  2. What tool can you use to trace out the hotspot and import into your game?




  3. What is the algorithm for detecting if someone has clicked within such a hotspot?






Answer



Besides the vector/polygon approach, another way to do this is to use a bitmap.


If each "color" in the bitmap represents a territory (France, Belgium etc.), then it's simply a matter of figuring out which pixel in the bitmap was clicked, looking up the color and determining if that color represents the territory of interest. You can even represent overlapping territories with specific colors, or treat your colors as a bitmask of territories.


In terms of tools, have your artists/content producer author the bitmap in any pixel editing tool. For example if you use Photoshop or the Gimp, you could represent different territories (France, Belgium etc.) as either named layers or as 1 layer but distinguishing the territories based on colors. You would then write a tool to convert the image/layers into a format that is suitable for game-internal purposes.


The game internal format would very likely be per-row run-length compressed (see: http://en.wikipedia.org/wiki/Run-length_encoding). You should be able to achieve very good compression ratios this way, as adjacent pixels on rows will very often belong to the same territory. The algorithm then becomes, for the current y coordinate of the mouse, traverse that row and figure out which run it belongs to, and therefore which corresponding territory.


networking - How can I simulate a bad internet connection for testing purposes?


I am developing an online multiplayer game. It works well when I test it on the local area network, but before I release it I would like to test how the user-experience works out for someone who has not such a good connection to the server. How can I simulate a bad internet connection with high latency, low bandwidth, jitter and occasional packet loss when in a local environment?




Sunday, December 29, 2019

articles - Singular Vs plural while making a general statement


I'm having a hard time understanding whether to use plural or singular while making general sentences.


Doing a bit of research I found both can be used. For example:





  1. Dogs are loyal animals.







  2. A dog is a loyal animal.





(Both these sentences are talking about all/any dogs in general)





  1. A child needs care.







  2. Children need care.





(Both these sentences talk about all/ any children in general).


Now, as for the question:

Recently, I looked up in the internet as to when is a definite article used. It says "We use the definite article in front of a noun when we believe 'the reader' knows exactly what we are referring to."


I think this statement is a general statement about the use of definite article. My first question, am I right in thinking that this is a general statement?


Second question is, what if we use 'readers' in place of 'the reader'? Will there be a change in meaning then? I'm asking this question because if this is a general statement then if I use 'a reader' or 'readers' in place of 'the reader' then it should all mean the same, i.e., all of them should be expressing 'any reader' just like the examples above (1 to 4). Right?


Another example:



(1) Banks are financial institutions where 'a lender' meets 'a borrower'.



I guess this is also a general statement about banks. So can I phrase this sentence like this without any change in meaning?



(2) Banks are financial institutions where 'lenders' meet 'borrowers'.




In sentence (1), 'a lender' expresses just one lender or any lender? In sentence (2), 'lenders' expresses more than one lender or any lender in general?




questions - Is there any good usage example for “Did I tell you”?



As far as I can tell, rephrasing Wikipedia, Simple Past draws attention to actual occurrence of the past action or event, as opposed to its present consequences. (See Present perfect).


Doesn't asking someone a question usually imply some consequences?



Answer



Here is an example. An man and wife are talking and the man says: "Did I tell you about the time I ate ten hamburgers?" The wife sighs and says "Yes honey, you've told me that story a hundred times!" (This sounds better with "Have I told you […]?" instead of "Did I tell you […]?")


or


A man says to his wife "Did I tell you to turn the oven off before we left?" "Did I tell you […]?" is requesting a response.


c++ - Circle-Rectangle collision resolution


I have a non axis aligned rectangle, like a car, in my game. I have to check and resolve the collision between the rectangle and circle, which is stationary.


I have found lots of ways to determine the collision, but couldn't find anything on resolving it. It is clear that i have to push back the rectangle away if there is a collision, but I can't find a proper way.



Is there a way of handling and resolving the collision between a rectangle and a circle? Like an algorithm?


I am developing in c++.



Answer



@ErikEsTT: the OP was specifically asking for more than a boolean "is intersecting", they need closest points or penetration depth or some other meaningful measurement of collision, not just a yes/no.


To answer the OP's question, circle-vs-rectangle can be implemented using a signed distance query between a rect and a circle. Probably the easiest thing to do is to transform the circle into the rect's local space (where it's an axis-aligned box) and then perform a point-vs-AABB signed distance query.


There is a brilliant (but quite confusing) signed box distance function here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm , or any good book (e.g RTCD or GeomTools) should have similar queries explained.


verbs - In Which Position To Place Adjective In Infinitive Form Of It


I Want to know when we use infinitive verb as an adjective what is the position of the to-infinity adjective as i noticed in this url examples it always use the last postilion https://www.grammar-monster.com/glossary/infinitive_form.htm


Give him an ornament to polish.


(The infinitive modifies ornament. This means it is functioning as an adjective.)


I need a volunteer to take the minutes. (The infinitive modifies volunteer. This means it is functioning as an adjective.)




sentence construction - When you cannot recognize identical twins


Please imagine your neighbor has identical twin sons and since you've met them you've been unable to recognize them properly. It seems strange to you and you're talking to a friend. I was wondering if someone could let me know which one of my self-made sentences below works here:





  • I always mistake twins up.




  • I always muddle twins up.





  • I always mix twins up.







game design - How to implement an experience system?


I'm currently writing a small game that is based on earning experience when killing enemies. As usual, each level requires more experience gain than the level before, and on higher levels, killing enemies awards more experience.



But I have a problem balancing this system. Are there any prebuilt algorithms that help to calculate how the experience curve required for each level should look like? And how much experience an average enemy on a specific level should provide?



Answer



You would want some kind of exponential curve, probably something like:


base_xp * (level_to_get ^ factor)

base_xp is a constant that decides how much xp you need to go up a level.
level_to_get is the level you are aiming for; at level 1, this will be level 2.
factor is another constant that decides how much of an increase of xp you need for each level.


Having a base_xp of 200 and a factor of, say, 2 gives something like this:


enter image description here



Whereas a base_xp of 50 and a factor of 2.6 gives:


enter image description here


The second has a much lower starting xp rate, but you need more xp very quickly.


As for monster xp, this is something you want to test. Try out various values. You want something that is not too high (you'll quickly become overpowered) yet not too low (players don't want to grind). Think about how many 'standard' enemies you would want the player to kill for level 10->11, for example.


xna - Mouse location is off due to camera


I'm building a top down shooter but I have a little issue with my camera and mouse. When I add the camera that I use to my game (see here) my mouse pointer seems to be in the wrong location. When I call my Mouse.GetState().X or Y the location seems to be about 300 pixels off. I've looked all over the net but I just can't find the solution.


I'm pretty new to coding, so I'll just post my main and my camera class. My objective is to get the green circle on the actual position of my mouse.



Camera class:


using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace ZombieSurvival
{
public class Camera2D
{
protected float _zoom; // Camera Zoom
public Matrix _transform; // Matrix Transform

public Vector2 _pos; // Camera Position
protected float _rotation; // Camera Rotation

public Camera2D()
{
_zoom = 1.0f;
_rotation = 0.0f;
_pos = Vector2.Zero;
}


// Sets and gets zoom
public float Zoom
{
get { return _zoom; }
set { _zoom = value; if (_zoom < 0.1f) _zoom = 0.1f; } // Negative zoom will flip image
}

public float Rotation
{
get { return _rotation; }

set { _rotation = value; }
}

// Auxiliary function to move the camera
public void Move(Vector2 amount)
{
_pos += amount;
}
// Get set position
public Vector2 Pos

{
get { return _pos; }
set { _pos = value; }
}

public Matrix get_transformation(GraphicsDevice graphicsDevice)
{
_transform = // Thanks to o KB o for this solution
Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *
Matrix.CreateRotationZ(Rotation) *

Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) *
Matrix.CreateTranslation(new Vector3(graphicsDevice.Viewport.Width * 0.5f, graphicsDevice.Viewport.Height * 0.5f, 0));
return _transform;
}


}
}

Game:



using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
//using Microsoft.Xna.Framework.Graphics.GraphicsDevice.SetCursorProperties;

namespace ZombieSurvival
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

int cursorX, cursorY;

Camera2D camera;

Player player;
Texture2D playertex;
Texture2D bulletTex;
Texture2D zombieTex;

public Game1()

{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";

}

protected override void Initialize()
{
this.IsMouseVisible = true;
graphics.IsFullScreen = true;

graphics.ApplyChanges();
Mouse.SetPosition(0, 0);
cursorX = Window.ClientBounds.X + Mouse.GetState().X;
cursorY = Window.ClientBounds.Y + Mouse.GetState().Y;

//graphics.

base.Initialize();
}


protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
playertex = Content.Load ("player");
bulletTex = Content.Load("bullet");
zombieTex = Content.Load("zombie");

player = new Player(new Rectangle(100, 100, 50, 50), playertex, 5, bulletTex);


// TODO: use this.Content to load your game content here
}

protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

protected override void Update(GameTime gameTime)
{

player.Update();

/*if (IsActive)
{
MouseState mouseState = Mouse.GetState();
int cx = graphics.GraphicsDevice.Viewport.Width / 2;
int cy = graphics.GraphicsDevice.Viewport.Height / 2;
int x = mouseState.X - cx;
int y = mouseState.Y - cy;
Mouse.SetPosition(cx, cy);

}*/

base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);



Camera2D cam = new Camera2D();
cam.Pos = new Vector2(player.playerPosition.X, player.playerPosition.Y);
// cam.Zoom = 2.0f // Example of Zoom in
cam.Zoom = 0.5f; // Example of Zoom out


//// if using XNA 3.1
spriteBatch.Begin(SpriteBlendMode.AlphaBlend,
SpriteSortMode.Immediate,
SaveStateMode.SaveState,

cam.get_transformation(graphics.GraphicsDevice));

player.Draw(spriteBatch);
spriteBatch.Draw(zombieTex, new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 50, 50), Color.White);
// Draw Everything
// You can draw everything in their positions since the cam matrix has already done the maths for you

spriteBatch.End();

//Console.WriteLine(camera.Pos);


/*if (camera._pos.X - player.PlayerRect.X >= 100)
{
camera.Pos = new Vector2(camera.Pos.X - player._PlayerSpeed, camera.Pos.Y);
}

if (camera._pos.X - player.PlayerRect.X <= -300)
{
camera.Pos = new Vector2(camera.Pos.X + player._PlayerSpeed, camera.Pos.Y);
}


if (camera._pos.Y - player.PlayerRect.Y >= 0)
{
camera.Pos = new Vector2(camera.Pos.X, camera.Pos.Y - player._PlayerSpeed);
}

if (camera._pos.Y - player.PlayerRect.Y <= 250)
{
camera.Pos = new Vector2(camera.Pos.X, camera.Pos.Y + player._PlayerSpeed);
}*/


/*spriteBatch.Begin();
player.Draw(spriteBatch);

spriteBatch.End();*/

base.Draw(gameTime);
}
}
}


I realy hope someone has a solution for this, because I'm stuck right now. I'd really appreciate the help.



Answer



The positions that you store within cursorX and cursorY hold the position of the cursor relative to top left corner of your screen monitor (since you add the ClientBounds to it). I'd guess that you used that exact position when drawing the circle, and since the Draw function takes a position relative to the top left corner of the game window, you'd be off by the position of the ClientBounds.


But I have to ask: why are you holding the "real" value of the mouse position? Is there any particular reason why you're storing it instead of the usual positions return by Mouse.GetState().X and Mouse.GetState().Y?




EDIT


After looking at your code, I think I found where the main problem is.


When defining the transformation matrix for your camera, you apply a translation to the center of the screen, like so:


_transform =       // Thanks to o KB o for this solution

Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *
Matrix.CreateRotationZ(Rotation) *
Matrix.CreateScale(new Vector3(Zoom, Zoom, 0)) *
Matrix.CreateTranslation(new Vector3(graphicsDevice.Viewport.Height * 0.5f,
graphicsDevice.Viewport.Width * 0.5f, 0));

the relevant part being:



Matrix.CreateTranslation(new Vector3(graphicsDevice.Viewport.Height * 0.5f, graphicsDevice.Viewport.Width * 0.5f, 0));




From the comment I'm guessing that someone proposed this solution and it probably is perfectly fine but here is how I've changed your code to make it work:


Ok, so I changed a couple of things.


First, I removed the translation to the center, making the camera point at the top left corner, like so (removed the last translation):


_transform =       // Thanks to o KB o for this solution
Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *
Matrix.CreateRotationZ(Rotation) *
Matrix.CreateScale(new Vector3(Zoom, Zoom, 0)));

Then, in your Game1.cs file, I put the player.Draw(spriteBatch) call within the spriteBatch.Begin() call affected by the camera's transformations, since the player should be affected by the camera. Like so:


spriteBatch.Begin(SpriteBlendMode.AlphaBlend,

SpriteSortMode.Immediate,
SaveStateMode.SaveState,
cam.get_transformation(GraphicsDevice));

player.Draw(spriteBatch);

spriteBatch.End();

Basically, you just have to think differently from usual. It's all about understanding the difference between screen positions and world positions (well, that's how I call them).


Screen positions are those that you use when you call spriteBatch.Draw(). They represent positions on your screen monitor.



World positions are those within your virtual world. You have to convert these to screen positions before drawing (by using the camera transformation matrix with a spriteBatch.Draw() call).


To illustrate the difference, here is an example: Let's say that you have a map with a size of 2500 x 2500. Your game window has a size of 500 x 500. Here is a quick drawing of that game world:


The green rectangle represents your game world (the one with a 2500 x 2500 size). The red rectangle represents the camera view (the size of the game screen). The blue rectangle represents an object within the world.


Now, the world position of that object would be (600, 600), because the world position is independent of where the camera is.


The screen position, however, is relative to the top left camera position. So its screen position (where it is drawn) would be (100, 100).


I think it's pretty clear with that example that to convert from a screen position to a world position, you must add the camera's position. To convert from world position to screen position, you must subtract the camera's position.


So, anything that is part of your world holds a world position (like a player or bullets). Anything that is part of the user interface holds a screen position (like the amount of ammo left or the aim of the player). All you have to do is put all the objects drawn using world positions within the spriteBatch.Draw() call using the camera. All objects independent of the camera should be drawn on the next spriteBatch.Draw() call.


So, let's go ahead and hide these implementation details within your Camera2D class:


public Vector2 GetScreenPosition(Vector2 worldPosition)
{

return worldPosition - Pos;
}

public Vector2 GetWorldPosition(Vector2 screenPosition)
{
return screenPosition + Pos;
}

I guess that you were using a translation to the center of the screen to keep the player centered. So let's place the player to the center within the LoadContent() function:


player = new Player(new Rectangle(

(int)(GraphicsDevice.Viewport.Width / 2f),
(int)(GraphicsDevice.Viewport.Height / 2f), 50, 50),
playertex, 5, bulletTex);

Next, let's add camera movement support (I changed the code you were using since I'm not applying the center-screen camera translation anymore):


Vector2 cameraDirection = Vector2.Zero;
const int TO_MOVE_SIDE_DISTANCE = 150; // the distance to the side required to move.

Vector2 playerScreenPosition = cam.GetScreenPosition(new Vector2(
player.PlayerRect.X, player.PlayerRect.Y));

Rectangle playerScreenRect = new Rectangle((int)playerScreenPosition.X,
(int)playerScreenPosition.Y, player.PlayerRect.Width, player.PlayerRect.Height);

//We make the camera follow the player if he goes too close to the sides.
if (playerScreenRect.Left < TO_MOVE_SIDE_DISTANCE) // move to the left
{
--cameraDirection.X;
}
if (playerScreenRect.Right > GraphicsDevice.Viewport.Width - TO_MOVE_SIDE_DISTANCE) // move to the right
{

++cameraDirection.X;
}
if (playerScreenRect.Top < TO_MOVE_SIDE_DISTANCE) // move up
{
--cameraDirection.Y;
}
if (playerScreenRect.Bottom > GraphicsDevice.Viewport.Height - TO_MOVE_SIDE_DISTANCE) // move down
{
++cameraDirection.Y;
}


cam.Pos += cameraDirection * player._PlayerSpeed; // move with the player.

So now the camera works. There's a new bug though: bullets start at the player's position, but are not aimed at the right place when the camera has been moved.


This is because we're aiming using the screen position (the cursor position, actually), when really we're aiming within the world. So, we have to convert the cursor's position to a world position to be able to aim properly. The shooting happens inside the Player class:


Vector2 targetWorldPosition = cam.GetWorldPosition(
new Vector2(Mouse.GetState().X, Mouse.GetState().Y)); // we're aiming at an object within the world.

BulletList.Add(new Bullet(new Vector2(_PlayerRect.X, _PlayerRect.Y),
targetWorldPosition, 5, bulletTex,

new Rectangle(_PlayerRect.X, _PlayerRect.Y, bulletTex.Width,bulletTex.Height), 90));

Notice that we're passing the target world position to the Bullet constructor now.


There you go, you have a working camera system.


I'm sure you could go with the centered transformation that you had at first, but I'm not used to that system. If you ever want to change system, just change the GetWorldPosition function, the GetScreenPosition function and the matrix transformation. Since those are hidden within the Camera2D class, changing the implementation details will be easy.


I hope this helped!




EDIT 2


To remove the problem where the camera transformation is applied twice when drawing the tile map, you must change this part of the code:


spriteBatch.Begin(SpriteBlendMode.AlphaBlend,

SpriteSortMode.Immediate,
SaveStateMode.SaveState,
cam.get_transformation(GraphicsDevice));

#region mapDrawing

Vector2 firstSquare = new Vector2(cam.Pos.X / Tile.TileWidth, cam.Pos.Y / Tile.TileHeight);
int firstX = (int)firstSquare.X;
int firstY = (int)firstSquare.Y;


Vector2 squareOffset = new Vector2(cam.Pos.X % Tile.TileWidth, cam.Pos.Y % Tile.TileHeight);
int offsetX = (int)squareOffset.X;
int offsetY = (int)squareOffset.Y;

if (Mouse.GetState().LeftButton == ButtonState.Pressed)
{
Console.WriteLine(firstSquare + " " + squareOffset);
}

for (int y = 0; y < squaresDown; y++)

{
for (int x = 0; x < squaresAcross; x++)
{
if(firstY >=0 && firstX >=0)
foreach (int tileID in myMap.Rows[y + firstY].Columns[x + firstX].BaseTiles)
{
spriteBatch.Draw(
Tile.TileSetTexture,
new Rectangle(
(x * Tile.TileWidth) - offsetX, (y * Tile.TileHeight) - offsetY,

Tile.TileWidth, Tile.TileHeight),
Tile.GetSourceRectangle(tileID),
Color.White);
}
}
}

#endregion

player.Draw(spriteBatch, cam);



spriteBatch.End();

The whole problem is that you tell the spriteBatch to use your camera's transformation with this statement:


spriteBatch.Begin(SpriteBlendMode.AlphaBlend,
SpriteSortMode.Immediate,
SaveStateMode.SaveState,
cam.get_transformation(GraphicsDevice));


but then you use the camera's position to find firstSquare and squareOffset (cam.Pos.X / Tile.TileWidth, cam.Pos.Y % Tile.TileHeight, etc).


To avoid applying the transformation twice, you must use the camera's transformation only once by either moving that Draw call on a different spriteBatch.Begin call that doesn't apply the transformation, or by removing all the calculations involving the camera's position. I chose the latter since it makes simpler code:


spriteBatch.Begin(SpriteBlendMode.AlphaBlend,
SpriteSortMode.Immediate,
SaveStateMode.SaveState,
cam.get_transformation(GraphicsDevice));

#region mapDrawing

for (int y = 0; y < squaresDown; y++)

{
for (int x = 0; x < squaresAcross; x++)
{
foreach (int tileID in myMap.Rows[y].Columns[x].BaseTiles)
{
spriteBatch.Draw(
Tile.TileSetTexture,
new Rectangle(
(x * Tile.TileWidth), (y * Tile.TileHeight),
Tile.TileWidth, Tile.TileHeight),

Tile.GetSourceRectangle(tileID),
Color.White);
}
}
}

#endregion

player.Draw(spriteBatch, cam);



spriteBatch.End();

This should work. If you prefer the other method, just us another spriteBatch.Begin() call without the matrix parameter and use the code you already have.


Saturday, December 28, 2019

Do verb tenses have to remain absolutely consistent through a piece of writing?


Generally, I've been told that I should maintain consistency of tenses in my writing. That is, if I begin a piece of writing in the past tense, I should ensure that all verbs agree with that through the document. But as I read more articles, books, and other such things, I get confused by the verb tenses used by these other authors.


For example, I copied a portion of an article below. I believe it started in the past tense, yet the second paragraph switched to the present tense (it sounds like the...) In the third paragraph, the past and present usage is mixed (the word gave is in past tense, yet remain is in the present tense). I understand that the writing in the article is most likely correct. But why can it switch verb tenses and be ok while I was told in school by my professor to keep my essays in a single tense? Is there a guideline I can adhere to?



REPRESSED for decades, the anger burst like a summer storm. Rioting youths flooded city streets. The shaken regime granted hasty concessions: freer speech; an end to one-party rule; real elections. But when Islamists surged towards victory in the first free elections the army stepped in, provoking a bloody struggle that lasted until the people, exhausted, acquiesced to a government similar in outlook, repression and even personnel to that which they had revolted against in the first place.


It sounds like the recent history of several Arab countries: Bahrain, Egypt, Libya, Syria, Tunisia and Yemen, the states of the 2011 Arab spring, have seen some or all of the story unfold. But this is also, and originally, Algeria, a quarter of a century earlier—the first major political crisis in the age of modern Islamism.


A flurry of freedom in the late 1980s gave way to a vicious civil war in the 1990s that left as many as 200,000 dead and Algeria’s Islamists more or less defeated, but not eradicated. Today the country’s citizens remain powerless spectators to a continued stand-off between what they call le pouvoir—the entrenched oligarchy that controls the state, the oil money and the army—and the now-marginalised Islamist radicals, who serve more as a justification for ongoing repression than as any sort of inspiration to ordinary people.





c++ - How to rotate to a target position over time


I know how to do rotations to vectors, but how do I rotate over time?



For instance say I made a function


RotateTo(vec2 iPosition, float iTime);

so it rotates to iPosition over iTime - how would this look? Does anyone know simple algorithm?




xna - Algorithm to find all tiles within a given radius on staggered isometric map


Given staggered isometric map and a start tile what would be the best way to get all surrounding tiles within given radius(middle to middle)?


I can get all neighbours of a given tile and distance between each of them without any problems but I'm not sure what path to take after that. This feature will be used quite often (along with A*) so I'd like to avoid unecessary calculations.


If it makes any difference I'm using XNA and each tile is 64x32 pixels.




Can I use "whether" instead of "if" in this sentence?



In the past, some experts wondered if Tut died in a chariot crash.



Can I use whether to take the place of "if" in this sentence?



Answer



The replacement is always tricky! It depends on the context. The meaning may change entirely if we interchange if and whether in all cases. Here is the general rule -



Use whether to show that there are two possible alternatives and use if if you have a conditional sentence.




For example:



In the past, some experts wondered whether Tut died in a chariot crash or from food poisoning.



In that case, we use whether, because the sentences is discussing two alternatives. However, in your case, it's interchangeable.


Useful information here.


How to render 2D particles as fluid?



Suppose you have a nice way to move your 2D particles in order to simulate a fluid (like water). Any ideas on how to render it?


This is for a 2D game, where the perspective is from the side, like this. The water will be contained in boxes that can be broken in order to let it fall down and interact with other objects. The simplest way that comes to my mind is to use a small image for each particle. I am interested in hearing more ways of rendering water.



Answer



Check out how PixelJunk Shooter did it (including simulation) in this presentation (PDF) at GDC2010.




Sample PixelJunk Shooter Image


Friday, December 27, 2019

semi modals - Is there an insinuation after 'had better'?



You’d better bloody well tell them you’ll need to discuss it with me first.
(The Casual Vacancy, by J. K. Rowling)



Whenever I saw a bare-infinitive follow close behind ‘had better,’ I thought ‘had better’-plus-verb is a loaf of meaning bread. But as you see, there’s a ‘bloody well’ intervention. This gives me this impression that the construction might be a combination of a matrix and a conditional clause - I mean two meaning-sub-breads. That is, ‘You had (in here, there might be an insinuation of ‘a treat, a situation, etc.’) better bloody well, (if you would) tell them you’ll need to discuss it with me first. As a to-infinitve can deliver a conditional meaning as in: People might take you for a girl, to hear you sing.
It’s hard to believe there could be any account for this in any grammar books. But do you perchance read the way I said?



Answer



It's an ingenious idea, and it has some historical support. When the idiom first arose (see OED 1,4,b), what is now the subject was a dative and the sense was It would be better for you, and you could certainly understand that as:




It would be better for you if you bloody well told them ...



But I don't think it works. I think you have to understand what follows better not as an adjunct but as a complement acting as an NP. Historically, in fact, it was the subject, expressed as a content clause with that:



Him wære betere Þæt he næfre ȝeboren nære ... = Him were better that he never born wasn’t = That he had never been born would be better for him.



Although the front end of the expression has changed drastically, I think that complement sense of the back end survives:



Tell them you’ll need to discuss it with me first is what you'd better bloody well do.




Let me offer you an alternate far-fetched analysis: ’d·better has become an ordinary modal verb, taking a bare infinitive (with its arguments) as its complement:



You’d better bloody well tell them ...
You should  bloody well tell them ...



This analysis may be a little more plausible in US speech, where the ’d at the beginning has practically disappeared:



You better f*****g tell them ..




gui - Libgdx actor bounds are wrong



enter image description here enter image description here


The Actor's boundaries are not centered at the ButtonText but I used the setBounds() method. The higher the Y position is, the less centered is the boundary. The weird thing is that i only created and added to the Stage one button but the screen shows two. When i click the top button, the bottom one is the one highlighted.


How can i fix that?


import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;



public class MyGame extends Game {
Stage stage;
@Override
public void create() {
stage=new Stage();
FileHandle skinFile = new FileHandle("data/resources/uiskin/uiskin.json");
Skin skin = new Skin(skinFile);
TextButton sas=new TextButton("dd",skin);
sas.setBounds(0, 500, 100, 100);
stage.addActor(sas);

Gdx.input.setInputProcessor(stage);
}

@Override
public void dispose() {
super.dispose();
}

@Override
public void render() {

super.render();
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}

@Override
public void resize(int width, int height) {
super.resize(width, height);
}


@Override
public void pause() {
super.pause();
}

@Override
public void resume() {
super.resume();
}


}




word usage - Is there any difference between 'get away' and 'run away' in this context?


For these expressions




The whole movie was about him getting away from cops.


The whole movie was about him running away from cops.



Both run away and get away mean escape, but does get away fit in this context?



Answer



Both verbs make sense in your context, but they mean slightly different things.


Getting away implies success: like FumbleFingers said, the movie probably ends with the character still on the lam. It also implies, albeit to a lesser extent, that the cops initially had custody of the character, which he escaped.


Running away does not imply success. I don't know if I'd go so far as to say it implies failure, mind you, but I wouldn't be as hopeful about the eventual fate of a character who was running away as I would be about one who was getting away. Running away also does not imply escape: he could have started off in police custody, or he could have started off free as a bird, we don't know which.


In other contexts, these verbs may or may not be interchangeable. For example, teenagers run away from home to get away from an abusive parent, but not the other way around.


grammar - Does '...time zone of in the morning' make sense?



I waited for my favorite time zone of in the morning.



Does the sentence above make sense? I mean that time zone is 'the range of time' in this sentence.




methodology - What are the most popular software development methodologies used by game studios?




What is the best (as in most used by professional game developers and/or companies) software development methodology used in game development?


I've heard that SCRUM is popular, but i'm not sure.



Answer



Honestly, it depends on the size and history of the team.


Most of the large teams I've worked on have utilized an adapted version of Scrum. Often, a studio will bring in Scrum instructors or require producers to get "Scrum Master" certification.


As noted above, Spiral is an option.


Generally, some sort of Agile development is used that involves stand-ups, product owners, etc.


There really isn't a "best methodology." Team size and experience dictate the correct process to use. If you're a believer in Lean, you'll also understand that process is very specific to the tasks at hand.


Thursday, December 26, 2019

c++ - Unity 3D vs openGL




i'm interrested in starting to learn abit about graphics programming through game development and i'm wondering what the pros/cons are when using Unity 3D over using something like C++ & openGL




informal language - What is the difference between Anyways, Anyway and Any way?


I have seen these words which looks pretty much the same in three different forms, why? what are the differences?


Which one is correct between anyway and anyways? Are they spoken English or can I write those in my essays are they formal words?



We're going to do it anyway!


Great, the service was terrible, but anyways the meal was gorgeous.



So, she's all "Anyways, let's go shopping at Target! "


I do not know any way to fix it.




Answer



Any way, written as two words, is the noun way with the quantifier any as its determiner.



I don't know any way to fix it, but George may know a way to fix it.
There isn't any way I know of from here to there.



Anyway and anyways are adverbs. At one they were equivalent to in any way = by any means, in any manner, but in Modern English they're mostly restricted to a contrastive sense approximately equivalent to nonetheless or regardless.




[They told us not to do it, but] we're going to do it anyway.



It's often used to resume the thread of one's discourse after a digression, with a similar contrastive sense of "you can disregard all that".


Adverbial anyway no longer has any undertone of the original meaning, and it is spoken differently, with -way unstressed—which is probably why people started writing it differently.


The version with -s is a hangover from the Old and Middle English "adverbial genitive", in which the genitive form gave an adverbial sense. Some of these have survived in Standard English—always, once, hence, towards, and expressions like *he works nights—but the construction is not productive today, and most of these -s forms appear only in dialect. Anyways is one of those; it is not used in Standard speech or writing.




You occasionally find uses in the old sense. For instance, They scrape by anyway may mean "They survive by any means they can", and "He does his work anyway* may mean "He does his work however it suits him, without any regard to its quality".


opengl - Checking if an object is inside bounds of an isometric chunk


How would I check if an object is inside the bounds of an isometric chunk? for example I have a player and I want to check if its inside the bounds of this isometric chunk. I draw the isometric chunk's tiles using OpenGL Quads.


My first try was checking in a square pattern kind of thing:


e = object;
this = isometric chunk;


if (e.getLocation().getX() < this.getLocation().getX()+World.CHUNK_WIDTH*World.TILE_WIDTH && e.getLocation().getX() > this.getLocation().getX()) {
if (e.getLocation().getY() > this.getLocation().getY() && e.getLocation().getY() < this.getLocation().getY()+World.CHUNK_HEIGHT*World.TILE_HEIGHT) {
return true;
}
}
return false;

What happens here is that it checks in a SQUARE around the chunk so not the real isometric bounds. Image example: (THE RED IS WHERE THE PROGRAM CHECKS THE BOUNDS)


What I have now:


enter image description here



Desired check:


enter image description here


Ultimately I want to do the same for each tile in the chunk.


EXTRA INFO:


Till now what I had in my game is you could only move tile by tile but now I want them to move freely but I still need them to have a tile location so no matter where they are on the tile their tile location will be that certain tile. then when they are inside a different tile's bounding box then their tile location becomes the new tile. Same thing goes with chunks. the player does have an area but the area does not matter in this case. and as long as the X and Y are inside the bounding box then it should return true. they don't have to be completely on the tile.



Answer



e = object;
this = isometric chunk;

//for readability(long version)//



pointX = e.getLocation().getX();
pointY = e.getLocation().getY();


chunkSizeX = World.CHUNK_WIDTH * World.TILE_WIDTH;
chunkSizeY = World.CHUNK_HEIGHT * World.TILE_HEIGHT;


chunkCenterX = this.getLocation().getX() + chunkSizeX / 2.0;
chunkCenterY = this.getLocation().getY() + chunkSizeY / 2.0;



deltaX = pointX - chunkCenterX;
deltaY = pointY - chunkCenterY;

if(deltaX < 0) deltaX *= -1;
if(deltaY < 0) deltaY *= -1;

//these two are floating point number


distanceX = deltaX / chunkSizeX;
distanceY = deltaY / chunkSizeY;

if(distanceX + distanceY < 1.0) return true
else return false;

Basically, imagine each player starts in the center of the chunk. Assuming the player can only move: up, down, left and right and speed is adjusted proportionally when moving on the y-axis to:


TILE_HEIGHT / TILE_WIDTH * X_AXIS_SPEED

She will need at least n steps to get out of the player will need exactly n steps to get out. of the chunk area. I will not prove this unless requested. Therefore, we just check if the player took 100% of the necessary steps to get out of the chunk.



geometry - a flexible data structure for geometries


What data structure would you use to represent meshes that are to be altered (e.g. adding or removing new faces, vertices and edges), and that have to be "studied" in different ways (e.g. finding all the triangles intersecting a certain ray, or finding all the triangles "visible" from a given point in the space)? I need to consider multiple aspects of the mesh: their geometry, their topology and spatial information.


The meshes are rather big, say 500k triangles, so I am going to use the GPU when computations are heavy.


I tried using arrays with vertices and arrays with indices, but I do not love adding and removing vertices from them. Also, using arrays totally ignore spatial and topological information, which I may need studying the mesh. So, I thought about using custom double-linked list data structures, but I believe doing so will require me to copy the data to array buffers before going on the GPU. I also thought about using BST, but not sure it fits.


Any help is appreciated. If I have been too fuzzy and you require other information feel free to ask.



Answer




Depending on your needs there are different data structure that you can use for geometry representation, before I answer your question I need to point out that geometric representation are usually chosen based on two basic factors,




  1. Topological Requirements: this includes the types of meshes you are going to store, triangles only? n-polys ? regular, irregular or semi regular?




  2. Algorithmic Requirements: Some algorithms work better on some data structure than other. This strictly depends on the type of the algorithm and you may want to use different data structures for different algorithms. For example you need to ask yourself if the structure/algorithm needs a pre-processing step? the time needed to answer specific query such as the adjacent edges of a vertex, edge ?




I will try to concisely list the most important mesh representations, while pointing out their pros and cons:





  • Face Based: The simplest form stores a set of faces, it can store faces(indices) and separate vertices or you can simply construct faces using vertex positions, this structure is more suitable to store one type of face/polys (e.g. tri) otherwise the implementation becomes complex with little benefit.


    Pros: Cache friendly(usually). Efficient to store in memory, used in many file formats (e.g. Obj, VRML). Maps nicely to GPU rendering, usually used in games.


    Cons: Edges and connectivity info are implicit and not explicitly defined making some geometric queries expensive to compute, Cannot store irregular meshes.




  • Edge Based: This defines a face in terms of the edges making a face, each edge stores a reference for it two end point vertices. It's also common for a vertex to have a reference for it's owner edge this is great for efficiently traversing the data structure. An example implementation is the winged-edge data structure. Edges can also store reference to the next and previous edges, which makes good candidate for traversing the structure.


    Pros: Can represent arbitrary polygon, good for traversing adjacent edges.


    Cons: Not so great for memory consumption, traversing a ring still needs distinctive cases. Requires extra processing for GPU rendering.



    enter image description here




  • Half-Edge Based: Similar to Edge-Based with the very important distinction that it defines each edge as a two distinct directed Half-Edges instead of a bidirectional single Edge.


    Half-edge data structure


    The importance boils down to that Half-edges are oriented consistently in counter-clock wise around each face modelling a ring-loop explicitly, and hence making traversal easier by avoiding some extra cases like asking at which vertex in the face are we standing. Getting a good implementation for this structure is hard so I recommend using OpenMesh which is a great implementation of the structure and many other algorithms.


    Pros: Great flexibility with traversal that other structures lack, can model arbitrary polygons, can explicitly model empty faces. Some implementations (AFAIK) can model irregular meshes. Great for geometric algorithms, and makes it easy to mix faces of different vertex count in one mesh.


    Cons: Harder to implement, not so memory friendly, and usually requires a lot of Heap allocations. Requires extra processing for GPU rendering.


    A sample implementation for the half-edge data structure would look like this:






struct Vertex
{
Vector3 Position;
HalfEdge* halfedge; // outgoing halfedge
};

struct HalfEdge
{

Vertex* vertex;
Face* face;
HalfEdge* next;
HalfEdge* prev;
};

struct Face
{
HalfEdge* halfEdge; // any halfedge
};



  • There is also Directed Edge Data Structure, which is a memory efficient implementation of the half edge that is designed for triangle meshes.


As a final note, I recommend Half-Edge or Directed Edge (if triangles only) for geometric processing, but depending on your application you may need multiple representations, since for example Half-edge are not particularly great for GPU rendering/streaming and may require extra processing for rendering.


Wednesday, December 25, 2019

game design - What underlying character stats would you put into your "character" object in an RPG engine



basically I'm making my own RPG/TBS engine named Uruk (making an rpg themed about the epic of gilgamesh) and I am thinking of a combat system similar to the Disgaea franchise or the Super Robot Wars franchise


I'm currently in the process of writing the "character" class (cant name it character since it causes confusion with the primitive data type "character") and right now i've decided to go with the regular RPG route of including the following base stats:



  • strength

  • Agility

  • Willpower

  • Endurance

  • Luck


and the base stats would then dictate the following stats




  • Attack (probably a combination of the strength stat and weapon stats)

  • Physical Defense (determined by endurance and armor)

  • Magic Resistance (maybe something to do with willpower and armor)

  • Crit Rate (luck and agility)

  • Max Health (endurance)

  • Max Mana (willpower)

  • Max Stamina (combination of strength and endurance)

  • Move per turn (determined by character class or agility)



of course there would also be a leveling system with level and experience stats


the biggest problem I am facing right now is whether I should put additional underlying stats (hidden from the play) for leveling purposes (for example stats such as strength per level and max health per level) and how would i go for implementing said underlying stats with a class system, currently I am using an enum within the character object (calling them objects to avoid confusion with programming classes and character classes) to implement the class system and I have been considering on whether I should just write multiple objects extending on the character object for each character class or should I keep on using enums to represent different classes



Answer



Which Stats?


First, with regards to what stats to implement, you need to work backwards from mechanics to derived stats to basic stats. Determine what effects and mechanics you want during play, and determine how you want those mechanics to work with one another.


The important notion when looking at relationships between mechanics is identifying the aspects you want to be orthogonal. This means which aspects are the atomic elements which are independent of one another.


For example, maybe you want misses and dodges in combat. If you want these to be separate derived stats, you might have derived stats Miss % and Dodge %. Then the question would be, should they be orthogonal? Should a character be able to dodge very well while also being very clumsy and missing often? If so, they should be orthogonal, and be based on atomic, independent basic stats. If you decide they should be related (a nimble person who can dodge well should also not miss very often), they should be derived (at least partially) from the same basic stat.


Hide Stats?


The question of blackboxing (whether or not to hide certain aspects of the system from the player) is a question of simplicity versus control. Do you want to make the choices, UI, and overall game simpler for the player to understand, or would you rather they feel more in control of the stats of their characters?


Multiple Classes or Single Class?



Finally, the question of individual Classes versus a table of variables for a single Class is a question of the level of difference between professions. If the game professions are the same except for stat levels, a single Class is fine. If there are fundamental differences in how the different professions function, multiple Classes might work better.


word meaning - Toy Line (Production) Run


I am not sure about the meaning of this:



link
Transformers: Generation 1 (also known as Generation One or G1) was a children's toy line that ran from 1984 to 1991 and was produced by Hasbro.



Would the following rewrite be better?



link

Transformers: Generation 1 (also known as Generation One or G1) was a children's toy line the production of which ran from 1984 to 1991 and was produced by Hasbro.





The meaning of the phrase "to have Helen all to herself"



Annie wanted to have Helen all to herself so that she could do anything with her.



Note: In this context, Annie (full name, Annie Sullivan) is the teacher of Helen (full name, Helen Keller).



What is the meaning of "to have Helen all to herself", and is the clause "she could do anything with her" correctly used in the sentence? The sentence above is the answer to the question " Why did Annie want to have Helen all to herself?" The question was created from the passage " The next day, I told Helen's father, " I can't do anything with Helen unless I have her all to myself. I want her to depend on me for her food, her clothes,everything. ....."




multiplayer - How to solve "server lag" problems that break the game


How do real-time multiplayer games deal with latency problems (or “server lag”)?


Imagine an online fighting game where 2 players battle head-to-head in real time. When a player performs an action, there'll be a short delay until that player's action appears on the opponent's computer screen. This delay causes many game-breaking problems.


Let's say 2 hypothetical players, Player A and Player B, are fighting against each other right now in the game, and the latency is 1 second. Player A is moving toward Player B, but then Player B places a wall (or something of the like) that stops Player A from moving toward Player B. Player A doesn’t see the wall appear on his/her computer screen until 1 second later, but by then Player A has already moved past where the wall was placed.


In a more game-breaking situation, Player B is just about to kill Player A. Right before that happens, Player A uses a special attack that instantly kills Player B. But on Player B’s computer, Player B kills Player A, because it takes 1 second before Player A’s special attack happens on Player B’s computer. This makes it so both players die even though only Player B was supposed to die.


One solution to deal with the latency issue is to implement an artificial delay so that when there’s a discrepancy, one player’s game is momentarily paused to wait for the other player’s game state to “catch up.” This is not a good solution because it makes the game feel extremely laggy and unresponsive, and it also renders some reactive actions useless (like dodging) because of the artificial delay.


What can be done to fix these latency problems?



Answer



The easiest solution to the "who did it first?" problem is an authoritative server. Both players connect to the server which handles all the game mechanics. Whatever arrives first at the server is considered as happening first.



So if the server receives a message "I place a wall" from player B and then a millisecond later a message "I move to where the wall is" from player A, the server will reject the move-message as impossible and send player A a corrected position for their character.


What then happens on the screen of player A is that their character moves at first, but then the wall appears and the character is snapped back to its position before the wall.


This method of resolving timing conflicts gives an advantage and a better game experience to those players who have a better connection to the server ("Low Ping Bastards").


A different way to resolve conflicts is to take latency into account when resolving actions. In order to do that, the server needs some way to keep a history of the game state. When the "I move to where the wall is" message arrives at the server, the server checks Player A's latency, looks into the history if a wall was already there a few milliseconds before, and decides accordingly. That means the game looks more consistent for high-pingers, but low-pingers will far more often witness situations where other players seem to walk through walls shortly after they were placed.


xna - How do I generate projectiles toward the mouse pointer?



I'm making a top-down space shooter where the player controls a ship and can aim and shoot using the mouse cursor. How can I fire bullets from the ship at the angle from the ship to the mouse cursor?



Answer



If I understood your problem properly, you just want to shoot a bullet towards a mouse position. Here is how I would do:


First of all, you must find the movement required for the bullet to get to the mouse, like so:


Vector2 movement = mousePosition - bulletStartPosition;

Then, you should normalize it to have a vector with a length of 1 so that you can hold a vector which tells you in which direction to go, like so:


movement.Normalize();


But here you have a little problem, if the direction is equal to (0, 0) (meaning that the mouse is on the bullet start position), then you'll divide by zero, so make sure you check for that with the last piece of code:


if (movement != Vector2.Zero)
movement.Normalize();

So, you've got the movement required to move towards the mouse. You have to keep a Vector2 within your bullet class which holds the Direction of the bullet.


What's next? You have to actually move the bullet!


In your bullet update code, do the following:


bullet.Position += bullet.Direction * bullet.Speed * gameTime.ElapsedGameTime.TotalSeconds; // multiply by delta seconds to keep a consistent speed on all computers.


Where bullet.Speed is a float representing the bullet's speed in units per second.


Basically, here are the things to change:


Inside you bullet class, add a float Speed and a Vector2 Direction.


When shooting, set your bullet.Direction to mousePosition - bullet.Position and safely normalize it (by checking for equality with Vector2.Zero first).


When updating your bullet, do the following: bullet.Position += bullet.Direction * bullet.Speed * gameTime.ElapsedGameTime.TotalSeconds;.


It should work.


Tuesday, December 24, 2019

Is 'rather + pronoun + root-verb' pattern possible?



I had much rather we not stay. (Random House)
I'd rather you didn't go out alone. (Longman)



If the first sentence is possible, I guess, the second one can be re-write as “I’d rather you not go out alone." Is this really possible?



Answer



SHORT ANSWER:
Yes, that rewrite is perfectly acceptable. It is however ‘rather’ (in the ‘somewhat’ sense) an old-fashioned way of expressing it.


LONGER (BUT STILL NOT NEARLY LONG ENOUGH) ANSWER:

Expressions with rather are quite complicated, because they are really ‘fossils’ from earlier states of the language. Some of the issues involved are:




  • The had in your first example is the full verb, not an auxiliary. Grammatically it is a rare instance of the past form representing contingency or unreality outside a conditional construction. Today we express this grammatically almost exclusively as would have; but well into the 18th century the form (which it is hard not to call ‘subjunctive’) sometimes represented the sense ‘to desire or wish [someone to do something]’ (I had rather that ye never maryed in yowyr lyffe - 1478) and at other times the sense ‘to experience or suffer’ (He had better been drowned - 1665).




  • The ’d in your second example would be understood by most speakers as a contraction not of had but of would, which since the middle of the 18th century has been far more usual than had with rather:


    enter image description here


    That would, again, represents what is now a fairly rare use: although its past form does as usual express the ‘subjunctive’ sense of contingency or unreality, the base sense is volitive, wish or want. (Would that it were so!)





  • The verb forms in the complement are also archaic in the cases which employ what you call the ‘root-verb’. I suspect you are being very diplomatic and carefully avoiding calling it either an ‘infinitive’ or a ‘subjunctive’; if you are not, you should be, because sometimes it is definitely an infinitive and at other times it may be called either infinitive or subjunctive.




    • Without a pronoun, expressing what the subject would rather do, it is definitely an unmarked infinitive, the final verb in the verbal chain of the main clause, not a component of a subordinate clause; this is possible only with the would version, which is grammatically an ordinary modal:



      He would rather be dead. derived from He would be dead [=He wants to be dead] derived from He will be dead.






    • But with a pronoun, expressing either what the subject would rather do himself or what he would rather someone else do, the verb is a component of a subordinate that-clause. Grammarians differ over whether this should be called an infinitive or a mandative subjunctive:



      I had/would rather [that] you be dead than that you marry her.





    • In any case, the version with the past form—“I would rather you were dead”—has been preferred at least since the early 19th century:




    enter image description here




    • That version of course, must be inverted in a negative, and needs DO-support if the tensed verb is not BE or an auxiliary:

      I would rather you did not marry her.







So the more frequent use would be that with the past form and *DO-support: “I'd rather you didn't go out alone. “



xna - How can I cleanly separate the UI from the game logic in my Cocos2d game?


I've been working on a little game for the last few months, trying to approach it as a software engineer and employ best patterns and practices in my coding. I have gotten to the point where I have to distinct elements in my game.




  1. The Game Logic: aka business logic. Its the meat of the game rules. It contains all information about game objects (such as Character, Weapon, and Item class definitions). It contains the game world as far as rules are required; mainly so Characters are aware of the world they are in, and who else is in it. It contains a chunk of logic use to determine how Fighting is resolved between Characters, as we as other game actions requiring rules. It contains my AI implementations. So in reality it's a combination of Class definitions and Service logic.


    As it stands, the Game Logic can actually play out a game without any interface. All I need to do is create a World, add some Characters to it, assign some AI's to them, then in a loop tell their AIs to run. The result of each AIs action is reflected in the states of the Characters (eg, if damaged, health is reduced), and a summary of what happened is returned by the execution (which is intended for the UI to make sense of what happened).




  2. The Game UI: which is using Cocos2d-xna for WP7. It contains definitions of all the different animations. It takes in inputs and sends the to the Game Logic, and renders its results.


    As it stands, as well as all UI components for a Character (textures, sprites, animations) a UI Character also contains a Begin method which executes a Cocos2d Sequence (ccSequence) to do two things 1) Execute AI and render result for this Character 2) Re-Execute the sequence (essentially its own call back loop for executing actions).





The problem I keep running into is, the more I try to keep these two layers separate, the more they need to come together. E.g., my UI Character which is used to render what the Game Logic character is doing, so it needs a reference to the Character object from Game Logic. When this Character's AI attacks someone in the Game Logic world, the UI needs to know what happened. This works fine for rendering its own Animations based of its results, but to know what to do for other Characters affected by this action is difficult as I dont have reference to them. At the moment I do this by queuing up Pending Animations in the other character's Game Logic Character and render it when that character next executes, but this is anti SoC (Separation of Concerns) as it now contains something specific for the UI to focus on.


I don't want the two projects to merge into one where a Game Logic Character contains all things UI as well, such as animations and actions. Is there a nice clean way that is used for this separation? Ideally something that works nicely with Cocos2d's Action pattern?




meaning - You are welcome


We say thank you when pleased with someone's help or attention. Usually it is replied: you are welcome.


questions



  1. does it mean that thanks are welcome?

  2. is it the same sense when we say you are welcome to somebody arriving at home?




Monday, December 23, 2019

What makes the need of a definite article?




(i) He works (a) at night and sleeps (b) during the day.
(ii) Nocturnal animals sleep (c) by day and hunt (d) by night.
(source: OALD)



There’s a definite article in (b), while there're zero articles in the others. Why does (b) need one, while the others don't?



Answer



All those bolded examples are adverbial phrases, that is, a group of words acting together as an adverb.


As often is the case with phrases, it is easier to learn their meanings than reasoning about them. I think your question gives a good example where the article use cannot be deducted from the meaning of the phrase.


The collocation dictionary ozdic lists three meanings of day when used with a preposition. Note that the meaning depends on the preposition, and not on the article:


Preposition + day





  1. period of 24 hours



    • by the day: He's getting stronger by the day.

    • for a day: They stayed for a day.

    • in a day: We hope to finish the job in a day.

    • on the day of: On the day of his wedding he was very nervous.





  2. time between sunrise and sunset



    • by day: We travelled at night and rested by day.

    • during the day: He sleeps during the day

    • for the day: We went to the seaside for the day.




  3. particular period of time




    • in somebody's day: Things were very different in my grandfather's day.

    • of the day: the government of the day




xbox360 - Can you access Kinect motion sensing from XNA?


As of 2010 with the release of XNA 4.0, if I buy an Xbox 360 with Kinect will I be able to access its motion sensing data with the XNA game I'm developing? Or is this only restricted to C++ developers with a devkit?



Answer




"The non-commercial Kinect SDK for Windows will be released this spring, Microsoft said, and a commercial version is planned for a later date. The company said the SDKs will include support for audio, the Kinect API and direct control of the sensor."




That being said, if you don't want to wait, there's a lot of work being done on several fronts with support for a number of languages (C++, C#, Java, JavaScript, ...) under Windows, Mac and Linux.


For the freshest 0-day Kinect hacks, read KinectHacks and FreeNect


If you want to get started writing code, have a look at these:




  • Code Laboratories released CL NUI Platform drivers for the Kinect, which also includes samples in several languages including C#. The latest 1.0.0.1210 seems to not work ATM, so maybe stick to the older version (1.0.0.1121).




  • I got started in minutes using the KinectTouch C# project together with CL NUI drivers.





  • For motion detection, check out the haar detection function inside OpenCV or the cross-platform .Net wrapper Emgu CV. Included are about 20 detection algorithms (XML files) for detecting e.g. hands, eyes, upper-torso, etc. A tool is also included to make your own. Google haar detect for more info.




  • The OpenKinect project is in charge of libfreenect and has sample source code to get you started. AFAIK you will have to use libusb-win32 to interface to the Kinect (which I was too lazy to get working in C#).




  • OpenNI just released an updated driver with Kinect support including sample source code for skeleton tracking using their PrimeSense PSDK.





sound - Is it reasonable to ask for all rights for music when hiring a musician?


I've made a game and now I need to add real sounds and music to it. For the first time I've decided to hire a musician to make music for my games. Before I used to buy sound packs and licenses for tracks.


The negotiations didn't go well as the price was too high for me and the artist didn't like the idea of selling me the music and wanted to only license it to me.


I'd like to know if I've made a mistake or if I've been unreasonable.


Just to be specific, we're talking about 6 tracks, 90 seconds long each. The music is chip-tune done by one musician (that's important since I understand that hiring an orchestra would cost more than hiring just one person).


What I wanted was to get the tracks with all the rights, other than the authors rights - putting their name in the credits.


I've been told that nobody does this and the musician always keeps the rights to later sell OST etc. And if I want all the rights, one track would cost me $500. And even just getting a one-title license would cost me $200.


I have no idea if that's a standard market price, it seems high for me.




  1. Is the price reasonable?

  2. Is it unreasonable for me to ask for music with all the rights?



Answer



When you are asking for "all the rights", then you need to ask youself if you really need "all the rights". I don't know your long-term business plan, so I don't know which of these rights you actually need:



  • Use the music for your current game (ok, that's obvious)

  • Use the music for any future games

  • Be the only one who is allowed to use the music for a game


  • Be the only one who is allowed to use the music for any form of media

  • Be allowed to resell the rights to the music to 3rd parties, in case you chang your mind about the previous two points

  • Be allowed to make derivative works of the music (remix or reinterpret it)

  • Be allowed to monetize the music by itself, for example in form of an OST album

  • Have these rights for all eternity (and not just a few years)


All these points mean that the original musician loses a potential way of monetizing their work in the future. The creator seems to believe that the amount they lose out on seems to be around $500, so that's the reimbursement they demand from you in order to give up on those business opportunities. What you need to ask yourself is if these rights are also worth that much to your business interests.


So the reasonable thing to do would be to figure out together with the musician what business needs you have, what business needs the musician has, and where you can find common ground regarding what rights exactly you buy and what rights the musician retains.


Keep in mind that none of these points need to be binary. Deals like "you can do that, but only under condition" or "only when you pay $x each time you do it" are not uncommon.


You can also agree on some form of revenue splitting agreement in cases where you both benefit from cross-promotion. For example, the sales of the OST album will depend just as much on the quality of the music as on the popularity of your game, so a revenue sharing deal could make sense here.



By the way, the more complex your agreement will get, the more useful can it be to get professional legal advise on board to draft the exact wording of the contract to make sure it really says what you want it to say.


monetization - Is there any way to earn money with an open source game?


I know FreeToPlay games are financed by advertisements and/or selling additional content, but what about an Open Source single player game to which several people have contributed? And how can a fair sharing be determined?



Answer



I would suggest that you sell:





  • Distributions of the source: Build versions of the source code, tools, etc that people can work with. If they are modifying the source themselves then this won't help them, but if they just want to include a dll for example, this can simply things especially if your build process is complex. Another options is to sell incremental revisions of the source and open source previous versions.




  • Art, Basic Levels, etc: As mentioned above, providing art resources and building block maps, objects, and other assets simplify development for others.




  • Server Rental: If your game is an open source multiplayer game, you can rent out time on servers you run. This makes supporting the game easier for people building off of your game, and ensures stability (this relies on you of course) for multiplayer games.





  • Advertising: A no brainer, advertising on your site and support forums could earn you something




  • Support: While I generally view selling support as evil, perhaps selling room in online training sessions, access to advanced tutorials, or "1 on 1"-ish support wouldn't be so bad (likely more like 1-or-2-on-team but hopefully you get the idea).




  • Microtransactions: You could sell content in game, or only provide certain content in the "premium" version of the game that YOU built. People building off of the game would have to either go without said content or pay you to include it.





  • Commercial Licences: While your game could be open sourced for non-commerical purposes, you could require that you be paid a certain amount or a cut of the profits for people planning to sell derivatives of your work.




  • Promotional Items: If your game gets popular enough, you could sell T-Shirts, etc relating to the original game.




  • Sponsorship Period: Following along the lines of point 1, you could sell the game for a certain amount of time and THEN open source it.




  • Donations: Simple--ask for donations to your project (this would probably look bad if you were doing too many of the other things but it may be worth a shot).





I'm sure there are more ways I didn't even think of as well. As for sharing, that's really up to your team and you but as this is an open source project and not something built in a corporate environment it would presumably be split evenly amongst you.


assets - Useful resources for beginning AI



What resources are available, including both free articles/ebooks and physical books and things, for game developers looking to begin simple AI programming/design?


Note: I know of this question, but that's more asking about where to start on a specific topic; I'm more asking about resources in general.



Answer



Programming Game AI By Example by Mat Buckland is an excellent resource to get started. He starts right from the basics of state machines and moves on to steering behaviours and graph theory for pathfinding. Probably one of the best resources I've found, especially when starting out.


The AI Game Wisdom books are also very good, but a lot of the articles are pretty advanced.


A good link for steering behaviours is this site: http://www.red3d.com/cwr/steer/


And as has been mentioned, http://aigamedev.com has amazing content, right from the frontlines.


Amit's Game Programming site is pretty decent at getting an overview (although admittedly, I haven't used it much): http://www-cs-students.stanford.edu/~amitp/gameprog.html#ai



I'd thoroughly recommended Buckland's book though. Very easy to follow and the source code actually works :)


Ray


grammar - Would be or will be





  1. Let's see what book would fit your taste.




  2. Let's see what book will fit your taste.




What is the difference between 1 and 2?




  1. The answer would be 200.





  2. It is not as easy as one would wish.




Why was "would" used in these sentences?




  1. If I had a wish, I would wish you would love me.





  2. If I had a wish, I would wish you loved me.






plural forms - Pluralising foreign words



I am writing a novel whose background is a foreign country. Some people say that I should not pluralise foreign words, but in my case it becomes quite difficult to grab the whole meaning of a sentence if the nouns (even if they are foreign words) are not pluralised. Should I pluralised them by adding an 's' at the end?




Sunday, December 22, 2019

tense - "If you explained what you ___ trying to achieve, I would ..."


I've written the next sentence




If you explained what you are trying to achieve, I would recommend a kind of workaround.



and it has raised doubts about the tense I should have used in the highlighted phrase.


The options I see:



  1. you are trying (my conversational partner is now trying)

  2. you were trying (to adhere to the initial tense in "If you explained")


Which one is correct? Can both of them be used?


Thank you in advance.




Answer



The sentence below is an example of using the past subjunctive in English; therefore, no tense is being used and, thus, verbs don't always have to correlate:



If you explained what you are trying to achieve, I would recommend a kind of workaround.



The verb "to explain" has equivalent forms in the past indicative as it does in the past subjunctive:



to explain (all forms in both paradigms are "explained")


I explained: first-person singular past indicative


I explained: first-person singular past subjunctive




In fact, the only verb in Modern English that shows a difference in its past subjunctive form when compared to its past indicative form is "to be":



to be


I was: first-person singular past indicative


I were: first-person singular past subjunctive



If you were to use "thou" or read "thou" in old literature, it would have a different form in the past subjunctive when compared to its past indicative form; however, the rule isn't always followed in old literature like Shakespeare and the King James Bible because "thou" was on its way out when the rules of grammar were being written; however, in Old and Middle English, it was followed (circa A.D. 600 to circa 1400):



to sit



thou sattest: second-person singular past indicative


thou sat: second-person singular past subjunctive



So here are some Modern English constructions using the archaic "thou" and its paradigm:



"Thou sattest at thy desk yesterday." (present indicative)


"Thou wouldst always play with dolls when thou wast / wert young." (past indicative)


"If thou sat at thy desk now, thou would get thy work done." (past subjunctive)



I would like to reiterate that the paradigm using "thou" above is not always consistent in Early Modern English because English grammar had not been formalized until about A.D. 1650, so these forms are not always consistent in literature. Despite the inconsistencies, if "thou" had survived into Modern English, this would have been most likely the prescribed paradigm.



Now getting back to your initial question: because the first verb of the protasis ("if" part of "if-then" statement, i.e. "explained") must be in the past subjunctive mood as well as the first verb of the apodosis ("then" part, i.e. "would"), this doesn't mean that the verbs of subordinate clauses have to be in the past subjunctive. There are times when conjunctions are used such as "before", "until", or "if", etc. wherein the past subjunctive would have to be used or technically should be used, but, in this instance, that is not the case:



If I explained it until I were blue in the face, you wouldn't understand what I am talking about.



This rule, however, is not always followed in Modern English. Many native speakers don't use the past subjunctive form with conjunctions like "before" and "until" anymore because they don't use them in their present subjunctive forms anymore particularly with conjunctions such as "before" and "until"; however, I am giving you the "proper" English construction and not necessarily the way it is often said.


P.S. Perhaps I didn't make it clear enough when I said above that the original example can mean the exact same thing whether it be "you are trying to achieve" or "you were trying to achieve". It is often said the way in the examples below and many native speakers hearken to this way of saying it:



"If I knew that he was cheating (now), I would tell you what was going on."


"If I were the person who was in charge (now), I would do it this way so that no one would be the wiser."




In the first example, "knew" in the protasis and "would" in the apodosis are in the past subjunctive whereas "was" in the protasis and "was" in the apodosis, both of which are emboldened in print just as I have emboldened their equivalents in the second example, are in the simple past tense. This is how many native speakers say it now because they try to align the verbs in subordinate clauses so that they look like their past subjunctive counterparts in the main clauses, and each example above does mean the same thing as it would if the verbs in the subordinate clauses were in the present tense, i.e., in the second example, "is" and "will" instead of "was" and the second "would".


In essence, what I am trying to say is that it could be said this way as Andrew has stated in his comment to your question above:



"If I knew that he is cheating (now), I would tell you what is going on."


"If I were the person who is in charge (now), I would do it this way so that no one will be the wiser."



This second way is less common and it clearly shows the subjunctive verbs. It is a matter of style in English now. Do you want to clearly point out that the information in the subordinate clauses are happening in the present tense or do you want it to appear to align in form with the past subjunctive verbs of the main clauses? That is often up to the writer or speaker who is using these constructions. The subjunctive is a tough subject in English because it looks so much like the past and present tenses in Modern English. Because of this, the rules are all over the place. I would tell you that you could use both "you are trying" and "you were trying" in your original example and you would have the same meaning because this is a rule that is not consistent in Modern English. I wish it were an easier subject to explain.


I hope this might have helped you out. Take care and good luck.


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...