• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 14:53
CEST 20:53
KST 03:53
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Voting3[ASL20] Ro4 Preview: Descent6Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
Weekly Cups (Oct 6-12): Four star herO65.0.15 Patch Balance Hotfix (2025-10-8)71Weekly Cups (Sept 29-Oct 5): MaxPax triples up3PartinG joins SteamerZone, returns to SC2 competition325.0.15 Balance Patch Notes (Live version)119
StarCraft 2
General
Ladder Impersonation (only maybe) 5.0.15 Patch Balance Hotfix (2025-10-8) The New Patch Killed Mech! TL.net Map Contest #21: Voting Weekly Cups (Oct 6-12): Four star herO
Tourneys
Master Swan Open (Global Bronze-Master 2) Tenacious Turtle Tussle WardiTV Mondays SC2's Safe House 2 - October 18 & 19 Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Custom Maps
External Content
Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers Mutation # 492 Get Out More
Brood War
General
BSL Season 21 BW caster Sayle BGH Auto Balance -> http://bghmmr.eu/ Brood War web app to calculate unit interactions Whose hotkey signature is this?
Tourneys
[ASL20] Semifinal B [ASL20] Semifinal A [Megathread] Daily Proleagues [ASL20] Ro8 Day 4
Strategy
Current Meta BW - ajfirecracker Strategy & Training Siegecraft - a new perspective TvZ Theorycraft - Improving on State of the Art
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread ZeroSpace Megathread Dawn of War IV Path of Exile
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
SPIRED by.ASL Mafia {211640} TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Men's Fashion Thread Sex and weight loss
Fan Clubs
The herO Fan Club! The Happy Fan Club!
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023 NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Inbreeding: Why Do We Do It…
Peanutsc
From Tilt to Ragequit:The Ps…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1199 users

Student Game Dev Part Four - Input and Physics

Blogs > Soan
Post a Reply
Soan
Profile Blog Joined August 2010
New Zealand194 Posts
Last Edited: 2013-11-29 22:45:35
November 29 2013 01:11 GMT
#1
Part One - It begins
Part Two - Technical Foundation
Part Three - Game Design

This Week
Hello again TeamLiquid!

Welcome back to my blog about the development of The Adventures of Sam the Pirate, the 2D platformer I'm creating as the final game project for my Bachelor of Software Engineering degree. Last week I covered some of the initial game design thoughts for Sam the Pirate. This week I'll be talking about how input events are handled, and the start of writing the physics code for Sam the Pirate.

Input
Handling input events in Sam the Pirate is designed around the observer pattern. Any class I create that needs to know about input inherits from an observer interface, and implements a Notify function on that interface.

class IInputObserver
{
public:
IInputObserver() {}
virtual ~IInputObserver() {}
virtual void Notify(SDL_Event* _e) = 0;
};

class CPlayer : public IInputObserver
{
public:
CPlayer();
virtual ~CPlayer();
virtual void Notify(SDL_Event* _e)
{
// Handle the event.
}
};


The CPlayer class then registers with the input manager, and the input manager notifies all observers whenever an SDL_Event happens. SDL_Event is a structure that contains all the information related to the event, like what type of event, key down, key up, controller joystick axis movement, etc, and any further information related to that event, such as what key was pressed/released, what direction the controller joystick was moved. For instance, basic left/right movement from pressing the left/right arrow keys would be detected like this:

virtual void Notify(SDL_Event* _e)
{
if (_e->type == SDL_KEYDOWN)
{
switch (_e->key.keysym.sym)
;{
case SDLK_LEFT:
// move left
break;
case SDLK_RIGHT:
// move right
break;
}
}
}


Currently, observers get notified about any event. I did consider breaking it up, so they could register for specific event, say keyboard input, and only be notified about keyboard input, but given I want to get the physics done (or mostly done!) before christmas, decided I don't have time to do that. It would certainly make things more efficient however.

Starting the physics
So when I started working on the physics I had a couple links from some previous research into whether or not I should use an existing 2D physics engine, one of which included a tutorial on using Runge Kutta, or RK4 to handle movement. We'd briefly covered RK4 in our physics paper, so I thought this sounded good and followed the tutorial. Upon implementation however, I ran into a couple of problems.

The first problem cropped up when I noticed, that even though I only have horizontal movement implemented, my character would gradually travel up the screen as I was moving it back and forth. It turned out, that for whatever reason, it wanted to head in the direction of (0,0) on the screen, which is the top left corner.

