New 32x game in development!

Importante releases or news for the communauty

Moderator: KanedaFr

matthewnimmo
Very interested
Posts: 87
Joined: Thu Jan 07, 2021 8:04 pm

Re: New 32x game in development!

Post by matthewnimmo » Thu Feb 16, 2023 6:10 am

Another Update:

I'm still working through the AI components, but I wanted to share a bit about NPC's and random encounters!

I've started to flesh out my NPC list within my game maps. I know have two new groups within my game maps (npcs, and mobs) Both are NPC_t structs but the mobs only contain battledata along with battle sprites. NPCs will have regular sprite data and may have battle data if it's a special NPC that you can fight later on.

I've also incorporated random encounters within maps (so as long as maps contain an array of mobs, then random encounters can occur. Randomness can be adjusted. When an encounter occurs the screen fades out and into the battle screen. the mob is then copied to a currentmob that your player will do battle with.

I've rigged up the A button to allow the mob to attack, the B button to escape the fight, and the C button for player to attack. With each attack i'm seeing the mob's HP go down. All of this is very basic and just proving out the mechanics. There will definitely be a lot more to the gameplay mechanics than this lol.

Below is a battle encounter with both player and mob looping through idle states (all running through my new animate sprite function!)

29.png
29.png (225.22 KiB) Viewed 64736 times
Below is me smashing both A and C lol and you can see the battle state animation for both the mob and player

30.png
30.png (232.95 KiB) Viewed 64736 times
Enjoy!

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: New 32x game in development!

Post by Chilly Willy » Thu Feb 16, 2023 9:19 pm

You've really put some work into this. Looks like those old RPGs; the battle screen looks good. Is it going to be turn-based?

matthewnimmo
Very interested
Posts: 87
Joined: Thu Jan 07, 2021 8:04 pm

Re: New 32x game in development!

Post by matthewnimmo » Fri Feb 17, 2023 3:46 am

Chilly Willy wrote:
Thu Feb 16, 2023 9:19 pm
You've really put some work into this. Looks like those old RPGs; the battle screen looks good. Is it going to be turn-based?
Hey Chilly! :) Yes, i'm serious about this. It's going to happen! I wish i can take credit for the background and sprites; but alas they are from one of my favorite RPG/Strat games (Shining Force). These are place holders for the art style, position, and feel for what my RPG is going to be like. So, my good graphics will come too; but for the time being we get to see some great graphics lol.

I was originally thinking turn based (keep it old school). However, I am toying with the idea of more of an responsive based game pay. For example, you could just spam the A button for basic attack while B button would allow for blocking and C maybe for a powerful attack; but the mobs will get smarter and stun you and attack themselves. Or, they'll block your spam of attacks. Maybe even some stamina/energy meter that allows you to spam as much as you want; but if that hits zero you SOL until some tics go by to replenish it. The recent wonder of this type of game play came to me as I had a grin on my face smashing the A and B buttons ticking down HP on both my player and mob lol.

But, there's something nice and comforting to "wait your turn" in an RPG....so still up in the air

Tonight and tomorrow I'll be working some more on AI but primarily on developing my Font drawing from scratch. After chatting with Vic and posing my idea about getting a spritesheet of my font and just draw_sprite out each character in my strings he told me that's typically how real fonts are done, so i'll probably put something together like that and leverage Vic's drawing routines further. The challenge i was having with debug font drawing within the existing code was that it was never consistently drawing in the same location on the screen as I moved around the map.

More to come!

matthewnimmo
Very interested
Posts: 87
Joined: Thu Jan 07, 2021 8:04 pm

Re: New 32x game in development!

Post by matthewnimmo » Fri Feb 17, 2023 10:40 pm

First, a correction I want to point out! Vic meant to say that using his draw_sprite function may be the best way when using yatssd for fonts (not overall rule of thumb). originally thought fonts/drawing text was going to be one of the easiest things for me to do...well i was wrong and i'm probably just too stupid to do it the 'right way' I'm learning though.

Second, Chilly/Vic I'm trying a few things here to draw text to my screen (not using the debug print ways within D32xr nor yatssd ... both don't show well on the screen when drawing tiles).

