
-----------------------------------
mwachna
Wed Mar 09, 2005 8:42 pm

[Tutorial] 2-D mapping I (eg. Tetris)
-----------------------------------
2-D Mapping

2-D mapping can be useful in creating games similar to Zelda, and Tetris.  This tutorial will cover the following topics:

1.1-What is an array?
1.2.-What is a 2-D ray?
1.3-What is an array of an array?
2.0-Tetris games
2.1-Creating the screen
2.2-Creating the pieces
2.3-Moving through empty space
2.4-Hitting block bottom
2.5-Game over

1.0	Introduction:
This is a brief overview of mapping in 2-D.  This will just be a general eye-opener, or a push forward in 2-D mapping.

1.1	An array is a grouping a variables with the same name, just different parameters (a parameter is similar to an independent variable in the way that you may manipulate it to create a different outcome).  Such as in math: f(x) is an array of points.  'f' is a function, and 'x' is a variable.  For every value of 'x', f(x) will store a dependent value.  So if f(x) represents a function of addition for 3x-x then the first 3 values of 'f' is:
f(1)=2
f(2)=4
f(3)=6

	In Turing, however, we can assign these values.  So if, we were to want to store the finishing times of runners in a race, we can use an array with the limits equaling the number of runners in the race.
In this example, we will input the results for 100 racers, using their tag number for identification.  We will store the results by MM.SS

var tag: int
var runner: array 1..100 of real
for rep 1..100 of int
	get tag
	get runner(tag)
put "Place ", rep, " - Runner ", tag, " : ", runner(tag)
end for


This code just stored the results of the race in an array while at the same time out putting them as:

Place 1 - Runner 32 : 23.33
Place 2 - Runner 1 : 24.21
Place 2 - Runner 93 : 24.55
"¦etc

1.2	2-D arrays are just arrays with more then one parameter, or dependent variable.  So if we wanted to group a population by their age and sex then we would need a 2-D variable as such:


var age, sex: int
var population: array 1..100, 1..2 of int
loop
	get age
	get sex
	if age>100 then
		age:=100
	elsif age 