Jump to content
Sign in to follow this  
Captain Spazer

Put a sprite in a random room?

Recommended Posts

I'm fiddling with a 3D dungeon crawler, the dungeon is made up of a 3x3 grid where each room is stored in variable "a" 0 - 9

And the big bad monster is stored in variable "h" which randomly chooses between number 1-9

 

My question is: How do I make it so that the number that "h" chooses, like 3 for example, a sprite is shown in room number 3? aka variable "a" = 3

EDIT: I figured it out, I could simply do an "if h = a" calculation.
Now I do have another question in a similar vain, but a bit more complicated that I need help optimizing. Any thoughts on how to make something like this more efficient? My thoughts is like this: If the dragon is calculated to be in room a1, and the player is in an adjacant room, in this case adjacant rooms would be a4 and a0 then player1's sprite is shown as an icon on the screen, indicating that the dragon is in an adjacant room. The way I set the code up, it works sometimes, sometimes the icon shows, sometimes the icon does not show up, also it eats up a big chunk of memory.
 

rem dragon is located in a1
 if n = 1 && a = 4 then player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 if n = 1 && a = 0 then player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 rem dragon is located in a 2
 if n = 2 && a = 5 then player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 if n = 2 && a = 0 then player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 rem dragon is located in a 3
 if n = 3 && a = 4 then player1x = 50 : player1y=50 : player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 if n = 3 && a = 0 then player1x = 50 : player1y=50 : player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 if n = 3 && a = 5 then player1x = 50 : player1y=50 : player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 if n = 3 && a = 6 then player1x = 50 : player1y=50 : player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 rem dragon is located in a 6
 if n = 6 && a = 3 then player1x = 50 : player1y=50 : player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 if n = 6 && a = 7 then player1x = 50 : player1y=50 : player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 if n = 6 && a = 8 then player1x = 50 : player1y=50 : player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 rem dragon is located in a 7
 if n = 7 && a = 6 then player1x = 50 : player1y=50 : player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 if n = 7 && a = 4 then player1x = 50 : player1y=50 : player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 rem dragon is located in a 8
 if n = 8 && a = 6 then player1x = 50 : player1y=50 : player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end
 if n = 8 && a = 5 then player1x = 50 : player1y=50 : player1:
 %11111111
 %11111111
 %00100011
 %00000011
 %01001011
 %11111111
 %11110101
 %00001111
end

 

 

Edited by Captain Spazer

Share this post


Link to post
Share on other sites

Okay, I managed to make it all work, and I expanded the dungeon to a whopping of 16 rooms. I had to expand the romsize to 8k, though and I'm struggling with memory yet again for all the checks, there has to be a memory saving way to check when the dragon is in room 1 to give you a clue when you are in room 0,2 or 6.

 

Map of the dungeon:

[30 ][31 ][32 ][33 ]
[20 ][21 ][22 ][23 ]
[10 ][11 ][12 ][13 ]
[A0 ][A1 ][A2 ][A3 ]

Basically, it's a first person hunt the wumpus with a skin.

 

 

EDIT:

