<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
/>
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>3D ONLINE GAME 2</title>
<link rel="stylesheet" href="/css/examples.css?ver=1.0.0" />
<script src="/js/examples.js?ver=1.1.1"></script>
<script src="/lib/phaser.min.js?ver=3.52.0"></script>
<script src="/lib/enable3d/enable3d.phaserExtension.0.25.0.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<body>
<!--- <div id="info-text">Use WASD, SPACE and your Mouse.<br />Try to play it on your mobile device :)</div> -->
<center>
<h1>
<?php
include_once 'db.php';
$sessionid = $_SESSION['user_id'];
echo $user_data['username'];
if(empty($sessionid)){
header('Location: index.php');
//echo $sessionid;
}
//skripts kurš pie katras čaraktera kustību apstājas updeito tabulas sadaļu *location*
//skripts kurš katru lietotāju kura datetime sakrīt ar intervālu pēdējās 15 min, zīmē ekrānā
?>
</h1> <a href="logout.php">Logout.</a>
</center>
<script>
const {
enable3d,
Scene3D,
Canvas,
ThirdDimension,
THREE,
JoyStick,
ExtendedObject3D,
ThirdPersonControls,
PointerLock,
PointerDrag
} = ENABLE3D
/**
* Is touch device?
*/
const isTouchDevice = 'ontouchstart' in window
class MainScene extends Scene3D {
constructor() {
super({
key: 'MainScene'
})
}
init() {
this.accessThirdDimension({
maxSubSteps: 10,
fixedTimeStep: 1 / 120
})
this.third.renderer.outputEncoding = THREE.LinearEncoding
this.canJump = true
this.move = false
this.moveTop = 0
this.moveRight = 0
}
async create() {
const {
lights
} = await this.third.warpSpeed('-ground', '-orbitControls')
const {
hemisphereLight,
ambientLight,
directionalLight
} = lights
const intensity = 0.65
hemisphereLight.intensity = intensity
ambientLight.intensity = intensity
directionalLight.intensity = intensity
//this.third.physics.add.box({ y: 10, x: 35 }, { lambert: { color: 'red' } })
// this.third.physics.debug.enable()
/**
* Medieval Fantasy Book by Pixel (https://sketchfab.com/stefan.lengyel1)
* https://sketchfab.com/3d-models/medieval-fantasy-book-06d5a80a04fc4c5ab552759e9a97d91a
* Attribution 4.0 International (CC BY 4.0)
E4E717
*/
this.third.load.gltf('/assets/glb/book6.glb').then(object => {
const scene = object.scenes[0]
const book = new ExtendedObject3D()
book.name = 'scene'
book.add(scene)
this.third.add.existing(book)
// add animations
// sadly only the flags animations works
object.animations.forEach((anim, i) => {
book.mixer = this.third.animationMixers.create(book)
// overwrite the action to be an array of actions
book.action = []
book.action[i] = book.mixer.clipAction(anim)
book.action[i].play()
})
book.traverse(child => {
if (child.isMesh) {
child.castShadow = child.receiveShadow = false
child.material.metalness = 0
child.material.roughness = 1
if (/mesh/i.test(child.name)) {
this.third.physics.add.existing(child, {
shape: 'concave',
mass: 0,
collisionFlags: 1,
autoCenter: false
})
child.body.setAngularFactor(0, 0, 0)
child.body.setLinearFactor(0, 0, 0)
}
}
})
})
//$.post( "postlocation.php", function( data ) {
//});
//this.man.position.set(35, -3.5, 0)
//function getData(ajaxurl) {
//return $.ajax({
//type: "GET",
//url: 'getlocation.php',
//data:{},
//success:function(html) {
//var obj = JSON.parse(html);
//}
//});
//};
//async function test() {
//try {
//const res = await getData()
//console.log(res)
//this.man.position.set(obj.x, obj.y, obj.z)
//} catch(err) {
//console.log(err);
//}
//}
//test();
let text = "";
var fruits = [];
$.ajax({
type: "GET",
async: false,
url: 'loaduserdata.php',
data: {},
success: function (data) {
fruits = data.split(",").map(String);
//const fruits = Array.from([data])
//console.log(fruits);
//console.log(typeof(fruits));
}
});
var skins = [];
$.ajax({
type: "GET",
async: false,
url: 'loadskins.php',
data: {},
success: function (data) {
skins = data.split(",").map(String);
}
});
console.log("zajebaļi", skins);
for (var i = 0; i < skins.length - 1; i++) {
let skin = skins[i];
/**
* box_man.glb by Jan Bláha
* https://github.com/swift502/Sketchbook
* CC-0 license 2018
*/
/// ievietos skin
this.third.load.gltf(skin).then(object => {
var myMans = new Array();
//console.log(fruits.length);
console.log("lohi2", myMans[i]);
for (var i = 0; i < fruits.length - 1; i++) {
const man = object.scene.children[0]
console.log("man", man);
myMans.push(man);
}
for (var i = 0; i < myMans.length - 1; i++) {
//console.log("womeni", myMans[i]);
console.log(myMans);
myMans[i] = new ExtendedObject3D()
//this.man = new ExtendedObject3D()
console.log("fruits", fruits);
myMans[i].rotateY(Math.PI + 0.1) // a hack
myMans[i].name = fruits[i]
//this.man.rotateY(Math.PI + 0.1) // a hack
//this.man.name = fruits[i]
var obj; /// koordinātes
$.ajax({
type: "GET",
async: false,
url: 'getlocation.php',
data: {},
success: function (html) {
obj = JSON.parse(html);
//console.log("noliek", obj);
}
});
//console.log(obj.x);
//console.log(obj.y);
//console.log(obj.z);
//{"x":-0.9553362921119645,"y":0,"z":0.2955208435521314}
///alert(obj.x, obj.y, obj.z);
if (i == 0) {
myMans[i].position.set(724.2014, 800, -205.63472)
} else {
myMans[i].position.set(754.2014, 1000, -205.63472)
}
console.log("pievieno", myMans[i].name);
//this.man.add(myMans[i])
//this.man.rotation.set(0, Math.PI * 1.5, 0)
//myMans[i].add(myMans[i])
myMans[i].rotation.set(0, Math.PI * 1.5, 0)
// add shadow
myMans[i].traverse(child => {
if (child.isMesh) {
child.castShadow = child.receiveShadow = true
// https://discourse.threejs.org/t/cant-export-material-from-blender-gltf/12258
child.material.roughness = 1
child.material.metalness = 0
}
})
/**
* Animations
*/
this.third.animationMixers.add(myMans[i].animation.mixer)
object.animations.forEach(animation => {
if (animation.name) {
myMans[i].animation.add(animation.name, animation)
}
})
myMans[i].animation.play('idle')
/**
* Add the player to the scene with a body
*/
for (var i = 0; i < fruits.length - 1; i++) {
//console.log("pievieno charakter",myMans[i]);
this.third.add.existing(myMans[i])
}
this.third.physics.add.existing(myMans[i], {
shape: 'sphere',
radius: 0.25,
width: 0.5,
offset: {
y: -0.25
}
})
myMans[i].body.setFriction(0.8)
myMans[i].body.setAngularFactor(0, 0, 0)
// https://docs.panda3d.org/1.10/python/programming/physics/bullet/ccd
myMans[i].body.setCcdMotionThreshold(1e-7)
myMans[i].body.setCcdSweptSphereRadius(0.25)
/**
* Add 3rd Person Controls
*/
this.controls = new ThirdPersonControls(this.third.camera, myMans[i], {
offset: new THREE.Vector3(0, 1, 0),
targetRadius: 3
})
// set initial view to 90 deg theta
this.controls.theta = 90
/**
* Add Pointer Lock and Pointer Drag
*/
if (!isTouchDevice) {
let pl = new PointerLock(this.game.canvas)
let pd = new PointerDrag(this.game.canvas)
pd.onMove(delta => {
if (pl.isLocked()) {
this.moveTop = -delta.y
this.moveRight = delta.x
}
})
}
} // beidzas myMans[i]
console.log("vai ir vai nav", object);
})
}
/**
* Add Keys
*/
this.keys = {
a: this.input.keyboard.addKey('a'),
w: this.input.keyboard.addKey('w'),
d: this.input.keyboard.addKey('d'),
s: this.input.keyboard.addKey('s'),
space: this.input.keyboard.addKey(32)
}
/**
* Add joystick
*/
if (isTouchDevice) {
const joystick = new JoyStick()
const axis = joystick.add.axis({
styles: {
left: 35,
bottom: 35,
size: 100
}
})
axis.onMove(event => {
/**
* Update Camera
*/
const {
top,
right
} = event
this.moveTop = top * 3
this.moveRight = right * 3
})
const buttonA = joystick.add.button({
letter: 'A',
styles: {
right: 35,
bottom: 110,
size: 80
}
})
buttonA.onClick(() => this.jump())
const buttonB = joystick.add.button({
letter: 'B',
styles: {
right: 110,
bottom: 35,
size: 80
}
})
buttonB.onClick(() => (this.move = true))
buttonB.onRelease(() => (this.move = false))
}
update();
console.log("city");
}
/// iegūst no datubāzes vai leciens ir animācija
jump() {
var skins = [];
$.ajax({
type: "GET",
async: false,
url: 'loadskins.php',
data: {},
success: function (data) {
skins = data.split(",").map(String);
}
});
console.log("zajebaļi", skins);
for (var i = 0; i < skins.length - 1; i++) {
this.third.load.gltf(skin).then(object => {
var myMans = new Array();
for (var i = 0; i < fruits.length - 1; i++) {
const man = object.scene.children[0]
console.log("man", man);
myMans.push(man);
}
if (!myMans[i] || !this.canJump) return
this.canJump = false
myMans[i].animation.play('jump_running', 500, false)
this.time.addEvent({
delay: 650,
callback: () => {
this.canJump = true
myMans[i].animation.play('idle')
}
})
myMans[i].body.applyForceY(6)
}
}
}
//ja tas notiek updeito datubāzi ar to ka palecās
update() { // lai Viņš strādātu object subklasēm būtu jābūt pieejamām, object rodās pašā sākumā pie skin izvēles
var fruits2 = [];
$.ajax({
type: "GET",
async: false,
url: 'loaduserdata.php',
data: {},
success: function (data) {
fruits2 = data.split(",").map(String);
//const fruits = Array.from([data])
//console.log(fruits);
//console.log(typeof(fruits));
}
});
var myMans = new Array();
//console.log(fruits.length);
console.log("lohi2", myMans[i]);
for (var i = 0; i < skins.length - 1; i++) {
this.third.load.gltf(skin).then(object => {
const man = object.scene.children[0]
console.log("man", man);
myMans.push(man);
}
}
for (var i = 0; i < fruits2.length - 1; i++) {
if (myMans[i] && this.man.body) {
/**
* Update Controls
*/
this.controls.update(this.moveRight * 2, -this.moveTop * 2)
if (!isTouchDevice) this.moveRight = this.moveTop = 0
/**
* Player Turn
*/
const speed = 4
const v3 = new THREE.Vector3()
/////console.log(time);
//if(time % 55 == 0){
//console.log(5000);
///{"x":0.9991227572113053,"y":0,"z":0.04187739273736313}
//{
//"x": -0.9994445004172535,
//"y": 0,
//"z": -0.03332702485530725
//}
setTimeout(function () {
var locatedata = JSON.stringify(v3);
$.post(
"postlocation.php", {
locatedata: locatedata
},
function (data) {
//console.log("izsaukta", v3);
}
);
}, 10000);
//}
// iegūtos rotācijas datus ievieto šeit ja nav jau iegūti manuāli
const rotation = this.third.camera.getWorldDirection(v3)
//gadijumā ja ir jau izveidoti updeito datubāzi
const theta = Math.atan2(rotation.x, rotation.z)
const rotationMan = this.man.getWorldDirection(v3)
const thetaMan = Math.atan2(rotationMan.x, rotationMan.z)
this.man.body.setAngularVelocityY(0)
const l = Math.abs(theta - thetaMan)
let rotationSpeed = isTouchDevice ? 2 : 4
let d = Math.PI / 24
if (l > d) {
if (l > Math.PI - d) rotationSpeed *= -1
if (theta < thetaMan) rotationSpeed *= -1
this.man.body.setAngularVelocityY(rotationSpeed)
}
/**
* Player Move
*/
if (this.keys.w.isDown || this.move) {
if (this.man.animation.current === 'idle' && this.canJump) this.man.animation.play('run')
const x = Math.sin(theta) * speed,
y = this.man.body.velocity.y,
z = Math.cos(theta) * speed
//iegūtos ātruma datus iegūst no datubāzes
this.man.body.setVelocity(x, y, z)
//gadijumā ja ir izveidoti updeito datubāzi ar tiem
} else {
if (this.man.animation.current === 'run' && this.canJump) this.man.animation.play('idle')
}
/**
* Player Jump
*/
if (this.keys.space.isDown && this.canJump) {
this.jump()
}
}
}
}
}
const config = {
type: Phaser.WEBGL,
transparent: true,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
width: window.innerWidth * Math.max(1, window.devicePixelRatio / 2),
height: window.innerHeight * Math.max(1, window.devicePixelRatio / 2)
},
scene: [MainScene],
...Canvas({ antialias: false })
}
window.addEventListener('load', () => {
enable3d(() => new Phaser.Game(config)).withPhysics('/lib/ammo/kripken')
})
//////////wqtttwrf
</script>
</body>
</html>
© 2022 GitHub, Inc.
Terms
Privacy
Security
Status
Docs
Contact GitHub
Pricing
API
Training
Blog
About