-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
144 lines (105 loc) · 3.32 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<html>
<head>
<title>Aave-gotcha</title>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://npmcdn.com/[email protected]/dist/moralis.js"></script>
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script>
</head>
<body>
<button id="btn-login">Moralis Login</button>
<button id="btn-logout">Logout</button>
<br>
<script>
// connect to Moralis server
Moralis.initialize("https://sfikz6mbm6qk.bigmoralis.com:2053/server");
Moralis.serverURL = "ARMSKjGobnWbXgJsrfg3KBNJzXXwBqOVKAFcYxh2";
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 300 },
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
var game = new Phaser.Game(config);
var platforms;
var player;
var cursor;
var jumpHeight = -100;
function launch(){
let user = Moralis.User.current();
if (!user) {
alert("Pls Login with Metamask")
}else{
console.log(user.get("ethAddress") + " " + " logged in")
game = new Phaser.Game(config);
}
}
launch()
function preload ()
{
this.load.image('background', 'assets/BK.png');
this.load.image('ground', 'assets/Tiles/grd.png');
this.load.image('player', 'assets/pp.png');
}
function create ()
{
this.add.image(400, 300, 'background').setScale(0.55);
platforms = this.physics.add.staticGroup();
platforms.create(470,400, 'ground').setScale(0.5).refreshBody();
platforms.create(535,400, 'ground').setScale(0.5).refreshBody();
platforms.create(600,400, 'ground').setScale(0.5).refreshBody();
platforms.create(665,400, 'ground').setScale(0.5).refreshBody();
player = this.physics.add.sprite(500, 150, 'player').setScale(0.4).refreshBody();
player.setBounce(0.2);
player.setCollideWorldBounds(true);
this.physics.add.collider(player, platforms);
cursors = this.input.keyboard.createCursorKeys();
}
function update ()
{
if (cursors.left.isDown)
{
player.setVelocityX(-160);
}
else if (cursors.right.isDown)
{
player.setVelocityX(160);
}
else
{
player.setVelocityX(0);
}
if (cursors.up.isDown && player.body.touching.down)
{
player.setVelocityY(jumpHeight);
}
}
// add from here down
async function login() {
let user = Moralis.User.current();
if (!user) {
user = await Moralis.Web3.authenticate();
launch()
}
console.log("logged in user:", user);
}
async function logOut() {
await Moralis.User.logOut();
console.log("logged out");
location.reload();
}
document.getElementById("btn-login").onclick = login;
document.getElementById("btn-logout").onclick = logOut;
</script>
</body>
</html>