Jump to content
Sign in to follow this  
Chainclaw

Implementing multiple levels

Recommended Posts

I am trying to implement a level selection in my current game, and am not quite sure how to do it. I tried making an array like "data tColumn0Level0", and then I wasn't sure how to assign a variable like a pointer to it.

 

I am on my phone, so I did minimal searching but it's really slow to find info

Share this post


Link to post
Share on other sites

I am trying to implement a level selection in my current game, and am not quite sure how to do it. I tried making an array like "data tColumn0Level0", and then I wasn't sure how to assign a variable like a pointer to it.

 

I am on my phone, so I did minimal searching but it's really slow to find info

tColumn0Level0 is the pointer.

 

This should have the information you're looking for Click Here

Share this post


Link to post
Share on other sites

I am trying to implement a level selection in my current game, and am not quite sure how to do it. I tried making an array like "data tColumn0Level0", and then I wasn't sure how to assign a variable like a pointer to it.

 

I am on my phone, so I did minimal searching but it's really slow to find info

tColumn0Level0 is the pointer.

 

This should have the information you're looking for Click Here

 

I read that, and couldn't find what I was looking for. Here is what I want to do:

 

dim currentLevel = a
dim selectedLevelIndex = b

data tColumn0Level0
some data for the first level
end

data tColumn0Level1
some data for the second level
end

if selectedLevelIndex = 0 then currentLevel = tColumn0Level0
if selectedLevelIndex = 1 then currentLevel = tColumn0Level1

rem fill in the playfield with the level data
var25 = currentLevel[index]
var29 = currentLevel[index+1]
var33 = currentLevel[index+2]

 

Is there any way to do something like that?

Share this post


Link to post
Share on other sites

I am trying to implement a level selection in my current game, and am not quite sure how to do it. I tried making an array like "data tColumn0Level0", and then I wasn't sure how to assign a variable like a pointer to it.

 

I am on my phone, so I did minimal searching but it's really slow to find info

tColumn0Level0 is the pointer.

 

This should have the information you're looking for Click Here

 

I read that, and couldn't find what I was looking for. Here is what I want to do:

 

dim currentLevel = a
dim selectedLevelIndex = b

data tColumn0Level0
some data for the first level
end

data tColumn0Level1
some data for the second level
end

if selectedLevelIndex = 0 then currentLevel = tColumn0Level0
if selectedLevelIndex = 1 then currentLevel = tColumn0Level1

rem fill in the playfield with the level data
var25 = currentLevel[index]
var29 = currentLevel[index+1]
var33 = currentLevel[index+2]

 

Is there any way to do something like that?

I see what you're saying and I don't think you can. I assume you tried the code and it didn't work. If so, then there's your answer I'm afraid.

Share this post


Link to post
Share on other sites

I'll preface this by saying that I'm a 6502 noob. Hopefully someone more experienced can jump in with corrections.

 

I think the reason what you're trying to do can't be done boils down to the fact that the opcodes that allow indirect/variable memory access have a base address hardcoded in the instruction and an 8-bit index, which only allows for access to 256 bytes. (Hence the limitation on array access in bB)

 

You might see if "sread" can do what you need, or use if statements to test your level variable and use different blocks of code for different levels, or...

 

You might be able to create a small ram-based value loader subroutine. Just change the instruction address in ram and jsr to the routine.

 

[Patiently waits to be schooled by one of the 6502 gurus :)]

Share this post


Link to post
Share on other sites

I am trying to implement a level selection in my current game, and am not quite sure how to do it. I tried making an array like "data tColumn0Level0", and then I wasn't sure how to assign a variable like a pointer to it.

 

I am on my phone, so I did minimal searching but it's really slow to find info

tColumn0Level0 is the pointer.

 

This should have the information you're looking for Click Here

 

I read that, and couldn't find what I was looking for. Here is what I want to do:

 

dim currentLevel = a
dim selectedLevelIndex = b

data tColumn0Level0
some data for the first level
end

data tColumn0Level1
some data for the second level
end

if selectedLevelIndex = 0 then currentLevel = tColumn0Level0
if selectedLevelIndex = 1 then currentLevel = tColumn0Level1

rem fill in the playfield with the level data
var25 = currentLevel[index]
var29 = currentLevel[index+1]
var33 = currentLevel[index+2]

 

Is there any way to do something like that?

 

Yes, there is a way to do this, but not the way you are attempting it. One of the problems is that you are trying to store your arrays in the variable "currentLevel" when in fact "currentLevel" should be your pointer. One way of doing what you want here would be to store *all* of your level data in one data statement (i.e. "Levels") and then treat that as a multidimensional array. In other words, if each level contained 30 values to describe it, then to access each individual level you would use:

 

include div_mul.asm
dim currentLevel = a
dim selectedLevelIndex = b

 Levels
 (30 values for level 1),
 (30 values for level 2),
 (30 values for level 3),
end

 selectedLevelIndex = currentLevel * 30

 

That would bring you to the first value of of each level, then you could use addition to access values 1-through-29 (or 31-through-59, or 61-through-89, etc). If that doesn't make sense to you, I can post an example later today when I have some free time.

 

Cheers,

Jarod.

Edited by jrok

Share this post


Link to post
Share on other sites

Yes, there is a way to do this, but not the way you are attempting it. One of the problems is that you are trying to store your arrays in the variable "currentLevel" when in fact "currentLevel" should be your pointer. One way of doing what you want here would be to store *all* of your level data in one data statement (i.e. "Levels") and then treat that as a multidimensional array. In other words, if each level contained 30 values to describe it, then to access each individual level you would use:

 

include div_mul.asm
dim currentLevel = a
dim selectedLevelIndex = b

 Levels
 (30 values for level 1),
 (30 values for level 2),
 (30 values for level 3),
end

 selectedLevelIndex = currentLevel * 30

 

That would bring you to the first value of of each level, then you could use addition to access values 1-through-29 (or 31-through-59, or 61-through-89, etc). If that doesn't make sense to you, I can post an example later today when I have some free time.

 

Cheers,

Jarod.

 

Thanks, that seems like it might do what I want. I will have to test it when I get a chance to sit down and work on this a little more. My only concern is the 256 array size limit.

Share this post


Link to post
Share on other sites

A more complicated example, without the 256-byte limitation on the total level data...

 

levelloader.bas

levelloader.bas.bin

 

...it loads the data into the score variable, but there's no reason why it couldn't be playfield data or any other variables.

 

rem ***********************************************************************
rem arbitrary level data loader example
rem 
rem features
rem   ...level data is loaded from an indexed array
rem   ...total level data can be bigger than 256 bytes
rem 
rem limitations
rem   ...level for any one level must be <257 bytes
rem   ...eats up cycles because in-ram routine is a subroutine and uses one
rem      sub call per byte. this could be fixed easily if you dedicate more
rem      ram to the ram-based asm routine.
rem
rem notes
rem   ...requires all-in-one score_graphics.asm file, found here:
rem      http://www.atariage.com/forums/topic/147450-custom-fonts-for-bb-all-in-one-score-graphicsasm
rem
rem ***********************************************************************

const fontstyle=CURVES
const fontcharSPACE = 1
const fontcharARIFACE = 1

const lvl1lo = #>lvl1
const lvl1hi = #<lvl1

const lvl2lo = #>lvl2
const lvl2hi = #<lvl2

const lvl3lo = #>lvl3
const lvl3hi = #<lvl3

const lvl4lo = #>lvl4
const lvl4hi = #<lvl4

rem *** the size of the level data, in bytes
const levelsize = 3

def sc1=score
def sc2=score+1
def sc3=score+2

def level=a
def delay=b

scorecolor=$0f
level=0

initlevel
rem *** call our level loader...
gosub loadlvldata
rem *** do any other level initialization

delay=0
gameloop

drawscreen
 
rem *** wait for 120 frames and then increment the level. If it's >3 make it smaller
if delay=120 then level=level+1 : level=level & 00011 : goto initlevel
delay=delay+1
goto gameloop


data lvlhipointers
lvl1hi, lvl2hi, lvl3hi, lvl4hi
end

data lvllopointers
lvl1lo, lvl2lo, lvl3lo, lvl4lo
end

data lvl1
$1a,$aa,$ab
end
data lvl2
$2a,$aa,$ba
end
data lvl3
$3a,$ab,$aa
end
data lvl4
$4a,$ba,$aa
end

loadlvldata
  rem the following code loads theses opcodes into the temp variables:
  rem 	ldx $XXXX,y  	($BE,XX,XX)
  rem 	stx $XX,y  	($96,XX)
  rem	rts		($60)

  temp1=$be
  temp2=lvlhipointers[level]
  temp3=lvllopointers[level]
  temp4=$96
  temp5=#score
  temp6=$60

  asm
    ldy levelsize
keeploadinglvl
    jsr temp1
    dey
    bpl keeploadinglvl
    clc
end
  return

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...