Questions tagged [oop]

Object-oriented programming. A paradigm using objects (instances of a class consisting of properties and methods) to design games. Techniques may include data abstraction, encapsulation, messaging, modularity, polymorphism, and inheritance.

Filter by
Sorted by
Tagged with
0 votes
3 answers
132 views

Is there any reason not to use classes in C++?

I'm a bit conflicted when it comes to the use of classes currently, I use them all the time, but I realized through the KISS and YAGNI principles I can simplify things by not using them, but is there ...
Konjointed's user avatar
1 vote
0 answers
46 views

When to use the same class for both client and server versions of an object, vs. when they should differ

I am learning about networking for game development and need some insight. My knowledge of Unreal Engine is that it uses RPCs and replicated variables for actors. I also know that Unity has Networked ...
Gus Funder's user avatar
3 votes
2 answers
2k views

In an object-oriented game engine, should there be seperate classes for objects with and without parents?

I am developing a game engine in C++ (for an idea of what kind of design I'm going for, think of ROBLOX, if you're familiar with that) and I need help with a problem I have. So basically, the objects ...
AcinonX's user avatar
  • 311
0 votes
0 answers
60 views

How to handle collision detection with different 2D shapes while maintaining performance? Is polymorphism appropriate?

If I'm making a small library for handling 2D shapes, should polymorphism generally be avoided? I know that it can worsen performance but it's not like polymorphism is never used in game development ...
JensB's user avatar
  • 157
0 votes
2 answers
121 views

Name for groups of cards in a card game [closed]

What would you call the groups of cards in a card game, including both piles (draw, discard...) and hands? I'm coding a generic card game engine and I've been unable to find a good name for the base ...
Jérémy Quentin's user avatar
0 votes
2 answers
82 views

Modeling a naturally circular relationship between three classes

I have three classes Location, Item, Character. Every ...
Michael Moreno's user avatar
0 votes
0 answers
83 views

Initializing prefabs with different scripts

I am creating a tower defense game. Currently I have 2 different tower types 'Shooting tower', amd 'Unit tower'. I have a Scriptable object to initialize the tower. It contains some tower properties ...
Taras Fityo's user avatar
1 vote
1 answer
264 views

How to include cross cutting concerns like sound/graphics effects in an ECS?

It does not seem like a good idea to include this functionality in the game logic like that even if the concrete implementation of the sound or graphics effect is abstracted away. Ideally, the game ...
codymanix's user avatar
  • 364
0 votes
1 answer
614 views

How to use AddComponent to add an instance of the derived class, not the base class that defines the method?

This is my base class ...
Sean Carey's user avatar
0 votes
1 answer
96 views

SFML: Object's shape not rendered on the window [closed]

I want to be able to render sf::CircleShape (representing pointwise charges) when pressing mouse buttons on the window. The problem is easy enough, however the ...
user avatar
3 votes
1 answer
1k views

Extra constructor call when using inheritance in Godot

I'm trying to design a character system for my game. Considering I'll need a player and non-player characters - and non-player characters will further come in many more forms, making use of ...
Marty Cagas's user avatar
0 votes
1 answer
113 views

Pygame bullet firerate not working sometimes

i have made this bullet class but i have a problem with the firerate. Sometimes i'm not able to shoot even when the little delay (700ms) between the two shots has ended. I guess it's due to the ...
Salem's user avatar
  • 226
0 votes
1 answer
112 views

How to deal with data that needs to be accessed by all objects?

I have a World class that currently only has one instance. It has data and methods that need to be accessed by all other game objects. Right now I'm hardcoding a ...
EnderShadow8's user avatar
0 votes
1 answer
52 views

How do I get my fish to face the right way?

I'm making this 2d collecting game in Unity where you collect fish. However I can't get them to face the direction they are going. I've asked on some Discords and got no answer. Thanks in advance. ...
Ratman's user avatar
  • 1
0 votes
0 answers
25 views

Overridden movement function doesn't work

I moved from C to C# so I am a novice in Object Oriented Programming. I wanted to implement OOP in my character movement, but it didn't work the way I expected. My character is instantiated when the ...
Gorlomi's user avatar
0 votes
2 answers
563 views

Should a game object class contain the information for how to render it?

If I have a class called Enemy: // Simplified version class Enemy { float xPosition_; float yPosition_; int hp_; }; Should this class also contain the ...
JensB's user avatar
  • 157
0 votes
1 answer
405 views

Extending a ScriptableObject to have a get property instead of a field, without losing serialized data

