Excelent stuff here! I'm new to Pico8 and I'm really loving it. But guys, I really don't understand the reason people uses multiple multiplications like x*x*x instead of x ^ 3. Is there any reason?
Does anyone know if pico8 had any updates that make this code a little broken? I have the exact same code and the sprites with the same flags, but my character randomly changes direction even if I don't press any button, it looks like it "collides" with blank spaces on the map and then goes on a different axis. Here's the code: grid_x=0 grid_y=0 flag_tile=0 x=63 y=63 dx=0 dy=0 function _update() grid_x=flr(x/8) grid_y=flr(y/8) flag_tile=fget(mget(grid_x,grid_y),0) if btn(0) then dx=-1 end if btn(1) then dx=1 end if btn(2) then dy=-1 end if btn(3) then dy=1 end if hit(x+dx,y,7,7) then dx=0 end if hit(y+dy,x,7,7) then dy=0 end x+=dx y+=dy end function _draw() cls() map(0,0,0,0,16,16) spr(2,x,y) print(grid_x..","..grid_y,5,5,7) print(flag_tile,5,11) end function hit(x,y,w,h) collide=false for i=x,x+w,w do if fget(mget(i/8,y/8))>0 or fget(mget(i/8,(y+h)/8))>0 then collide=true end end return collide end
Great vid! I have one question, how do you make it for the up and down animations. I tried to make it with the same code just different animations, it didn’t work. Could you please help:)
Well I got to 2mins 20 before being utterly out of my depth. Was worth a look though but jeez I wish pico-8 had a built-in collision command (like detectSpriteCollision(sprite1, sprite2) and it returned true if there was a collision.) as it stands now, pico-8 is fun but collision is an utter nightmate and might be the one thing that stops me from making games in this. a pity
Random numbers were such a headache in NES games. Pseudorandom numbers are often calculated as a bit shifting and reordering operation, but you need to be extremely careful to use an operation that doesn't have any predictable results. Imagine if your random number generator always returned 4, then 6, then 1, 4, 6, 1, 4, 6, 1. That could be a disaster, if you want it to be unpredictable, or to produce every possible value. The original Final Fantasy hardcoded a list of a few hundred predetermined numbers, and calling the equivalent of rnd() just looked up the next value in that table; that was the most reliable solution the programmer came up with. PICO8 being emulated allows it to pull unpredictable values from the host system, so rnd() is incredibly easy and incredibly reliable.
Hey Doc, thank you for all your tutorials. You have a very clear and calm way of explaining things, please don’t give up on making these excellent Pico-8 tutorials! We are sorely lacking in excellent video tutorials for this wonderful software!
Hi. Not really. BTNP reports TRUE only for the next frame after the button has not been pressed, so it reports FALSE for a button hold. You'd need to mash the button to have it use BTNP.
Amazing tutorial, as always. I was coming into this thinking I'd know everything already, but I was entirely unprepared for being able to put FUNCTIONS into objects. Not that I'm an expert, but I had read the documentation and, as far as I could tell, it makes no mention of this function-ality (ha). I'm going to have to revamp a couple of my projects to use this knowledge now.
Instead of adding values one by one all the time, you can check if the x+SPEED value is not going to collide and add the whole speed otherwise you add values one by one until you reach the collision point. Great tutorial!
Quick Question, what if i wanted to make a space shooter, and my ship is trying to move in a way where if i go right it goes to one sprite change of it turning left or right.
If you mean rotating a sprite, that's on a whole new level. You could draw several sprites or apply some maths to the whole thing but that's a whole new tutorial!
my map is larger than 127x127, i wanted to make my character stop when on the edge of the camera, but its stoping on the edge of the map tile please help
If you have a camera and a map, they each have their own coordinate system. You need to be careful to know when "x" refers to the map coordinates or the camera coordinates. I hope you managed to solve this on your own. Good luck in your future endeavors!
@doc_robs thank you for the wonderful tutorial series! However, I do have a question regarding collision. I have followed both this tutorial and the fget mget collision tutorial. I have attempted to combine the two but when I try to return the X, Y, W, H to the collision i am receiving runtime error at IF HIT(X+DX,Y,W,H) THEN. "ATTEMPT TO PERFORM ARITHMETIC ON GLOBAL 'X' (A NIL VALUE)". Is this because the object BULLET has no way to index values? Any help would be greatly appreciated. Cheers!
function _init() x=63 y=63 dx=0 dy=0 w=1 h=1 bullet={} end function _update() if btnp(🅾️) then add_new_bullet(2,0) dx=bullet.dx dy=bullet.dy x=bullet.x y=bullet.y w=bullet.w h=bullet.h end for b in all(bullet) do b:update() end if hit(x+dx,y,w,h) then dx=0 end if hit(x,y+dy,w,h) then dy=0 end x+=dx y+=dy end function _draw() cls() map(0,0,0,0,16,16) spr(2,x,y) for b in all(bullet) do b:draw() end end function hit(x,y,w,h) collide=false for i=x,x+w,w do if fget(mget(i/8,y/8))>0 or fget(mget(i/8,(y+h)/8))>0 then collide=true end end return collide end --bullet function add_new_bullet(_dx,_dy) add(bullet,{ x=63, y=63, w=1, h=1, dx=_dx, dy=_dy, draw=function(self) pset(self.x,self.y,7) end, update=function(self) self.x+=self.dx self.y+=self.dy end }) end
Hi, It could be that you have the function HIT running in the UPDATE function every turn but not specifically for an instance of BULLET. Try embedding the HIT function into the BULLET UPDATE function instead. There is a good chance that this might break things the first time you try it, so I would use the comments to delete code rather than actually deleting it, then you can roll back changes if it doesn’t work!
hey mate, loved all your videos. sad to see they seem to have ended, but i appreciate that you made them in the first place! Would love to see how you make a functioning game with different tabs for the init, update, draw!