Angus Cheng
  • Posts

Posts

December 12, 2023

Building a Web Game in C

Christmas is coming up. When I used to work at a bank the entire month of December and a bit of January we were placed under “Change Freeze”. We weren’t allowed to deploy updates to our applications during this period. The thinking was:

  1. A lot of people are away over Christmas
  2. Application changes can lead to crashes
  3. People who know how to fix those crashes might be away

To prevent this they just stopped us from deploying updates. That meant December was a pretty relaxing time to be working at a bank, and it was also a good time to do big refactors, clean up TODOs or mess around with some new technology. So how about learning to code a game in C and build it out to WebAssmebly?

December 7, 2023

Simple Feature Gross Code

A few days ago I talked about supporting text events with multiple colours and multiple text speeds. I spent about eight hours writing the code. It took me a lot longer than I expected so I thought I’d share the details here.

Example Data

set_title(data, PHOENIX);
set_text_color(data, SKYBLUE);
add_show_text_V2(data, "They're saying the jay walker was... ");
set_text_color(data, RED);
add_show_text_V2(data, "you.");
set_text_color(data, SKYBLUE);

This is how I was expecting to set up the events. There are four distinct events there, which normally would require me to make four different event lists and four different event counts. Instead I got lazy and merged them into one called SetTextConfig.

December 4, 2023

Busty Barrister - Week 4

A few weeks ago I talked about implementing a generic list of objects that conform to an interface in C. The code is not the nicest, but it’s working well enough and I think it’ll hold up until this game is done. This is what the EventData structure looks like at the moment.

typedef struct EventData {
    int eventIndex;
    int eventCount;
    enum EventType eventTypes[1000];
    int eventIndices[1000];
    
    // Event lists
    int showTextCount;
    ShowText showTexts[1000];
    int playMusicCount;
    PlayMusic playMusics[100];     
    int setCharacterCount;
    SetCharacter setCharacters[100];  
    int setAnimationCount;
    SetAnimation setAnimations[100];
    int setBackgroundCount;
    SetBackground setBackgrounds[100];
    int startSoundCount;
    StartSound startSounds[100];
    int greyFlashCount;
    GreyFlash greyFlashes[100];
    int queueAnimationCount;
    QueueAnimation queueAnimations[100];
    int screenShakeCount;
    ScreenShake screenShakes[100];
    int fadeEventCount;
    FadeEvent fadeEvents[100];
    int configMusicCount;
    ConfigMusic configMusics[100];
    int delayCount;
    Delay delays[100];
    int fadeMusicCount;
    FadeMusicEvent fadeMusics[100];
    int setBlackRectCount;
    SetBlackRect setBlackRects[100];
    int setChyronCount;
    SetChyron setChyrons[1000];
} EventData;

It’s gettting a bit gross, every time I add a new EventType I add two properties for it. The only problem I’ve seen with this so far is in the Event creation functions. It’s very easy to accidentally write to the wrong array or count variable. Which will cause weird behaviour.

November 28, 2023

Kuala Lumpur Trip

Last Monday I went hiking and hung out with my friend Toby. He said he was going to Kuala Lumpur for a few days and asked me to join. I had a little think about it and decided yes I would go. The next day I booked a flight to be in KL Wednesday morning to Saturday night.

Wednesday

The flight was pretty good, I worked on Busty Barrister until I ran out of batteries then I read Number Go Up on my Kindle. I worked in crypto for a year, and somehow I’ve kept up to date with it without trying, because of this I think I knew 90% of what goes on in Number Go Up. Still it was a good read.

November 21, 2023

List<IEvent> using C

Yesterday I was in the mood to go for a hike. The weather is a lot cooler now so it’s actually nice wandering around in the country parks of Hong Kong. I was originally going to go up to Sunset Peak, but then I felt a bit lazy, so I did a much easier flat hike that goes around sunset peak.

Midway through the walk, I think this is Cheung Sha Beach.

November 18, 2023

Coding a Browser Game in C

For the last few months I have been working on Bank Statement Converter and a Raylib game called “Customer Support Sim”. I coded “Customer Support Sim” using Raylib and Kotlin. Raylib is a really awesome game programming library and Kotlin is my favourite language. However sadly I’ve hit a bit of a wall with the game, I’m not really sure how to make it fun. I thought about releasing it ‘as is’, but I think it’s better just to abandon it.

September 9, 2023

Customer Support Sim Dev Log #5

Saturday

  • Added the ability for NPCs to send image messages
  • Linked up level 2 and level 3
  • Linked up level 3 and level 4
  • Figured out how to build Jaylib https://github.com/electronstudio/jaylib
  • Upgraded Jaylib from 4.2.0 to 4.5.0

Sunday

It was a nice day so I went for a hike with Candice from Pak Kung Au to Mui Wo.

