Log In  

Cart #20859 | 2016-05-19 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

I've been working on a tile based puzzle game recently and to make things easy initially I setup random generating levels. While this helped me get through adding and testing the mechanics and my code I realised that some times in testing I'd get a level I might want to play again but as it was one of eight million I wasn't likely to generate it again.

So I realised that I would need to create Level IDs and a system for inputting them. This is my first attempt at a very basic input and the screen displays the output too that I would feed into some variables in my game to get back to that challenging level.

As a complete novice any feedback or improvements are greatly appreciated. My known bugs so far are not knowing a slick method to stop the highlight moving off either end of the row and not being able to limit the range of letters (you can go down from A etc.)

--basic levelid i/o
--by lorcav

function _init()
cls()
hlight={}
hlight.x=32
hlspr=29
l1=1
l2=1
l3=1
l4=1
l5=1
l6=1
l7=1
actsprpos=1
end

function _update()
cls()
map (0,0,0,0,16,8)
move(hlight)
spr(hlspr,hlight.x,40)
spr(30,hlight.x,24)
spr(l1,32,32)
spr(l2,40,32)
spr(l3,48,32)
spr(l4,56,32)
spr(l5,64,32)
spr(l6,72,32)
spr(l7,80,32)
movebound()
end

function move()
if(btnp(0)) --left
  then
 hlight.x-=8
 actsprpos-=1
 end
if(btnp(1))--right
 then
  hlight.x+=8
  actsprpos+=1
 end
if(btnp(2))--up
 then
 entryup()
 end
if(btnp(3))--down
 then
 entrydown()
 end
if(btnp(4))--confirm
 then
 end
end

function entryup()
if actsprpos==1
 then l1+=1
end
if actsprpos==2
 then l2+=1
end

if actsprpos==3
 then l3+=1
end

if actsprpos==4
 then l4+=1
end

if actsprpos==5
 then l5+=1
end

if actsprpos==6
 then l6+=1
end

if actsprpos==7
 then l7+=1
end
end

function entrydown()
if actsprpos==1
 then l1-=1
end
if actsprpos==2
 then l2-=1
end

if actsprpos==3
 then l3-=1
end

if actsprpos==4
 then l4-=1
end

if actsprpos==5
 then l5-=1
end

if actsprpos==6
 then l6-=1
end

if actsprpos==7
 then l7-=1
end
end

function movebound()
if hlight.x>=81 then
   hlight.x=32
   actsprpos=1
end
if hlight.x<=31 then
   hlight.x=80
   actsprpos=7
end
if l1>=14 then  l1=1
end
end

function _draw()
print ("please enter level id",19,44,10)
print (l1,35,52,8)
print (l2,43,52,8)
print (l3,51,52,8)
print (l4,59,52,8)
print (l5,67,52,8)
print (l6,75,52,8)
print (l7,83,52,8)
end
P#20861 2016-05-19 15:04 ( Edited 2016-05-20 17:48)

I've implemented something similar for a naming screen. For going down, the trick I use is incredibly simple. Decrement, and then if it's below the lowest number assigned to a letter set it to the highest one. Arithmetic and comparisons are so fast as to be basically free on pico-8 unless you're doing some serious heavy-duty calculation.

P#20933 2016-05-20 13:48 ( Edited 2016-05-20 17:48)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 16:06:40 | 0.009s | Q:12