Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <Spore\Object.h>
- #include <Spore\Messaging.h>
- #include <Spore\UserInterface.h>
- #include <Spore\Simulator\cVehicle.h>
- using namespace App;
- using namespace UTFWin;
- using namespace Simulator;
- class DrivableCarScript
- : public DefaultObject
- , public IUpdatable
- , public IWinProc
- {
- public:
- // It is always recommended to use a TYPE
- static const uint32_t TYPE = id("DrivableCarScript");
- DrivableCarScript();
- virtual ~DrivableCarScript();
- virtual int AddRef() override;
- virtual int Release() override;
- virtual void* Cast(uint32_t type) const override;
- // The update function from IUpdatable
- virtual void Update() override;
- // For IWinProc:
- // We can just return UTFWin::kEventFlagBasicInput | UTFWin::kEventFlagAdvanced
- virtual int GetEventFlags() const override;
- // Here we will detect key presses/releases
- virtual bool HandleUIMessage(IWindow* pWindow, const Message& message) override;
- // Ensures the user is playing an adventure.
- static bool IsPlayingAdventure();
- // We will call this method when the key is pressed
- void OnKeyPress();
- // We will call this method when the key is pressed
- void OnKeyRelease();
- // Returns the vehicle closest to the player, only if it's inside a certain radius
- cVehicle* FindVehicle() const;
- // This simple task just sets mIsDriving to true/false, the Update function will do the rest.
- void ToggleDriving();
- private:
- // The vehicle we might be driving
- intrusive_ptr<cVehicle> mVehicle;
- // True if the user is "inside" the vehicle, false otherwise
- bool mIsDriving;
- // We keep this to remove the task if the user releases the key
- intrusive_ptr<Simulator::ScheduledTaskListener> mTask;
- // Helps us detect whether the user is still pressing the key
- bool mIsPressing;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement