IKD - Atari Combat remake

Use this forum to share and discuss Uzebox games and demos.
Post Reply
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: IKD - Atari Combat remake

Post by danboid »

After taking over a year off this project, I'm now motivated to try and finish it after the recent success I had of working out how to print debug messages to the cuzebox console, which will be a big help to a C, Uzebox and game dev newb like me. Thanks to Artcfox for providing the patch for cuzebox to enable that!

I'm still trying to work out the simplest way to implement collision detection between the tanks, the walls and the bullets. Currently, there is no wall/tank or bullet/wall collision detection.

There aren't many walls used in the combat maps so I have the option of implemeting the walls as individual sprites. Could this simplify collision detection? I thought it might but I don't see any function/ key word to fetch the dimensions or current position of a mapped sprite so it seems I have to calculate them myself? I was hoping using sprites would spare me this but I only see calls to set, not get sprite data.

If there is no way to get this data (the top, bottom, left and right edges of a sprite) or auto-detect sprite collisions then I probably am better off implementing the mazes as a maps instead of collections of wall sprites. The walls don't move so this must make things easier, whichever method I choose.

I want to implement this in the simplest and easiest to understand way, not the necessarily the most efficient or cleverest way to do it, which I probably won't understand yet anyway.
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: IKD - Atari Combat remake

Post by danboid »

I don't think using sprites will make anything easier but I think I've got a solution I might be able to implement for the wall collision detection by making heavy use of GetTile().
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: IKD - Atari Combat remake

Post by danboid »

I've commited some POC code for the IKD wall / tank collision detection but currently only for player one.

I put this in a function because adding my basic as possible collision detection code has already doubled the size of the IKD .c file so of course I want to re-use all of this code for both players but I'm not fluent enough at C to have wrote it in the correct way to be used by both players in this first working attempt. I thought it would be easier to get it working for one player first and I'm hoping someone will be kind enough to explain the correct way to modify the wall collision detection fuction wallTankCollision() so that it works for both players.

All wallTankCollision() does is gets the angle (ie direction that the players tank is pointing) of the player from p1_tank.angle (where angle is 0 for straight up, 4 is right/90 degrees, 8 for 180 degrees (pointing down) etc) and for each of the 8 squares surrounding the players current grid position it enables or disables the player being able to move forward depending on if there is a wall in that grid location. For the diagonals it disables p1_tank.advance if any of the 3 grid blocks in that quadrant of the diagonal has a wall in it. The 4x three diagonal frames of the tank are all defined using the same outcomes ie there are 16 frames to show the tanks angle but as far as wallTankCollision() is concerned there are only 8 directions you can face.

To adjust wallTankCollision() to work for both players, I think I'd need change the prototype and first line of the funtion to something like:

void wallTankCollision(struct tankStruct tank) {

then I should be able to call wallTankCollision like wallTankCollision(p1_tank) or wallTankCollision(p2_tank) to pass the players structs into them but I've never done this before in C so I need to work out how to correctly manipulate the struct values after that.

The tankStruct tank would then be created within that function but do I need to copy the elements of the new struct tank, I am modifying back into the coriginal struct from tank, or should I use poiinters or...!? I want to do it the easy way that is least likely to cause errors, if that is an option. I'd like someone who claims to understand the basics of C to describe the best (but easy) way to do what I need to do here so that I can then try to (learn how to) do it, please!

p1_tank and p2_tank are globally defined stucts so I think I can manipulate them directly but how do I do that by using a struct passed into a function? All of the values I need to manipulate in the wallTankCollision funtion are contained within the p1_tank / p2_tank structs so what is the cleanest / easiest way for me to adjust wallTankCollision to work for both players?

I'm well aware there is already a lot of duplicated code in this project and I intend to try to minimise the code duplication after I have got the game fully working. Its really only a case of getting the bullet/wall collision implemented after I've got this done. Adding extra mazes and a menu and anything else I need to do should be easy enough in comparison to what I've done so far.

I've managed to get this far into writing this game and I still don't know when I should be using pointers. This may or may not be a good time to use them? I won't feel like I know how to program in C until I know when and how to use pointers. Any current use of pointers is because of copy/paste, monkey see monkey do. I get worried when any mention of them and the stack appears. This is my first C program and I realise this is total beginner stuff so I hope I'm not boring you all.
CunningFellow
Posts: 1445
Joined: Mon Feb 11, 2013 8:08 am
Location: Brisbane, Australia

Re: IKD - Atari Combat remake

Post by CunningFellow »

I think your would be best off working out a general purpose was of doing the collision than hard coding the walls/map.

Something like drawing the map. Then drawing the tanks/missiles on top of the map and checking if you are colliding with a something as you draw it.

Even if you stick with the way you are going - using a switch/case statement instead of a whole lot of else-if will make better readability maybe.
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: IKD - Atari Combat remake

Post by danboid »

Thanks for your feedback CF!

I've adapted my tank/wall collision function to work for both players now. Its ugly and very likely much bigger than it could be but it seems to work and I understand how it works.

I've got to do the bullet collision routine yet so maybe I'll end up rewriting the tank/wall collision function if I come up with a better, more readable way to handle the bullet/wall collisions.
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: IKD - Atari Combat remake

Post by danboid »

Tonight I added wall/bullet collision detection to IKD so although I'm not quite finished with it yet, the game has finally reached the point where it actually plays like the original because all of the core code is in place now except for bouncy bullets. I want to add at least one more maze, the death animation, bouncy bullets and a menu before I'll consider it worth a release,
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: IKD - Atari Combat remake

Post by danboid »

Today I added the second maze and I managed to remove almost 200 lines of code from the wall/tank collision detection function by adding a wall that surrounds the playfield to both mazes, which is how it was in the original game anyway.
Screenshot at 2022-09-11 22-34-57.png
Screenshot at 2022-09-11 22-34-57.png (25.82 KiB) Viewed 2807 times
CunningFellow
Posts: 1445
Joined: Mon Feb 11, 2013 8:08 am
Location: Brisbane, Australia

Re: IKD - Atari Combat remake

Post by CunningFellow »

She's lookin' good, Vern!
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: IKD - Atari Combat remake

Post by nicksen782 »

Thank you, this is awesome! I was thinking about making this game at some point. I'm very happy that somebody now is! I played the heck out of that game on the Atari 2600 way back in the day. I look forward to more posts about this.
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: IKD - Atari Combat remake

Post by danboid »

Its cool to know that a few people do want to play this and its not been purely an educational exercise. All that remains is to implement bouncy bullets, the death animations and a menu to pick the maze and a couple of other options then I'm done for 1.0.

I had a good look but I was unable to find any open source remakes of Combat which is surprising as its one of the most fondly remembered games for the 2600, being the original pack-in game. Think how many Space Invaders clones there are in comparison.

Combat and the 2600 are 45 years old this month, not trying to make anyone feel old!
Post Reply