stardance has been extended another month! the new deadline is october 31 :)

You are browsing as a guest. Sign up (or log in) to start making projects!

Pointer Fighter (C based)

  • 26 Devlogs
  • 58 Total hours

Roguelike room crawler with an RPG like battle system completely built in C !!!

Check out the github for the bin or watch the demo video !!

Ship #1 Changes requested

A roguelike room crawler completely built in C!

What is in it?

  • Randomly generated rooms with a fog of war for you to explore
  • Three different enemy types with scaling difficulty
  • Boss fights with unique item drop
  • RPG Style fighting
  • An interactive inventory that can be used during battle
  • A battle log that tracks everything that happens in battle
  • Items, pickups and a persistent highscore

What am I proud of?

The enemy pursuit and fleeing system. It was somewhat hard to implement but I think it made the game wayyyy better than before. I’m also proud of how the state machine turned out in the end. The game has strict separations between the different game states and first handles what the player/the game did during the game loop iteration and then after that is done draws it to the screen. That state machine was very prone to bugs and I had to spend a bunch of time to fix (fallthrough bug, etc. all talked about in devlogs). But I think the result that turned out at the end was great and I am very content with it

How is it built?

As said its completely built in C using ncurses as its graphics library using 12 source files (currently) with each one having a specific task only it does. The build is released using GitHub workflows and the binary can easily be downloaded and used on (almost) all glibc linux distros (the project was compiled for Ubuntu and you will have to install ncurses though)

What I learned

The game was actually my first real coding project ever apart from a few simple websites so I learned a bunch. I learned how to separate state transitions, I learned the importance of good and bad switch statements, bounds checking (really rough path) and I think most importantly: The power of code separation and making every file do its designated task. I often caught myself picking the easy and sloppy path and then fixing it properly and in retrospect helped with preventing a bunch of bugs

Known limitations / plans for the future

It’s my first project, so there are likely still issues I haven’t found. Even though I tried to find everything (a.e. using Valgrind told me there are no memory blocks definitely lost) there are still potentially memory safety issues or potential segfaults. It’s possible some edge cases might have slipped through. I’ve tested the project thoroughly and haven’t found any crashes since the last few debugging sessions but I cannot safely say it’s perfect.

I think if I will find the time I will maybe add some new features like new special item related enemies or player status effects though I cannot safely say if i can

Closing word

