GithubHelp home page GithubHelp logo

arsenic-atg / tetris Goto Github PK

View Code? Open in Web Editor NEW
21.0 3.0 11.0 3.16 MB

Tetris™ clone created in c++ and SDL

Home Page: https://tetrisplusplus.netlify.app

License: MIT License

C++ 98.09% HTML 1.56% CSS 0.35%
cpp emscripten game sdl2 sdl2-ttf tetris-clone good-first-issue goodfirstissue cplusplus sdl

tetris's Introduction

Tetris

Tetris™ clone created in C++ and SDL, The project is also designed to be compile with emscripten to webasm and be deployed online.

Start a new game

controls

key Action
left_arrow move left
right_arrow move right
z or up_arrow rotate clockwise
x or left-ctrl rotate counter clockwise
space hard drop
down_arrow soft drop
p pause game
r reset game

Dependencies

  • Git: for version control
  • Standard C++ compiler conforming to C++17 and above standards: to build the project locally (tested on gcc12.0 and clang 13.0)
  • Emscripten : to compile the program to WebAsm
  • SDL2.0 library :for rendering stuff on screen.
  • SDL TTF library : for rendering font from TrueType (.ttf) font files.

Build instructions

( This section or README.md is still under construction, you may help in improving this by opening a PR/issue regarding the same )

perform the following steps to build the project on your native machine :

  1. Clone/download the repository

  2. Navigate to src subdirectory of repository

  3. Now compile the program (depending on whether you want to build the online deployable version or native build, follow one of the following steps )

    caveat: currently the repository doesn't have a build system/script to automate the build process, so sadly for now, manual build is the only way to get the project running on the system (If you are interested in setting up one for the project then feel free to open an issue discussing the same)

    3.1. WebAsm build using emscripten :

    To build the online deployable version of the game, we would be using emscripten to compile the program to webasm.

    • Executing the following command is I think all you need to compile the project ( do note that Emscripten tend to take relatively long time than your average C++ compiler to build the project, and compilling for the first time would almost always take much longer to build than subsequent builds )
    $ em++ -std=c++17 renderer.cpp game.cpp app.cpp main.cpp -O2 -s TOTAL_MEMORY=67108864 -s USE_SDL=2 -s USE_SDL_TTF=2 -s USE_SDL_MIXER=2 --preload-file assets -o ../build/index.js

    TODO: explain what the above command does in detail

    • The build files should be in build subdirectory of the repository
    • Once in build directory, you can simply use emrun to run the HTML pages via a locally launched web server.
    $ emrun index.html

    FWIW: you may also like to visit emscripten documentation regarding more info about building a project with emscripten if you are interesting to know more about the same.

    3.2. Native build using native C++ compiler :

    • Just use your native C++ compiler to build and executable from all the source files (order in which they should be provided to the command should not matter in most cases )

    • Make sure to link SDL2 and SDL2_ttf libraries properly.

     $ g++ -std=c++17 renderer.cpp game.cpp app.cpp main.cpp -O2 -lSDL2_ttf -lSDL2
    • run the built executable.

These instructions are meant to be understood by developers of every level, so if you are unable to understand anything or face any difficulty in building the project then make sure to complaint about the same by opening an issue or in discuss section.

For Hacktoberfest

This repository is participating in hacktoberfest, so any contribution done on this project during the month of october should be counted towards hacktoberfest.

Contribution

Contribution of all kinds ( code, non-code, low-code) are appriciated.

  • If you are looking to contribute to the project then make sure to read contribution guidelines before making a new pull request.

  • If you want to report a bug, or want to share ideas/contribute to the project then feel free to open an issue/PR regarding the same

Also feel free to open an issue for asking queries.

If you liked the project then make sure to support the developers by giving it a star 🤩.

License

License

tetris's People

Contributors

andrewrgarcia avatar arsenic-atg avatar deleonroselle21 avatar jjwesker10 avatar omk-coder avatar ppitu avatar pscoder10462 avatar shivam-mittal01 avatar

Stargazers

 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

tetris's Issues

write control instructions on title screen

Current behaviour

The only place to get info about the controls is the source code or reading the README.md of this repo, which is not optimal for someone who is maybe playing game directly from the web link.

Desired behaviour

the title screen should contain the info about controls.

Center the build canvas of web version

Current behaviour

The template HTML shell document that the project use for web version of the game is a bit bland. Not only is it offcentered, it is also contain distracting white background.

Expected behaviour

