dmitrc / duo-pong Goto Github PK
View Code? Open in Web Editor NEWA game of ping-pong, played on shared screen of two computers. WARNING: Veeeery raw :D
A game of ping-pong, played on shared screen of two computers. WARNING: Veeeery raw :D
So, in Ray.draw() there is a lot of intersection logic. By default a Ray know how to intersect Rectangles. The way intersection should be done is by every base class (Rectangle, Circle, Polygon) to implement .intersect() methods where they define each intersection they can do with what kind of other classes (preferably all combinations - although this does scale exponentially which is not nice). If an instance has an intersect() method it overrides the default line intersection
Polygon already implements this so that should be a good start. For performance considerations, Polygon.intersectRay() does an estimation to see if the ray intersects with the outer and inner circle and if not return no intersection. If the initial check happens, then the standard go through all Rectangle components and compile all the intersections and return them at the end.
Wee need similar features for Rectangle, Circle. Check the included intersection Math library: http://www.kevlindev.com/gui/math/intersection/index.htm
So the idea of multi-pong is the following:
you start off with a traditional 2 player pong and when a 3d person joins you transform the whole area into a triangle. N players implies N edges and you already have the Polygon class for that.
Paddles should be one per edge and you should be able to control one of them. Each paddle should provide API-s for setting color, position (along its axis) at the very least.
The paddle that you control should slide on one edge, not passing into other edges and being mouse-bound
The way reflection is currently implemented is by taking every element in the scene and trying to see if the Ray and that Sprite intersect. All intersections are stored in array which is then sorted and the closes one is chosen and all others are discarded.
This works most of the times quite well, but it is still broken in some cases. Most notably now with Polygons.
// min 600 x 600 canvas
stage.
add(new Rectangle({x:0, y:0, w:600})).
add(new Rectangle({x:0, y:600, w:600, angle:Math.PI * 3/2})).
add(new Rectangle({x:600, y:0, w:600, angle:Math.PI * 1/2})).
add(new Rectangle({x:600, y:600, w:600, angle:Math.PI * 2/2})).
grid(50).
add(new Polygon({x:300, y:300, radius:150, edges:6, style:{fillStyle:'cyan', lineWidth:10}})).
add('ray', new Ray({x:300, y:250, angle:Math.PI * 3/8, style:{strokeStyle:'crimson'} })).
draw();
So the focus has been currently on the Ray class as it makes it a hell of a lot easier to test and understand where stuff is failing but this is just a means to an end
We need a Ball class which probably will share a lot of code with the Ray class in terms of intersection. The idea of this is to don't copy paste any code (or as little as possible)
Ultimately the Ray class can become obsolete (unless we want to keep it around for stuff like fancy trajectory prediction which what is it currently)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.