## mathematics – Formula to convert zoomed in game space co-ords to UI

I need to come up with a formula to convert variable zoomed-in game space co-ords to UI co-ords. The engine I’m using is not traditional so there’s no inbuilt function (convertToUISpace etc).

Now I have a feeling this is extremely easy, but I cannot get my brain to work the math…

It’s a top down 2D game with 2 layers, game and UI. The screen is 640×360 res, but there is a zoom overlay on the game layer that can take it anywhere up to 400×225. The HUD layer remains the 640×360 res throughout though.

So I need to translate x,y positions on the game layer (at whatever zoom) to correctly position on the HUD. At the moment if I use exact co-ords they don’t quite match up, unless the object is exactly in the screen centre.

Could anyone assist or clue me down the right path? I’m guessing I have to work out from the screen centre using the zoom ratio.

## unity – Workflow for authoring Pokémon-like game database content

I would generally not use a SQL database (not even SQLite) for handling static data in a singleplayer game. The only exception would be if I had so much data that it won’t all fit into RAM. But when the data is less than a couple hundred MB, I would look for a solution which loads all the data when the game starts and then allow the game to access it directly.

## Solution within Unity: Scriptable Objects

A solution completely within Unity would be to work with scriptable objects. A scriptable object is a game-specific asset type. So you could create a class CreatureType : ScriptableObject. This enables you to create “CreatureType” assets in the Unity editor which you can then manage in the Unity project outline like any other Unity asset.

You can then assign these assets to inspector properties of MonoBehaviour‘s and thus assign them to prefabs or objects within your scene. You can also have ScriptableObjects referencing other ScriptableObjects. So you can, for example, have another ScriptableObject type for the various attacks your creatures can perform and then assign attacks to creature types via drag&drop.

When the standard controls for public fields are insufficient for your purpose, you can use Editor Scripting to enhance the inspector of these assets to better fulfill your game designers needs.

## Working with files

However, scriptable objects have their limitations when it comes to editor support. While the Unity editor is very extensible, it can take a lot of development resources to to essentially reinvent what you can already do in a spreadsheet application.

So another solution is to keep the data in a file format editable with a spreadsheet application, import that file into a Unity project as a Text Asset and then load and parse that file at game start.

Perhaps the most developer-friendly format for that is CSV, because:

• It can be handled by most spreadsheet applications, but can also be edited with a simple text editor when in a pinch.
• It is very easy to write a parser for it.
• The raw files are pretty human-readable and use one text-line per data entry, which means it can be handled well by text-based version control systems like Git.

But depending on the needs of your designers you might need to compromise and use a more advanced spreadsheet file format.

## What in the BOTW game engine makes physics behave wildly when certain actions are triggered during bullet-time?

Thanks for contributing an answer to Game Development Stack Exchange!

But avoid

• Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.

## Develop a simple serious game to dedramatize git merge conflict

I’m creating a course on GIT for non computer scientist.
As you know, developper already fear merge conflict (Do developers fear merge conflicts?), so that even worse for non computer scientist (ex in Humanity…)

So, i decide to take some time to think/build a scenario to de-dramatize this common problem, by creating a serious game.

After many hours to search on boardgamegeek website, i’m convainced that there already exist some game/mechanisms on abstract boardgame that adapt well to merge conflict.

The game need to be played using a board game representend as a text/Ascii file. This text file / Ascii file is synchronized with all users, and all users have a local copy of this file on their computer. Each users could change the text file at any time and push/sync the modified file/board on the server. Each push from users to the server generate a new state for the boardgame. There is no problems until two user change the same line on the board …

My Objective was to generate “git merge conflict” and “conflict resolution” when multiple players try to compete for one shared resource.

My actual finding (26/10/2020) :

