• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 11:09
CET 17:09
KST 01:09
  • 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
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
BGE Stara Zagora 2026 announced12[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge2
StarCraft 2
General
Information Request Regarding Chinese Ladder BGE Stara Zagora 2026 announced SC: Evo Complete - Ranked Ladder OPEN ALPHA When will we find out if there are more tournament Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win
Tourneys
Constellation Cup - Main Event - Stellar Fest RSL Revival: Season 3 Tenacious Turtle Tussle [Alpha Pro Series] Nice vs Cure $5,000+ WardiTV 2025 Championship
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death
Brood War
General
BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ A cwal.gg Extension - Easily keep track of anyone Which season is the best in ASL? soO on: FanTaSy's Potential Return to StarCraft
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET [BSL21] RO16 Group C - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Game Theory for Starcraft How to stay on top of macro? Current Meta PvZ map balance
Other Games
General Games
Nintendo Switch Thread The Perfect Game Stormgate/Frost Giant Megathread Beyond All Reason Should offensive tower rushing be viable in RTS games?
Dota 2
Official 'what is Dota anymore' discussion
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
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread The Big Programming Thread Things Aren’t Peaceful in Palestine Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1677 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
3D!Clan Event
14:00
3D!COMMUNITY OLD SCHOOL 2X2 3
3DClanTV 45
Liquipedia
WardiTV Korean Royale
12:00
Playoffs
Solar vs herOLIVE!
WardiTV1576
TKL 406
IndyStarCraft 292
Rex129
IntoTheiNu 14
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
TKL 406
IndyStarCraft 292
mouzHeroMarine 195
Rex 129
Codebar 25
Clem_sc2 1
StarCraft: Brood War
Britney 29906
Calm 3980
Rain 2175
Soma 1000
Larva 830
BeSt 704
actioN 657
firebathero 478
hero 421
Rush 249
[ Show more ]
Hyun 125
Barracks 108
LaStScan 99
zelot 95
Last 76
Sharp 73
Mong 58
JYJ50
sorry 35
Noble 19
Terrorterran 16
Dota 2
Gorgc7407
singsing3102
syndereN274
XcaliburYe264
League of Legends
Reynor85
Counter-Strike
fl0m3642
zeus1740
Heroes of the Storm
Khaldor490
Other Games
B2W.Neo1651
FrodaN1161
crisheroes336
Hui .294
Fuzer 251
KnowMe99
QueenE52
ArmadaUGS48
Organizations
Other Games
EGCTV1241
gamesdonequick899
Dota 2
PGL Dota 2 - Main Stream76
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• poizon28 6
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV544
• Ler108
League of Legends
• Jankos2964
Upcoming Events
BSL 21
3h 51m
Hawk vs Kyrie
spx vs Cross
Replay Cast
7h 51m
Wardi Open
19h 51m
Monday Night Weeklies
1d
StarCraft2.fi
1d
Replay Cast
1d 7h
Wardi Open
1d 19h
StarCraft2.fi
2 days
PiGosaur Monday
2 days
Wardi Open
2 days
[ Show More ]
StarCraft2.fi
3 days
Replay Cast
3 days
The PondCast
3 days
Replay Cast
4 days
Korean StarCraft League
5 days
CranKy Ducklings
5 days
SC Evo League
5 days
BSL 21
6 days
Sziky vs OyAji
Gypsy vs eOnzErG
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

Proleague 2025-11-28
RSL Revival: Season 3
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
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.