GithubHelp home page GithubHelp logo

axelson / scenic_asteroids Goto Github PK

View Code? Open in Web Editor NEW
46.0 7.0 4.0 2.71 MB

A toy Asteroids clone written in Elixir with the Scenic UI library

License: BSD 3-Clause "New" or "Revised" License

Elixir 81.87% Makefile 0.09% Shell 4.10% HTML 2.58% CSS 8.39% JavaScript 2.95%
elixir game example nerves

scenic_asteroids's Introduction

Scenic Asteroids Logo

Scenic Asteroids

Demo of Gameplay

This is an Asteroids clone written in Elixir with Nerves, more for fun and learning than for anything else. Also since the code (and behavior) is relatively simple, I hope that it can serve as an example for Scenic, Nerves, and as a simple poncho project.

It is licensed under the 3-clause BSD license (see LICENSE) for details.

Instructions

From the root of the repository run the following commands:

Note: if scenic doesn't launch then you may be affected by the bug ScenicFramework/scenic_new#36

Keys:

  • W - Move up
  • A - Move left
  • S - Move down
  • D - Move right
  • SPC - Shoot an asteroid

Use the mouse to target the asteroids (or your finger if you're running with a Nerves touch screen)

Have fun!

Implementation Notes

SchedEx is used to implement the core animation timer which runs at a rate of 60 frames per second.

Collision detection is incredibly basic and non-performant. Ideally either scenic or a cooperating library would implement some collision detector helpers. If you're interested in collision detection then please contribute to Scenic issue #91.

Projects

  • play/ - The main game logic
  • play_ui/ - Run via scenic on the desktop
  • fw/ - Run on a Nerves device with a touchscreen
    • Official Raspberry PI touch screen is supported

JS Multiplayer (in progress)

TODO:

  • Get basic nerves install working on network
  • Run scenic play application on nerves!
  • Add multiplayer via Phoenix channels
    • Add single player control via browser
    • Ask for player name
    • Add a waiting screen/lobby
  • Splash screen add option to choose single player or multiplayer
    • Logo will come down and then the options appear
    • Pressing "SPC" or "s" will start single player immediately
    • Pressing "m" will start multi player immediately
  • Test possibility of rendering the current scene to an html canvas

The player javascript will record action states (not key states) Actions:

  • move_aim_direction (vector)
    • Note: This will also be used for aiming direction
  • move_up
  • move_right
  • move_down
  • move_left
  • aim_direction (vector)
  • shoot

NOTE: if move_aim_direction is used then the other move and aim actions should not be used. This will be enforced on the server-side.

  • Channel actions
    • set:actions
      • When the channel receives this it will do a GenServer.cast to the Asteroids scene to update that players currently set actions
      • If the channel process goes down, the scene will clear all actions for that player
        • Perhaps this can be accomplished with a process link?

scenic_asteroids's People

Contributors

axelson avatar dependabot[bot] avatar fhunleth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

scenic_asteroids's Issues

What is up my dude?

I was hoping to be the first person to release a realtime game in scenic (that is continuous, not just discrete grid stuff like Snake), but you beat me to it. :)

Anyways, I was hacking on this last night and a couple of things:

  • You can really simplify the "constrain" behavior by using :math.fmod to just wrap the player or asteroid coordinates to the screen dimensions.
  • You can also use pattern matching in the shoot method to remove the case statement in the try_shoot stuff.
  • I'm a little weirded out by your use of protocols (instead of behaviors) for entities, but I like the idea and would subscribe to your news letter.
  • You need to add drawing twice (maybe more?) to gracefully handle entities overlapping edges and wrapping on the screen.
  • The really fun part about collision detection/updating should use worker processes.

Anyways, it's really awesome that you put up a nice PoC that's easy to hack on, and I'd love to talk with you more on this stuff. HMU on the twitters (same username).

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.