-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
138 lines (117 loc) · 4.42 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
<!DOCTYPE html>
<html>
<head>
<title>Vanilla Boilerplate</title>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script>
</head>
<body>
<button id="btn-login">Moralis Metamask Login</button>
<button id="btn-logout">Logout</button>
<br>
<script>
/** Connect to Moralis server */
const serverUrl = "https://ec30bwtvaqao.usemoralis.com:2053/server";
const appId = "HkuRL1zMk9tsy3fFd1FnxLC7KUA1jaUYTlShZIk7";
Moralis.start({ serverUrl, appId });
/** Add from here down */
async function login() {
let user = Moralis.User.current();
if (!user) {
try {
user = await Moralis.authenticate({ signingMessage: "Hello World!" })
console.log(user)
console.log(user.get('ethAddress'))
} catch (error) {
console.log(error)
}
}
}
async function logOut() {
await Moralis.User.logOut();
console.log("logged out");
}
document.getElementById("btn-login").onclick = login;
document.getElementById("btn-logout").onclick = logOut;
// config
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 300 },// - means up on y ; x is for left or right
debug: false //true to enable collision box and keypress force direction
}
},
scene: {//functions below are called
preload: preload,
create: create,
update: update
}
};
var platforms;
var player;
var cursor;
//new game having config
var game
(function launch(){
let user = Moralis.User.current();
if (!user) {
console.log("Please log in using MetaMask");
}
else {
console.log(user.get("ethAddress")+" "+"logged in");
// location.reload();
game = new Phaser.Game(config);
}
})()
//Loading assets pic/movie/music
function preload ()
{
this.load.image('background', 'assets/BG.png');
this.load.image('ground', 'assets/Tiles/Tile (2).png');
this.load.image('player', 'assets/a_player1.png');
}
//initial setup ex: draw the preloaded img on screen put players on the map
function create ()
{
this.add.image(400, 300, 'background').setScale(0.5);
platforms = this.physics.add.staticGroup();//load physics in config ; when user hits platform then reaction to take place on user and not on platform , platform are static but player is affected by gravity
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(490, 250, 'player').setScale(0.08).refreshBody();
player.setBounce(0.5);
player.setCollideWorldBounds(true);
this.physics.add.collider(player, platforms);
cursors = this.input.keyboard.createCursorKeys();
}
//60 times (frames) per second movement in a designed frame : game
function update ()
{
// console.log("Update");
//Check ? ex: If bullet is hit then health decreased or not ?
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(-330);
}
}
</script>
</body>
</html>