Sync the players positions and stuff on a server, and send the positions out everytime they change.
[QUOTE=neos300;37607295]Sync the players positions and stuff on a server, and send the positions out everytime they change.[/QUOTE]
How would you sync them exactly? What if it was an RTS styled game with hundreds of units on the map at any given time, would it work the same way? I'm designing an RTS and the only thing I don't know how to implement is a client server architecture because I've never done programming with sockets and the like over a network. How would I update the player's position if from the client's computer? Would it just have to send the server the new position or the information telling it to move?
[QUOTE=neos300;37607295]Sync the players positions and stuff on a server, and send the positions out everytime they change.[/QUOTE]
Do you have the player running the main loop and the server waiting for events? Or have the server receive al events and ten update them in its loop?
[QUOTE=FrankOfArabia;37607946]How would you sync them exactly? What if it was an RTS styled game with hundreds of units on the map at any given time, would it work the same way? I'm designing an RTS and the only thing I don't know how to implement is a client server architecture because I've never done programming with sockets and the like over a network. How would I update the player's position if from the client's computer? Would it just have to send the server the new position or the information telling it to move?[/QUOTE]
Generally, you would simply have the client tell the server that it told the units to move to a place, then the server would actually move the units.
Unless you were developing for a high-lag enviorment, which would be different.
[editline]9th September 2012[/editline]
[QUOTE=Richy19;37608470]Do you have the player running the main loop and the server waiting for events? Or have the server receive al events and ten update them in its loop?[/QUOTE]
The server should always decide what actually happens, the client should only be responsible for telling the server that it wants to do something.
The way networking should work is that the client tells the server "I want to move this thing here". Then the server runs some code specific to that thing and tells the client the results of that, whether it includes moving the thing successfully or not...
Never leave anything up to the client to calculate unless it is rendering or something that doesn't affect the world, other players, etc.
Anyone know of what android form element thing I can use to display a blank fullscreen of a certain color? That can be used with android 1.5/1.6?
RTS networking is usually different from, say, FPS networking. In the latter you have relatively few objects to synchronize, so the server is authoritative and sends object positions and other information to the clients. In RTS games, however, a common model is lockstep networking (AFAIK used in most RTS games out there) , where authority is shared between all clients, and user commands (e.g. "Move unit x to position y") and the exact tick that they should be executed on are distributed and then executed by all clients, with the game only moving forward once that is finished. (Note that this while this approach is effecient in terms of networking, it [i]requires[/i] a completely deterministic simulation. I believe that checksums get compared between clients often to prevent desyncing/cheating, at which point the offending client is either resynced(hard) or disconnected (easy).)
The requirement that all clients stay synchronized is what causes the stuttering that you may notice in some RTS games when another player is lagging.
Give this a look: [url]http://www.gamasutra.com/view/feature/3094/1500_archers_on_a_288_network_.php[/url]
Disclaimer: I haven't delved too deep into this, so forgive any inaccuracies, but I have done some investigation into the topic, as it will be a crucial part of a project I've been working on.
Hey guys, in Lua how could I match a user's input to search a ton of nested tables for a matching name variable, then only edit the variables inside of that table?
[QUOTE=JakeAM;37613236]Hey guys, in Lua how could I match a user's input to search a ton of nested tables for a matching name variable, then only edit the variables inside of that table?[/QUOTE]
[lua]local function deepsearch(t, name)
for k, v in pairs(t) do
if type(v) == "table" then
if k == name then
return v
end
local r = search(v, name)
if r then
return r
end
end
end
end[/lua]
This will do a deep search into t returning the first table it comes across with name as it's key.
That's great thanks MakeR. I have realised that instead of making the key the name, the name is stored inside of the table, so how would I make the key the name in this case?
[code]
chests = {}
function chests:insert()
local chest = {param1 = a, param2 = b}
table.insert(chests, chest)
end
[/code]
[lua]chests[name] = chest[/lua]
[editline]10th September 2012[/editline]
instead of table.insert
[editline]10th September 2012[/editline]
You may want to use this code instead to prevent infinite loops.
[lua]local function deepsearch(t, name, searched)
searched = searched or {}
for k, v in pairs(t) do
if type(v) == "table" and not searched[v] then
searched[v] = true
if k == name then
return v
end
local r = deepsearch(v, name, searched)
if r then
return r
end
end
end
end[/lua]
Does anyone have a great resource on understanding vectors?
Backtracking was quite easy and fun to understand but divide and conquer, greedy and dynamic programming just leave me with a headache.
Tried searching but didn't find any good tutorials. Does anybody know any?
[QUOTE=Asgard;37614262]Does anyone have a great resource on understanding vectors?[/QUOTE]
[url]http://khanacademy.org/[/url]
Went here, never looked back.
I'm thinking of learning HTML/CSS/JavaScript to start programming windows 8 apps.
Will this give me enough functionality? Or should I skip it and go to C++/C# instead? I'm not trying to build games or anything, just basic tasks that would work well as apps.
Also, is CodeAcademy a good resource? I've started doing the Javascript tutorials on it, should I be using a different resource instead? Microsoft has a tutorial on building apps, but I wanted to get proficient before I started doing it.
[cpp] public static void randNums(double arr[], int i){
double u1 = Math.random();
double u2 = Math.random();
double r, theta;
double z1;
double z2;
r = Math.sqrt((-2)*(Math.log(u1)));
theta = ((2)*(3.14)*(u2));
z1 = (r)*(Math.cos(theta));
z2 = (r)*(Math.sin(theta));
arr[i] = z1;
arr[i+1] = z2;
System.out.println(u1 + " " + u2);
System.out.println(r + " " + theta);
System.out.println(z1 + " " + z2);
}[/cpp]
Hey guys, I'm having some trouble with my code. For some reason, z1 and z2 don't appear to be printing out the correct numbers. The instructions in the lab were...
1. Generate two uniformly-distributed random numbers u1 and u2 between 0 and 1 (what Java's built-in random number generator gives you).
2. Compute the quantities r and θ, as given by the following equations:
r2 = -2 ln(u1)
θ = 2πu2
3. Compute two normally-distributed random numbers z1 and z2 using the following equations:
z1 = r cos(θ)
z2 = r sin(θ)
I did just that, but I'm punching it into my own calculator, and z1 and z2 don't appear to be correct. Anyone know what's up?
These are the results I get when I run it.
0.8780174484195997 0.46937746245781886 <-- This line being u1 and u2 respectively.
0.5100760975172676 2.9476904642351025 <-- This line being r and theta respectively.
-0.5005171680564261 0.09828626424491034 <-- This line being z1 and z2 respectively.
Thanks...
[QUOTE=Elements;37616649]I'm thinking of learning HTML/CSS/JavaScript to start programming windows 8 apps.
Will this give me enough functionality? Or should I skip it and go to C++/C# instead? I'm not trying to build games or anything, just basic tasks that would work well as apps.
Also, is CodeAcademy a good resource? I've started doing the Javascript tutorials on it, should I be using a different resource instead? Microsoft has a tutorial on building apps, but I wanted to get proficient before I started doing it.[/QUOTE]
Windows 8 Apps :/ Well that depends what you want to to. More advanced stuff will need C#/C++ while if you only want to do a simple game you can do that with HTML/CSS/JavaScript.
[editline]11th September 2012[/editline]
[QUOTE=Leonmyster;37620023]Math[/QUOTE]
I got the same as the program do, what do you calculate it to?
[QUOTE=Leonmyster;37620023]-snip-[/QUOTE]
Mix-up between radians and degrees?
[QUOTE=Leonmyster;37620023]
public static void randNums(double arr[], int i){ double u1 = Math.random(); double u2 = Math.random(); double r, theta; double z1; double z2; r = Math.sqrt((-2)*(Math.log(u1))); theta = ((2)*(3.14)*(u2)); z1 = (r)*(Math.cos(theta)); z2 = (r)*(Math.sin(theta)); arr[i] = z1; arr[i+1] = z2; System.out.println(u1 + " " + u2); System.out.println(r + " " + theta); System.out.println(z1 + " " + z2); }
Hey guys, I'm having some trouble with my code. For some reason, z1 and z2 don't appear to be printing out the correct numbers. The instructions in the lab were...
1. Generate two uniformly-distributed random numbers u1 and u2 between 0 and 1 (what Java's built-in random number generator gives you).
2. Compute the quantities r and θ, as given by the following equations:
r2 = -2 ln(u1)
θ = 2πu2
3. Compute two normally-distributed random numbers z1 and z2 using the following equations:
z1 = r cos(θ)
z2 = r sin(θ)
I did just that, but I'm punching it into my own calculator, and z1 and z2 don't appear to be correct. Anyone know what's up?
These are the results I get when I run it.
0.8780174484195997 0.46937746245781886 <-- This line being u1 and u2 respectively.
0.5100760975172676 2.9476904642351025 <-- This line being r and theta respectively.
-0.5005171680564261 0.09828626424491034 <-- This line being z1 and z2 respectively.
Thanks...[/QUOTE]
Is your calculator on radian mode?
EDIT: I just tested this real quick in Python and I'm getting an answer consistent with the one your Java program provided. Double check that you're not messing something up on your calculator (the most likely culprit being you're using the wrong units for sin/cos).
I am trying to upgrade Eclipse to Juno, and I have to choose between Eclipse Platform, SDK, and Platform SDK. I downloaded the Eclipse for Java dev on the website originally, and it says Eclipse SDK when I press about. Is that the one I should upgrade with?
Are those choices mutually-exclusive? Generally you should just upgrade all the modules you have installed.
The [url=http://www.eclipse.org/platform/]Eclipse Platform[/url] is the core UI; everything else comes from plugins. The "Eclipse for Java Developers" download is just the platform with the Java plugins preinstalled. If you'd downloaded "Eclipse for C/C++" developers, you'd have gotten the same platform, but with the C/C++ plugins preinstalled instead. And those downloads are just a starting point; you can install both the Java [i]and[/i] the C/C++ plugins in the same copy of Eclipse, for example.
So, if you're using the Eclipse update manager, you should probably just let it upgrade the platform and whatever plugins have updates available. Or, you could download the new [url=http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/junor]Eclipse for Java Developers[/url] and just point it at your existing workspace.
I could only upgrade one. It seems to be working, so it's all good.
I'm making a turn-based RPG in console in C#.
The battle itself is a loop (one iteration=one turn) that continues as long as the enemy or player's HP don't drop below 0.
I want to make it so that if the player is stunned, it skips his part of the loop straight to the enemy's part, and if the enemy is stunned, it skips his part and only does the player's part.
At first I thought of continue, but that skips the whole iteration including the enemy's part (depending on who isn't stunned).
So with the enemy (whose code is after the player's), it isn't a problem to just write continue and skip back to the player, but it isn't possible to use continue at the start of the player's turn without also skipping the enemy's turn and making it pointless.
So my question is: Is there a way to skip only a part of a loop instead of a whole iteration?
I think you are going about this the wrong way. Some pseudo code may help you.
[code]while (playerHealth > 0 && enemyHealth > 0)
{
if (!playerStunned)
{
// do player's turn
}
if (!enemyStunned)
{
// do enemy's turn
}
}[/code]
Thanks!
After doing that, I immediately ran into another problem on the next thing I worked on.
[code] case 1:
if (EnemyAbility1Cooldown > 0)
{
EnemyAction = RandomAction.Next(3, 9);
EnemyAbility1Cooldown = EnemyAbility1Cooldown - 1;
goto case (EnemyAction);
}[/code]
Basically, if his ability is on cooldown, he randomly chooses another ability to use.
However, I get the error that a constant value is expected.
Is there a way around this (or another way to do this)?
[QUOTE=NotAName;37627170]Thanks!
After doing that, I immediately ran into another problem on the next thing I worked on.
[code] case 1:
if (EnemyAbility1Cooldown > 0)
{
EnemyAction = RandomAction.Next(3, 9);
EnemyAbility1Cooldown = EnemyAbility1Cooldown - 1;
goto case (EnemyAction);
}[/code]
Basically, if his ability is on cooldown, he randomly chooses another ability to use.
However, I get the error that a constant value is expected.
Is there a way around this (or another way to do this)?[/QUOTE]
goto case requires a constant expression.
[QUOTE=MakeR;37627197]goto case requires a constant expression.[/QUOTE]
I figured that out, what can I use instead, if I can use anything at all?
Set whatever value you do switch on to EnemyAction?
It is. It's also a random value, which makes me wonder why it doesn't give that error too.
Instead of doing that, try putting that switch inside of a while loop that checks if an action has been taken yet. If the action is on cooldown, run through it again.
But honestly, there's probably a better way to do this that doesn't require guessing at which one is on cooldown. Just use a vector or list or something, then randomly choose one from it[1]. Add and remove from it based on cooldowns, and you're done. Even better, create a priority list to have a very basic AI.
[1] Get the number of elements in the container, then use a random function that lets you limit it to a custom range of integers (very simple to build yourself if not available). The container itself should be a list/vector/something of integers which are the "IDs" of the abilities. Then at each turn, you just check each of the cooldowns and see which ones need to get placed back into the list.
Sorry, you need to Log In to post a reply to this thread.