Coder Social home page Coder Social logo

e05a-input's Introduction

E05-Input

Complete the assignement that allow mouse to show current x and y, also allow spaceship moved by WASD This is an exercise to help you become accustomed to how Godot treats user input.

Instructions are as follows:

  • Fork and Clone this repository. Choose a location where it will be downloaded on your computer.
  • Open Godot. In the Project Manager, select "Import".
  • Click "Browse", navigate to the folder you downloaded when you cloned the repository, and select the project.godot file. Press "Import & Edit"
  • In the Scene panel, you should see a Game node with three children. In the Info node, you should see an Alpha node (the background for the label) and a Label node. The Label node has an attached script. Edit that now.
  • In the _physics_process function, your assignment is to update the text of the label with the current x and y coordinates of the mouse pointer:
    • To get the current position of the mouse, you can ask the viewport for that value:
      • get_viewport().get_mouse_position()
      • This will return the value as a Vector2 object. You can then access the x and y properties:
        var mouse_pos = get_viewport().get_mouse_position()
        print(mouse_pos.x)
      
    • You will then need to update the Label's text with the current x, y position of the mouse. Remember that the Text property will require you to convert your values to a string.
      text = str(mouse_pos.x) + ", " + str(mouse_pos.y)
    
  • The next step will be to move the Ship based on keyboard control:
    • Under the Project menu, select Project Settings
    • The second tab over should be "Input Map". Select this tab.
    • In the action box at the top of the window, add a new input: left
    • To the right of the new "left" item in the list, press the plus icon. Select "Key"
    • In the "Please Confirm…" modal that appears, press the "A" key and hit OK.
    • Repeat this process to add inputs for right, up, and down. Assign W to up, D to right, and S to down.
    • Close the Project Settings window, and then open the script attached to the Ship node.
    • in the _physics_process(delta): function, replace pass with the following lines:
    if Input.is_action_pressed("left"):
        position.x = position.x - 10
    
    • Make sure that the function is properly indented, and that you are using tabs instead of spaces
    • Repeat this, adding conditions for the other three inputs you created. Note: to move up, you will need to add a negative value to position.y.
  • Run the project, and make sure the program is behaving as you would expect.
  • Update the LICENSE and README.md, commit your changes, and push them back to GitHub. Turn in the URL of your repository on Canvas.

e05a-input's People

Contributors

yh17 avatar bl-msch-c220-s22 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.