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.
127 questions
0
votes
0
answers
71
views
Best way to structure code for a character dependent on its environment and vice versa
What is the neatest way in a strict OOP language (c++ say) to avoid the following circular dependency. Imagine I create a character class and a world class. A character requests data from the world to ...
1
vote
0
answers
80
views
Restructure OOP Architecture for two classes that are currently circular dependent
I'm working on a simple 2D game using C++ and SFML.
In this game, I have a class WorkbenchBlock which inherits from class Block. ...
0
votes
0
answers
89
views
Command Pattern or/and Event Handling porgramming paradigm?
I have created a dynamic library that contains all the tools I want my game executable to have. Additionally, I want to create a world editor/tools for my engine to be more user-friendly.
I'm ...
0
votes
3
answers
247
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 ...
1
vote
0
answers
143
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 ...
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 ...
0
votes
0
answers
89
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 ...
0
votes
2
answers
207
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 ...
0
votes
2
answers
114
views
Modeling a naturally circular relationship between three classes
I have three classes Location, Item, Character.
Every ...
0
votes
0
answers
120
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 ...
1
vote
1
answer
406
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 ...
0
votes
1
answer
773
views
0
votes
1
answer
113
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 ...
3
votes
1
answer
2k
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 ...
0
votes
1
answer
200
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 ...
0
votes
1
answer
160
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 ...
0
votes
1
answer
87
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.
...
0
votes
0
answers
43
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 ...
0
votes
2
answers
693
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 ...
0
votes
1
answer
480
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:
...
0
votes
0
answers
92
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 <...
0
votes
1
answer
94
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 ...
2
votes
0
answers
171
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 ...
0
votes
1
answer
124
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 ...
0
votes
1
answer
105
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 ...
0
votes
2
answers
113
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 ...
0
votes
0
answers
53
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 ...
0
votes
1
answer
131
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
...
1
vote
0
answers
649
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 ...
0
votes
0
answers
45
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 ...
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 ...
3
votes
1
answer
249
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 ...
2
votes
2
answers
4k
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
...
0
votes
0
answers
55
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-...
0
votes
2
answers
106
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 ...
1
vote
2
answers
167
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 ...
2
votes
1
answer
164
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.
...
0
votes
1
answer
115
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 '...
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)
...
1
vote
2
answers
6k
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 ...
38
votes
8
answers
19k
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.
...
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 ...
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 ...
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 ...
1
vote
1
answer
431
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 ...
1
vote
1
answer
621
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? ...
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 <...
0
votes
1
answer
127
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), ...
1
vote
0
answers
50
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 ...
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:
...