LikeTheRogue [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=25228 A-Taco-Lypse Driving <p> <table><tr><td> <a href="/bbs/?pid=43300#p"> <img src="/bbs/thumbs/pico43299.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=43300#p"> A-Taco-Lypse Driving</a><br><br> by <a href="/bbs/?uid=25228"> LikeTheRogue</a> <br><br><br> <a href="/bbs/?pid=43300#p"> [Click to Play]</a> </td></tr></table> </p> <p>For LOWREZJAM</p> https://www.lexaloffle.com/bbs/?tid=29799 https://www.lexaloffle.com/bbs/?tid=29799 Wed, 16 Aug 2017 18:56:19 UTC Trouble with vertical scrolling loop <p>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.</p> <p>Here is the current issue I'm encountering: <img style="margin-bottom:16px" border=0 src="https://www.lexaloffle.com/bbs/files/25228/car1.gif" width=470 height=511 alt="" /></p> <p>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. </p> <p>The code I've written is as follows:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> 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&lt;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 &gt;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&lt;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&lt;-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 </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>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!</p> https://www.lexaloffle.com/bbs/?tid=29752 https://www.lexaloffle.com/bbs/?tid=29752 Thu, 03 Aug 2017 15:25:08 UTC