PreLoading Map
Author |
Message |
Archi
|
Posted: Thu Aug 21, 2003 2:33 pm Post subject: PreLoading Map |
|
|
In my game, I want to have a maze type thnig where the player can only see the areas which he has already uncovered and about 2 "pixels' in front of him. Now I want the maze to be one of say 4 random mazes which I create. How would I go about doing that? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Homer_simpson
|
Posted: Thu Aug 21, 2003 2:55 pm Post subject: (No subject) |
|
|
well how are u loading yer maze? in a 2d array of booleans?! |
|
|
|
|
|
Archi
|
Posted: Thu Aug 21, 2003 3:39 pm Post subject: (No subject) |
|
|
Thats another thing I'm not sure how to do...what would be my best way to create the maze? |
|
|
|
|
|
Homer_simpson
|
Posted: Thu Aug 21, 2003 4:57 pm Post subject: (No subject) |
|
|
well it's an easy way.... very easy...
u can just have yer arrays like this :
{t,t,t,t,t}
{t,t,f,f,t}
{t,f,t,f,t}
{t,t,t,t,t}
where it true it's solid where it is false it's not solid... |
|
|
|
|
|
Homer_simpson
|
Posted: Thu Aug 21, 2003 5:05 pm Post subject: (No subject) |
|
|
here... i wrote u an example:
code: | var maze : array 1 .. 100, 1 .. 100 of boolean;
for x : 1 .. 100
for y : 1 .. 100
if Rand.Int (0, 1) = 0 then
maze (x, y) := false
else
maze (x, y) := true
end if
end for
end for
for x : 1 .. 100
for y : 1 .. 100
if maze (x, y) = true then
drawfillbox ((x*5), (y*5), (x*5) + 5, (y*5) + 5, 9);
end if
end for
end for
|
this is my first tutring program after like 2/3 months!!! |
|
|
|
|
|
Homer_simpson
|
Posted: Thu Aug 21, 2003 5:58 pm Post subject: (No subject) |
|
|
here's another code which didn't com out as good as i thought it would =Þ
code: | const MAX_MAZE := 100
var maze : array 1 .. MAX_MAZE, 1 .. MAX_MAZE of boolean;
for x : 1 .. MAX_MAZE
for y : 1 .. MAX_MAZE
maze (x, y) := true
end for
end for
var dir := 1
var x, y := 50;
var quitb := false;
var randdir := 1;
var badc := 0;
for i : 1 .. 10000
case dir of
label 1 :
if y < MAX_MAZE then
y += 1
end if
label 2 :
if x < MAX_MAZE then
x += 1
end if
label 3 :
if y > 1 then
y -= 1
end if
label 4 :
if x > 1 then
x -= 1
end if
label :
end case
maze (x, y) := false;
%Generate Random Movement
quitb := false;
loop
randdir := Rand.Int (1, 4)
case randdir of
label 1 :
if y < MAX_MAZE - 1 then
if maze (x, y + 1) = true and maze (x, y + 2) = true then
dir := 1;
quitb := true
badc := 0
%drawfillbox ((x * 5), (y * 5), (x * 5) + 5, (y * 5) + 5, 10);
end if
else
badc += 1;
end if
label 2 :
if x < MAX_MAZE - 1 then
if maze (x + 1, y) = true and maze (x + 2, y) = true then
dir := 2;
quitb := true
badc := 0
%drawfillbox ((x * 5), (y * 5), (x * 5) + 5, (y * 5) + 5, 10);
end if
badc += 1;
end if
label 3 :
if y > 2 then
if maze (x, y - 1) = true and maze (x, y - 2) = true then
dir := 3;
quitb := true
badc := 0
%drawfillbox ((x * 5), (y * 5), (x * 5) + 5, (y * 5) + 5, 10);
end if
badc += 1;
end if
label 4 :
if x > 2 then
if maze (x - 1, y) = true and maze (x - 2, y) = true then
dir := 4;
quitb := true
badc := 0
%drawfillbox ((x * 5), (y * 5), (x * 5) + 5, (y * 5) + 5, 10);
end if
badc += 1;
end if
label :
end case
exit when quitb = true or badc >= 4
end loop
end for
if badc >= 4 then
x := Rand.Int (1, MAX_MAZE);
y := Rand.Int (1, MAX_MAZE);
end if
for xx : 1 .. MAX_MAZE
for yy : 1 .. MAX_MAZE
if maze (xx, yy) = true then
drawfillbox ((xx * 5), (yy * 5), (xx * 5) + 5, (yy * 5) + 5, 9);
end if
end for
end for
|
/EDIT
here's one that's a little better :
code: | const MAX_MAZE := 100
const SIZE := 3
var maze : array 1 .. MAX_MAZE, 1 .. MAX_MAZE of boolean;
for x : 1 .. MAX_MAZE
for y : 1 .. MAX_MAZE
maze (x, y) := true
end for
end for
function inrange (x, y : int) : boolean
if y < MAX_MAZE and x < MAX_MAZE and x > 1 and y > 1 then
result true
else
result false
end if
end inrange
for xx : 1 .. MAX_MAZE
for yy : 1 .. MAX_MAZE
if maze (xx, yy) = true then
drawfillbox ((xx * SIZE), (yy * SIZE), (xx * SIZE) + SIZE, (yy * SIZE) + SIZE, black);
end if
end for
end for
var dir := 1
var x, y, randx, randy := 50;
var quitb := false;
var randdir := 1;
var badc, ii := 0;
for i : 1 .. 6000
case dir of
label 1 :
if y < MAX_MAZE then
y += 1
end if
label 2 :
if x < MAX_MAZE then
x += 1
end if
label 3 :
if y > 1 then
y -= 1
end if
label 4 :
if x > 1 then
x -= 1
end if
label :
end case
maze (x, y) := false;
%Generate Random Movement
quitb := false;
badc := 0;
loop
randdir := Rand.Int (1, 4)
case randdir of
label 1 :
if inrange (x, y) then
if maze (x, y + 1) = true and maze (x, y + 1) = true and maze (x + 1, y + 1) = true and maze (x - 1, y + 1) = true then
dir := 1;
quitb := true
badc := 0
drawfillbox ((x * SIZE), (y * SIZE), (x * SIZE) + SIZE, (y * SIZE) + SIZE, white);
end if
else
badc += 1;
end if
label 2 :
if inrange (x, y) then
if maze (x + 1, y) = true and maze (x + 1, y) = true and maze (x + 1, y + 1) = true and maze (x + 1, y - 1) = true then
dir := 2;
quitb := true
badc := 0
drawfillbox ((x * SIZE), (y * SIZE), (x * SIZE) + SIZE, (y * SIZE) + SIZE, white);
end if
badc += 1;
end if
label 3 :
if inrange (x, y) then
if maze (x, y - 1) = true and maze (x, y - 1) = true and maze (x - 1, y - 1) = true and maze (x + 1, y - 1) = true then
dir := 3;
quitb := true
badc := 0
drawfillbox ((x * SIZE), (y * SIZE), (x * SIZE) + SIZE, (y * SIZE) + SIZE, white);
end if
badc += 1;
end if
label 4 :
if inrange (x, y) then
if maze (x - 1, y) = true and maze (x - 1, y) = true and maze (x - 1, y - 1) = true and maze (x - 1, y + 1) = true then
dir := 4;
quitb := true
badc := 0
drawfillbox ((x * SIZE), (y * SIZE), (x * SIZE) + SIZE, (y * SIZE) + SIZE, white);
end if
badc += 1;
end if
label :
end case
exit when quitb = true or badc >= 100
end loop
if badc >= 4 then
ii := 1;
loop
ii += 1;
randx := Rand.Int (2, MAX_MAZE - 1);
randy := Rand.Int (2, MAX_MAZE - 1);
if maze (randx, randy) = true and maze (randx, randy) = true and maze (randx + 1, randy) = true and maze (randx + 1, randy + 1) = true and maze (randx, randy - 1) = true then
x := randx
y := randy
exit
end if
exit when ii > 1000
end loop
end if
delay (0)
end for
for xx : 1 .. MAX_MAZE
for yy : 1 .. MAX_MAZE
if maze (xx, yy) = true then
drawfillbox ((xx * SIZE), (yy * SIZE), (xx * SIZE) + SIZE, (yy * SIZE) + SIZE, 9);
else
drawfillbox ((xx * SIZE), (yy * SIZE), (xx * SIZE) + SIZE, (yy * SIZE) + SIZE, 10);
end if
end for
end for
|
BTW none of thse maze generation ways that i'm using are based on any standards... |
|
|
|
|
|
Asok
|
Posted: Thu Aug 21, 2003 6:49 pm Post subject: (No subject) |
|
|
holy shit homer, get a job or something you have too much time on your hands |
|
|
|
|
|
Homer_simpson
|
Posted: Thu Aug 21, 2003 7:11 pm Post subject: (No subject) |
|
|
that whole thing took me like 30 minutes or less.... i was bored any ways
a job eh?! that's one of the things people dont give me for some reason!!!
Homer AD: "Design websites for 10 bux!!!" |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|