I have a ScriptableObject that's already used extensively in my project: ...
Commodore Yournero's user avatar
0 votes
0 answers
85 views

is there any different solution for different buildings different behaviours

I'm trying to make different behaviours for workers of different buildings, let's say an agricultural worker would need to sow wheat seed and collect the wheat grain when it's grown. let's call that <...
MilitaryG's user avatar
0 votes
1 answer
79 views

OOP architecture problem between Camera, Player, Weapon

I am making an FPS game in Unity, trying to keep myself to OOP principles as much as I can but I found dead-end. I want to add recoil to my game, now logically thinking the amount of recoil should be ...
66Gramms's user avatar
  • 135
2 votes
0 answers
136 views

How can an Entity trigger changes to the world in C++?

I'm writing a simple physics based game in C++ using SFML. I want to trigger a scene change when my playerCharacter collides with a door. Since C++ does not have any native Event Sender/Listener ...
john_shreds's user avatar
0 votes
1 answer
73 views

How do i make a list of generic classes?

First of all, I want mods in my game, as stated in a previous question, I want to do that via registries. Users make content known to the game in the form of 'Registering' it, then it can be used in ...
Faih Faih's user avatar
0 votes
1 answer
62 views

Best way to implement a class or interface for a set of UI buttons that only differ in their Draw() function?

I have three types of UI buttons that go on a cooldown bar: A traditional cooldown bar button where once the corresponding key is pressed, a timer shows over the button and dims the texture. A button ...
Thisisstackoverflow's user avatar
0 votes
2 answers
89 views

How do I design my classes so that my Player.cs code can use class-specific abilities from another script? [duplicate]

Right now, I have a Player.cs class that handles button pushes, movement speed, damage, Update() etc. At the moment, all of the logic for button presses triggering an ability, and the logic ...
Thisisstackoverflow's user avatar
0 votes
0 answers
37 views

Efficient system to reach the "parent" variable

I've been stuck doing this in a very inefficient way and really want to know if there's some design pattern that solves this because it seems like a pretty common problem to have. I have a system ...
Taceo's user avatar
  • 1
0 votes
1 answer
89 views

Confused, maybe the mistake ik is the foreach loop

I dont know why but my jump method does not work. My character can only jump on one single object. The other obstacle haven't any influence on the player. I really don't see my mistake ...
MoonyTown's user avatar
1 vote
0 answers
572 views

What design pattern would be most suitable for RPG skills?

I'm developing a small Java digital card game project. In my game, players can perform skills when using cards. Each skill does different things, like deal damage, heal etc.. I'm looking for a way to ...
uchi23's user avatar
  • 11
0 votes
0 answers
36 views

most flexible way to implement a buff /debuff system for a RPG game [duplicate]

I'm making an RGP board game where I have different heros, each one of them belongs to some types for example ("Aatrox" is a Dragon and a Ninja hence he belong to these two types),and each player has ...
Joe's user avatar
  • 1
0 votes
1 answer
2k views

How to pass renderer through classes?

I am making a game with SDL and C++. I am trying to render simple image to the screen but I can't. I am not getting any error but I see only black screen. I think because the renderer in ...
younlok's user avatar
  • 19
3 votes
1 answer
222 views

Mob generation design - is creating a class for each mob efficient?

I'm working on an RPG game for my coursework project. Everything is going fine but I've reached a stage where I do think that my project's code is not the most efficient. Here I have a constructor of ...
thesameritan's user avatar
2 votes
2 answers
3k views

How to update the value of all owners of shared_ptr?

I’m writing a render, there is a class that shaders should store, something like a shader manager. These shaders are stored as ...
Денис Ковешников's user avatar
0 votes
0 answers
35 views

Unity - referencing the player's renderer

I have a bit of a problem with transferring my Game/Health Manager across scenes. My current Health Manager is set up so when the player gets hit, they flash, which is controlled by activating and de-...
DustyShinigami's user avatar
0 votes
2 answers
66 views

How to modularly call a script based on parameters within the script?

I am coding an interaction system in Unity that does things based on whether the player taps interaction, or holds interaction. Each object holds their own scripts of how a player can interact with ...
Visulth's user avatar
  • 107
1 vote
2 answers
81 views

How to use OOP to handle different requirements

I've been trying to make games for a while now, but even when making a very simple one, I've always run into a problem - Because different subclasses have different functionality, therefore needing ...
Sarah's user avatar
  • 59
2 votes
1 answer
140 views

