owenashurst / agar.io-clone

Agar.io clone written with Socket.IO and HTML5 canvas
MIT License
2.88k stars 1.12k forks source link

Level system #472

Closed CoderJoeW closed 1 year ago

CoderJoeW commented 7 years ago

I can implement the database for a level system but I would need someone to code it into the game so how this would work

in the database tableName->users fields->id,name,level,xp pool.query ("SELECT * FROM users WHERE name='currentPlayer.name'", function (err,rows){ if (err) throw err; var user = rows; }); This will store the following in the variable user [{id:1,name:'player',level:'1',xp:'1'}] Now data can be accessed using var playerLevel = parseInt (user[0].level);

Now playerLevel is equal to 1

It's a pretty straightforward process and sql and database management has always been one of my specialties and I would be happy to implement the database for this as long as someone can actually out it into the game

vikramdurai commented 7 years ago

Wow! Nice! I'll try implementing a function like this:

function levelUp (playerName) {
        tableName->users
        fields->id,name,level,xp
        pool.query ("SELECT * FROM users WHERE name="'playerName'" function (err,rows){ if (err) throw   err; var user = rows; });
}

I haven't had much experience coming out of Python so if you find bugs please report.

CoderJoeW commented 7 years ago

from what ive been working on recently in a different branch you could use this function getInfo(){ client.query("SELECT * FROM users WHERE uid='<USER_ID>'", function(err,res){ if(err){ console.log(err); } infoArray = res; } } now set that to your users info

var level = infoArray["level"];

send to database

client.query("UPDATE users (name,level,xp) VALUES (name=<USER_NAME>,level=<USER_LEVEL>,xp=<USER_XP>);

Dve4Ever commented 5 years ago

is this still being worked on?

CoderJoeW commented 5 years ago

I wish I could spend more time on it but I really don't have the time the foundation for this exist in the current project but a full level system would still need to be worked out @Dve4Ever

Dve4Ever commented 5 years ago

Ok, and could you add my version to the demo list? The link is 'https://devooooyt.com' @flaminggenius

CoderJoeW commented 5 years ago

@Dve4Ever You can submit a pull request with yours added to the list