Skip to content

Commit

Permalink
Finally added whole converted tested verlet script into server as module
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoe Love committed Nov 12, 2016
1 parent 4bec52f commit efe3027
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 33 deletions.
108 changes: 86 additions & 22 deletions __server__/__client__/webgl/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,8 @@ class Body {

this.tentacles = [] ;
this.Settings() ;

this.tentacle1 ;
}
Settings() {
this.gravity = 0 ;
Expand All @@ -750,7 +752,27 @@ class Body {
// tentacle.Move(this.Transform.position , true);
this.tentacles.push(tentacle);
}

// DrawTenta() {
// if(this.tentacle1) {
// var c , i ;
// c=0;
// i=0;
// console.log(this.tentacle1[0]) ;
// var ctx = elements.ctx ;
// for (i in this.tentacle1) {
// for (j in this.tentacle1.pos) {
// var particles = this.tentacle1[i] ;

// ctx.save() ;
// ctx.beginPath() ;
// ctx.arc(particles[j].pos.x , particles[j].pos.y , 10,0,Math.PI*2,false) ;
// ctx.stroke() ;
// ctx.fill() ;
// ctx.restore() ;
// }
// }
// }
// }
Translate(vec) {
this.Transform.position.x = vec.x ;
this.Transform.position.y = vec.y ;
Expand Down Expand Up @@ -795,6 +817,26 @@ class Body {
ctx.restore();
ctx.save() ;

// if(this.tentacle1) {
// var c , i ;
// c=0;
// i=0;
// console.log(this.tentacle1[0]) ;
// var ctx = elements.ctx ;
// for (i in this.tentacle1) {
// for (j in this.tentacle1.pos) {
// var particles = this.tentacle1[i] ;

// ctx.save() ;
// ctx.beginPath() ;
// ctx.arc(particles[j].pos.x , particles[j].pos.y , 10,0,Math.PI*2,false) ;
// ctx.stroke() ;
// ctx.fill() ;
// ctx.restore() ;
// }
// }
// }

// console.log(ctx.measureText(width));
ctx.font="23px Georgia";

Expand Down Expand Up @@ -1220,6 +1262,27 @@ function Init() {
data.Transform.position.y += elements.canvas.height ;

Players[data.id].newTransform.position = data.Transform.position ;


// Players[data.id].tentacle1 = data.tentacles ;
// var c , i ;
// c=0;
// i=0;
// var ctx = elements.ctx ;
// for (i in data.tentacles) {
// for (j in data.tentacles.pos) {
// var particles = data.tentacles[i] ;

// ctx.save() ;
// ctx.beginPath() ;
// ctx.arc(particles[j].pos.x , particles[j].pos.y , 10,0,Math.PI*2,false) ;
// ctx.stroke() ;
// ctx.fill() ;
// ctx.restore() ;
// }
// }


}
else if(data.type == 'food') {
Foods[data.id].position = data.Transform.position ;
Expand Down Expand Up @@ -1347,7 +1410,7 @@ window.onresize = function() {
room.Draw(ctx , camera. xView , camera.yView);
}

var sim ; //= new VerletJS(width, height, canvas);
// var sim ; //= new VerletJS(width, height, canvas);
window.onload = function() {

var canvas = document.getElementById("game" );
Expand All @@ -1362,18 +1425,18 @@ window.onload = function() {
canvas.width = width ;
canvas.height = width ;

sim = new VerletJS(width, width, canvas);
// sim = new VerletJS(width, width, canvas);

MouseHandler = new Mouse(canvas) ;
KeyboardHandler = new Keyboard(canvas) ;
elements.canvas = canvas ;
elements.ctx = ctx ;


sim.gravity = new Vec2(0,0);
sim.friction = 0.98;
// sim.gravity = new Vec2(0,0);
// sim.friction = 0.98;

var tree1 = sim.tree(new Vec2(width/2,height-120), 5, 70, 0.95, (Math.PI/2)/3);
// var tree1 = sim.tree(new Vec2(width/2,height-120), 5, 70, 0.95, (Math.PI/2)/3);
// var FPS =30 ;
// var INTERVAL = 1000/FPS ;
// var STEP = INTERVAL/1000 ;
Expand Down Expand Up @@ -1449,25 +1512,26 @@ function Draw() {
Players[IDs[i]].tentacles[j].Draw(elements.ctx , camera.xView , camera.yView) ;
}
Players[IDs[i]].Draw(elements.ctx , camera.xView , camera.yView) ;
// Players[IDs[i]].DrawTenta() ;
// console.log(IDs[i] +" , "+socket.id);
}

var c , i ;
c=0;
i=0;
var ctx = elements.ctx ;
for (c in sim.composites) {
for (i in sim.composites[c].particles) {
var particles = sim.composites[c].particles;
// var c , i ;
// c=0;
// i=0;
// var ctx = elements.ctx ;
// for (c in sim.composites) {
// for (i in sim.composites[c].particles) {
// var particles = sim.composites[c].particles;

ctx.save() ;
ctx.beginPath() ;
ctx.arc(particles[i].pos.x , particles[i].pos.y , 10,0,Math.PI*2,false) ;
ctx.stroke() ;
ctx.fill() ;
ctx.restore() ;
}
}
// ctx.save() ;
// ctx.beginPath() ;
// ctx.arc(particles[i].pos.x , particles[i].pos.y , 10,0,Math.PI*2,false) ;
// ctx.stroke() ;
// ctx.fill() ;
// ctx.restore() ;
// }
// }

}

Expand Down Expand Up @@ -1513,7 +1577,7 @@ function Update() {
5 , 4);
}
}
sim.frame(16);
// sim.frame(16);

camera.Update();

Expand Down
7 changes: 4 additions & 3 deletions __server__/__client__/webgl/js/verlet-1.0.0.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions __server__/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fw.on('connection' , function(socket) {
if(Players["/#"+id] == null) {
var __player = new Octopod.Body.Player(oath , id , secId) ;
__player.Init(10,1,5);

__player.AddTentacle() ;
Players["/#"+id] = __player ;

socket.init = true ;
Expand Down Expand Up @@ -170,7 +170,7 @@ fw.on('connection' , function(socket) {
// Players[socket.id].Stop() ;
// Players[socket.id] = null ;
});
socket.on('Bind-Tentacle' , function(x,y) {
socket.on('Bind-Tentacle' , function(x,y) { // trash in this branch
var angleToMouse = Octopod.OctoMath.Angle.MouseToAngle(x,y) * Math.PI/180 ;
var player = Players[socket.id];
var d1 = Octopod.Geometry.Vector2.Distance(
Expand Down
23 changes: 21 additions & 2 deletions body/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var Geometry = require('../module/geometry.js');
var Component = require('../module/component.js');
// var Geometry = require('../module/geometry.js');
var OctoMath = require('../module/octomath.js');

var Tentacle = require('../body/tentacle.js') ;
class Player {
constructor(oath , id , name , secId) {
this.oath = oath ;
Expand All @@ -14,6 +16,7 @@ class Player {
this.Camera = new Component.Camera(0,0,700,550);
this.status = false ;

this.tentacles = [] ;
// this.oath = "socket" ;
this.secId = secId ;
// this.range = 0 ;
Expand Down Expand Up @@ -55,6 +58,10 @@ class Player {
object_player["Transform"] = this.Transform ;
object_player["oath"] = this.oath ;
object_player["active"] = false ;
object_player["tentacles"] = [] ;

for(var i=0 ; i < this.tentacles.length ; i++)
object_player["tentacles"].push(this.tentacles[i].particles) ;

return object_player ;

Expand All @@ -65,9 +72,21 @@ class Player {
// t.Transform.angle = 0 ;
this.Updating = setInterval ( function() { t.Update(); } , time) ;
}

AddTentacle() {
// console.log(Tentacle) ;
// console.log(OctoMath) ;
// console.log(Geometry) ;
// console.log(Component) ;
this.tentacles.push(new Tentacle(this.Transform.position , 5, 70, 0.95, (Math.PI/2)/3)) ;
}
FocusTentacles(node) {
for(var i = 0 ; i < this.tentacles.length ; i++)
this.tentacles[i].particles[this.tentacles[i].particles.length - 1].pos.Renew(node) ;
}
Update() {

for(var i = 0 ; i < this.tentacles.length ; i++)
this.tentacles[i].Update() ;

if(this.Jerk > this.JerkMax) {
this.JerkSpeed = -Math.abs(this.JerkSpeed) ;
}
Expand Down
Loading

0 comments on commit efe3027

Please sign in to comment.