aboutsummaryrefslogtreecommitdiff
path: root/bin/rand.rb
blob: a3e7e41bd431356f1aec33f6309d607e308d3ff9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

##
# Generate a table of 256 bytes of pseudo-random values. These values are
# constrained with the upper and lower margins of the screen where enemies can
# appear, and discard certain positions like platforms that can be troublesome
# on enemy creation. All in all not exactly super pure randomness, but on the
# other hand this game just needs a bit of randomness.
#
# Whenever you update values on background.s, you are supposed to call this
# script again and replace the values on 'valid_y_rand_table' in prng.s.

# See values on background.s. They are the same +/- some margin so enemies are
# not right on the border.
UPPER_MARGIN_Y_COORD = 0x1A + 32
GROUND_Y_COORD = 0xC8 - 64

# The available values for the Y axis for enemies are above ground, below the
# sky, and avoiding the left-most and right-most platforms.
available = (UPPER_MARGIN_Y_COORD..GROUND_Y_COORD).to_a - (0x58..0x69).to_a - (0x40..0x50).to_a

# With this produce the array containing a randomized sample from the
# 'available' values.
random_byte_array = Array.new(256) { format('$%02X', available.sample) }

# And now print it in the assembler format.
random_byte_array.each_slice(16) do |row|
  puts ".byte #{row.join(', ')}"
end