Page 38 of 91

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Jul 18, 2015 1:35 pm
by louie999
I have another set of questions, about lua-enet , how can I make players control their character with lua-enet?
like:
host created
player 1 joins
player 2 joins
...
Then each player can control 1 unit/character, like player 1 can control unit1, player 2 controls unit2 etc. will peer:connect_id() suffice for that? or is there a complicated approach I need to do to achieve that?

Is it possible to create a lobby or something similar where players can see all the created rooms/host then they can connect to it by simply pressing a "Connect" button ?

How can I update everything that's happening in the game to all the connected clients of a enet host? like if player 1 moved his unit or using a weapon/firing then the other players can see it too. Or if player 1 shoots then when the projectile hits a player then that player will see that he got hit. I hope someone can help me with these things as it's hard as hell for me :death:

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Jul 24, 2015 2:25 pm
by nkorth
louie999 wrote:I have another set of questions, about lua-enet , how can I make players control their character with lua-enet?
like:
host created
player 1 joins
player 2 joins
...
Then each player can control 1 unit/character, like player 1 can control unit1, player 2 controls unit2 etc. will peer:connect_id() suffice for that? or is there a complicated approach I need to do to achieve that?

Is it possible to create a lobby or something similar where players can see all the created rooms/host then they can connect to it by simply pressing a "Connect" button ?

How can I update everything that's happening in the game to all the connected clients of a enet host? like if player 1 moved his unit or using a weapon/firing then the other players can see it too. Or if player 1 shoots then when the projectile hits a player then that player will see that he got hit. I hope someone can help me with these things as it's hard as hell for me :death:
You'll need to use peer:send whenever each player does something to tell the server the new "state" of their character. (ie. their position, direction, whatever is changing) The server's job could then potentially be as simple as simply receiving these updates, then sending them along to all the other players. (an "echo server".) Of course, the server will probably end up being more complex than that, especially if you want to make a lobby, or do cheating prevention, or batch together updates to improve network speed.

Edit: also, make sure that you include some sort of player "id" in the peer:send messages, so the other game instances know what to do with them! You could make the server assign and send each player their "id" as soon as they connect, or better yet you could solely distinguish them on the server (because it can already tell peers apart), and make it add the player id as it forwards the update messages.

Re: "Questions that don't deserve their own thread" thread

Posted: Thu Aug 06, 2015 3:29 pm
by Grubby
Develop games for what target resolution?

The title says it all. What resolution do most of you target? Do you shoot for widescreen 16:9/16:10 -> (1280x720 or 1920x1080) or do you go for 4:3 -> (1024x768 or 1280x1024) I'd assume by default, that most modern monitors cater to widescreen.

Just curious...

Re: "Questions that don't deserve their own thread" thread

Posted: Thu Aug 06, 2015 3:45 pm
by zorg
Grubby wrote:Develop games for what target resolution?

The title says it all. What resolution do most of you target? Do you shoot for widescreen 16:9/16:10 -> (1280x720 or 1920x1080) or do you go for 4:3 -> (1024x768 or 1280x1024) I'd assume by default, that most modern monitors cater to widescreen.

Just curious...
I'm fond of 4:3 and 5:4 (1280x1024 is the latter) currently, but if one has a different aspect ratio, then i believe games should adapt in any way possible (and fair, depending on the type of game), with letter/pillarboxing, or stretching (mostly useful when drawing to a canvas).
To tell the truth, i believe that this depends most on the game you want to make.

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Aug 07, 2015 6:37 am
by airstruck
Given two vectors, how can I determine the shortest direction to rotate the first vector to project it onto the second vector (clockwise or counterclockwise)?

Right now I'm converting both vectors to angles and checking whether the difference between the angles is positive or negative. Is there a shortcut?

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Aug 07, 2015 11:40 am
by davisdude
You could try projecting one vector onto the other, then correct it's magnitude. I don't know if this will be any easier/faster, but you could try it. If magnitude doesn't matter it's even better.
Never mind, misread question :P

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Aug 08, 2015 12:51 pm
by Fantos
Hi there guys, I'm new around here and I stuck on something, or more accuretly don't know what cause it and it gonna be good to know.
So I use STI, and simply I have a platform(polygon), and a box. The box fall on the platform, that good but when I move it sideway the box don't fall when reach end of the platform. What weird its happening only if the box touch the platform for around one second. After that the box have to touch another platform, or gravity don't affect it again. I overlook something about love.physics? I miss something?
Here the code:
http://pastebin.com/zQ8ePQMj
And here the love file:

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Aug 15, 2015 7:41 am
by Jasoco
I didn't want to create a thread for a simple question like this.

Why doesn't this code work?

Code: Select all

local shuffleRNG = love.math.newRandomGenerator(seed)
function shuffle(t)
	table.sort(t, function(a, b) return shuffleRNG:random() > 0.5 end)
end
If I use normal math.random() instead, it works fine. But if I use the love.math RNG, it errors with a "Invalid sort function" message.

I thought I could create a simple shuffle function, but I guess I'll use a more complex version from online that will probably work fine with the love.math RNG stuff.

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Aug 15, 2015 10:47 am
by Robin
I didn't think using math.random() would work either.

I'd just use:

Code: Select all

local shuffleRNG = love.math.newRandomGenerator(seed)
function shuffle(t)
    for i = #t, 2, -1 do
        local j = shuffleRNG:random(1, i)
        t[i], t[j] = t[j], t[i]
    end
end
I don't think sorting with a random comparison function would work well in any case, since it depends so much on the order of comparison.

EDIT: quoting Wikipedia:
A variant of the above method that has seen some use in languages that support sorting with user-specified comparison functions is to shuffle a list by sorting it with a comparison function that returns random values. However, this is an extremely bad method: it is very likely to produce highly non-uniform distributions, which in addition depends heavily on the sorting algorithm used.

[...]

In principle this shuffling method can even result in program failures like endless loops or access violations, because the correctness of a sorting algorithm may depend on properties of the order relation (like transitivity) that a comparison producing random values will certainly not have. While this kind of behaviour should not occur with sorting routines that never perform a comparison whose outcome can be predicted with certainty (based on previous comparisons), there can be valid reasons for deliberately making such comparisons. For instance the fact that any element should compare equal to itself allows using them as sentinel value for efficiency reasons, and if this is the case, a random comparison function would break the sorting algorithm.

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Aug 15, 2015 10:55 am
by zorg
Jasoco wrote:I didn't want to create a thread for a simple question like this.

Why doesn't this code work?

Code: Select all

local shuffleRNG = love.math.newRandomGenerator(seed)
function shuffle(t)
	table.sort(t, function(a, b) return shuffleRNG:random() > 0.5 end)
end
If I use normal math.random() instead, it works fine. But if I use the love.math RNG, it errors with a "Invalid sort function" message.

I thought I could create a simple shuffle function, but I guess I'll use a more complex version from online that will probably work fine with the love.math RNG stuff.
I tried recreating it in the online lua sandbox, substituting math.random for love's prng that you use, and sometimes it worked, other times it didn't.
I'm guessing table.sort errors if the sorting function behaves unexpectedly or something.
Edit: behaving unexpectedly, like for values of 2 and 3, both being bigger and smaller than each other.
Try it out:

Code: Select all

local shuffleRNG = {}
math.randomseed(os.time())
shuffleRNG.random = function(self) return math.random() end
function shuffle(t)
   table.sort(t, function(a, b)
local r = shuffleRNG:random()
local d = r > 0.5
print(a,b,r,d)
return d end)
end
local tbl = {4,2,5,3}
shuffle(tbl)
for i,v in ipairs(tbl) do print(i,v) end