# Where to start making a game in assembly.

## Recommended Posts

Hello everyone,

For learning purposes, I want to try to make a small graphical snake game in assembly. I've thought about where to start and which tools to use and personally I thought about using SDL and C to handle the keyboard input and the graphical output, but I would really like to know from other if there are better/easier ways to do this.

Thanks

##### Share on other sites

You want to make it in C or in Assembly?

Both are programming languages and, thought it is totally possible to write a game in assembly, is it recommendable? No. Not just because it takes a lot of work do get done, but maintainability is also difficult.

As for in C, you can do it. Lazy Foo has some very practical tutorials with SDL2.

32 minutes ago, Romee said:

but I would really like to know from other if there are better/easier ways to do this.

But, your problem here doesn't seems to be (only) language, but lack of understanding of game architecture. For that, I think this is a good read: http://gameprogrammingpatterns.com/contents.html. The topics State, Game Loop, Update Method and Object Pool are, in my opinion, the most useful to understand how to design a (good) game architecture (at least as a start point).

##### Share on other sites
Quote

You want to make it in C or in Assembly?

Both are programming languages and, thought it is totally possible to write a game in assembly, is it recommendable? No. Not just because it takes a lot of work do get done, but maintainability is also difficult.

As for in C, you can do it. Lazy Foo has some very practical tutorials with SDL2.

1 hour ago, Romee said:

but I would really like to know from other if there are better/easier ways to do this.

But, your problem here doesn't seems to be (only) language, but lack of understanding of game architecture. For that, I think this is a good read: http://gameprogrammingpatterns.com/contents.html. The topics State, Game Loop, Update Method and Object Pool are, in my opinion, the most useful to understand how to design a (good) game architecture (at least as a start point).

First, thanks for the quick reaction. But excuse me for my bad explaination, to me it sounded pretty logical, but I think I was mistaken. Namely, this is my case:

I will be making the game using both Assembly and C. Assembly will be used as the main language of the game, i.e. all the gameplay logic (for example, incrementing position, incrementing scores, etc.) will be done in this language. But, as input handling and graphics drawing is slightly out of the scope of my goal for this small project, I will do that by writing the functions that do that in C, using a media library, like SDL. To call the functions I make in assembly, I use the call instruction.

This way, I can divide the input handling, graphics drawing, etc. to C and the graphics library and the gameplay logic to assembly. But, my question still remains, is SDL a good option for this, or are there any better solutions.

Thanks by the way for the Game  Architecture link, a long time ago, I made a small game with C++ and SFML, but my knowledge was a bit rusty, so I will read that page without a doubt!

##### Share on other sites

Why do you want to do a whole game in assembly?  You'll kill yourself over something that doesn't have much practical use.  Also if you don't plan on becoming an assembly expert the compiler will likely beat you.  If you want to get a feel for assembly from top to bottom try something non-graphical.

My suggestion is if you want to play with assembly try inline assembly in a C/C++ program.  You can also mess with intrinsics if you're interested in SIMD programming.  Inline assembly would be your best bet at getting a taste of assembly.  If you want to go further, your C++ compiler likely outputs assembly as well, so you can make small programs and examine the assembly output to see how the compiler handles it.

##### Share on other sites
1 hour ago, Romee said:

First, thanks for the quick reaction. But excuse me for my bad explaination, to me it sounded pretty logical, but I think I was mistaken. Namely, this is my case:

I will be making the game using both Assembly and C. Assembly will be used as the main language of the game, i.e. all the gameplay logic (for example, incrementing position, incrementing scores, etc.) will be done in this language. But, as input handling and graphics drawing is slightly out of the scope of my goal for this small project, I will do that by writing the functions that do that in C, using a media library, like SDL. To call the functions I make in assembly, I use the call instruction.

This way, I can divide the input handling, graphics drawing, etc. to C and the graphics library and the gameplay logic to assembly. But, my question still remains, is SDL a good option for this, or are there any better solutions.

Thanks by the way for the Game  Architecture link, a long time ago, I made a small game with C++ and SFML, but my knowledge was a bit rusty, so I will read that page without a doubt!

It's totally up to you, but I wouldn't advise making a game using Assembly if you're looking at being as productive as possible, and looking to reduce the amount of time spent debugging, as well as making future changes. Even using C would be a better option, but I would still not recommend using either for a new game developer.

I would suggest sticking to any language that supports more mainstream OOP concepts like C#, C++, or JAVA.

Are you looking to do this just as a hobby project to toy around with Assembly and C? You're going to be putting yourself through a lot of headaches using Assembly. If you're looking at making the program fun as fast as possible, it's not going to make enough of a difference to avoid other languages like C#, C++, or JAVA with today's machines.

