Coder Social home page Coder Social logo

pycasting's Introduction

...

2D Raycasting

Implementation of a 2D raycasting algorithm using Pygame

Hex.pm


Using the app

If you want to use the web in your computer, you should follow this steps.

Prequisites
  • Python (v3.7+) installed.
  • Git installed and configured
  • pip (v3) instaled
Steps
Clone the repository in your local machine
git clone https://github.com/PabloCorbCon/pycasting.git
Move inside the repository
cd 2d-raycast
Install all the packages needed
pip install -r requirements.txt
Start the Pygame app
python app.py
If you have multiple Python instalations use Python 3(+7)
python3 app.py

For contributing to the project read the CONTRIBUTING.md file


Configuration

All the configuration of the application has been externalized to the code itself so that you can modify it to your liking in the simplest way possible.

You can see the default configuration in the CONFIG.json file.

You can modify this configuration to your liking, for example to change the width of the tiles or the color of the walls.

Adding walls

You can also add walls to the game. Just go to the /walls/walls configuration file section and you will see a list of values with this syntax.

[
  [[a1, b1], [c1, d1]],
  [[a2, b2], [c2, d2]],
  ...
  [[aN, bN], [cN, dN]]
]

These lists represent Cartesian coordinates, in a plane a segment has a start point and an end point. This two points can be seen as a & bwhere a = {x1, y1} and b = {x2, y2}. So the wall segments are determined in the form of:

[
  [[x1, y1], [x2, y2]]
]

...

Segment in a full cartesian plane

In our game we consider that {a, b} โˆˆ N.


About RayCasting

The so-called RayCasting is a technique designed to solve multiple problems in ray tracing to an object by simulating natural light rays. In RayCasting a ray is traced from a point a to a point a + 1 as long as this ray does not collide with any obstacle.

Taking this into account, we can launch rays that advance in a certain direction. These rays will never stop moving unless they hit an obstacle.

Techniques as complex as Envidia RTX can be simplified to the maximum with a two-dimensional demonstration like the one in this repository. After all, Ray tracing is based on bouncing light rays with the most light-like properties possible against solid objects.

...

When a casting beam detects an obstacle, it can produce a signal, this could be used for countless purposes such as improving the physics of a simulator or even improving the layout of lasers in a game. The possibilities are endless. To check the distance of the ray to an object, you can use any mathematical equation. In this project we use the Euclidean distance formula to calculate the distance.

...


This project is under the Apache 2.0 License

Copyright 2020 - @pablocorbcon

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Read more here

pycasting's People

Contributors

pablocorbalann 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.