Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Godot;
- using System;
- public class Invee : KinematicBody2D {
- private AnimatedSprite player_sprite;
- private Vector2 _vel = new Vector2();
- private string _animState = "idle";
- private int _gravity = 15;
- private int _walkSpeed = 100;
- private int _jumpHeight = 400;
- public override void _Ready() {
- player_sprite = (AnimatedSprite)GetNode("AnimatedSprite");
- player_sprite.Play(_animState);
- }
- public override void _PhysicsProcess(float delta) {
- _vel.y += _gravity;
- _vel.x = 0;
- if (Input.IsKeyPressed((int) KeyList.D)) {_vel.x = _walkSpeed;}
- else if(Input.IsKeyPressed((int) KeyList.A)) {_vel.x = -_walkSpeed;}
- if (_vel.x > 0) {player_sprite.FlipH = false;}
- else if (_vel.x < 0) {player_sprite.FlipH = true;}
- //player_sprite.FlipH = (_vel.x > 0) ? false: (_vel.x < 0) ? true: false;
- if (IsOnFloor()) {
- if (Input.IsKeyPressed((int) KeyList.Space)) {
- _vel.y = -_jumpHeight;
- }
- }
- if (_vel.x == 0) {_animState = "idle";}
- else {_animState = "run";}
- if (player_sprite.Animation != _animState) {
- player_sprite.Play(_animState);
- }
- _vel = MoveAndSlide(_vel, Vector2.Up);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement