Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <godot_cpp/core/Godot.hpp>
- #include <godot_cpp/KinematicBody2D.hpp>
- #include <godot_cpp/Input.hpp>
- using namespace godot;
- class Player : public KinematicBody2D {
- GODOT_CLASS("Player")
- float speed = 200; // pixel/second
- public:
- godot_object* owner;
- void _fixed_process(float delta)
- {
- static Vector2 pos = this->get_position();
- Vector2 input;
- if (Input::is_action_pressed("ui_up")) {
- pos.y -= 1;
- }
- if (Input::is_action_pressed("ui_down")) {
- pos.y += 1;
- }
- if (Input::is_action_pressed("ui_left")) {
- pos.x -= 1;
- }
- if (Input::is_action_pressed("ui_right")) {
- pos.x += 1;
- }
- set_position(input.normalized() * speed * delta);
- }
- static void _register_methods()
- {
- register_method("_fixed_process", &Player::_fixed_process);
- }
- static const char *___get_base_type_name()
- {
- return ___get_type_name();
- }
- };
- NATIVESCRIPT_INIT()
- {
- register_class<Player>();
- }
- GDNATIVE_INIT(godot_gdnative_init_options *options)
- {
- }
- GDNATIVE_TERMINATE(godot_gdnative_init_options *options)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement