This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:orx:tutorials:community:acksys:scroll1 [2012/05/28 18:11 (12 years ago)] – [Giving the Bugs a Brain (Deriving the ScrollObject Class)] acksys | en:tutorials:orxscroll:binding-orxscroll [2021/02/17 09:06 (3 years ago)] (current) – iarwain | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== The Binding of Objects ====== | + | ====== The Binding of Objects |
I keep a github repository for the code in this tutorial at https:// | I keep a github repository for the code in this tutorial at https:// | ||
Line 7: | Line 7: | ||
When we refer to " | When we refer to " | ||
- | This means when an Orx/Scroll Object is created, it can automatically be set to use a C++ of choice for its implementation. This makes it easy to implement behavior that is specific to certain object types. | + | This means when an Orx/Scroll Object is created, it can automatically be set to use a C++ class of choice for its implementation. This makes it easy to implement behavior that is specific to certain object types. |
For instance, you want game objects to do certain things every frame. You want enemies to move on a path, or possibly attack. You want the player' | For instance, you want game objects to do certain things every frame. You want enemies to move on a path, or possibly attack. You want the player' | ||
Additionally, | Additionally, | ||
+ | |||
+ | {{: | ||
In this tutorial, we're going to create a small game with two specific examples of object binding. We'll create an Enemy Bug object and a Hero object and bind them to classes. Our enemy bugs will move semi-randomly across the screen. Our Hero will be controlled by the player. He'll flash red if he collides with an enemy bug, showing that he's hurt. | In this tutorial, we're going to create a small game with two specific examples of object binding. We'll create an Enemy Bug object and a Hero object and bind them to classes. Our enemy bugs will move semi-randomly across the screen. Our Hero will be controlled by the player. He'll flash red if he collides with an enemy bug, showing that he's hurt. | ||
Line 25: | Line 27: | ||
===== Create a new Scroll Project ===== | ===== Create a new Scroll Project ===== | ||
- | Before you begin this tutorial, you need a basic Orx/Scroll project ready. For details on doing this, see the previous tutorial, [[en:orx:tutorials:community: | + | Before you begin this tutorial, you need a basic Orx/Scroll project ready. For details on doing this, see the previous tutorial, [[en: |
This tutorial assumes you've made a new Orx/Scroll project by following the instructions in the previously tutorial exactly! | This tutorial assumes you've made a new Orx/Scroll project by following the instructions in the previously tutorial exactly! | ||
Line 33: | Line 35: | ||
You'll need to download these textures ((Thanks to Daniel Cook of www.lostgarden.com for the great prototyping graphics)) for use in your config: | You'll need to download these textures ((Thanks to Daniel Cook of www.lostgarden.com for the great prototyping graphics)) for use in your config: | ||
- | {{http:// | + | {{tutorials:orxscroll: |
- | {{http:// | + | {{tutorials:orxscroll: |
Then, you'll need to prepare this config in your main Orx .ini file for use with this tutorial: | Then, you'll need to prepare this config in your main Orx .ini file for use with this tutorial: | ||
Line 274: | Line 276: | ||
* This class makes use of the SetRotation, | * This class makes use of the SetRotation, | ||
* OnCreate is called when the object is first created. We didn't define a constructor, | * OnCreate is called when the object is first created. We didn't define a constructor, | ||
+ | * In OnCreate, we query values in config without pushing the object' | ||
* We initialize our class members using the " | * We initialize our class members using the " | ||
* OnDelete is called when the object is deleted. We must provide a body for the function, but it does nothing in our case. | * OnDelete is called when the object is deleted. We must provide a body for the function, but it does nothing in our case. | ||
Line 326: | Line 329: | ||
virtual orxBOOL OnCollide (ScrollObject *_poCollider, | virtual orxBOOL OnCollide (ScrollObject *_poCollider, | ||
const orxSTRING _zPartName, | const orxSTRING _zPartName, | ||
+ | const orxSTRING _zColliderPartName, | ||
const orxVECTOR & | const orxVECTOR & | ||
const orxVECTOR & | const orxVECTOR & | ||
Line 343: | Line 347: | ||
void Hero:: | void Hero:: | ||
{ | { | ||
- | // Push class config section | ||
- | orxConfig_PushSection (" | ||
// Get movement speed from config value | // Get movement speed from config value | ||
m_movementSpeed = orxConfig_GetFloat (" | m_movementSpeed = orxConfig_GetFloat (" | ||
- | // Pop class config section | ||
- | orxConfig_PopSection (); | ||
} | } | ||
Line 382: | Line 382: | ||
orxBOOL Hero:: | orxBOOL Hero:: | ||
const orxSTRING _zPartName, | const orxSTRING _zPartName, | ||
+ | const orxSTRING _zColliderPartName, | ||
const orxVECTOR & | const orxVECTOR & | ||
const orxVECTOR & | const orxVECTOR & | ||
Line 425: | Line 426: | ||
When you run the game, you'll be able to control the hero with the arrow keys. Be careful, the bugs will bite him if he gets too close and the OnCollision callback will make him " | When you run the game, you'll be able to control the hero with the arrow keys. Be careful, the bugs will bite him if he gets too close and the OnCollision callback will make him " | ||
- | {{http:// | + | {{ :tutorials: |
===== What Now? ===== | ===== What Now? ===== |