I think building a game for my first real project was the right decision for me because I really had a bunch of fun building this project. I currently have some ideas for unrelated new projects (one is up on my profile check it out (; ) and I think this project was a really good pathway into coding for me. Check the GitHub and the demo video out and I hope you like the project

  • 26 devlogs
  • 58h
Try project → See source code →
Open comments for this post

3h 6m 33s logged

LOG 26: FINAL DEVLOG MAINLY BUG FIXES AND SOME MINOR CHANGES

CHANGES

Enemies previously scaled to strongly and beat you too hard after the boss fight. Also because it was hard to scale the opponents down i decided to make the hp of everyone higher (everything got stronger in theory, player has 100 starting hp, does 20 damage etc.)

LATE ADDITIONS

LICENSE

I licensed the project under the MIT licesne because it seemed fitting

BUILD FILE

I added a build file for the repo so i could upload a release binary (ncurses is required tho)

BUG FIXES

HIGHSCORE BUG

There was a bug with the highscore not being displayed when there was no highscore.txt file. I needed to change the handling of the fact that the open function returned NULL, because NULL either meant, no file was there or no file could be found which resulted in no file being created because the function exited when the open function returned NULL, the fix was pretty simple overall tho (just adding an extra if conditional to check)

FULL INVENTORY BUG

Previously when having a full inventory, you couldnt pick up new items, issue was when using items that state didnt reset so one full inventory meant no items anymore :( . The fix was just to reset the state after using items

BOSS ITEM INVENTORY BUG

I forgot to make the boss item return the correct state which resulted in the item sometimes not being put in the inventory. The fix was just to add return ENTER_LEGAL to the boss items if statement

SET ROOM ISSUE

Because of random rooms sometimes boss room dimensions where bigger than current room which resulted in bugs (see previous devlogs). My previous fix worked in theory but had more affinity for potential bugs so i changed the set room function from two static values to two values that get passed into the function

0
0
18
Open comments for this post

5h 0m 51s logged

LOG 25: FLEEING ENEMIES (CONTAINS MANY CHANGES), BOSS ITEM REFACTOR

FLEEING ENEMIES

Enemies (except the boss) now have the ability to run away if the enemy would get killed by the next attack. The chance for this to happen is 10% and when they run away, they gain 1 HP per step they take and return to chasing the enemy if their hp is back at half of their max HP.

FLEEING REWORK

Before adding this feature, fleeing was the same practically as winning (the return type of the fight was STATE_VICTORY), i changed that to the proper STATE _FLED. Also before when fleeing, if you fled and another enemy of another type collided with you, he had normal stats but the enemy before that also got his stats reset. The same went for enemies of the same type. When fleeing from enemy A from type A and then colliding with enemy B from type A, he would have the stats of enemy A. The fix for both was to make a 2D Array of all enemies and their types, so each individual enemy stores its stats, not the battle function.

PLAYER POSITION STRUCT

Previously the player had ~ 8 different position variables, which was pretty clunky if i wanted to transport the player position to another function. Because of that i put all player positions into a singular struct, so i could pass all the player positions at once if i needed to.

ENEMY PURSUIT FUNCTION REWORK

Because enemies have to run away instead of chasing i had to rework the pursuit function a bit so it could also work in a reverse way. I had to make the function branch between the two states which took a bit more work than originally anticipated because i had a bunch of wrong ideas for how the function should work. Overall the function implementation was essentially to just use the inverse vector of the normal vector for the direction function

BOSS ITEM FUNCTION/ITEM FUNCTION REFACTOR

Because previously the boss item detection function and the item detection were separate the code didnt feel clean at all (felt like a lazy implementation for me), so i made the item function work with the boss item which makes the item function overall more open for new item types (if i will add any more)

0
0
13
Open comments for this post

4h 13m 51s logged

LOG 24: BOSS ITEM DROP, CONTROLS SCREEN, NEW IN-GAME BANNER, ITEM TO INVENTORY REFACTOR, BUG FIXES

FEATURES

BOSS ITEM DROP

I added an item that only the boss drops, when killed. Its ability is to make the enemy unable to attack for one turn. You will always get it when defeating the boss and has the ‘?’ glyph compare to regular items (‘+’). Its also the only item that can always be picked up (with normal items, if your inventory is full you cannot pick them up, with the boss item your first slot gets overwritten).

CONTROLS SCREEN

I added a basic controls screen so people that try the game out (now or when it ships), know what to do when playing. Currently most things are really straightforward but i added it just in case. The most important aspect will probably how to end the game because thats the most unintuitive one (even though i hope anyone testing the game doesnt want to quit it)

ITEM TO INVENTORY REFACTOR

I thought that the previous state of my item to inventory were pretty lazy so i changed the logic up a bit. Previously when picking up items the items would go into the spot after the last item that was picked up and when the inventory ran full the first item was swappped with the newly picked up item. I didnt like that looking back and because of that the logic now scans through the inventory until it finds an empty spot and puts the item in that empty slot. If the inventory is full no item can be picked up (except the boss item) and the player gets a message on their screen. They can then leave the item screen using ESC and the item is not removed and can be picked up later if you somehow make space in your inventory

NEW IN-GAME BANNER

Also pretty straightforward, i added a banner so the menu looks a little bit prettier :)

BUG FIXES

BOSS ROOM BUG

Because of map and gamestates and me forgetting to implement a feature in the door collision checks, there was a bug when defeating the boss (the map stayed as it was, but had the usual visible map ‘#’ everywhere you hadnt already explored (you cant really explore much so there where many ‘#’ ’s around the map which was really ugly. The fix was to move a mapstate change from the function that is responsible for handling victory to the function handling doors

BOSS BUG

There was a bug after defeating the boss which resulted from the previous bug and its fix. Because i forgot an additional check in my door function when defeating the boss the boss would spawn again and overwrite your boss item. The boss also chased you (which normally doesnt happen) and you couldnt leave the room. The fix was just to add another condition to the if statement in the door function responsible for the boss room

ENEMY REMOVAL BUG

For some reason (i dont know how i made the bug happen), when defeating enemies the visible map lagged behind the normal map which resulted in defeated enemies appearing to still exist on the map for one iteration of the loop (pressing any button made them vanish). The fix was to add a call to the visible_map_init function after defeating enemies

0
0
5
Open comments for this post

2h 16m logged

LOG 23: BATTLE LOG FOR ITEMS, BUG FIXES, BUG FIXES, BUG FIXES, BUG FIXES

FEATURE

BATTLE LOG FOR ITEMS

The previous battle log only logged attacks and the damage dealt, now the log also tracks if items are used or items deal damage

BUG FIXES

SEGFAULT

There was a segfault when trying to render the bottom of deeper rooms because the render guard had a major fault (only disjunctions no conjunctions). Because of that the game tried to reach spaces of the visible_map array out of reach of the array which resulted in a segfault when trying to go into spaces out of reach of the array. The fix was changing the guard from if ((player_y + y) < MAX_HEIGHT || (player_x + x) < MAX_WIDTH || (player_y + y ) >= 0 || (player_x + x >= 0)) to if ((player_y + y) < MAX_HEIGHT && (player_x + x) < MAX_WIDTH && (player_y + y ) >= 0 && (player_x + x >= 0)) which fixed the issue

BATTLE LOG NULL TERMINATOR FIX

There was a bug with the battle log, where ^ were printed (NUL ascii in ncurses) because the battle log printed out every part of the string character by character (including the \0 terminator). The fix was to just not print out the \0 terminator to the screen

BATTLE SELECTION BUG

There was a bug with conflicting selection variables (multiple variables where named selection which resulted in wrong selections being displayed). The fix was to give every function their own selection variable which fixed the issue

VISIBLE MAP GLITCH

Because the visible map only updated itself in the perimeter you are standing in if you moved fast enough some characters lagged behind and made it look like there were way more enemies than there actually were. The fix was to update not only the perimeter on every movement but also update everything that had already been explored

1
0
131
Open comments for this post

4h 2m 42s logged

LOG 22: POISON ITEM, BATTLE LOG, MAIN LOOP AND ITEM SELECTION REWORK

POISON ITEM

A new item that does 3 tick damage every enemy turn, for 2 turns. Its the rarest item in the game as of right now and was somewhat complex to add (because of the tick damage and tracking how many turns have passed)

BATTLE LOG

A log that tracks the last two actions that have happened in the game. It currently only tracks damage and attacks but will track item usage and more detailed information in the future. It was a real headache to implement because i had contradictory logic between the log and my main loop and i had to reimplement it multiple times. But went well overall :)

REWORKS

MAIN LOOP REWORK

I reworked the main loop a bit because even though it worked well in theory it was not really optimized and it was prone to bugs in the future which is why i felt like redoing it a bit. Now instead of every function handling their own init, every changing gamestate instantly also inits the state it was changed to. Because of this there are less possible bugs and its overall easier to do for future gamestates

ITEM PICKUP REWORK

I noticed that the logic for my items wasn’t really perfect and seemed unoptimized which is why i felt like changing it a bit. Because when picking up items there are only two possible things to do (which both result in the same exit scenario) i swapped my if/else if logic for a switch statement which made the code shorter, and more optimal

0
0
25
Open comments for this post

3h 9m 46s logged

LOG 21: FOG OF WAR, HOMING ENEMIES, BATTLE LOGIC OVERALL AND BUG FIXES

FEATURES

HOMING ENEMIES

The enemies now home on you with every step you take, meaning you actually have to think about where you will go or the enemies will catch up to you. This was implemented by adding a sign function that decide whether the enemy should move +1 or -1 and then moving the enemy by that value. There were some bugs regarding enemies in previous rooms which got fixed by resetting the whole array during map init

FOG OF WAR

I added a fog of war feature that obstructs everything in the map you
haven’t explored yet. This also pairs very well with the homing enemies
feature. You have to go around the map to look out for items and enemies
which now also walk towards you, so every step matters now

BATTLE LOGIC OVERHAUL

After revisiting most of my code for commenting i realized how terrible most of my battle logic was so i made it a bit more efficient and most importantly more readable. Overall i realized how great switch statements are in the last few logs

BUG FIXES

DOOR BUG

There was a bug with the map that was somewhat useful when testing but still was a bug. The issue was that if you tried to step into the door the game let you step onto that char. The issue was that i forgot to make the game think that the door (when closed) should behave exactly like a wall. So the fix was just to add the door char to the wall collision check function

0
0
20
Open comments for this post

1h 27m 34s logged

LOG 20: DYNAMIC STATS, BUG FIXES, SMALL UPDATE TO DEBUG MODE AND MORE COMMENTS

DYNAMIC STATS

The stats of all enemies are now connected to the boss counter which is the number of boss fights that have been fought during the current run so there is real progression and you dont just get stupidly overpowered

DEBUG MODE

I basically just added the boss to the debug mode nothing much

BUG FIXES

There was a glitch with the boss room being cut off because the randomly generated room was smaller than the boss room. I had to push a few things around and put every type of map generation (standard, debug, boss) into a switch statement to make it work properly

COMMENTS

I pretty much forgot most of the comments in the game so i started adding way more comments where they should be so the code is hopefully more intuitive to follow

NOTE

I think the next update will be pretty big so watch out when it finally drops!!!

0
0
19
Open comments for this post

3h 5m 44s logged

LOG 19: NEW ENEMY TYPE: BOSS FIGHTS, BETTER DOOR LOGIC, NEW SPRITES

NEW ENEMY TYPE

Because i thought that the normal enemies would be too easy to beat down the run i added the main boss (the pointer which stole the star sprite from the address enemy) and he will always be fought every 5-10 rooms (im not sure on the number) . Currently his stats are static but i plan on making them dynamic based on the number of rooms you went through.

BOSS ROOM/BETTER DOOR LOGIC

The old door logic practically only worked with a normal room and needed the regular enemies to all be defeated. I tweaked it a little so it works with boss triggers/defeating the boss

NEW SPRITE(s)

As i said the boss got the star sprite because he is the true pointer so i gave the address an ampersand sprite (which is way more fitting btw). But i am not completely satisfied with the current ampersand sprite (i will maybe change it sometime)

NOTE

This time there werent really any bugs except during building the boss logic but they got fixed along the way. This time it actually went rather smoothly :)