I personally use C++ with SFML, and OpenGL when needed. I was never a fan of C with SDL, but that was way back when it was still version 1, not 2. I've heard good things about SDL 2, so it's worth a look if you're looking at sticking with C along side Assembly.

I wish you the best on this interesting journey.

##### Share on other sites

I would say there is merit in making such a simple game in Assembly for classic computers such as the C64, Amiga or ZX Spectrum.  The cpus and memory maps are much easier to learn - especially the 8-bit machines.

The communities for those machines also appreciate new projects.

##### Share on other sites

What you want to do is perfectly feasible.

If I understand your intention correctly you want to use the SDL to develop a C framework for your snake game to run in? Something like:

int main()
{
init();

while (!quit)
{
poll_input();	// Update input state
update_game();	// Call your assembly entry point; assembly code updates the game state and renders to a bitmap
present();		// Use SDL to display the bitmap
}

shutdown();

return 0;
}

If that's your approach then it's a sensible way to limit just your game state and logic to being developed in assembly.

I'd recommend first just writing a single routine in assembler and working out how to assemble that and link it with an object file compiled from C, then work out the ABI so you know how to handle parameters and return values, and finally how to share data between the assembly and C parts. Once you have that plumbing in place you can iterate away on your game in assembly.

31 minutes ago, Anri said:

I would say there is merit in making such a simple game in Assembly for classic computers such as the C64, Amiga or ZX Spectrum.  The cpus and memory maps are much easier to learn - especially the 8-bit machines.

The communities for those machines also appreciate new projects.

I agree, I've done a couple of hobby games for the 8-bit Atari, it was the first computer I had and learned to program on and it's a lot of fun and very rewarding to develop for it using an adult's brain and modern dev tools.

##### Share on other sites

It is a great learning exercise, and I agree there is much value to it if this is something you want to learn.

11 hours ago, Romee said:

Assembly will be used as the main language of the game, i.e. all the gameplay logic (for example, incrementing position, incrementing scores, etc.) will be done in this language. But, as input handling and graphics drawing is slightly out of the scope of my goal for this small project, I will do that by writing the functions that do that in C, using a media library, like SDL. To call the functions I make in assembly, I use the call instruction.

Fair enough.  Split it however you want.

12 hours ago, Romee said:

I would really like to know from other if there are better/easier ways to do this.

Sounds like you have a reasonable set of tools.  As you increase in skills you'll want better tools, but it doesn't take much to build what you described.

It has been a few years, but I made several similar projects back in my high school and college days using simple text editors and command-line compilers. It can still be done today.

The best question to ask now is:  What is stopping me now?

If nothing is stopping you now, then get to work!   If something is stopping you, identify that one thing and get it resolved. Then once it is resolved, get back to work.

So instead of asking if you have the best tools, let's turn it back on you.  What is stopping you from making progress on the project?  Why aren't you typing away at your solution right now?

##### Share on other sites
15 hours ago, Romee said:

Hello everyone,

For learning purposes, I want to try to make a small graphical snake game in assembly. I've thought about where to start and which tools to use and personally I thought about using SDL and C to handle the keyboard input and the graphical output, but I would really like to know from other if there are better/easier ways to do this.

Yes, libSDL2 and assembly are a good combination for game development.  I'd recommend using Linux because the traditional toolchain is slightly easier for assembly development (gas, ld, make, and gdb; simpler and more consistent calling conventions; plenty of Free libraries you can leverage) but you can bend your workflow to fit other tools if that's more your thing.

You'll want to stay away from mixing C++ or Objective-C libraries with assembly because of the complication of name mangling.  Other languages like Java, Rust, or the interpreted languages would be painful to use with assembly.

Good luck and enjoy the trip.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628329
• Total Posts
2982104
• ### Similar Content