I managed to make the code smaller and free up a lot of memory by making the code a lot more efficient. Now my only trouble is how I'm going to do a check if both the dragon and the pit is next to the room the player is in.
The piece of code:

 rem RANDOM COUNTERS
 Dragon_Spawner = (rand&15) + 1
 Pit1_Spawner = (rand&15) + 1

 rem TRANSLATES RANDOM COUNTER INTO POSITION
 if Dragon_Spawner = 1 then Dragon_Position = 1
 if Dragon_Spawner = 2 then Dragon_Position = 2
 if Dragon_Spawner = 3 then Dragon_Position = 3

 if Dragon_Spawner = 4 then Dragon_Position = 10
 if Dragon_Spawner = 5 then Dragon_Position = 11
 if Dragon_Spawner = 6 then Dragon_Position = 12
 if Dragon_Spawner = 7 then Dragon_Position = 13

 if Dragon_Spawner = 8 then Dragon_Position = 20
 if Dragon_Spawner = 9 then Dragon_Position = 21
 if Dragon_Spawner = 10 then Dragon_Position = 22
 if Dragon_Spawner = 11 then Dragon_Position = 23

 if Dragon_Spawner = 12 then Dragon_Position = 30
 if Dragon_Spawner = 13 then Dragon_Position = 31
 if Dragon_Spawner = 14 then Dragon_Position = 32
 if Dragon_Spawner = 15 then Dragon_Position = 33
 if Dragon_Spawner = 16 then Dragon_Position = 33

 if Pit1_Spawner = 1 then Pit1_Position = 1
 if Pit1_Spawner = 2 then Pit1_Position = 2
 if Pit1_Spawner = 3 then Pit1_Position = 3

 if Pit1_Spawner = 4 then Pit1_Position = 10
 if Pit1_Spawner = 5 then Pit1_Position = 11
 if Pit1_Spawner = 6 then Pit1_Position = 12
 if Pit1_Spawner = 7 then Pit1_Position = 13

 if Pit1_Spawner = 8 then Pit1_Position = 20
 if Pit1_Spawner = 9 then Pit1_Position = 21
 if Pit1_Spawner = 10 then Pit1_Position = 22
 if Pit1_Spawner = 11 then Pit1_Position = 23

 if Pit1_Spawner = 12 then Pit1_Position = 30
 if Pit1_Spawner = 13 then Pit1_Position = 31
 if Pit1_Spawner = 14 then Pit1_Position = 32
 if Pit1_Spawner = 15 then Pit1_Position = 33
 if Pit1_Spawner = 16 then Pit1_Position = 33

 rem IF THE ROOM THE PLAYER IS IN IS NEXT TO THE DRAGON OR THE PIT, THE BACKGROUND CHANGES COLOR
 if Room_Number = Dragon_Position - 1 then COLUBK = $34
 if Room_Number = Dragon_Position + 1 then COLUBK = $34
 if Room_Number = Dragon_Position + 10 then COLUBK = $34
 if Room_Number = Dragon_Position - 10 then COLUBK = $34

 if Room_Number = Pit1_Position - 1 then COLUBK = $A0
 if Room_Number = Pit1_Position + 1 then COLUBK = $A0
 if Room_Number = Pit1_Position + 10 then COLUBK = $A0
 if Room_Number = Pit1_Position - 10 then COLUBK = $A0

 

Edited by Captain Spazer

Share this post


Link to post
Share on other sites


I'm not really sure I understand what you're doing

I'd just asign a room number so that it can be used as an index
then use tables

untested

 

  proom = rand & 15                      ;  pit room
  droom = rand & 15                      ;  dragon room

  hrow = hroom / 4                       ;  hero row
  hcol = hroom & 3                       ;  hero column

  prow = proom / 4
  pcol = proom & 3

  ;  if same row and if adjacent columns
  if hrow = prow && af[hcol] & rc[pcol] then COLUBK = $A0 : goto BK_color_done

  ;  if same column and if adjacent rows
  if hcol = pcol && af[hrow] & rc[prow] then COLUBK = $A0 : goto BK_color_done

  drow = droom / 4
  dcol = droom & 3

  ;  etc
  if hrow = drow && af[hcol] & rc[dcol] then COLUBK = $34 : goto BK_color_done 
  if hcol = dcol && af[hrow] & rc[drow] then COLUBK = $34

BK_color_done

  ;  row or column position flag
  data rc
  %00000001, %00000010, %00000100, %00001000
end

  ;  adjacent position flags
  data af
  %00000010, %00000101, %00001010, %00000100
end
Edited by bogax

Share this post


Link to post
Share on other sites

I'm attempting to make the game pick a room at random, place a dragon in that room, and then check if the player is in an adjacant room.

Thank you for your idea, gave me a fresh perspective.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...