Also ignore the absurd stats of the player

0
0
18
Open comments for this post

1h 43m 42s logged

LOG 18: NEW ITEM AND BUG FIXES BUG FIXES BUG FIXES

NEW ITEM

DAMAGE POTION

I added a new item that can be used in the inventory during battle which deals (currently) 4 damage to the opponent. Its the rarest item in the game right now (i think 1 in 11). Because of the new item i had to make a bunch of code more modular in the inventory logic (a trend in my code). But overall this was the reimplementation that went the smoothest

BUG FIXES

BATTLE INPUT BUG

There was a bug in the battle screen that made the overall input very clunky and previously was only fixed by letting another bug happen but i fixed it by changing something in the switch statements of the battle logic

INVENTORY ACCESS AND SELECTION BUG

A bug that mainly happened because of the previous bug: When trying to access the inventory in battle the game automatically selected the first item and returned to battle and only after the second time accessing the inventory you could really use your items as you wished

INVENTORY SELECTION BUG

In the inventory itself a bug was caused by a lazy implementation which caused the display (not the real logic behind the inventory actually) to become very glitched out and very confusing. I just fixed this by fixing my old and bad implementation for a better more modular one (an overall trend in my code to be not that modular lol)

0
0
61
Open comments for this post

2h 2m 48s logged