a) This is probably the dumbest thing to do, but i'm trying so bear with me! I've created another .bmp that was 1376 x 16 ( that's 86 different characters ... includes upper and lower case alphabet, numbers, and special characters). Then i used my function below that I had previously created for drawing specific sprites from a sprite sheet

Code: Select all

void Draw_Sprite_From_SpriteSheet(int x, int y, unsigned char* spriteBuffer, int crop_x, int crop_y, int crop_width, int crop_height, int src_width, int flags)
{
	//unsigned char* src = (unsigned char*)(spriteBuffer + crop_y * src_width + crop_x);
	unsigned char* src = (unsigned char*)spriteBuffer + crop_y * crop_height * src_width + crop_x * crop_width;

	draw_sprite(x, y, crop_width - crop_x, crop_height - crop_y, src_width, src, flags); //test
}
Was drawing A - Uppcase D just fine ... then the wheels started to fall off and I'm not sure why. So that's the 0 - 6 frames. Starting 7 frames i start to get partially drawn characters until eventually nothing is drawn anymore even though i technically have 0-85 frames.

So then i created some smaller 48x48 with just 9 letters 16 pixels w/h and those all print well. Then i created a 64x64 and i started to notice the same behavior happening again that the last characters start to get "shaved"

Any thoughts on what's going on? Why is this function seeming to be limited to 3x3 spritesheets?

b) My second method was just playing around and learning some from the debug print function using the msx font. I'm not quite sure how that msx array is built. But looks like the font pointer "knows" where to get to the right position by

Code: Select all

unsigned char* font = &msx2[(int)c * 8]
So, I thought I wonder if i can some how "just print" the font this way like I do other .bmp images. Obviously, it doesn't work but I throw it in here to give everyone here who knows i'm an idiot a good laugh

Code: Select all

unsigned char c = 'W';
unsigned char* font = &msx2[(int)c * 8];
draw_sprite(1, 1, 8, 8, 8, font, DRAWSPR_OVERWRITE | DRAWSPR_PRECISE);
Hopefully my question(s) are clear. Where am I off? What am I doing wrong here? Also, is there something off with my draw_from_spritesheet code?

Thanks again guys,

matthewnimmo
Very interested
Posts: 87
Joined: Thu Jan 07, 2021 8:04 pm

Re: New 32x game in development!

Post by matthewnimmo » Sat Feb 18, 2023 4:57 am

*Facepalm*

Well i figured out my own problem with option a. While I'm not sure this is a good idea on how to get a font to work within this starterkit and my game, I found my issue. It seems that as x and or y got greater i was slowly shaving away what was being drawn via width and height by the below code....code that i forgot to change (i didn't notice it because all my spritesheets up to this point have been very small and have extra transparent space that can be ate up without no problem.

Code: Select all

draw_sprite(x, y, crop_width - crop_x, crop_height - crop_y, src_width, src, flags); //test
So now, it's been fixed to this and i can print all 86 characters just fine with the adjustment below

Code: Select all

draw_sprite(x, y, crop_width, crop_height, src_width, src, flags);
But my previous question still stands, am i doing this right? Is there a better way?

Vic
Interested
Posts: 27
Joined: Wed Nov 03, 2021 6:01 pm

Re: New 32x game in development!

Post by Vic » Sat Feb 18, 2023 11:18 am

a) the best way to do something is usually the one that works. your code looks fine to me
b) the stride that you pass for the msx font is most likely wrong. the stride has to encompass all horizontal pixels of the image/spritesheet, it can't be 8

matthewnimmo
Very interested
Posts: 87
Joined: Thu Jan 07, 2021 8:04 pm

Re: New 32x game in development!

Post by matthewnimmo » Sat Feb 18, 2023 5:05 pm

Vic wrote:
Sat Feb 18, 2023 11:18 am
a) the best way to do something is usually the one that works. your code looks fine to me
b) the stride that you pass for the msx font is most likely wrong. the stride has to encompass all horizontal pixels of the image/spritesheet, it can't be 8
This is perfect! Thanks for the feedback. How do I gather the overall with of msx or any font for that matter? Just more curious than anything. As some fonts include more special characters than others

I think im going to take your advice and use what is working well and thats my new font that I created in aseprite thats 1376x16. Then create a look up table for characters used in a string and draw the corresponding sprite location. My initial testing works pretty well really and allows me to change my font to others in the future by creating new bmp files if i wanted. Can even get artsy with my fonts this way if i wanted

Vic
Interested
Posts: 27
Joined: Wed Nov 03, 2021 6:01 pm

Re: New 32x game in development!

Post by Vic » Sat Feb 18, 2023 7:09 pm

matthewnimmo wrote:
Sat Feb 18, 2023 5:05 pm
How do I gather the overall with of msx or any font for that matter?
Number of characters * character width, which I assume must be 8

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: New 32x game in development!

Post by Chilly Willy » Sat Feb 18, 2023 11:04 pm

