Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ddf.minim.*;
- import gifAnimation.*;
- import processing.serial.*;
- Minim minim;
- class State {
- void State (){}
- void logic(){}
- void draw(){}
- }
- State currentState;
- GameState gameState;
- MenuState menuState;
- // Assets
- PImage img, bg, flare;
- AudioPlayer shootSound;
- PFont font;
- Gif heart;
- // Serial
- String serial;
- Serial port;
- // Game variables
- int gameStart;
- int points;
- int lastPoint;
- int lives;
- int starttime;
- int end = 10;
- int deadBird = 0;
- // Mouse variables
- float cursorX = 0;
- float cursorY = 0;
- float skott = 1;
- boolean joystickEnabled = true;
- void setup() {
- size(600,600);
- frameRate(60);
- minim = new Minim(this);
- // Setting up serial joystick
- try{
- port = new Serial(this, Serial.list()[0], 9600);
- port.clear();
- serial = port.readStringUntil(end);
- serial = null;
- }
- catch (Exception e){
- print("Could not initialize serial");
- joystickEnabled = false;
- }
- // Loading assets
- img = loadImage("sikte.png");
- bg = loadImage("landscape.png");
- flare = loadImage("flare.png");
- shootSound = minim.loadFile("gunshot.wav");
- font = createFont("Arial",24,true);
- textFont(font,24);
- // Loading states
- menuState = new MenuState();
- gameState = new GameState();
- currentState = menuState;
- }
- void draw () {
- background(bg);
- fill(0);
- input();
- currentState.logic();
- currentState.draw();
- }
- void input() {
- // Joystick input
- if (joystickEnabled){
- while (port.available() > 0 ) {
- serial = port.readStringUntil(end);
- }
- String[] a = split(serial, ',');
- String x = a[0];
- String y = a[1];
- String z = a[2];
- println(x);
- println(y);
- println(z);
- float xpos = new Float(x);
- float ypos = new Float(y);
- skott = new Float(z);
- cursorX = map(ypos, 0, 1023, 550, 0);
- cursorY = map(xpos,0,1023,420,0);
- }
- else {
- cursorX = mouseX-25;
- cursorY = mouseY-25;
- }
- }
- void mousePressed() {
- skott = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement