+ 12

OOP?

When are objects used in real life? Like, I'm looking into game development, I'm currently learning c++. Would I be using objects at all? If so, can you provide a real life example?

25th Nov 2018, 7:32 PM
Daniel Cooper
Daniel Cooper - avatar
17 Réponses
+ 27
Daniel Cooper The simple answer is everything in a game like Call of Duty are objects of some class type. The first person camera view, each weapon, each ammo for each weapon, the player's health, the vegetation, buildings, fire, ground, etc... Heck, even the game engine will likely represent gravity, light, reflection, fog, sound, the sun, texture maps... all of it will be represented as objects. Some objects will implement interfaces or have base types required for movement, reflection, physics, etc. So... yes... OOP is heavily used in game development.
26th Nov 2018, 7:55 AM
David Carroll
David Carroll - avatar
+ 14
Here a basic sample of of defining a game object in oop class Something { private: int width; int height; int x; int y; public: Something(int initWidth, int initHeight, int initX, int initY) { width = initWidth; height = initHeight; x = initX; y = initY; } moveRight(int dist) { x += dist; } moveLeft(int dist) { x -= dist; } }; int main() { Something thing1(0,0,100,200); // init an obj with size and location thing1.moveRight(10); // move to right thing1.moveLeft(20); // move to left return 0; } https://code.sololearn.com/cqYO8x7oBY61/?ref=app
26th Nov 2018, 2:37 AM
Calviղ
Calviղ - avatar
+ 8
An Example I could provide for you would be as follows. Let us assume that you are developing a game which requires a functional "Library". This, from an OOP perspective, means that you will need a Book! So, your "Book" would perhaps look something like this: [PSEUDO-CODE] class Book { //you could go very deep with this ofc, adding page styles etc and use different storage methods, inheritence of object heirarchies etc but for this example I will keep it simple //variables that the object "Book" has, defined by it's real life equivalent page[] pages; //page class might contain -> string[] pageText; Texture bookCoverArt; //okay, so, what functionality does a real book have? func Open(); func WriteIn(); func DrawIn(); func Close(); } class Book might inherit from a more abstract object class like GameObject or InteractiveObject and so on. //quick syntactical example of the inheritence from C# class Book : GameObject, IInteractible { //code here }
25th Nov 2018, 8:14 PM
Joshua Cade Barber
Joshua Cade Barber - avatar
+ 7
Joshua Cade Barber I just wanted to pop in and say how much I enjoyed the few responses I've seen so far. The quality is great and reminds me of many of the other fantastic members here... like Calviղ for example. 😉
26th Nov 2018, 5:15 AM
David Carroll
David Carroll - avatar
+ 6
GameObject might contain very helpful features like Vector Co-ordinate manipulation functions and Instantiation Methods to spawn the Object into the World. The OOP Design pattern, is to, before anything else, focus on immitating the real structure and functionality of the Object in the Real World, in the Code Pattern(s).
25th Nov 2018, 8:16 PM
Joshua Cade Barber
Joshua Cade Barber - avatar
+ 6
Oop is the holy grail for game development. An oop example(not a game): https://code.sololearn.com/WJhC1ROV39yO/?ref=app
27th Nov 2018, 11:47 AM
Haris
Haris - avatar
+ 4
David Carroll Thank you. This helped my understanding a lot.
26th Nov 2018, 8:26 AM
Daniel Cooper
Daniel Cooper - avatar
+ 4
Game development is super fun.. it's actually how I taught myself c++... if you really want to continue forward with game development i would recommend Unreal Engine 4.. there is also a newly made engine that also supports c++ .. but requires some setup if I'm not mistaken. It's called godot isnt a very old engine at all is still pretty new. So I cant truly recommend it for starting out.. Unreal is super intimidating but very rewarding and not difficult to learn at all.
26th Nov 2018, 3:20 PM
Daen Rowe
Daen Rowe - avatar
+ 4
Daen Rowe Nope... I mean, yeah, godot can use c++, but it has its own language called GDScript (a python like) and it doesn't require any setup except the exe file. Btw, it's more recommanded for beginners than unreal. It's easier because of its GDScript (a really easy language)
27th Nov 2018, 12:07 PM
Mao
Mao - avatar
+ 3
Thanks everyone. Daen Rowe What would you recommend for an absolute beginner? I want to learn about c++, but I've heard that most of these languages are similar. So should I learn about an easier language first or dive directly into c++? I'm not at all worried about how long c++ takes to learn, so time isn't an issue
26th Nov 2018, 8:41 PM
Daniel Cooper
Daniel Cooper - avatar
+ 3
I see already nice answers. So I am just gonna add one more useful resource for you here to learn from, along with sololearn. You might want to look up MakingGamesWithBen on youtube. He has a nice playlist for beginners!
27th Nov 2018, 1:51 PM
Jay Amitroy
Jay Amitroy - avatar
+ 2
Extending to what David Carroll said, in CS:GO, the damage that a bullet deals depends on distance of gun and target. This could be possible only by making each bullet an object.
26th Nov 2018, 1:40 PM
Aditya Rana
+ 2
I also want to make another note if dont want to use c++ or Unreal 4 is too much to deal with (which Is totally understandable for first time use) i would reccomend unity 5! Another great engine that uses c# .. P.S. unity 5 and unreal engine 4 are both free. Unreal 4 is actually open source! Unity is not..
26th Nov 2018, 3:24 PM
Daen Rowe
Daen Rowe - avatar
+ 2
Daniel Cooper I would recommend learn as much C++ as you can. Sololearn is a great start to get curious with the language but after you will need to quickly move to outside sources I would recommend learncpp.com it will teach you C++ 11 and even some C++ 17 as a bonus. Then after I would recommend in trying to develop in UE4 (Unreal Engine 4). Both of these tasks are going to take a lot of time to learn. This path isn't easy at all. You will become frustrated and confused a lot of the time. But don't let that discourage you. There are tons of resources that will aid you in your goal in game development and this path. I have loads of resources I have saved over the last couple of years in my adventures of game development. I would be happy to share them with you through a DM if you're really interested in this as a hobby or even if you wish to pursue this as a potential professional career.
26th Nov 2018, 9:42 PM
Daen Rowe
Daen Rowe - avatar
+ 1
So is it realistic to ask about an already existing game? Like, what exactly are objects in games that already exists. For example, let's pick Call of Duty. Simple concept. Are there objects in that, and if so, what are they? (You might not know that kind of information, so pick whatever game you can)
26th Nov 2018, 5:32 AM
Daniel Cooper
Daniel Cooper - avatar
+ 1
This isn't really an important question, just want to make sure I'm understanding this correctly.
26th Nov 2018, 6:07 AM
Daniel Cooper
Daniel Cooper - avatar