Put the canvas in the centre of the screen, and make the background color a bit dark to make the experience a bit more immersive.

Files of interest

  • /build/index.html

Make a CI/CD pipeline to build and deploy project automatically

currently, in order to update the web build, project need to first be built locally and then changes are pushed to the repository which is then hosted by netlify.

This method is inconsistent and pollutes the commit history of the repository.

Reading the emscripten docs, I came across different ways to integrate different continues integration pipelines to build the project automatically when the master branch is updated.

Create Readme.md

Create a readme file with all the required information about the app that one need to know

Implement ghost piece

What is ghost piece ?

It's the shadow representation of piece if we would happen to perform a hard drop.

Some blocks stick to the sides when rotated

Current Behavior

Some blocks for e.g. a straight vertical block when on the right most lane if rotated clockwise, sticks to the sides like this

Expected behavior

Such blocks should move away enough from sides to make space for their new orientation

Input doesn't process properly at high speed

Once speed increases above threshold, game stops processing inputs and blocks are almost hardfalling.
The tetromino can only be manipulated for a small instance when it is just displayed at the top of canvas.
Please fix it.

Host the web version of the app

The game is designed to also compile to webasm (using emscripten), however it need to be hosted publicly for anyone to play anywhere via their browsers.

Phone-Compatible Version of Tetris

I thought it'd be great if a phone-compatible version for this game could be made in the future, also using the SDL2 library to keep things consistent.

I looked around a little, and found there are FINGERDOWN , FINGERUP and FINGERMOTION events in the SDL_events.h module of the SDL2 library. I was thinking for such a [phone-compatible] version, the left-up-down-right would all have to be replaced by a TOUCH event and bring the piece down with a FINGERMOTION event function.

This idea may be a bit on the complex side but it would broaden the functionality of the game, and perhaps turned into an app later on.

Add background music to game

I thought it would be a nice feature to add some chiptune background song for the game.

I believe the SDL library supports the addition of background music as well. The music should ideally be on the Tetris theme and can be easily created on the chiptune style with Bosca Ceoil.

Implement a levelling system

current status

There is no levelling system present in the game and the game remains at the same level thought the gameplay, making it quite boring.

desired status

player's difficulty level should increase progressively once they clear a set number of lines in the game session.
The current idea of increasing the difficulty with higher level is to increase the falling speed of the tetrominos.

create contributing.md

The project should be more friendly towards new contributors, making a contributing.md which documents everything a new contributor need to know in order to contribute to this project should be a good step towards that.

Make the project meet community standards

This is a meta issue tracking dev of all the changes required to lay down to get this project meet open source community standards.

  • README.md
  • Contributing.md ( individual issue #35 )
  • Code of conduct ( individual issue #36 )
  • License
  • Issue templates ( individual issue #38 )
  • pull request template (individual issue #39 )

Implement a scoring system

Current status

The game doesn't count score in any way.

Desired behaviour

though the including the modern scoring system should be ideal, I think implementing the basic scoring system first is a good start.

Here is how the original scoring system count score (source : https://tetris.wiki/Scoring )

Action Points
Single-line perfect clear 800 × level
Double-line perfect clear 1200 × level
Triple-line perfect clear 1800 × level
Tetris perfect clear 2000 × level
Back-to-back Tetris perfect clear 3200 × level

currently there is no levelling system so value of level would always be one for the time being

Implement advanced scoring system

Current status

After #6 ,the game calculates score based on conventional tetris syle ( 100*level) per line clear

Desired behaviour

though the including the modern scoring system should be ideal, I think implementing the basic scoring system first is a good start.
To make the game more exciting, the game should reward score for even risky moves like hard-drop and T-spings

currently there is no levelling system so value of level would always be one for the time being

Add `.clang-format` file to repository

The code base uses GNU coding convention, most of which can easily be enforced using clang-format, the project should contain a .clang-format containing the clang format's configuration for GNU coding style.

fortunately clang format supports GNU coding standards as one of it's presets so we can simply use clang format to generate that file for us using a command like this :

$ clang-format -style=gnu -dump-config > .clang-format

Types detected in Contributing.md

These are the typos detected in CONTRIBUTING.md by codespell

CONTRIBUTING.md:15: usefull ==> useful
CONTRIBUTING.md:24: seperate ==> separate

leaving this issue for a newcomer to introduce themselves to the repository.
As these changes are not going to take much time, it's not mandatory to be assigned before opening a PR.

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.