Passing a value to a stuct

So I've been making a 2D grid and pathfinder using SFML. Now I ran into a problem. I've been making a vector for the path nodes. ...
Yamarai Akizuki's user avatar
0 votes
1 answer
79 views

How to use This Keyword and using iterators to call class methods?

I've been over this for a long time, I can't seem to understand what is wrong, is the use of the this keyword right? I want to add the instance of the class that is being created to the vector '...
noobProgrammer's user avatar
0 votes
1 answer
2k views

Read access violation, pointer was nullprt

Im trying to figure out how to use pointers to make a single instance of an object that in this example will just change direction on x-axis. Splav.h (eng. Paddle.h) ...
Marko Petričević's user avatar
1 vote
2 answers
5k views

Design pattern for turn based strategy game in C++

I'm studying computer science at university. So far I've created several programs for school projects and homeworks in C++. They were usually smaller programs up to 1000 lines of code. Now I want to ...
kocourOggy's user avatar
38 votes
8 answers
18k views

Should I avoid using object inheritance as possible to develop a game?

I prefer OOP features when developing games with Unity. I usually create a base class (mostly abstracted) and use object inheritance to share the same functionality to the various other objects. ...
modernator's user avatar
  • 1,213
8 votes
1 answer
4k views

Unity Hybrid ECS with "old way"

Is it possible to use Hybrid ECS with some components and the standard MonoBehaviour with all your old code? I want to know because I already have some game ...
Marc Rasmussen's user avatar
0 votes
1 answer
2k views

Unity Custom EventManager, multiple arguments, and order

I have some hard question for me... I have a nice EventManager, who handle multiple arguments. (no argument, one int, one bool, a GameObject and a bool... but for each sort, I have to create a special ...
Ugo Hed's user avatar
  • 281
3 votes
2 answers
3k views

How to create custom methods for sprite groups in pygame?

I want to use sprite groups in my game using pygame and the default draw isn't enough. I have tried some tutorials but I failed. So, being more specific: I want to create custom methods for sprite ...
CFLS's user avatar
  • 165
1 vote
1 answer
424 views

why does a type alias to engine specific header violate encapsulation?

In a class called Sprite.h my teacher asked this question which I don't fully understand. A generic interface has to include an engine specific header in order to expose different sprites. This ...
Steffen Jorgensen's user avatar
1 vote
1 answer
555 views

LIBGDX - group as child of an actor?

I've looked in forums, the doc, and the code, and I'm thinking this isn't currently possible, but maybe I'm missing something, so just to be sure: is there a way to set a group as child of and actor? ...
ontheway's user avatar
1 vote
1 answer
1k views

Detecting Overlapping Shapes

I have two classes Circle and Square which derive from an abstract base class Shape. A <...
Edward's user avatar
  • 63
0 votes
1 answer
113 views

Should I separate the Pathfinding info from the Tile Info class? [closed]

I have implemented A* on a Tile Based Game, my Tile class contains a lot of info like Position, TileType, Items, Characters, etc on it. Right now that class has the Edges references(neighbours), ...
user264560's user avatar
1 vote
0 answers
44 views

Javascript: world tile generator bug? collision not working, player falls down? [closed]

Hi I have a serious problem here, When I generate my tile map from an array with numbers [0,4, ...] (0 > for air, 4 for solid) inside of generateWorld()... the ...
vincent thorpe's user avatar
1 vote
1 answer
3k views

How to link my weapons with their corresponding ammo supply in the Unity Inspector?

In my game I would like to implement a universal ammo and weapon system that would be usable for any kind of weapon. So I declared an ammo class: ...
xuwenbuwer's user avatar
4 votes
1 answer
457 views

When should I acquire game objects with dependency injection, find-with-tag, or singletons?

This is sort of a best practice/efficiency kind of question, and I haven't really seen any other question talking about these three things together. Essentially, Dependency Injection, Find with Tag (...
rachica's user avatar
  • 43
0 votes
2 answers
162 views

Java - Declaring a random Vector affects a Vector in another class?

I'm working on a 2D game and I've come across something strange which I've been working to fix the whole day but can't. I'm trying to make an arrow fly, but modifying it's class affects my ...
Dennis Björk's user avatar
0 votes
1 answer
225 views

Three levels deep composition (player<-character<-spell), with preset character+skill sets

So I'm creating a rather generic strategy game similar to Warcraft or League of Legends, which needs to have: a Player class for representing the users playing the ...
Markus Meskanen's user avatar