Using a BMP with the font is a good idea as you can easily change fonts by changing the BMP. It seems you figured out your problems - it should be almost the same as drawing sprites, just without the animation... unless you want an animated font. Maybe a metallic font that gleams? Or a font that drips blood... :twisted:

matthewnimmo
Very interested
Posts: 87
Joined: Thu Jan 07, 2021 8:04 pm

Re: New 32x game in development!

Post by matthewnimmo » Mon Feb 20, 2023 9:25 pm

Chilly Willy wrote:
Sat Feb 18, 2023 11:04 pm
Using a BMP with the font is a good idea as you can easily change fonts by changing the BMP. It seems you figured out your problems - it should be almost the same as drawing sprites, just without the animation... unless you want an animated font. Maybe a metallic font that gleams? Or a font that drips blood... :twisted:

Very cool! Well thank you Chilly and Vic! I went ahead and built out my own way of printing text to the screen. I stuck with option a. So, I have a simple wide font .bmp that has each character in its own 16x16 block (I may make that smaller). then i have a simple switch case that looks at my string input and matches it to the character position within that wide spritesheet. I even added some VERY basic word wrapping (essentially just max characters per line before new line return). So, i can draw text with simply supplying text string, x, and y and viola i have text in my own font on the screen.

I also went ahead and created some place holders for dialog boxes so that my text has a backdrop to display on. As i draw my dialogbox I pause my tilemap and sprite drawing (since they are not needed) and then i resume when the dialogbox is dismissed (start button...currently for testing)

On my battle screen i have some smaller dialogboxes that which i'm drawing simple dynamic text such as HP that goes down as the battle continues. All works well thus far!

Below is a simple dialog that is displayed from the world/map view
32.png
32.png (66.33 KiB) Viewed 64578 times
Below is another example of my battle screen with textblocks
31.png
31.png (251.08 KiB) Viewed 64578 times

haroldoop
Very interested
Posts: 160
Joined: Sun Apr 29, 2007 10:04 pm
Location: Belo Horizonte, MG, Brazil

Re: New 32x game in development!

Post by haroldoop » Tue Feb 21, 2023 9:43 am

Hello; great work so far!

If you want some code for drawing variable-width fonts on a 32X with word wrapping, you could take a look at the source code for VN32X:
https://github.com/haroldo-ok/vn32x

The code is not optimized, but it can use variable-width fonts (converted using BMFont), performs true word-wrapping and has antialiasing.

matthewnimmo
Very interested
Posts: 87
Joined: Thu Jan 07, 2021 8:04 pm

Re: New 32x game in development!

Post by matthewnimmo » Wed Feb 22, 2023 5:14 am

haroldoop wrote:
Tue Feb 21, 2023 9:43 am
Hello; great work so far!

If you want some code for drawing variable-width fonts on a 32X with word wrapping, you could take a look at the source code for VN32X:
https://github.com/haroldo-ok/vn32x

The code is not optimized, but it can use variable-width fonts (converted using BMFont), performs true word-wrapping and has antialiasing.
Thank you for the information. Unfortunately, this was one of the first projects i looked into when thinking about fonts (I really like how you handle word wrap!) and the drawchar function just doesn't quite work with this build (maybe its the latest toolchain...i'm not entirely sure...probably me and my stupidity lol). But, I do plan on learning from your word wrap and applying it within here :)

Update for others!

