- Godot Engine Game Development Projects
- Chris Bradfield
- 262字
- 2021-06-18 18:51:33
Inheritance
In Object-Oriented Programming (OOP), inheritance is a powerful tool. Put briefly, you can define a class that inherits from another class. An object created using the first class will contain all of the methods and member variables of the master class as well as its own.
Godot is strongly object-oriented, and this gives you the opportunity to use inheritance not just with objects (scripts) but also with scenes, allowing you a great deal of flexibility when designing your game's architecture. It also removes the need to duplicate code—if two objects need to share a set of methods and variables, for example, you can create a common script and let both objects inherit from it. If you make a change to that code, it will apply to both objects.
In this project, the player's character will be controlled by key events, while the mobs will wander around the maze randomly. However, both types of character need to have a number of properties and functions in common:
- A spritesheet containing the four directional movement animations
- An AnimationPlayer to play the movement animations
- Grid-based movement (the character can only move one full tile at a time)
- Collision detection (the character can't move through walls)
By using inheritance, you can create a generic Character scene containing the nodes that all characters need. The player and mob scenes can inherit the shared nodes from that scene. Similarly, the actual movement code (though not the controls) will be identical between player and mob, so they can both inherit from the same script to handle movement.
- 腦動力:Linux指令速查效率手冊
- Canvas LMS Course Design
- 我的J2EE成功之路
- Hands-On Artificial Intelligence on Amazon Web Services
- 并行數(shù)據(jù)挖掘及性能優(yōu)化:關(guān)聯(lián)規(guī)則與數(shù)據(jù)相關(guān)性分析
- Hands-On Cloud Solutions with Azure
- 圖形圖像處理(Photoshop)
- 數(shù)據(jù)運(yùn)營之路:掘金數(shù)據(jù)化時(shí)代
- Python Algorithmic Trading Cookbook
- 21天學(xué)通Java Web開發(fā)
- Learning C for Arduino
- 工業(yè)機(jī)器人運(yùn)動仿真編程實(shí)踐:基于Android和OpenGL
- 網(wǎng)絡(luò)管理工具實(shí)用詳解
- LMMS:A Complete Guide to Dance Music Production Beginner's Guide
- Excel 2010函數(shù)與公式速查手冊