Later that day I did a bunch of coding.

  • Wasted a ton of time trying to get JPEGs to load. Decided to give up and stick with PNGs.
  • Fixed a bug when you give a user’s password to a hacker.
  • Changed the opening dialog in level two
  • Fixed a bug where randomly generated users have the same name
  • Hiding most icons in level four.
  • Created a generator for fan girl conversations
  • Created conversations for level 3

Monday

  • Added sound effects when messages come in
  • Reduced delays in sales script
  • Converted JPGs to PNGs

Tuesday

  • Took the day off and did an easy hike from Quarry Bay to Mount Parker. It was a very hot day.

Wednesday

  • User can only type in input boxes when they have an active prompt
  • Created a prompt that lets you choose responses, instead of typing them

Thursday

  • Used the multiple choice prompt in the fangirl conversations

September 2, 2023

Customer Support Sim Dev Log #4

Monday

  • Added sound effects for when messages come in, player actions are correct and when player actions are incorrect.
  • Added functionality to randomly create users. The names all come from obscure F1 drivers. I found a list of all F1 drivers, sorted them by the number of races they attended from least to most.
  • Conversation closes when the user gives out an incorrect password.
  • Lowered the music volume. This should be something the user can set in the settings page. Will make a settings page sometime in the future… or maybe not.
  • Created conversation type where user asks for a password, but they don’t have an account
  • Create a conversation type where a malicious user asks for a real user’s password.
  • Added functionality to randomly create password request conversations. Before this all conversations were static.
  • Added the ability to close ValuedBehaviour windows.

Tuesday

  • Went hiking in Quarry Bay, didn’t do any work.

Wednesday

  • Close button animates when you hover/unhover over it.
  • Went hiking in Lantau

Thursday

  • Added my name to the title screen because I am an ego maniac. Also because of this talk:

August 25, 2023

Customer Support Sim Dev Log #3

  • // TODO: You can just use Delay
  • // TODO: You can just use PlaySong
  • // TODO: Does this need to be a MutableList?
  • // TODO: Try wiping out these lateinit var declarations. Nicer if they can be vals
  • // TODO: Consider adding a OnEnter and OnExit methods
  • Delays on successEvents/failEvents don’t seem to be working
  • Level 2 call should change photos when different people are talking.
  • Create a SetSkypePhoto Event
  • Create LevelDataBuilder class?
  • Create a CloseSkypeWindow event
  • Class that creates ValuedBehaviourWindows every X seconds
  • Create a ValuedBehaviourWindow
  • Level 2 core values spamming
  • //TODO: Do some deduplication
  • //TODO: Dedupe this code
  • ValueBehaviourSpammer should only trigger after the SkypeCall
  • ValueBehaviourSpammer should only run on Level2.
  • Players should close chats
  • Level 2: After five chats
  • Level 2: Users ask for information
  • Do not let users drag windows off the screen
  • Sometimes users just say Hi
  • Type up notes you made into STORY.md or LEVELS.md
  • See how kickstarter is doing
  • Create a GenericConversation class
  • Replace all other conversations with GenericConversation
  • Conversation objects should hold onto IEvents not UserEvents
  • Rename V2 methods
  • Read and organise LEVELS.md
  • Read and organise PLANNING.md
  • Merge PLANNING.md into STORY.md
  • Read and cleanup backlog in TODO.md
  • Read and organise STORY.md
  • Message history can bleed over the window
  • Handle case where message is long
  • Chat input field can bleed over the window
  • One long word in WrappedText can bleed across the maxWidth
  • Break into levels, after a certain amount of events you go to the next level
  • Log slow frames
  • Model the rules for your sales script
  • GenericConversation -> Conversation
  • InformationPrompt should take a list
  • Fill out events in SalesConversationFactory
  • Code that generates X Conversations from a SalesScript
  • Should be able to play through a few sales conversations
  • “Please Greet Me” softlock.
  • Add Delays to failEvents
  • When a window pops up, give it focus?
  • Create sales-script.txt icon
  • Create a SalesScriptWindow
  • SalesScript window describes how to sell to users
  • Level 1 -> Level 4
August 16, 2023

Customer Support Sim Dev Log #2

  • // TODO: You can just use Delay
  • // TODO: You can just use PlaySong
  • // TODO: Does this need to be a MutableList?
  • // TODO: Try wiping out these lateinit var declarations. Nicer if they can be vals
  • // TODO: Consider adding a OnEnter and OnExit methods
  • Delays on successEvents/failEvents don’t seem to be working
  • Level 2 call should change photos when different people are talking.
  • Create a SetSkypePhoto Event
  • Create LevelDataBuilder class?
  • Create a CloseSkypeWindow event
  • Class that creates ValuedBehaviourWindows every X seconds
  • Create a ValuedBehaviourWindow
  • Level 2 core values spamming
  • ««
  • «
  • 1
  • 2
  • 3
  • »
  • »»
© Angus Cheng 2026