dragonruby-parallax

a simple parallax made with dragon-ruby
git clone https://github.com/TanguyAndreani/dragonruby-parallax
Log | Files | Refs | README

commit 165758acedac0851ecae64ce8edace80d5342267
parent 8b847456ef4d2b89499a7acb28f95b03f2fea43e
Author: Tanguy Andreani <tanguy.andreani@tuta.io>
Date:   Sun, 23 Feb 2020 21:19:41 +0100

avoiding repetition and magic numbers

Diffstat:
Mapp/main.rb | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/app/main.rb b/app/main.rb @@ -1,3 +1,6 @@ +WIDTH = 1280 +HEIGHT = 720 + def layers [ 'layer1.png', @@ -11,8 +14,9 @@ end def tick args layers.each_with_index do |f, i| i += 1 - t = args.state.tick_count % (1280 / i) - args.outputs.sprites << [t * -1 * i, 0, 1280, 720, f] - args.outputs.sprites << [1278 + t * -1 * i, 0, 1280, 720, f] + t = args.state.tick_count % (WIDTH / i) + x_coord = t * i * -1 + args.outputs.sprites << [x_coord, 0, WIDTH, HEIGHT, f] + args.outputs.sprites << [WIDTH - 2 + x_coord, 0, WIDTH, HEIGHT, f] end end \ No newline at end of file