Skip to content

proofnetworks/proofnetwork-phaserplugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

proofnetwork-phaserplugin

Phaser plugin for proofnetwork

Plugin Usage

The ProofNetworkPlugin provides easy access to proofnetwork features within phaser games:

import ProofNetworkPlugin from './plugins/ProofNetworkPlugin.js';

export default class MyGameScene extends Phaser.Scene {
    constructor() {
        super({ key: 'MyGameScene' });
    }

    create() {
        // Initialize ProofNetwork
        this.proofNetwork = this.plugins.get('ProofNetworkPlugin');
        // Your game logic here
        this.createPlayer();
        this.setupBlockchainFeatures();
    }

    async createPlayer() {
        // Create player with VRF positioning
        const x = await this.proofNetwork.getRandomNumber(50, 750);
        const y = await this.proofNetwork.getRandomNumber(50, 550);
        
        this.player = this.physics.add.sprite(x, y, 'player');
    }

    async setupBlockchainFeatures() {
        // Load game state from smart contract
        try {
           const gameState = await this.proofNetwork.callContract(
                '0xMultiplayerContract',
                'getGameState',
                { roomId: this.roomId,message:"hi gib game state thx" }
            );
            this.score = gameState.score || 0;
        } catch (error) {
            console.log('No previous game state found');
        }
    }
}
// Get the plugin in any scene
this.proofNetwork = this.plugins.get('ProofNetworkPlugin');

// Initialize with wallet (optional)
this.proofNetwork.init(walletAddress, sessionToken);

// VRF random number
const randomNum = await this.proofNetwork.getRandomNumber(1, 100);

// VRF array selection  
const items = ['sword', 'shield', 'potion'];
const selected = await this.proofNetwork.selectFromArray(items, 1);

// Smart contract calls
    const gameState = await this.proofNetwork.callContract(
        '0xMultiplayerContract',
        'getGameState',
        { roomId: this.roomId,message:"hi gib game state thx" }
    );

About

Phaser plugin for proofnetwork

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors