Giter Club home page Giter Club logo

pong's Introduction

PONG

A Rust implementation of classic pong using Piston and nphysics. This is primarily being used as an intro for me to Rust and writing games.

I have attempted to "glue" together the Piston window and nphysics world for this game. It feels a little fragile right now but I'm hoping that with more experience with the two crates I'll be able to harden it.

Implementation

Game

The world consists of the physics world, the ball, and the two players. When the world is initialized, it builds the physics world and creates colliders for the ball and the two players, which are the put into the world. Over every loop the game "updates", which steps the physics world once; this is when the physics engine does its work (I think).

After updating the world, we render it. The game's call to render then renders both the ball and the players in the piston window.

PongPlayer

The body essentially has an infinite mass via the nphysics BodyStatus::Kinematic so that when the ball collides it doesn't move. It should only be moved via player input.

PongBall

The pong ball creates a custom material type in nphysics so that it does not lose a lot of inertia when it collides with players. The thought is to have all of its energy conserved every time it bounces. I'm not sure if this is the best way to accomplish this yet.


TODO

  • Player input
    • specifically the player inputs need to be async b/c they're currently blocking
    • Player input now uses a HashSet to find the keys that are currently being pressed. This feels very hacky and gross. It looks like there is a set of event traits for buttons that I may be able to leverage for individual buttons in the piston input module.
  • Scoring
    • Still need to show the score after a goal, and need to figure out when a player has won
  • Boundaries
  • Split the structs into their own files/modules
  • The Game knows too much about how to create the ball and player objects. Should split that logic out into the appropriate mods.
  • Need a menu to exit

pong's People

Contributors

nhyne avatar

Watchers

 avatar  avatar

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.