I've been busy refactoring/restructoring some more and of course adding new things. First, I pulled out my collision functionality into its on c file so that both my map sprites and player can easily reference it. I now have the game loop going through all npcs within a map and running their separate AI functions (currently I just have a simple walk, No AI, and start of scripting section). I've created my main_character structure and have that all wired up as well (so instead of hard coded player information it's defined with everything else with gameworld.h). I've pulled out my gamemap information into its own gamemap.h and simply left my gameworld.h file just for implementation of my gameworld and all objects within it. The idea is that I'm going to create a separate helper tool that allows a user to easily change the gameworld.h file (so instead of making changes manually to a file like below)

Code: Select all

sprite_state_t Player_Battle_States[] = { {2,IDLE_STATE,10, 0},{2,ATTACKING_STATE, 10, 0} };
npc_t map1_mobs[] = {
	{"Dwarf Lord",
	"",
	{},
	30,
	90,
	{10,3,1,{2,(sprite_state_t*)DwarfLord_Battle_States,(unsigned char*)((int)spritesheettest3 + 0x36 + 1024),100,100,200,0,0, IDLE_STATE}},
	NO_AI, 0, 0,
	NOT_WALKING},
	{"Player",
	"",
	{},
	220,
	120,
	{10,3,1,{2,(sprite_state_t*)Player_Battle_States,(unsigned char*)((int)spritesheettest4 + 0x36 + 1024),100,100,200,0,0, IDLE_STATE}},
	NO_AI, 0, 0,
	NOT_WALKING}
};
There will be a nicer gui executable that allows you to define a map, npcs, mobs, etc within that map and world and save the gameworld.h

matthewnimmo
Very interested
Posts: 87
Joined: Thu Jan 07, 2021 8:04 pm

Re: New 32x game in development!

Post by matthewnimmo » Fri Feb 24, 2023 4:17 am

Update time!

As i mentioned earlier I've been refactoring and cleaning some of my test code out. Also, I had my NPC's wondering around my maps looping through their walking AI functions (respecting map boundaries, even when map sizes change...so nothing is hardcoded anymore).

My biggest focus lately is starting to build out the GameWorldEditor tool. I keep scoping creeping in my head the things I want to do with it (almost to the point of a light 32x IDE engine ... think like unity but for 32x games). So I have to keep myself grounded on focused on the MVP which is (a simple editor that allows me to create and organize my game world objects and to export out my gameworld.h file)

I'm in the process of doing just that! Currently I have a simple windows form that reads in a json file that will store game assets in json form (npc, mobs, maps, items, player) currently. Then, I'll have another function that allows me to "add/remove" those assets to my gameworld.h file. I wanted to create this approach that way I'm only having to create NPC's once and just reference them in my editor during the export process.

Currently my entire 32x code knows to pull in gameworld.h from rom to start the game. So, in theory when a developer gets a hold of this project they can simple create tiled maps within Tiled and their GameWorld objects within this editor. Then compile their game and it should work. I plan to have this editor within the tools folder directory for others to enjoy.

More to come.

matthewnimmo
Very interested
Posts: 87
Joined: Thu Jan 07, 2021 8:04 pm

Re: New 32x game in development!

Post by matthewnimmo » Mon Feb 27, 2023 10:46 pm

Short Update:

Work has picked up, so been a little challenging to get some of this fun stuff done. Nevertheless, I have some updates to share mostly around the game world editor. The reason for that is because as I continue to add more content even within this engine/sdk/whatever i'm going to label it, I find it necessary to have some world editor to make everyone's lives easier.

Below is a simple setup right now of the win forms up. Currently, it loads up a gamesword.json file and it displays the two main areas: 1) Game Assets to use. 2) GameWorld itself that uses the game assets. the idea is that you would edit/create your game assets in the top part of the tree and right click "add" to include within the GameWolrd. GameWorld section will have context menu as well to remove assets. Each asset will be clickable and show the properties in which you can adjust. Right now, it saves and loads the .json. I'm working on exporting the gamworld.h file.

Once i have the basics done:

1) load/save .json file
2) Exporting my gameworld.h file

Then i'll gold plate some of it. Here are some items i'm considering to add

1). Include more assets, such as music and sounds.
2). Export options include updating assets.s file directly.
3). (this is a big one) include Tiled map files to be loaded and show (so draw out the tile map). Then give users the ability to draw/drop npcs/assets on the screen to their x/y locations that will be saved to .json file and exported in the .h file
4). (this one maybe harder to do, but curious). Add build functionality. So essentially kick off the "make" process directly from the editor and open up your emulator of choice.

MVP screen shot of what i've got so far (lots of screen GUI work to do)
33.png
33.png (61.94 KiB) Viewed 64413 times

matthewnimmo
Very interested
Posts: 87
Joined: Thu Jan 07, 2021 8:04 pm

Re: New 32x game in development!

Post by matthewnimmo » Tue Feb 28, 2023 11:20 pm

So, I couldn't help myself! I went ahead and started to figure out how to include Tiled maps and tilesets within my editor. Currently, it will load up the corrisponding .tmx file as well as any .tsx files associated to that map and draw the tiles out into a panel. This is probably stupid, but it works thus far; I'm filling that panel with pictureboxes that are sized to each tile. Each picturebox has separate events that allow for mouse events such as hovering over to show you your X, Y location. I'll have the ability to put NPC's, items, etc within the map and store that information with the .json file.

i wanted a visual represenation of where assets on a game world map would be without the (trial and error) of sprite placement on maps during build time. Below is a simple screen shot of the poof of concept (its ugly but it works thus far). I'll keep working on it and improving the usability of it.
34.png
34.png (27.02 KiB) Viewed 64387 times
enjoy!

Post Reply