In my first post before Global Game Jam 2019 I mentioned I was working on porting Donsol to the N64, and that I’d be spending the weekend getting the game code running in C.
Since I’ll be at a Jam site I wont have access to my N64 or computer with Windows XP on it, I’ll just be doing the game code in a console window.
Well, I did just that. https://github.com/xoorath/c-donsol
The main design goal was pretty obvious: don’t shoot yourself in the foot by making the game overly memory intensive or overly specific to the mac terminal and whatever library I used to do the UI.
I ended up using ncurses for the UI and jammed all that code inside main.c. The layout is driven mostly with relative positions defined from lines 48 to 75 in a big static structure.
The card layout in donsol-card.h is pretty neat. Every card in the game is represented by 1 byte that tells you what the card should do mechanically, what its value is, and what the gameplay state is.
Bits 0, 1, 2, 3: store the card value (a, 2, 3, 4, 5, 6, 7, 8, 9, 10, j, q, k, J1, J2)
Bits 4 & 5: store the card suit (hearts, diamonds, spades, clubs)
Bit 6: indicates if the card is face up (not beaten by the player) or face down (beaten)
Bit 7: is unused / wasted
The deck of cards itself is stored static in donsol-game.c in a big hard coded array. Cards are never removed from the array - basically what I do is flip all the cards face up and shuffle the deck before playing. Every game uses the same 44 byte deck of cards.
The way I get meaningful game values out of the cards with so little memory, is by keeping the 4 face up cards in a slightly larger structure and populating that every time the cards are about to be shown to the player, it’s done progromatically from donsol_game_set_slot.
The N64 Code
So now the N64 version of the game just needs to create a global DonsolGame_t instance, and call the 4 functions defined in donsol-game.h:
// init the game object void donsol_game_start(DonsolGame_t* game); void donsol_game_pick_run(DonsolGame_t* game); void donsol_game_pick_card(DonsolGame_t* game, u8 index); // index can be: [1,2,3,4] // perform cleanup void donsol_game_quit(DonsolGame_t* game);