LOG 17: DEBUG MODE FOR FASTER TESTING

DEBUG MODE

I added a debug mode because i found that most of my testing time was wasted finding items or players in rooms (which was very annoying most of the time), so i added a debug room so that goes way faster. Though it is very useful it was somewhat hard to implement but it made the code modular the same way the enemy logic is modular now which is an improvement in two ways

0
0
37
Open comments for this post

3h 39m 31s logged

LOG 16: NEW NPC, BETTER CODE MODULARITY, FIXED SOME BUGS

NEW FEATURES

New “Modulo” / % enemy (based on the modulo operator in c)! It has weaker stats but is way stronger in terms of attack power

BETTER CODE MODULARITY

Because at the start of the game my main idea was to only implement one enemy type (which was pretty dumb tbh), i had to rework most of the map and battle logic so it was more generic and welcoming to multiple entities (and will help me add more enemies in the future).

BUG FIXES

VISUAL GLITCH

There was a bug for the most of the time in the game (an issue with unititialized variables being printed, which resulted in a visual glitch), which was actually a pretty easy fix (i had to change the switch statements that handle state input and drawing output a bit so that changing the gamestate doesn’t skip to drawing instantly)

MEMORY LEAK

Because of a dumb implementation of a function that was supposed to carry over the value of a variable in file A to file B which used pointers allocated with malloc i had a memory issue because in a common case i forgot to implement free which resulted in lost memory (the fix was actually just switching over to passing by value because it was just a single char being transported from file A to file B and passing by reference wasn’t necessary)

