Code Monkey home page Code Monkey logo

blockbreaker's Introduction

BlockBreaker

A fork of the BlockBreaker project. This fork provides a full Skillz integration, including both normal and turn-based tournaments as well as the "skillz_difficulty" param that is passed in to make the game harder for more experienced players.

A simple Unity game designed for iOS. The player(s) clear groups of identical blocks; bigger groups give exponentially more points.

Game Modes

There are two game modes:

  • Timed
    • One player tries to get as high a score as possible in the allotted time
  • Turn-based
    • Two players take turns clearing blocks. The player with the highest score after a certain number of turns is the winner.

Code

Game Grid

The blocks are organized on a rectangular grid of a fixed size. Grid-related scripts are stored in "Assets/Scripts/Game Grid Stuff".

The grid representation is stored in the "GameGrid" MonoBehaviour script; it holds a 2D array of integers (representing the different types of blocks) and provides methods for modifying the grid.

The block objects each have a "GameGridBlock" MonoBehaviour component, which constantly seeks toward its position in the grid. The blocks are given animation by simply moving them away from their grid position, making them move back towards it again (this is most easily accomplished through the use of the "PushBlockAway" Monobehaviour script).

The blocks are generated by the "GameGridGenerator" MonoBehaviour script on its "Start()" method.

Player Input

Player input is handled by the script "Assets/Scripts/PlayerInput.cs". It waits for a finger tap (or mouse click if testing in the editor) and checks whether the tap was on a block, in which case it clears the block and any blocks that touch it.

Gameplay Flow

All game flow scipts are in "Assets/Scripts/Gameplay Controllers". "GameplayController.cs" is an abstract MonoBehaviour class that represents some game mode. There are two classes that inherit from it: "GameplayController_Timed" and "GameplayController_TurnBased".

Both of these game modes have their own gameplay scene, as well as an accompanying "Review" scene that shows the scores once the game is over.

UI

All UI scripts are in "Assets/Scripts/UI". They use the old UI system for Unity (using the "GUI" class).

Skillz Integration

Integrating Skillz with the timed game-type was easy -- just put in a game scene before the main menu that initializes the Skillz SDK, and add some hooks for the "GameplayController_Timed" script that report the score to Skillz if in a Skillz tournament.

Integrating Skillz with the turn-based game-type is a bit more involved, because the game state has to be serialized and sent to the Skillz server so that the other player can read it in, deserialize it, and start the game from there. This was accomplished in the following way:

  1. Create a "TurnBasedGameData" data structure that holds all the stuff needed for a turn-based game (game grid, number of turns left, player scores, etc) and give it the ability to serialize/deserialize the data to/from a string.

  2. In the GameplayController_TurnBased script, if in a Skillz tournament, then load the data from the "TurnBasedGameData" struct and start the game from there instead of generating a new game. Along with this, the GameGridGenerator script is changed so that it must be manually told to generate the level, instead of automatically doing it on "Start()". Finally, after a player takes his turn, the script has to submit the results of the turn to Skillz and end the scene instead of just moving to the next turn.

  3. Add a new game-type, GameplayController_Review (and a corresponding game scene), that just shows the current state of a turn-based game so that the player can review the current state of his turn-based tournament as he waits for his opponent to take their turn.

License

This game is released under the MIT License:

The MIT License (MIT)

Copyright (c) 2015 William Manning

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

blockbreaker's People

Contributors

heyx3 avatar jamesmcmahon 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.