Handling 4 Players. Combine Events

0 favourites
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • Hi Guys!

    I am working on a single device multiplayer game for tablets

    ***-->Main Thread: Jelly Jam!<--**

    And I have big trouble with handling events for all players without writing the same event for every player over and over again.

    In my game i want to have different cooldown times. at first I used a cooldown plugin which worked like that:

    I wasn't happy with it because I couldn't reduce the cooldown for every player. I tried nearly EVERYTHING with families, instance variables and stuff like that.

    The latest thing i came up with is a cooldown-system that uses an array.

    Here's a live preview:

    Cooldown-System with an Array

    and here's the .capx

    drive.google.com/file/d/0B9IR6fhnjEUvUnpyRzRCWW9Od0k/edit

    Here is a sketch for the Array i use:

    My Array system is like 10 times more complicated then my system I had before which had 10 times more events but does not work half as good!

    If you click the buttons fast or click one while the other is on cooldown, the system gets bugged really fast.!

    Why is it not working properly?

    what would you guys recommend for creating games with multiple players?

    with placeholders this would be like the easiest task ever.

    On touched p*_button : p*_char - spawn p*_bullet

    where * can stand for player 1,2,3 or 4.

    please help me, it's really grinding my gears.

    ask me if you need further information.

    by the way I made a similar post 2 and a half months ago, but no one answered. Maybie you can imagine my problem better if you also have a look at this:

    Old Thread

    cheers! Phil

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'll take a look today when I have some more time. If there is no answer that is :D

  • jayderyu

    I actually got something to work 5 minutes ago. I'll post it here tomorrow.

  • Use functions.

  • jayderyu

    I actually got something to work 5 minutes ago. I'll post it here tomorrow.

    Awesome. good work :)

  • instead of sepperate keys, use 1 touch object with vars, spawn that, give it variables like: name and action.

    ie

    name: player 1

    action: moveleft

    on layout start spawn all objects on desired locations

    Make 1 input on touch event for the spawned objects.

  • instead of sepperate keys, use 1 touch object with vars, spawn that, give it variables like: name and action.

    ie

    name: player 1

    action: moveleft

    on layout start spawn all objects on desired locations

    Make 1 input on touch event for the spawned objects.

    ok. that sounds interesting. Are you talking of something like Sprites with different UID's ?

    You cant creat them if you hold control while you drag a sprite.

    couldn't you use family variables then?

    and how would you go on with the movement events then?

    on "Buttons" touched (family)

    ---> if player variable = 1 -> move player 1 to the left

    ?? could you explain?

  • > jayderyu

    > I actually got something to work 5 minutes ago. I'll post it here tomorrow.

    Awesome. good work :)

    i didn't get it done. and haven't got time at the weekend but i will definetly work on it a lot on monday. and i hope i can post it on monday evening.

    How have you dealt with the movement in your multiplayer game? Have you created something like this yet?

  • > instead of sepperate keys, use 1 touch object with vars, spawn that, give it variables like: name and action.

    >

    > ie

    > name: player 1

    > action: moveleft

    >

    > on layout start spawn all objects on desired locations

    >

    > Make 1 input on touch event for the spawned objects.

    >

    >

    > ok. that sounds interesting. Are you talking of something like Sprites with different UID's ?

    > You cant creat them if you hold control while you drag a sprite.

    >

    > couldn't you use family variables then?

    >

    > and how would you go on with the movement events then?

    >

    > on "Buttons" touched (family)

    > ---> if player variable = 1 -> move player 1 to the left

    >

    > ?? could you explain?

    check the test page

    Its part of a game im making, I stripped of the other stuff, was quicker then rebuilding, lol

    Its an on screen login keyboard

    If you pres any key it appears in the top input box

    I added some compare stuff, and see what happens if you press x,y or z

    Capx

  • I create a variable called PLAYER in botht he controller objects and the Player object.

    Then when a controller object is pressed. I have direct access to the Player ID. Which then I compare to create a SOL of just that 1 player.

  • Here's an example file you can see how i've delt with reusing assets and spawing "prefab" characters based on one setup and multiple controls

    Basically its all based on functions though.

    You create a single player entity, and give it a unique owner ID at the time of creation. Then program a function for each different type of attack or movement etc.

    Then you call the function using its Unique ID as a parameter, and thus only the player that matches that Unique ID performs the action.

    eg: On Function Fire Bullet (1) (100) (250)

    Function "Fire Bullet"

    create object "bullet" at function.param(0) (player 1's position)

    set bullet.damage = function.param(1)

    set bullet.speed = function.param(2)

    This way you can reuse this one section of code over and over for any player no matter how many you have etc.

    Example

    dl.dropboxusercontent.com/u/403350/SpawnPlayerExample/index.html

    click player 1 and player 2's) gamepad to spawn them.

    use WASD and SPACE for player 1 and arrow keys and "/" For player 2

    you can see how i've used the same technique for dealing with other ares such as collision detection as well, one function that gets reused over and over

    Capx

    dl.dropboxusercontent.com/u/403350/SpawnPlayerExample/SpawnPlayerExample.capx

  • Allright guys I got pretty much uf my stuff to work.

    I worked with sub-events like lennaert in your example. Thanks for sharing.

    justifun I can't have a look at your capx because of a missing plugin but i'll definetly check it out later when i have more time.

    jayderyu I finally had the time to finish it.

    This is what I came up with for my cooldown behaviour:

    Live Demo

    with these little events I achieved more or less the best cooldown system i ever had xD I didn't test it on a mobile device for multiple touch inputs at the same time but i really hope it works lol

    (edit: url did not work for some reason)

    CAPX

    EDIT: ignore the animation frame for now. It does not reset properly, If you have a good solution feel free to write me.

    This is the new array which i store almost all information about players in. (edit: url did not work)

    y0 - player number

    y1 - wheather a shoot button is on cooldown or not

    y2 - custom cooldown time, can easily be reduced on kill

    y3 - amount of degrees I change the bullet.angleOfMotion while a movement key is in touch.

    y4 - bullet.speed of each character .. very easy to change if someone picks up a speed power up for example.

    y5 - player kills ...

    y6 - bullet speed ..

    y7 - animation / "skin"

    and so on ..

    this is my movement example which i also reduced the events a lot.

    Live Demo

    CAPX

    If you have any questions about the array just ask.

    cheers!

    phil

    11.11.13

  • nice one :D and your welcome

    Might I add a suggestion,stuff each control in a corner ;)   max space usage, more comfortable playing.

    You could also ponder placing it on the center of each side, but it would give an unequal devide.

  • nice one :D and your welcome

    Might I add a suggestion,stuff each control in a corner ;)   max space usage, more comfortable playing.

    You could also ponder placing it on the center of each side, but it would give an unequal devide.

    lennaert

    Thanks for your suggestion. Have a look at the "second version" Live Demo in my Main Thread This is how the controlls are going to be placed.

    By the way! Has someone a good Idea how I could manage the spawn system? where should the characters spawn after death? random? with spawn protection? or would it be better to play like elimination .. without respawn wait untill the last one is left, he gains the most points and then the next round starts.. ?

    jayderyu how do you spawn players in your game?

  • Well in my game all the players are a

    SpritePlayer with a PLAYER_ID variable.

    I create the player. Set the ID. then create and pin the visual part of the player. If the player is complex with lots of sensors. Then it's a big list of positioning and pinning the sensors to player.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)