SHARE
TWEET

ModAPI Tutorial: DrivableCarScript.h

a guest Feb 27th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma once
  2.  
  3. #include <Spore\Object.h>
  4. #include <Spore\Messaging.h>
  5. #include <Spore\UserInterface.h>
  6. #include <Spore\Simulator\cVehicle.h>
  7.  
  8. using namespace App;
  9. using namespace UTFWin;
  10. using namespace Simulator;
  11.  
  12. class DrivableCarScript
  13.     : public DefaultObject
  14.     , public IUpdatable
  15.     , public IWinProc
  16. {
  17. public:
  18.     // It is always recommended to use a TYPE
  19.     static const uint32_t TYPE = id("DrivableCarScript");
  20.  
  21.     DrivableCarScript();
  22.     virtual ~DrivableCarScript();
  23.  
  24.     virtual int AddRef() override;
  25.     virtual int Release() override;
  26.     virtual void* Cast(uint32_t type) const override;
  27.  
  28.     // The update function from IUpdatable
  29.     virtual void Update() override;
  30.  
  31.     // For IWinProc:
  32.     // We can just return UTFWin::kEventFlagBasicInput | UTFWin::kEventFlagAdvanced
  33.     virtual int GetEventFlags() const override;
  34.     // Here we will detect key presses/releases
  35.     virtual bool HandleUIMessage(IWindow* pWindow, const Message& message) override;
  36.  
  37.     // Ensures the user is playing an adventure.
  38.     static bool IsPlayingAdventure();
  39.  
  40.     // We will call this method when the key is pressed
  41.     void OnKeyPress();
  42.  
  43.     // We will call this method when the key is pressed
  44.     void OnKeyRelease();
  45.  
  46.     // Returns the vehicle closest to the player, only if it's inside a certain radius
  47.     cVehicle* FindVehicle() const;
  48.  
  49.     // This simple task just sets mIsDriving to true/false, the Update function will do the rest.
  50.     void ToggleDriving();
  51.  
  52. private:
  53.     // The vehicle we might be driving
  54.     intrusive_ptr<cVehicle> mVehicle;
  55.    
  56.     // True if the user is "inside" the vehicle, false otherwise
  57.     bool mIsDriving;
  58.  
  59.     // We keep this to remove the task if the user releases the key
  60.     intrusive_ptr<Simulator::ScheduledTaskListener> mTask;
  61.  
  62.     // Helps us detect whether the user is still pressing the key
  63.     bool mIsPressing;
  64. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top