Strategy game project

Made something in Assembly? Show it off, and tell us how it works...
Absolute beginners welcome... we want to see what you've done!
Forum rules
There is a special rule on this forum...
This forum is intended to offer equal amounts encouragement and constructive feedback...
Therefore, if you say 2 negative things about someones work, you must think of 2 or more equally positive things...

Eg: "Great first effort, the idea is absolutely fascinating... However I noticed a few bugs, and maybe the graphics could be improved..."

If you can't think of anything good to say, then don't say anything!

If we don't encourage newbie programmers they won't have the confidence and motivation to stick at it and become great programmers! *speaking from experience*
Post Reply
Voyager_sput
Posts: 15
Joined: Tue Jan 07, 2020 11:45 am

Strategy game project

Post by Voyager_sput » Tue Mar 10, 2020 7:50 pm

Hello everyone!

I'm here to share a game I made for the Commander X16. This game is based on a popular strategy game here in the Netherlands.
I'll avoid posting the exact name to prevent any issues with the company who has the rights to the product.

As such i'll mention that I claim no rights for the intellectual property of the game. Those rights will stay firmly with: Jumbo Games in the Netherlands.

So what is this game? It's a board based strategy game where two armies are placed against each other, 40 pieces per army, 12 unique kinds of pieces. Each team gets to move one piece per turn, and all pieces can only move 1 square on the game board per turn, with the exception of the Scout (rank 1). The Spy (rank 0) is the only piece to kill the Marshall (rank 11). Bombs can only be defused by a Miner (rank 2). For the rest the higher rank beats a lower rank in combat, and if two pieces of the same rank fight, both bite the dust. The first team to finds the other team's flag, wins! The player get's to choose if they want to play the Red or Blue pieces.

The game itself is split into 6 'phases'. Each phase covers a part of the game. These phases are:

- Phase 0: Preperation of the game, initialization of the screen, loading of the sprites in VRAM, initializing the randomizer, setting and clearing variables.

- Phase 1: Placement of the game pieces. First the computer will place it's 40 pieces, mostly based on random numbers, then the player can place his pieces down using cursors, enter and selecting numbers, or though hotkeys (0-9,f,b). Now on to phase 2!

- Phase 2: The player can make a move, selecting a source location and a destination. If the move passes 10 checks for illegal moves, then it moves the piece. If it's just a move, the game goes on to Phase 5, if the move is a attacking move, the game moves on to Phase 4.

- Phase 3: The computer makes a move, this is based on calculating all available moves it can do, and assigning a score to each move (based on 5 factors). Lastly it will perform the highest scoring move. If it just moves, we go to Phase 5, if it's a attacking move, on to Phase 4.

- Phase 4: There we handle any attacks, and see which piece wins, The losing piece is taken from the board, the winning piece takes it's place (unless the winning piece is a bomb). And we move on to phase 5.

- Phase 5: We change turns here, if the player was playing before, now it's the computers turn (goto phase 3), otherwise, goto phase 2.

And so the game runs though Phase 0, 1, 2, 5, 3, 5, 2,..... etc, this goes on until in Phase 4 someone tries attacking the other team's flag, and then it's game over!

Each phase has it's own asm file. And common subroutines not specific to just one phase and put in the Functions.asm file. The most important part of the game is the Sprite Data array,
where I used three bytes of data per piece/sprite to store the information of the sprite. There are subroutines to set and get the data for a piece.
The Sprite data's 3 bytes are layed out as followed:

- The first byte is empty. I was going to put the sprite/piece number in there, but I figured I could just calculate that instead. I left it in because I might need it later on. And I didn't want to change all the code that already relied on looping through the array's 3 bytes...(/lazy)

- The second byte contains the XY position. Since the game board is only 10x10 in size, the X and Y position will only ever need 0-9. So i used 4 bits for X and 4 bits for Y (XXXXYYYY)

- The third byte contains some flags: The 'Dead' flag (signifying if a piece has been killed), and the 'Detected' flag. I put that last one in for the computer, so that it could keep track of which pieces it's 'seen' already and adjust strategy. I ended up not using it though, the computer's 'AI' took more then enough time as it was :). The first 4 bits are the piece type. Meaning which of the 12 kinds of piece it is. Since we only need to store 0-11, I only used 4 bits for that.

I do have to add that if you look carefully, you'll see Chibiakumas's tutorial code buried in the code. I mostly used his code for printing characters on the screen, the font, load sprites into VRAM and showing the sprites on the screen (using SetSprite). However the code has been modified a bit to suit my needs.

For example I modified the SetSprite subroutine to also be able to disable sprites, and load 32x32 and 64x64 sprites. Similarly I made some changes to the PrintChar function to allow for some cursor control. (X and Y manipulation).

All the sprites are made in AkuSprite Editor.

All kudo's for these functions go to Chibiakumas! Thanks for teaching me how to make something for the Commander X16 as well as teach me 6502 Assembly in general! This project took me about 90 hours of work. It was quite a learning experience with many obstacles along the way, but in the end I have a game i'm proud of :)

The included ZIP file has the source data files, as well as a pre-assembled binary ready to be loaded in the X16 emulator (version r35 or r36). Using: x16emu.exe -prg Strategy.prg -run
Attachments
Strategy.zip
(60.83 KiB) Downloaded 340 times

Voyager_sput
Posts: 15
Joined: Tue Jan 07, 2020 11:45 am

Re: Strategy game project

Post by Voyager_sput » Tue Mar 10, 2020 7:55 pm

Oh, There's a few point you might want to call known bugs:

- Once you select a piece to move, you can't un-select it. It has to be the piece to move. I call it a feature.

- You also can't move pieces around in the placement phase, once placed, that's where it'll be put.

- When you win/lose a game, i'm pushing to the stack but not pulling 2 bytes, so I think, after playing 64 games in a row, the stack will corrupt itself. It's a bug, but I don't seriously expect anyone to play 64 games in one sitting :D

Post Reply

Return to “Show and Tell”