0
0
6
Open comments for this post

2h 55m 32s logged

LOG 15: MAINLY BUG FIXES AND SOME MINOR NEW FEATURES

NEW FEATURES

Better life/strength display

A feature that was originally used for debugging has turned out as a good feature for the game overall. It always displays your and the enemies HP, and attack power (even though the attack damage is partly random which i have to note somewhere so there will be no confusion)

An item descriptor that tells you what the item you are looking at currently does

There is only one item to be used in the inventory right now so you can only see what the heal item does but more will be added in the future.

BUG FIXES

Memory unsafety fixed

There was an issue with unsafe memory access if the items in the inventory where bigger than 10. My fix is that if you have more than 10 items and you pick up a new one, the new item will replace the first item, the next one the second one etc. It also resolved a smaller issue with blank inventory space that ate up inventory space even though it was empty.

Items not working fixed

The functions responsible for changing your hp, healing you or making you stronger hat an issue with their pointer assignment (they were pointing to the wrong variable) which i fixed for all function which work great now.

Bug with doors acting the same as item pickups

Because of something what seemed to be a typo (a function returned 1 instead of 0), if you tried to go through a door and you haven’t beaten every enemy, instead of nothing happening you got a free item (which turned out to be a great testing feature for items, because i can get many items fast and easily). The fix was really easy (just swap the 1 for a 0)

Health bar not drawing properly

Because of a badly implemented function i added in the past which turned out to be completely redundant (got cut out) the current hp weren’t imported properly to the function that handles printing out the health bar which i fixed by using another variable responsible for storing the current hp of the player

Misc fixes

After having to audit most of the code again i noticed that there were some issues with the code (partly because it was fine as it was when it was written, part was just sloppy implementation) which i also fixed even though most of it was minor.

