Since my last post, I've been working on the game a little sporadically and less than I've wanted to. But, I'm really excited cause I'm digging into drawing sprites to the screen and animating them. Also creating maps and drawing those too. Like I mentioned before, I'm not a programmer so it's definitely been a struggle but I'm learning a lot! Also, I'm gonna keep plugging Nerdy Teachers cause their tutorials have been great.
So the first thing I did was create all the sprites for my main character. This lil' wizard dude
The first few sprites consist of his idle animation, which is just 2 sprites of him looking left and right. The next 3 are his running animation, and this definitely took me a few tries to get down! I was able to test out his running animation with some quick and dirty code that looks like this:
these variables are a really simple setup for me to just draw the running animation to the screen and see it in action. Nothing fancy here, no button interactions just playing the animation by iterating through a certain number of sprites. The number in the sprite variable corresponds to where the sprite is in the actual sprite sheet. To test out the animation, I made a separate pico8 cart just so I could isolate my running sprites which is why it starts at 1. Now here's what the code looks like for looping through the running sprites and moving them across the screen on the X axis:
The code above is in the _update() function which updates the game 30 times a second. Here I'm essentially making the sprite variable loop through all the sprites in my run cycle, once it does it starts over. Then I'm checking if the sprite reaches the right side of the screen, and if it does I just return the sprite to the left side of the screen. The _update() function isn't actually drawing anything to the screen, just updating and changing variables. This is what the code looks like for actually drawing all this to the screen:
Here all I'm doing is using some of pico-8's built-in functions to draw stuff to the screen. the spr() function draws a sprite and accepts values to decide what sprite to show and where to show it. So I'm using my sprite, x and y variables in place of hard numbers since I'm changing them for the animation. I'm also using the print() function to show the actual number inside the sprite variable on the screen. This helps me see the sprite numbers that the variable is looping through, so I can figure out if it's actually using all the sprites in the run cycle or if I messed something up somewhere. Here's what all that together actually looks like:
All of this code is really rough and simple, so it most likely won't be what the final code will look like for actually moving the character with controls. I'm not even really sure what that will end up looking like, but I'm gonna find out! Aside from that, I also made a bunch of map tiles and used another built-in function map() to really quickly show that on the screen so I could see what it looks like.
When I dropped my character into the map I realized the contrast of the character to the map was really low, so I ended up changing the color of the lil' wizards robe. I'm still tweaking it so I'll probably change it again. I'll most likely add some more polish to my map tiles as well, like a better background. Next up I'm gonna be focusing on creating the physics of my character and the map so I could to map collision and actually move my character. Really looking forward to that!
Till next time 👋🏽