Code Monkey home page Code Monkey logo

duo-pong's Introduction

duo-pong's People

Contributors

smirea avatar

Watchers

Dmitrii Cucleschin avatar Nikolche Kolev avatar

duo-pong's Issues

Implement .intersect() to all base classes

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

Create layout

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

Fix Intersection Sorting

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.

Steps to reproduce:
screen shot 2013-08-28 at 28 08 13 1 16 24 am

// 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();

Create Ball Class

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.