Log In  
Follow
hongus

Hi all, so I've been working on my table that adds bread slices to my duck game. It's working fine now and I can add the desired amount of bread. But there is a strange oddity - I have a little animation of the water rippling under the bread slices, but for some reason the more bread slices there are, the faster the animation goes, so if there's a lot of bread it's just a crazy flickering. I can't really get my mind around why this would be happening, so would appreciate any thoughts.

Here is all the code relating to the bread and ripple animation (rip stands for ripple):

--bread

--contents:
--init bread (empty table)
--breadset
--update bread
--draw bread
--ripple animation

function initbreadslice()

bread={}
breadtime=true

end

function breadset()

add(bread,{
sp=42,
x=20+rnd(75),
y=20+rnd(75),
act=true,
dis=4,
draw=function(self)
if self.act==true then
ripples(self)
spr(self.sp,self.x,self.y)

[ Continue Reading.. ]

2 comments



So I'm currently working on a little practise game about a duck in a pond. In the game you have to avoid slices of bread which damage your health if you eat them.
Until recently I just manually added 3 slices of bread as individual objects. But I'm now wanting to add multiple levels, where the amount of bread slices resets and increases to make the game more difficult, so I've been trying to learn more about tables to make this happen.
My goal with this code was to be able to add a different number of slices to the bread table each time the game state is triggered, based on the level number. So the 'for i=0,(level+2)' is meant to make it so that the number of slices is the level number plus two, so 3 for level one, 4 for level two, and so on.
But when I run the code below, I don't get any errors, but the bread doesn't even appear. I've definitely added these custom functions to the main code, so I'm not sure where I'm going wrong. Any guidance greatly appreciated as the concepts here are very new to me!

[ Continue Reading.. ]

1
3 comments



So I'm currently trying to make a little game that features some fish being generated in a random spot in a pond, then swimming back and forth. As a start I've just been trying to generate the fish and have them point in the direction they will be going first. The random location generation worked fine, but when I tried to add the fx to flip the fish in the direction it's heading, I get the error 'unexpected symbol near '='' But I've been looking for a while and can't see where the issue is. The error is flagging the 'o.x+=1 and o.fx=true' and 'o.x-=1 and o.fx=false' lines

This is the offending chunk of code, thank you for any guidance!

function initfish()

fish1={
sp=6,
x=40+rnd(60),
y=40+rnd(60),
fx=false
}

end

function fishmove(o)
waypicker=rnd(2)
if waypicker==1 then
direction="left"
elseif waypicker==2 then
direction="right"
end

if direction=="left" then
o.x-=1 and o.fx=false
elseif direction=="right" then
o.x+=1 and o.fx=true
end
end
end

function updatefish()
fishmove(fish1)

end

4 comments



Hello again, I am a complete beginner for those who didn't see my previous post. Been trying to create my own functions to perform certain tasks, but having trouble. In this case I was trying to make functions that could draw and move a player, in a way where I could substitute in different players using the brackets at the end of the function. However when I run this I'm just getting a black screen - so I'm guessing something wrong with the draw function? Would appreciate if anyone can point me in the right direction. Thanks in advance for any responses!

my code:

function _init()
--players
jim={
sprite=1,
x=63,
y=63,
w=1,
h=1
}

jon={
sprite=2,
x=63,
y=63,
w=1,
h=1
}

end

function _update()
cls()
move(jim)

end

function _draw()

drawplayer(jim)

end

function move(player)
if btn(➡️) then player.x+=1 end
if btn(⬅️) then player.x-=1 end
if btn(⬆️) then player.y-=1 end
if btn(⬇️) then player.y+=1 end
end

function drawplayer(player)

spr(player.sprite,player.x,player.w,player.h)

end

6 comments



Hi, I am totally new to coding and have been learning little bits on pico-8 for a couple of weeks now. I was trying to practise a very basic wraparound effect, so that a circle being moved with the arrow keys can go off one side of the screen and reappear on the other.

This is the code:
'function _init()

x=63
y=63
speed=2
radius=15
leeway=2*radius

end

function _draw()
cls()
circfill(x,y,radius,8)

end

function _update()

if btn(➡️) then x+=speed end
if btn(⬅️) then x-=speed end

if x>(127+leeway) then x=(0-leeway) end

end'

The above code works as expected, but I originally wrote the wraparound effect line as:
'if x=(127+leeway) then x=(0-leeway) end'

(So 'if x=' rather than 'if x>')

But with the original version I get a syntax error of 'then' expected near '='

Can anyone explain to me why one version is functional but the other isn't?

Many thanks for any help!

3 comments