Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <godot_cpp/core/Godot.hpp>
  2.  
  3. #include <godot_cpp/KinematicBody2D.hpp>
  4. #include <godot_cpp/Input.hpp>
  5.  
  6. using namespace godot;
  7.  
  8. class Player : public KinematicBody2D {
  9.     GODOT_CLASS("Player")
  10.  
  11.     float speed = 200; // pixel/second
  12.  
  13. public:
  14.     godot_object* owner;
  15.  
  16.     void _fixed_process(float delta)
  17.     {
  18.         static Vector2 pos = this->get_position();
  19.         Vector2 input;
  20.  
  21.         if (Input::is_action_pressed("ui_up")) {
  22.             pos.y -= 1;
  23.         }
  24.         if (Input::is_action_pressed("ui_down")) {
  25.             pos.y += 1;
  26.         }
  27.         if (Input::is_action_pressed("ui_left")) {
  28.             pos.x -= 1;
  29.         }
  30.         if (Input::is_action_pressed("ui_right")) {
  31.             pos.x += 1;
  32.         }
  33.  
  34.         set_position(input.normalized() * speed * delta);
  35.     }
  36.  
  37.     static void _register_methods()
  38.     {
  39.         register_method("_fixed_process", &Player::_fixed_process);
  40.     }
  41.  
  42.     static const char *___get_base_type_name()
  43.     {
  44.         return ___get_type_name();
  45.     }
  46.  
  47. };
  48. NATIVESCRIPT_INIT()
  49. {
  50.    register_class<Player>();
  51. }
  52.  
  53. GDNATIVE_INIT(godot_gdnative_init_options *options)
  54. {
  55.    
  56. }
  57.  
  58. GDNATIVE_TERMINATE(godot_gdnative_init_options *options)
  59. {
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement