For LOWREZJAM
Working on a game for LOWREZJAM 2017 and I'm running into some issues with getting the background to scroll up to simulate movement while still maintaining the player's position.
Here is the current issue I'm encountering:
My issue is arising from the camera moving up along the drawn map and snapping back to the bottom when it reaches a certain y value. That works fine for the background but I'm not sure how to get the player to maintain their y position when the map snaps back to the bottom.
The code I've written is as follows:
function _init() --renders game at 64x64 poke(0x5f2c,3) cls() --creates variable t to store timer info later in code t=0 --establishes boundaries of the level level={ w=64, h=250, cy=0 } cam_x=0 cam_y=0 player = { sp=1, x=28, y=50, h=100, t=0, imm=false } end function _update() --autoscrolling code --moves both the level/background and the player at the same speed, to simulate movement if level.cy<level.h-64 then level.cy-=2 player.y-=2 end --statement that will trigger invincibility frames --inactive atm if player.imm then player.t += 1 if player.t >30 then player.imm = false player.t = 0 end end --timer and statement that flickers back and forth between sprites to simulate movement t=t+1 if(t%8<3) then player.sp=1 else player.sp=2 end --basic movement code if btn(0) then player.x-=1 end if btn(1) then player.x+=1 end if btn(2) then player.y-=1 end if btn(3) then player.y+=1 end end function _draw() cls() --camera that follows level's movement --also keeps player on screen camera(0,level.cy) if level.cy<-80 then level.cy=0 player.y=50 end --draws map, extended to -100 to allow for longer stretch of road map(0,0,0,-100,12,63) --draws player car spr(player.sp,player.x,player.y,.75,2) end |
I'm still fairly new to programming so good coding practices and math functions aren't things I'm entirely familiar with yet. If anyone could help me figure out what tools I should look into to solve my problem or different approaches I should be taking with vertical scrolling loops, I'd greatly appreciate it!