Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

how to load a level

A topic by ramjing created Oct 20, 2023 Views: 86 Replies: 2
Viewing posts 1 to 2
(2 edits)

I'm not sure if this is the appropriate forum to ask questions like this. But I have made this code to load a level onto the screen : 

:alias row v0 
:alias col v1 
:alias bx v2 
:alias by v3 
:alias temp ve  
: block
  0x00 0x70 0x70 0x70 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00  
: level1   
  0b11111111 0b11111110   
  0b10000000 0b00000010   
  0b10000000 0b00000010    
  0b10000000 0b00000010   
  0b10000000 0b00000010   
  0b10000000 0b00000010   
  0b11111111 0b11111110
: main   
  bx := 0   
  by := 0      
  
  loop     
    i := level1
    #increment i
    temp >>= by
    i += temp     
    load row   
    
    #reset bx and col
    bx := 0     
    col := 0b10000000
  
    i := block     
    loop       
      #read each bit of row and draw block if bit == 1
      temp := row       
      temp &= col            
      if temp != 0 then sprite bx by 4       
             
      bx += 4             
      col >>= col    
      
      #after 8 bit, reset
      if col == 0 begin       
        i := level1
        temp >>= by                 
        temp += 1                                  
        i += temp                 
        load row                     
        col := 0b10000000                            
        i := block
      end
      
      #if bx > 56, do next row
      if bx <= 56 then     
    again      
    by += 4     
    
    #finish if b > 24
    if by <= 24 then   
  again

How can I load a different level without rewriting the entire thing? I would appreciate it if someone could point me in the right direction.

HostSubmitted

You'll need to introduce indirection somehow.

One approach would be to write a routine that runs before level-drawing which copies a particular level's data into a working array. For example, perhaps something like:


The details will always be highly case-specific. For larger level data you probably need a loop for performing the copying, and you may need a different strategy for arriving at the base address of each level without overflow.

Thank you so much! it works!