GithubHelp home page GithubHelp logo

piercelbrooks / godot-slot-machine Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jeffbusch/godot-slot-machine

0.0 1.0 0.0 4.34 MB

Simple slot machine based on the Godot engine.

License: MIT License

GDScript 100.00%

godot-slot-machine's Introduction

Godot Slot Machine

Simple slot machine based on the Godot engine.

Icons were copied from this memory game and originate from Game-Icons.

Alt Text

Parameters

  • array of pictures
  • number of reels
  • number of pictures per reel
  • speed of the animation
  • duration of the animation (does not include spin_up and spin_down time)
    • if set to 0, runs until stopped by user
  • delay between individual reels

Implementation

The slot machine consists of a number of spinning reels, each showing a number of pictures. We call the pictures SlotTiles, which are Sprites positioned in an N x M grid with randomly assigned textures based on a provided image list.

On start, each reel is spun with a pre-defined delay. A spin-up animation is played using the AnimationPlayer with a Bezier curve affecting the position of each tile. Afterwards, the SlotTiles are moved by one position at a time using Tweens on the tiles' position. Instead of relying on timers for the movement, we count how often each reel moved. This allows us to define an exact number of movements for every time we run the slot machine. When the counter for a reel reaches the desired number of movements, we play a spin-down animation. In order to still define a runtime in seconds, we calculate the number of movements as runtime * speed. The speed is normalized to be independent of the number of tiles displayed.

The slot machine is enclosed in a Viewport. When a moved SlotTile leaves the viewport we adjust its position to be above all other tiles and assign a new random texture. That way it looks as if an infinite stream of new pictures is running in from the top.

If we only display as many pictures as fit inside the viewport, moving the top most tile downwards would leave an empty slot during the animation which would only be filled when the animation is finished and the bottom most tile is repositioned to the top. In order to remove these artifacts, we add an extra tile above and below the viewport. If the spin-up animation moves the tiles farther than the tile_size, the number of extra tiles needs to be increased. We automatically compute the number of extra tiles required by ceil(SPIN_UP_DISTANCE / tile_size.y) * 2.

Issues

Given that we move tiles by one grid position at a time, the maximum speed is limited by the framerate. At the same time, we notice movement jitter on slow speeds. In order to fix this, the movement would need to be computed in the _process function instead of using Tweens.

License

Distributed under the MIT License. See LICENSE for more information.

Icons are licensed CC BY 3.0 Game-Icons.

Contact

Fabian Bolte - [email protected]

godot-slot-machine's People

Contributors

cadanox avatar jeffbusch avatar

Watchers

 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.