• I am currently attempting to make a navigation mesh for our 2D top down game, which is a multiplayer game using Node.js as the server communication. At the moment, I have implemented A* over an obstacle hardnessmap, which is awfully slow and laggy at times when we test our game on Heroku. I have been trying to find an algorithm to automatically generate the navmesh after map creation, instead of me having to do this manually. I am currently attempting to use Delaunay's Triangulation Divide and Conquer algorithm, but I am running into some issues. I have already asked a question on StackOverflow and am not getting many suggestions and help from it, so I figured I would come here. Is there another algorithm that might be better to use for the navmesh generation in comparison to Deluanay's Triangulation? My current implementation seems extremely buggy during the merge step and I cannot find the error. I have checked over the code countless times, comparing it to the description of the algorithm from http://www.geom.uiuc.edu/~samuelp/del_project.html.
My current code is this:
class MapNode { constructor(x, y) { this.position = new Vector(x, y); this.neighbors = []; } distance(n) { return this.position.distance(n.position); } inNeighbor(n) { for (let i = 0; i < this.neighbors.length; i++) { if (this.neighbors[i] === n) return true; } return false; } addNeighbor(n) { this.neighbors = this.neighbors.filter((node) => node != n); this.neighbors.push(n); } addNeighbors(arr) { let self = this; arr.forEach((n) => self.neighbors.push(n)); } removeNeighbor(n) { this.neighbors = this.neighbors.filter((neighbor) => neighbor != n); } } class Triangle { constructor(p1, p2, p3) { this.p1 = p1; this.p2 = p2; this.p3 = p3; this.neighbors = []; } addNeighbors(n) { this.neighbors.push(n); } } function genSubMat(matrix, ignoreCol) { let r = []; for (let i = 0; i < matrix.length - 1; i++) { r.push([]); for (let j = 0; j < matrix[0].length; j++) { if (j != ignoreCol) r[i].push(matrix[i + 1][j]); } } return r; } function determinantSqMat(matrix) { if (matrix.length != matrix[0].length) return false; if (matrix.length === 2) return matrix[0][0] * matrix[1][1] - matrix[1][0] * matrix[0][1]; let det = 0; for (let i = 0; i < matrix.length; i++) { let r = genSubMat(matrix, i); let tmp = matrix[0][i] * determinantSqMat(r); if (i % 2 == 0) det += tmp; else det -= tmp; } return -det; } // if d is in the circle formed by points a, b, and c, return > 0 // d is on circle, return 0 // d is outside of circle, return < 0 function inCircle(a, b, c, d) { let arr = [a, b, c, d]; let mat = [ [], [], [], [] ]; for (let i = 0; i < arr.length; i++) { mat[i][0] = 1; mat[i][1] = arr[i].position.x; mat[i][2] = arr[i].position.y; mat[i][3] = arr[i].position.x * arr[i].position.x + arr[i].position.y * arr[i].position.y; } return determinantSqMat(mat); } function walkable(from, to, hardnessMap) { let diff = new Vector(to.x - from.x, to.y - from.y); if (Math.abs(diff.x) > Math.abs(diff.y)) diff.scale(Math.abs(1 / diff.x)); else diff.scale(Math.abs(1 / diff.y)); let current = new Vector(from.x + diff.x, from.y + diff.y); while (Math.round(current.x) != to.x || Math.round(current.y) != to.y) { if (hardnessMap[Math.floor(current.y)][Math.floor(current.x)] === 1) return false; current.x += diff.x; current.y += diff.y; } return true; } function getLowest(nodes) { let lowest = nodes[0]; for (let i = 1; i < nodes.length; i++) { if (nodes[i].position.y < lowest.position.y) lowest = nodes[i]; } return lowest; } // returns the angle between 2 vectors, if cw is true, then return clockwise angle between, // else return the ccw angle between. b is the "hinge" point function angleBetween(a, b, c, cw) { let ba = new Vector(a.position.x - b.position.x, a.position.y - b.position.y); let bc = new Vector(c.position.x - b.position.x, c.position.y - b.position.y); let v0 = new Vector(0, 1); let angleBA = v0.angleBetween(ba) * 180 / Math.PI; if (angleBA < 0) angleBA += 360; let angleBC = v0.angleBetween(bc) * 180 / Math.PI; if (angleBC < 0) angleBC += 360; let smallest = Math.min(angleBA, angleBC); let largest = Math.max(angleBA, angleBC); let angle = largest - smallest; return (cw) ? angle : 360 - angle; } function sortSmallestAngle(a, b, list, cw) { list.sort((m, n) => { let vab = new Vector(a.position.x - b.position.x, a.position.y - b.position.y); let vmb = new Vector(m.position.x - b.position.x, m.position.y - b.position.y); let vnb = new Vector(n.position.x - b.position.x, n.position.y - b.position.y); if (cw) return vab.angleBetween(vmb, cw) - vab.angleBetween(vnb, cw); else return vab.angleBetween(vnb, cw) - vab.angleBetween(vmb, cw); }); } // a is in list, b is in the other list function getPotential(a, b, list, cw) { sortSmallestAngle(b, a, list, cw); for (let i = 0; i < list.length - 1; i++) { let angle = angleBetween(b, a, list[i], cw); if (angle > 180) return false; else if (inCircle(a, b, list[i], list[i + 1]) <= 0) return list[i]; else { a.removeNeighbor(list[i]); list[i].removeNeighbor(a); } } let potential = list[list.length - 1]; if (potential) { let angle = angleBetween(a, b, potential, cw); if (angle > 180) return false; return potential; } return false; } function merge(leftNodes, rightNodes, leftBase, rightBase, hardnessMap) { leftBase.addNeighbor(rightBase); rightBase.addNeighbor(leftBase); let newLeft = leftNodes.filter((n) => n != leftBase); let newRight = rightNodes.filter((n) => n != rightBase); let potentialLeft = getPotential(leftBase, rightBase, newLeft, false); let potentialRight = getPotential(rightBase, leftBase, newRight, true); if (!potentialLeft && !potentialRight) return; else if (potentialLeft && !potentialRight) merge(newLeft, newRight, potentialLeft, rightBase, hardnessMap); else if (potentialRight && !potentialLeft) merge(newLeft, newRight, leftBase, potentialRight, hardnessMap); else { if (inCircle(leftBase, rightBase, potentialLeft, potentialRight) <= 0) merge(newLeft, newRight, potentialLeft, rightBase, hardnessMap); if (inCircle(leftBase, rightBase, potentialRight, potentialLeft) <= 0) merge(newLeft, newRight, leftBase, potentialRight, hardnessMap); } } // divide and conquer algorithm function delaunay(nodes, hardnessMap) { if (nodes.length <= 3) { for (let i = 0; i < nodes.length; i++) for (let j = 0; j < nodes.length; j++) if (i != j) nodes[i].addNeighbor(nodes[j]); return nodes; } else { nodes.sort((a, b) => { let tmp = a.position.x - b.position.x; if (tmp === 0) return b.position.y - a.position.y; return tmp; }); let l = nodes.length; let leftNodes; let rightNodes; if (l === 4) { leftNodes = delaunay(nodes.slice(0, 3), hardnessMap); rightNodes = delaunay(nodes.slice(3, 4), hardnessMap); } else { leftNodes = delaunay(nodes.slice(0, Math.floor(nodes.length / 2)), hardnessMap); rightNodes = delaunay(nodes.slice(Math.floor(nodes.length / 2), nodes.length), hardnessMap); } let leftBase = getLowest(leftNodes); let rightBase = getLowest(rightNodes); merge(leftNodes, rightNodes, leftBase, rightBase, hardnessMap); console.log("=============================MergeComplete================================"); return nodes; } }
• By Hilster
Hello 2D Artists,
I've started making a 2D Puzzle Adventure game for mobile and I'm looking for someone who would want in on creating assets for the game. The core of the programming is pretty much complete, you can walk within the grid laid out and push boxes, when there is an object on top of a pressure pad it will activate the linked objects or if there is one object with multiple linked pressure pads it requires you to activate all points for the object to become active.