The second problem cropped up when I changed the fps to a fixed value around, or below, the fixed rate the physics was being calculated at, as covered in the 2nd tutorial I followed. When this happened, the character would either speed up or slow down, depending on which direction the fps changed. Obviously this is not desired behaviour, the character should behave the same regardless of if the fps is fixed or not.

With these two problems in mind, and after a bit of thinking on how to solve it, I realised that actually, RK4 is far too complicated for what I want to do. I don't need the level of accuracy that RK4 can provide, so I'm scrapping it, starting over and keeping things much simpler. This has cost me a couple days of work, but that's ok! I wasn't expecting things to always work out the first time anyway. I'm planning on implementing acceleration, force, gravity etc, but as simple as possible. Just good enough to get characters behaving how they should.

The plan is still to have a character moving around and jumping on platforms by christmas, and I'm still confident of being able to achieve this. I had been planning to have an interface framework setup by then too, but I don't think that'll be happening.

What's next?
Next week I'll go over where I'm at with the physics code, and cover some of my plans for the levels, including how you progress from one level to the next. I have plans for how the first few levels will be laid out on paper, so if I can figure out scanning works around here I'll look at putting up a couple of those as well.

Keep up to date!
Be sure to follow me on Twitter, and like the Facebook page to stay up to date on future content and blog posts when they happen. If you have any questions don't hesitate to ask, either through Twitter or Facebook!

CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
November 29 2013 22:33 GMT
#2
Hi there, just posted on part 2. To reiterate, you're wasting so much time on physics that it has compelled me to post twice. I did write some articles on creating custom physics that you can try reading. However you really ought to just use Box2D. Your goal is learn computer science and make a game. Most importantly your goal should be to create an awesome portfolio piece. You know what is most important for portfolio projects? For them to finished, released and used by someone (even if only used by yourself). You want something a future employer will click on and play for 3 minutes before giving you an interview; you want the project finished and you'll run out of motivation long before your physics is in a good state with the way you're going about it.
Soan
Profile Blog Joined August 2010
New Zealand194 Posts
November 29 2013 22:49 GMT
#3
And I just replied to part 2 haha. :p I'm not attempting to write realistic physics (so trying to follow this tutorial using RK4 is a mistake), platformers don't exactly have the most realistic physics after all. Given my time constraints I feel I'm better off keeping things simpler and writing my own basic stuff. I'm confident enough in my abilities that I expect to have it done or mostly done by christmas. I'm expecting to partially work through christmas/new years anyway, if not on the physics, on another part of the game.
Phyre
Profile Blog Joined December 2006
United States1288 Posts
December 02 2013 18:11 GMT
#4
Just found this blog by chance, pretty cool stuff. I'm actually in the process of spinning up my own project in SDL/C++ so following your progress has been very informative. Thanks for doing this.
"Oh no, I got you with your pants... on your face... That's not how you wear pants." - Nintu, catching 1 hatch lurks.
Please log in or register to reply.
Live Events Refresh
OSC
18:30
Mid Season Playoffs
MaxPax vs GeraldLIVE!
Solar vs Krystianer
PAPI vs Lemon
Ryung vs Moja
Nice vs NightPhoenix
Cham vs TBD
MaNa vs TriGGeR
SteadfastSC87
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 656
SteadfastSC 87
IndyStarCraft 70
MindelVK 22
Railgan 1
StarCraft: Brood War
Calm 3861
Rain 1283
Bisu 981
Larva 483
firebathero 268
Mini 258
Dewaltoss 191
Hyun 124
Backho 91
Barracks 57
[ Show more ]
scan(afreeca) 26
NaDa 11
Dota 2
Gorgc8056
Fuzer 165
Counter-Strike
fl0m1373
pashabiceps799
FunKaTv 34
Heroes of the Storm
Liquid`Hasu255
Other Games
Grubby2581
FrodaN2067
Beastyqt677
ceh9596
B2W.Neo387
Skadoodle363
Mlord201
C9.Mang0139
Pyrionflax104
QueenE71
Trikslyr52
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• poizon28 218
• Adnapsc2 19
• davetesta18
• Reevou 4
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• intothetv
• Migwel
• Kozan
• IndyKCrew
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 3539
• WagamamaTV209
League of Legends
• TFBlade894
Other Games
• imaqtpie1236
• Shiphtur301
Upcoming Events
PiGosaur Monday
5h 7m
OSC
1d 4h
The PondCast
1d 15h
OSC
1d 17h
Wardi Open
2 days
CranKy Ducklings
3 days
Safe House 2
3 days
Sparkling Tuna Cup
4 days
Safe House 2
4 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.