Month: December 2012

Ideas for Apps – Year 9

We now have some initial designs and ideas for the first apps.

1 – Tic Tac Toe – 3D – a really nice idea.

I have looked at doing it – it should be ok in Processing.  I thought we could have 6 games going at once…  ambitious!

xox

2 – The Helicopter Game – A helicopter flies up and down and tries to avoid objects

3 – A Driving game – with lasers to avoid

4 – A Snake game – maybe with objects or lasers to avoid – excellent idea and should work really well

5 – Epilepsy – a flashing platform game – the player will struggle to get from one side to another – maybe even some monsters!

All great ideas – we’ll do the development in January – hopefully we will have them up on the web by the end of Feb!

Advertisements

How to Detect a Key Press in Processing

This Sketch shows you how to detect a key pressed. Note that in the draw function there is no code for the key. The function “public void keyPressed()” is automatically called when a key is detected. It then stores the key in two variables. key which stores the key character – and keyCode which stores the number. If you want to detect an arrow key use the keyCode variable. See the main functins on how this works.

Great for games that need a keypress


// Simple sketch to show key pressed
int ballx=0;
int bally=0;
int speed=10;

public void setup()
{
    size(600, 600);
    background(0);
}

void draw()
{
  smooth(); 
  background(0);
  ellipse(ballx,bally,20,20);   
}

public void keyPressed()
{
  
    println("Key code pressed: " + keyCode);
    
    if (key == 'w')
    {
      ballUp();
    }
    else if (key == 'z')
    {
        ballDown();
    }
    else if (key == 'a')
    {
        ballLeft();
    }
    else if (key == 's')
    {
        ballRight();
    }
        
}
public void keyReleased()
{
    println("Just to let you know a key has been released");
}

void ballUp()
{
  if ( bally >=0 && bally <= width )
  {
    bally = bally-speed;
  }
}

void ballRight()
{
  if ( ballx >=0 && ballx <= width )
  {
    ballx = ballx+speed;    
  }
}

void ballLeft()
{
  if ( ballx >=0 && ballx <= width )
  {
    ballx = ballx-speed;   
  }
}
void ballDown()
{  
  if ( bally >=0 && bally <= height )
  {
    bally = bally+speed;   
  }
}

GUI Stuff

Simple intro to GUI Builders – use the Examples on the new Processing 2.x to see more


import guicomponents.*;

GButton btnSmile0, btnSmile1,btnControl;

GLabel label;

void setup()
{

    size(480, 540);

  G4P.setColorScheme(this, GCScheme.BLUE_SCHEME);
  G4P.setFont(this, "Verdana", 12);

  G4P.setMouseOverEnabled(true);
  
  btnSmile0 = new GButton(this,"Tytheringon Rocks",50,150,400,70);
  btnSmile0.tag = "Button1";
  
  btnSmile1 = new GButton(this,"Beech Hall Rocks",50,270,400,70);
  btnSmile1.setFont("Verdana", 20, false);
  btnSmile1.tag = "Button2";
  
  //btnControl = new GButton(this, "Open Panel Position Window", 10, 0 - 100,200,30);
}

void handleButtonEvents(GButton button) {
  
  System.out.print(button.tag+"\t\t");
  
  switch(button.eventType){
  case GButton.PRESSED:
    System.out.println("PRESSED");
    break;
  case GButton.RELEASED:
    System.out.println("RELEASED");
    break;
  case GButton.CLICKED:
    System.out.println("CLICKED");
    break;
  default:
    System.out.println("Unknown mouse event");
  }
}  

void draw(){
  background(200);
}