The level iteration for the game is quick and simple, a Photoshop file that is made of individual pixels that represents objects is put into the game and it creates the level out of those pixels with the assigned objects.
The objects that need sprites created so far is the character, box, pressure pad, door, trap door, the walls, the stairs and the tiled background.
I intend to add more objects so the amount I'd like to add will be extended.
My motivations for posting here is to have something that looks nice to be able to display on my portfolio, so if you're looking for a working game that you can place your art into and improve the look of your portfolio then we're in business.
• By suliman
Hi!
My game is coming along nicely and I would love some feedback.
You play as one (or two in co-op) survivor that must travel the land and survive the infected hordes, looners and bandits. You stop in locations but are always pressed as the hordes will start pouring in. Collect resources (food, fuel, medical supplies and ammo) and weapons and head for the goal!
Tips
Always quickly switch to a melee weapon if running out of ammo Loot everything if you have time to loot, including cartrunks Choose locations that have the loot you need (such as gas station for fuel) Try to avoid running out of fuel or having your car break down. Walking is dangerous! Download (50 MB, works with windows only, you DON'T need dropbox to download):

• I am a beginner in the Game Dev business, however I plan to build a futuristic MMO with some interesting mechanics.
However, I have some doubts about shooting mechanics that I chose for this game and would like to know your opinion on this. The mechanic goes as follows:
- Each gun would have it's damage-per-shot value
- Each gun would have it's shots-per-second value
- Each gun would have it's accuracy rating
Now the question is: how to calculate the output damage? I have three available options:
1) Calculate the chance of each shot hitting the target (per-shot accuracy)
2) Multiply the damage output of a weapon by it's accuracy rating (weapon with 50% accuracy deals 50% of it's base damage)
3) Don't use accuracy at all and just adjust the weapon damage output
Which of these three mechanics would you like to see in a game? Mind, this will be an MMO game, so it will have lock-on targets, AoE effects and all that jazz.
• By Vityou
I am thinking of making a game like screeps, where you use actual programming to control the game, but I'm not sure about the best way to do this.  I'm probably going to use lua or javascript for the language, and I would like to represent units in the game as objects that the user can command and modify, with restraints based on the actual game, like how screeps does it.  However, I am not sure how to get started.  I think I have to use C or C++ and then embed the languages, but I'm not sure where to go from there, for example, having objects in lua actually correspond to units in the game.  Are there any resources that explain how to do this?  Also, I'm not concerned about the graphics of the game whatsoever, it might as well just be a text adventure as far as I'm concerned, I just want the user to be able to control the game through scripting.

• 22
• 9
• 9
• 13
• 11