CURRENT PLANS FOR THE FUTURE

More items that can be used in battle

MORE ENEMIES!!!

Im planning to add more and stronger enemies in the future even though that will probably will be one of the biggest newfeatures as it requires rewriting most of the battle and map logic

Enemies getting stronger if you get farther for better progression

Overall some more optimization and bug fixes (there is always something to be fixed ;) )

0
0
21
Open comments for this post

4h 5m 58s logged

LOG 14: Made the items more interactive and functional (items can now be picked up or ignored and will vanish if either is done) and i built a somewhat functional inventory accessible only in battle as of right now. I also had to clean up a bunch of code and had to re-implement some stuff as i implemented some things rather poorly before. There are still some things to be made a bit cleaner which will come in the next few devlogs but i felt like posting one for the current state of the game.

0
0
17
Open comments for this post

2h 33m 24s logged

LOG 13: Added items that are supposed to give you power-ups in the future. currently they dont really do anything except open a screen with a sprite for the corresponding item (SPRITES ARE AI GENERATED). The plan for the future is to deicde between regular and activatable items (the first give permanent buffs, the second can be activated) and to be able to choose the items while in battle. For now they can spawn on the map (anywhere except 1|1 and spots where enemies are) and open a random sprite of the 3 that are available right now!

0
0
9
Open comments for this post

46m 9s logged

LOG 12: This came quicker than i thought it would lol. I implemented the two things i spoke about in the last log. I added a highscore system so you can always see how far you came with beating the evil pointers and i also “locked” the rooms until youve beaten every enemy in the room. I plan on adding power ups and some other features (read the README in the repo). STAY UPDATED!!!

0
0
12
Open comments for this post

1h 18m 47s logged

LOG 11: Im Back. After a short break i started to implement that enemies really “die” if you beat them! Now there is some kind of progress added into the game as you can actually beat the enemies!!! The next features will probably be a real highscore and restricitions in leaving the room until youve beaten every enemy. Till then stay updated!!!!

0
0
7
Open comments for this post

1h 27m 38s logged

LOG 10: Added multiple enemies (dynamic based on room size) and stats get reset after battle. Battle still issnt finished yet as i think of two more things to add for every one thing i implement. Stay updated !!!

0
0
17
Open comments for this post

1h 23m 36s logged

LOG 9: Battle now works better and you can see enemy h now. Code is way less tangled (though some stuff still needs to be improved and the battle still isnt fully polished). There are some bugs regarding memory right now (will be fixed ASAP). But as of now you can finally really battle the evil evil evil pointer!

0
0
13
Open comments for this post

2h 0m logged

added the first implementation of working battle (taking and dealing damage, working health bar)! The main issues right now are that the code is a bit tangled and that the logic isnt polished at all. But after 2 hours of work i felt like i had to post a log so this is the current state (you can attack or try to run) (winning and running have the same effect as of now)

0
0
56
Open comments for this post

1h 23m 33s logged

Kinda added a battle screen (not reactive yet but will happen soon) and made the ASCII designs for my characters with AI (i cannot make any good ASCII art sadly :( … yet). In the top left is what is supposed to resemble a health bar which also still needs to be implemented. Also made the code a bit cleaner added a few header guards and most importantly i added structs for the entities so their stats could be recorded. Thats it :)

0
0
4
Open comments for this post

1h 15m 47s logged

Added a (somewhat) functional menu screen to view highscore and start the game (highscore function will be implemented soon!!!!. Also built the first prototype of the battle screen though it is no where near finished. I will probably make the menu screen a bit prettier in the future but the current design has to suffice for now. :)

0
0
9
Open comments for this post

1h 35m logged

Implemented doors (currently a minus sign probably going to change that). If you collide with said door/minus sign you will enter a new, different sized room. I did that by choosing a random wall, a random spot on that wall which is the spot where the door will be and if you make contact with the door a new room will be initialized.

0
0
1

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…