• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 07:39
CEST 13:39
KST 20:39
  • 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
BGE Stara Zagora 2025: Info & Preview27Code S RO12 Preview: GuMiho, Bunny, SHIN, ByuN3The Memories We Share - Facing the Final(?) GSL47Code S RO12 Preview: Cure, Zoun, Solar, Creator4[ASL19] Finals Preview: Daunting Task30
Community News
Weekly Cups (June 2-8): herO doubles down1[BSL20] ProLeague: Bracket Stage & Dates9GSL Ro4 and Finals moved to Sunday June 15th13Weekly Cups (May 27-June 1): ByuN goes back-to-back0EWC 2025 Regional Qualifier Results26
StarCraft 2
General
The SCII GOAT: A statistical Evaluation How does the number of casters affect your enjoyment of esports? CN community: Firefly accused of suspicious activities Serious Question: Mech The Memories We Share - Facing the Final(?) GSL
Tourneys
$3,500 WardiTV European League 2025 Bellum Gens Elite: Stara Zagora 2025 Sparkling Tuna Cup - Weekly Open Tournament SOOPer7s Showmatches 2025 Master Swan Open (Global Bronze-Master 2)
Strategy
[G] Darkgrid Layout Simple Questions Simple Answers [G] PvT Cheese: 13 Gate Proxy Robo
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 477 Slow and Steady Mutation # 476 Charnel House Mutation # 475 Hard Target Mutation # 474 Futile Resistance
Brood War
General
BGH auto balance -> http://bghmmr.eu/ BW General Discussion Mihu vs Korea Players Statistics Will foreigners ever be able to challenge Koreans? [BSL20] ProLeague: Bracket Stage & Dates
Tourneys
[ASL19] Grand Finals NA Team League 6/8/2025 [Megathread] Daily Proleagues [BSL20] ProLeague Bracket Stage - Day 2
Strategy
I am doing this better than progamers do. [G] How to get started on ladder as a new Z player
Other Games
General Games
Stormgate/Frost Giant Megathread What do you want from future RTS games? Armies of Exigo - YesYes? Nintendo Switch Thread Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
LiquidLegends to reintegrate into TL.net
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Vape Nation Thread European Politico-economics QA Mega-thread
Fan Clubs
Maru Fan Club Serral Fan Club
Media & Entertainment
Korean Music Discussion [Manga] One Piece
Sports
2024 - 2025 Football Thread Formula 1 Discussion NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Cognitive styles x game perf…
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
Poker
Nebuchad
Customize Sidebar...

Website Feedback

Closed Threads



Active: 20946 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
Wardi Open
11:00
$400 Mondays 39
WardiTV389
OGKoka 323
IndyStarCraft 101
CranKy Ducklings95
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 510
OGKoka 323
Lowko284
Rex 120
IndyStarCraft 101
ProTech87
EnDerr 42
StarCraft: Brood War
Sea 5973
Hyuk 4842
Rain 2379
Horang2 1326
EffOrt 415
Larva 355
Mini 349
firebathero 274
Stork 260
Zeus 199
[ Show more ]
Rush 138
Pusan 115
ToSsGirL 104
Hyun 87
[sc1f]eonzerg 50
Backho 49
sorry 49
Sharp 35
GoRush 35
Aegong 32
Movie 30
sSak 27
Sea.KH 26
Icarus 23
Yoon 13
yabsab 10
Shine 9
Noble 8
ajuk12(nOOB) 7
Bale 7
Dota 2
Gorgc930
XcaliburYe535
BananaSlamJamma463
420jenkins387
League of Legends
Dendi1175
Counter-Strike
shoxiejesuss1121
Stewie2K898
x6flipin559
allub191
Super Smash Bros
Mew2King106
Heroes of the Storm
Khaldor231
Other Games
singsing1902
B2W.Neo925
crisheroes388
Fuzer 299
Pyrionflax246
XaKoH 231
Organizations
Dota 2
PGL Dota 2 - Secondary Stream3897
StarCraft: Brood War
UltimateBattle 48
StarCraft 2
IntoTheiNu 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• StrangeGG 39
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV399
League of Legends
• Stunt582
Upcoming Events
Replay Cast
12h 21m
Replay Cast
22h 21m
WardiTV Invitational
23h 21m
WardiTV Invitational
23h 21m
PiGosaur Monday
1d 12h
GSL Code S
1d 21h
Rogue vs GuMiho
Maru vs Solar
Online Event
2 days
Replay Cast
2 days
GSL Code S
2 days
herO vs Zoun
Classic vs Bunny
The PondCast
2 days
[ Show More ]
Replay Cast
3 days
WardiTV Invitational
3 days
OSC
4 days
Korean StarCraft League
4 days
CranKy Ducklings
4 days
WardiTV Invitational
4 days
Cheesadelphia
5 days
GSL Code S
5 days
Sparkling Tuna Cup
5 days
Replay Cast
6 days
Liquipedia Results

Completed

CSL Season 17: Qualifier 2
BGE Stara Zagora 2025
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
BSL Season 20
KCM Race Survival 2025 Season 2
NPSL S3
Rose Open S1
CSL 17: 2025 SUMMER
2025 GSL S2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
ECL Season 49: Europe
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025
YaLLa Compass Qatar 2025
PGL Bucharest 2025
BLAST Open Spring 2025

Upcoming

Copa Latinoamericana 4
CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
K-Championship
SEL Season 2 Championship
Esports World Cup 2025
HSC XXVII
Championship of Russia 2025
Murky Cup #2
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.