• I found that “Pent a rush” or “5er-finden” (see “https://boardgamegeek.com/boardgame/285535/5er-finden” was interesting because there is one board with pattern shared for all users, and all users have limited time to report their finding on the local board to win the step.

So if someone find a pattern and report it before you and before the end of time for this step, you need to resolve a conflict by accepting the other player answer.

Real time playing, with auction/bidding mechanism. Players acquire ownership of sections of city blocks then place tiles, representing businesses, onto the shared block-sections. So there is competition between users.

If you already think or develop something related to de-dramatize git merge-conflict, or if you have a game with some of these caracteristic in mind, i’m interested to share expertise here as community post.

Ps : I also cross post and open discussion here :

## Designer-friendly Database Tool for Pokémon-like Game

I’m programming on a game that relies on a database for a lot of the creatures and items in the game (think Pokémon). Currently, we have a Google Sheet that the designers are making. They will be using it to populate all of the items necessary for the game, so it acts as a ‘source of truth’. However, to translate this into the database (SQLite) we’ll need to write some code to pull the data, format it and put it into the database. The maintenance of this will also be pretty annoying, as we already need to maintain the database schema and the code representation (Unity C#).

Before writing this code I’m exploring other options. I’ve looked into Microsoft Access (and similar programs) but they seem to be geared towards making applications now and don’t have much in the way of SQLite integration.
I’m leaning towards using a visualiser tool like DB Browser for SQLite or SQLiteStudio, but the lack of cloud syncing might mean a janky solution with Google Drive or AWS.

I’m looking for a solution/tool that:

1. will be accessible for game designers (who have little to no SQL experience, but willing to learn)
2. will keep changes between designers synced
3. will be easy to manage and maintain for the codebase and SQLite database.

Is there anything out there that does this? I realise some compromises will have to be made for both areas but has anyone had experience with this?

Thank you!

## web browser does not show image for sleuth game?

My teacher gave me this assignment for something called a sleuth game. I go to the website here: sleuth game

basically I go to this website and I download the puzzle and before I start working on it I try to open it in the browser yet all the web browsers firefox, Edge, Brave all of them show the same thing:

## beginner – C++ Number Guessing Game

I created a simple guessing game where the player can choose whether the player is guessing the number or the computer.

If the player is guessing the number, then the computer will generate a random number between 1 to 100. Then, the player must guess the computer’s number.

First, the player will type their guessed number. If it is too high than the computer’s number, then the program will print out that the player’s number is too high if it is too low, vice versa.

If it is correct, then the computer will congratulate the player and ask if the player wants to play again or no. If the player wants to play again, the program will restart, but if the player does not want to play again, the program will exit.

If the computer is guessing the number, then the player will think of a number. The computer will print out a number and ask if the player’s number is higher or lower. The computer will keep doing this until it finds the number.

I’m looking for feedback on absolutely everything that could make me a better programmer, especially a better C++ programmer, such as:

• Optimization
• Bad practice and good practice
• Code structure
• Functions and variable naming (to be honest, I’m not really good at naming, lol)
• Bugs
• etc

Thank you very much!

I’m using Visual Studio Community 2019 ver 16.7.6

Globals.h

#ifndef GUARD_GLOBALS_H
#define GUARD_GLOBALS_H

static const char COMPUTER_GUESSER = 'c';
static const char PLAYER_GUESSER = 'p';
static const char QUIT = 'q';
static const char ANSWER_IS_YES = 'y';
static const char ANSWER_IS_NO = 'n';
static const int MAX_NUMBER = 100;
static const int MIN_NUMBER = 1;

#endif


BracketingSearch.h

#ifndef GUARD_BRACKETINGSEARCH_H
#define GUARD_BRACKETINGSEARCH_H

int randomNumGenerator(const int max, const int min);
int rangeNumToGuess(const int max, const int min);
int rangeNum(const int max, const int min);

bool startGame();
bool computerOrPlayer(const char userchoice);

bool computerGuesser();
bool playerGuesser();

bool restart();

#endif


BracketingSearch.cpp

#include <iostream>

#include "Globals.h"
#include "BracketingSearch.h"

int randomNumGenerator(const int max, const int min)
{
return rand() % max + min;
}

int rangeNumToGuess(const int max, const int min)
{
return ((max - min) / 2) + min;
}

int rangeNum(const int max, const int min)
{
return max - min;
}

bool startGame()
{
char userChoice{};

std::cout <<
"Who will be the guesser?n"
"C - for computern"
"P - for playern"
"Q - for quitn"
"Type one of the choice: ";
std::cin >> userChoice;

computerOrPlayer(tolower(userChoice));
restart();

return true;
}

bool computerOrPlayer(const char userchoice)
{
if (userchoice == COMPUTER_GUESSER)
{
return computerGuesser();
}
else if (userchoice == PLAYER_GUESSER)
{
return playerGuesser();
}
else if (userchoice == QUIT)
{
std::cout << "Thank you for playingn";
}
}

bool computerGuesser()
{
char userInput{};
int maxNum = MAX_NUMBER;
int minNum = MIN_NUMBER;
int guessNum{};
int guessCount{ 1 };
int range;

std::cout << "Think of a number between 1 to 100n";

while(maxNum != minNum)
{
++guessCount;
range = rangeNum(maxNum, minNum);

if (range == 1)
{
guessNum = maxNum;
}
else
{
guessNum = rangeNumToGuess(maxNum, minNum);
}

std::cout << "Is your number less than: " << guessNum << "?(y/n): ";
std::cin >> userInput;

switch (userInput)
{
maxNum = guessNum - 1;
break;
minNum = guessNum;
break;
default:
std::cout << "That is a wrong optionn";
guessCount -= 1;
break;
}

if (maxNum == minNum)
{
std::cout << "Your number is: " << maxNum << std::endl;
std::cout << "It took " << guessCount << " guesses for me to guess" << std::endl;
}

}
return true;
}

bool playerGuesser()
{
int userGuess{};
int guessCount{ 1 };
int number = randomNumGenerator(MAX_NUMBER, MIN_NUMBER);

std::cout << "Enter your guess number: ";

while (std::cin >> userGuess)
{
++guessCount;

if (userGuess > number)
{
std::cout << "Too high!n";
}
else if (userGuess < number)
{
std::cout << "Too low!n";
}
else if (userGuess == number)
{
std::cout <<
"It took you: " << guessCount << " guessesn";
break;
}

std::cout << "Guess another number: ";
}
return true;
}

bool restart()
{
char userChoice{};
std::cout << "Play again? (y/n): ";
std::cin >> userChoice;

char lowerUserChoice = tolower(userChoice);

{
startGame();
}
{
computerOrPlayer(QUIT);
}
else
{
std::cout << "Please choose the available optionn";
restart();
}

return true;
}


main.cpp

#include "BracketingSearch.h"
#include <cstdlib>
#include <ctime>

int main()
{
srand((unsigned)time(0));

startGame();

return 0;
}


## Ask for character in game?

I have some question in 2D game (pac-man, bomberman, ..) :

1. How to calculate velocity for character?
2. When I move character between two wall (see picture below, I want to go right) , it so hard. How I can fix it? (Wall and character is 16×16 pixel)
P/S: Sorry for my bad English!

## unity – What’s the best way to make a game launcher?

I am a new game dev, and would like to make a launcher for my games. All my games would be in ONE launcher, and it’d be similar to the Minecraft Launcher. I wanna do it for free too.

The main reason I wanna do it is to update my games. I don’t have a file server, so the files would be on Google Drive.

Thanks!

## unity – How to move one Game unit with every key press?

This solution is for grid based games. The idea is to have “turns”. A turn will happen regardless of whatever or not there is input or not. At the end of the turn the avatar will be aligned to the grid, and a turn always takes the same time.

Pseudo-code:

var current_time = get_current_time();
var elapsed_time = current_time - start_time;
var got_input = get_input();
input = got_input ?? input;
if (elapsed_time > turn_duration)
{
elapsed_time -= turn_duration;
start_time += turn_duration;
start_position = end_position;
end_position = compute_next_position(start_position, input);
}

current_position = interpolate(start_position, end_position, elapsed_time);


The duration of the turn can be computed from the velocity and the size of the grid. We know that speed = distance / time, solve for time:

speed = distance / time

=>

time * speed = distance

=>

time = distance / speed


Thus:

turn_duration = grid_side_length / speed;


We are storing where it was at the start of the “turn”, and where it will be at the end of the turn. Those positions should be aligned to the grid. We use the elapsed time since the start of the turn to compute the current position via interpolation.

When, the turn ends, we use the input and the last position to compute the next position. That would be the position plus the size of the grid in the direction dictated by input, if any.

You can buffer input if you like. You can treat no input as going in the same direction if you like.

We can make the end_position nullable (declare it Vector2? instead of Vector2), and take that as signal that no movement is happening at the moment. We can also work with end_time instead of elapsed_time. Similarly make end_time nullable.

var current_time = get_current_time();
var got_input = get_input();
input = got_input ?? input;

if (input != null && end_position == null)
{
start_time = current_time;
end_time = start_time + turn_duration;
start_position = current_position;
end_position = compute_next_position(start_position, input);
}

if (end_time == null || end_position == null)
{
return;
}

if (current_time > end_time.Value)
{
current_position = end_position.Value;
end_position = null;
end_time = null;
}
else
{
current_position = interpolate(start_position, end_position.Value, elapsed_time);
}



The above code differs in that it will move when it gets some input, and stays there until new input arrive. Note, however, that it will not interrupt the current motion. I do not know what you may want to happen when a key is pressed while the object is moving, it varies from game to game. However, the key to interrupt the motion is to drop the check for end_position == null, and be careful to set the new end_position still on the grid.

In my implementation for Unity and Godot, I made a Motion struct to encapsulate some of this. It holds start and end position, and also duration, and will do the interpolation given the elapsed time since the start of the motion. I also ended up accumulating delta time (Time.deltaTime) instead of using current time.

My code looks something like this (this is Unity code):

if (!_motion.HasValue)
{
var nextMotion = NextMotion(transform.position, GetNewTarget(), speed);
if (nextMotion != null)
{
_motion = nextMotion;
_time = 0.0f;
}
}

if (!_motion.HasValue)
{
return;
}

_time += Time.deltaTime;
var motion = _motion.Value;
if (_time > motion.Duration)
{
_motion = null;
transform.position = motion.End;
}
else
{
transform.position = motion.GetCurrent(_time);
}


GetNewTarget() computes a target position based on input. In your case, it should check the input, and if there is any, add to the current position the length of the side of the grid in the appropriate direction.

NextMotion creates a new motion, given the current position, the target position, and the speed.

As you can imagine GetCurrent is a linear interpolation. Its code is simply:

return Start + ((End - Start) * time / Duration);


Where Duration is pre-computed as:

var diff = end - start;
var length = diff.magnitude;
Duration = length / speed;


If you want to allow interrupting motion, the code should look something like this:

var target = GetNewTarget();

if (!_motion.HasValue || _motion.Value.End != target)
{
var nextMotion = NextMotion(transform.position, target, speed);
// ...


And GetNewTarget would work from the start position of the current motion if any, if there is no current motion the use the current position.