Skip to content

Instantly share code, notes, and snippets.

@jmdejong
Created February 15, 2018 20:42
Show Gist options
  • Save jmdejong/8711e9ad760218f5a75ae4015e7739e7 to your computer and use it in GitHub Desktop.
Save jmdejong/8711e9ad760218f5a75ae4015e7739e7 to your computer and use it in GitHub Desktop.
design of linkworlds game(s)

Linkworlds (WIP name) is a tildetown project to link several games together and pass player data around.

Let's say that there are different rooms. Each room is it's own independent webpage.

A player can move and play within a room, and when entering some kind of portal, the player goes to another room, giving that room the current player data.

Example setup (pseudo-javascript):

function main(){
    gameData = JSON.parse(localStorage.getItem("linkworlds"))
    player = new Player(storedData.player)
}

function changeToRoom(link){
    save()
    document.location = link
}

function save(){
    gameData = Object.assign(gameData, {player: player.getData()})
    localStorage.setItem("linkworlds", JSON.stringify(gameData))
}

class Portal {
    
    link = "https://tilde.town/~troido/linkworlds/otherroom.html"
    
}

class Player {
    
    constructor(playerData){
        // playerdata in this case represends all data that is passed between rooms
        // this is stuff like the inventory
        
        this.inventory = playerData.inventory
        this.x = START_X
        this.y = START_Y
        
        this.data = playerData
    }
    
    
    collidesWithPortal(portal){
        
        changeToRoom(portal.link);
        
    }
    
    getData(){
        return Object.assign({}, this.data, {inventory: this.inventory})
    }
    
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment