Book Image

Processing 2: Creative Coding Hotshot

By : Nikolaus Gradwohl
Book Image

Processing 2: Creative Coding Hotshot

By: Nikolaus Gradwohl

Overview of this book

Processing makes it convenient for developers, artists, and designers to create their own projects easily and efficiently. Processing offers you a platform for expressing your ideas and engaging audiences in new ways. This book teaches you everything you need to know to explore new frontiers in animation and interactivity with the help of Processing."Processing 2: Creative Coding Hotshot' will present you with nine exciting projects that will take you beyond the basics and show you how you can make your programs see, hear, and even feel! With these projects, you will also learn how to build your own hardware controllers and integrate devices such as a Kinect senor board in your Processing sketches.Processing is an exciting programming environment for programmers and visual artists alike that makes it easier to create interactive programs.Through nine complete projects, "Processing 2: Creative Coding Hotshot' will help you explore the exciting possibilities that this open source language provides. The topics we will cover range from creating robot - actors performing Shakespeare's "Romeo and Juliet", to generating objects for 3D printing, and you will learn how to run your processing sketches nearly anywhere from a desktop computer to a browser or a mobile device.
Table of Contents (16 chapters)
Processing 2: Creative Coding Hotshot
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Initiating the landing sequence


The second task of our current mission is to implement the physics simulation and the game controls for our moon-lander game. In this task, the game should able to run on desktop computers and laptops running Java. We will add keyboard controls to enable the player to turn the rocket left and right, and when the player hits the up cursor key, the thruster will fire and accelerate the rocket a bit in the direction it has been turned.

Engage Thrusters

Let's start implementing the physics by adding moon gravity:

  1. The first thing we need to implement for our moon physics simulation are the variables to store the ship's position, the direction, the current speed, and the strength of the moon's gravity.

    int[] moon;
    int landingX = 0;
    PImage ship;
    
    PVector pos = new PVector( 150, 20 );
    PVector speed = new PVector( 0, 0 );
    PVector g = new PVector( 0, 1.622 );
    
  2. Now we need to update the position of our ship at every frame, so we add an update() method to our sketch and call...