• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 22:00
CEST 04:00
KST 11:00
  • 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
Code S Season 2 - RO4 & Finals Results (2025)6Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy4Code S RO8 Preview: herO, Zoun, Bunny, Classic7Code S RO8 Preview: Rogue, GuMiho, Solar, Maru3
Community News
Weekly Cups (June 9-15): herO doubles on GSL week0Firefly suspended by EWC, replaced by Lancer12Classic & herO RO8 Interviews: "I think it’s time to teach [Rogue] a lesson."2Rogue & GuMiho RO8 interviews: "Lifting that trophy would be a testament to all I’ve had to overcome over the years and how far I’ve come on this journey.8Code S RO8 Results + RO4 Bracket (2025 Season 2)14
StarCraft 2
General
Code S Season 2 - RO4 & Finals Results (2025) Nexon wins bid to develop StarCraft IP content, distribute Overwatch mobile game Rain's Behind the Scenes Storytime Firefly suspended by EWC, replaced by Lancer How herO can make history in the Code S S2 finals
Tourneys
RSL: Revival, a new crowdfunded tournament series $3,500 WardiTV European League 2025 [GSL 2025] Code S: Season 2 - Semi Finals & Finals WardiTV Mondays Sparkling Tuna Cup - Weekly Open Tournament
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers [G] Darkgrid Layout
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 478 Instant Karma Mutation # 477 Slow and Steady Mutation # 476 Charnel House Mutation # 475 Hard Target
Brood War
General
ASL20 Preliminary Maps BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion Recent recommended BW games FlaSh Witnesses SCV Pull Off the Impossible vs Shu
Tourneys
[Megathread] Daily Proleagues [BSL 2v2] ProLeague Season 3 - Friday 21:00 CET Small VOD Thread 2.0 [BSL20] ProLeague Bracket Stage - Day 4
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do. [G] How to get started on ladder as a new Z player
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread Beyond All Reason What do you want from future 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
Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia TL Mafia Community Thread
Community
General
Things Aren’t Peaceful in Palestine US Politics Mega-thread Russo-Ukrainian War Thread UK Politics Mega-thread Echoes of Revolution and Separation
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Korean Music Discussion [Manga] One Piece
Sports
2024 - 2025 Football Thread Formula 1 Discussion NHL Playoffs 2024 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
A Better Routine For Progame…
TrAiDoS
StarCraft improvement
iopq
Heero Yuy & the Tax…
KrillinFromwales
I was completely wrong ab…
jameswatts
Need Your Help/Advice
Glider
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 32811 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
PiGosaur Monday
00:00
#36
PiGStarcraft713
CranKy Ducklings162
SteadfastSC98
EnkiAlexander 72
rockletztv 48
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft713
SteadfastSC 98
Nina 96
StarCraft: Brood War
Artosis 821
HiyA 152
Icarus 9
ajuk12(nOOB) 0
Dota 2
monkeys_forever55
LuMiX1
Counter-Strike
Fnx 1770
taco 515
Heroes of the Storm
Khaldor130
Other Games
summit1g13488
C9.Mang0929
shahzam914
JimRising 389
Mew2King175
Maynarde112
Trikslyr61
Sick51
Organizations
Other Games
gamesdonequick756
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Hupsaiya 74
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
StarCraft: Brood War
• RayReign 53
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Doublelift4507
Counter-Strike
• Shiphtur330
Other Games
• Scarra1264
Upcoming Events
RSL Revival
8h
herO vs sOs
Zoun vs Clem
Replay Cast
22h
The PondCast
1d 8h
RSL Revival
1d 8h
Harstem vs SHIN
Solar vs Cham
Replay Cast
1d 22h
RSL Revival
2 days
Reynor vs Scarlett
ShoWTimE vs Classic
uThermal 2v2 Circuit
2 days
SC Evo League
3 days
Road to EWC
3 days
Circuito Brasileiro de…
3 days
[ Show More ]
Sparkling Tuna Cup
4 days
Road to EWC
4 days
Online Event
6 days
Liquipedia Results

Completed

Acropolis #3 - GSC
2025 GSL S2
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
NPSL S3
Rose Open S1
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025
YaLLa Compass Qatar 2025
PGL Bucharest 2025

Upcoming

CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
K-Championship
SEL Season 2 Championship
Esports World Cup 2025
HSC XXVII
Championship of Russia 2025
BLAST Open Fall 2025
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
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.