Post

Visualizzazione dei post con l'etichetta reference

User interface - Adding functionalities

Immagine
In the previous post we created the layout for our user interface. Before going on with the work on it, I want to add some useful stuff to C++ code. I decided to store all informations about the player status (health points, resources, etc.) in the PlayerController class, becuse it seems the most logic place for them. So I'm adding a bunch of new variables: lives:  the number of actual health points left; maxLives:  the maximum number of available health points (it's 3 for now); resources:  the number of collected resources; maxResources:  the maximum number of collectible resources (let's say it's our cargo space, and I'm setting it to 5 for now). All these variables are created with the UPROPERTY macro, so that they're visible from the Blueprints, and can be used to modify the User Interface widget. I'm also going to create some new UFUNCTION methods that will handle the events coming from the User Interface buttons: selectOpti...

Referencing the map from PlayerController

Immagine
Now that I'm starting to write the game logic inside the Player Controller, I want a way to reference my map from it, so that I can have access to its tiles, and eventually pass it to my Player ship and enemy ships, to let them perform their own logic and know what tile they're on, etc. I found 2 ways to achieve this goal, one using blueprints and the other from code, and I want to show you both: Blueprints procedure: Since Player Controller and MainMap are both Blueprint classes and I created the map by dragging it inside the level editor, I don't have a reference of it inside the code as I have, for example, for the Player ship (do you remember the p1 variable?). There's an entity, though, that knows everything that is created inside the level, and it's the Level Blueprint , that we already met when creating a custom camera. The first part of the procedure is somewhat similar to that one, so it should sound familiar. While we have the MainMap ...