beta exhibition & some quests. 8bit game
in
Programming Questions
•
1 year ago
Is a defender game searching for information against twitter. It search active for tweets containing keywords like 2012 and search in those results after END n such. It converts tweets into comets that spawns randomly outside the sketch, aimin at the center..
Your job as starfleet captain commander Buck is to save the earthlings against confusion AND mass destruction.
Achieve this by crashing your spaceship into every comet possible...
It's working but need som few tweaks and a mutch cleaner code.
1:
How do I make the comets "lag" their way towards earth?
(as In old 8 bit "grid"-games and as in;" low frame rate", like the movement of the spaceship in this sketch)
Can i fake it in some kind of way?
2:
Please look it thru and se if you find any superbig mistakes (exept the "press H for help"- loop, that's under construction).
- //import liberaries
- import ddf.minim.*;
- import ddf.minim.signals.*;
- import ddf.minim.analysis.*;
- import ddf.minim.effects.*;
- PImage gameover;
- PImage skull;
- PImage jorden;
- PImage heart;
- import simpleML.*;
- int e = 0;
- //boolean showComet;
- ArrayList kometer = new ArrayList();
- int y = 0;
- int x = 0;
- int douche = 0;
- int i1 = 503;
- int i2 = 245;
- int i3 = 62;
- int i = 0;
- int rx = 100;
- int ry = 50;
- int hp = 10;
- int kills = 0;
- int sqx = 500;
- int sqy = 250;
- int sqr = 20;
- komet k;
- PFont Font;
- XMLRequest xmlRequest;
- int startTime; // for the timer to make request ever N seconds
- String html = ""; // String to hold data from request
- import ddf.minim.*;
- Minim minim;
- AudioPlayer groove;
- void setup() {
- // Music
- minim = new Minim(this);
- groove = minim.loadFile("test_rymd2.mp3", 512);
- groove.loop();
- // Creating and starting the request
- xmlRequest = new XMLRequest(this, "http://search.twitter.com/search.rss?q=2012");
- xmlRequest.makeRequest();
- size(height = 1000, width = 500);
- smooth();
- //showComet = true;
- }
- void draw() {
- background(0);
- ellipse(i1, i2, i3*2, i3*2);
- fill(255, 255, 255);
- // Every 5 seconds, make a new request
- int now = millis();
- if (now - startTime > 5000) {
- xmlRequest.makeRequest();
- println("Making request!");
- startTime = now;
- }
- jorden = loadImage("earth.png"); //Bilden
- imageMode(CENTER);
- image(jorden, 500, 250);
- for (int i = 0; i < kometer.size(); i++) {
- komet k = (komet)kometer.get(i);
- k.smart();
- }
- Font = loadFont("PressStartK-25.vlw"); //text corners
- textFont(Font, 25);
- text(hp, 15, 40);
- text("H=help", 835, 485);
- text(kills, 150, 40);
- // text(kills, 15, 485);
- heart = loadImage("heart2.png"); //hp heart
- imageMode(CENTER);
- image(heart, 90, 29);
- skull = loadImage("skull.png"); //hp heart
- imageMode(CENTER);
- image(skull, 220, 28);
- // image(skull, 80, 475);
- fill(255, 255, 255);
- if (hp < 5) {
- fill(255, 255, 0);
- }
- if (hp < 2) {
- fill(255, 0, 0);
- }
- if (hp < 1) {
- gameover = loadImage("gameover.png");
- imageMode(CENTER);
- image(gameover, 500, 250);
- // groove = minim.loadFile("gameover2.mp3", 512);
- // groove.loop(0);
- }
- jorden = loadImage("ship10.png"); //Bilden
- imageMode(CENTER);
- image(jorden, sqx, sqy);
- // ellipse(sqx,sqy,sqr*2,sqr*2);
- if (sqx > 980) {
- sqx = 980;
- }
- if (sqy < 20) {
- sqy = 20;
- }
- if (sqx < 20) {
- sqx = 20;
- }
- if (sqy > 480) {
- sqy = 480;
- }
- }
- void stop() {
- groove.close();
- minim.stop();
- super.stop();
- }
- // When the request is complete
- void netEvent(XMLRequest ml) {
- // Retrieving an array of all XML elements inside "<title*>" tags
- String[] headlines = ml.getElementArray("title");
- for (int i = 0; i < headlines.length; i++) {
- // println(headlines[i]);
- }
- for (String html: headlines) {
- if (html.toLowerCase().contains("end")) {
- douche++;
- println(douche);
- switch ((int) random(4)) {
- case 0:
- // top edge
- k = new komet( random(width), -10 );
- break;
- case 1:
- // right edge
- k = new komet( width+10, random(height) );
- break;
- case 2:
- // left edge
- k = new komet( -10, random(height) );
- break;
- case 3:
- // bot edge
- k = new komet( random(width), height+10 );
- break;
- }
- kometer.add(k);
- }
- }
- }
- void keyPressed() {
- if (keyPressed);
- if (key == ('r') && (hp <= 10)) {
- hp = 10;
- kills = 0;
- println("RESTART");
- }
- if (key == CODED) { //Gamepad
- if (keyCode == RIGHT) {
- sqx = sqx + 10;
- }
- if (keyCode == LEFT) {
- sqx = sqx - 10;
- }
- if (keyCode == UP) {
- sqy = sqy - 10;
- }
- if (keyCode == DOWN) {
- sqy = sqy + 10;
- }
- }
- if (key == 'h') { //////////////HELP ME HERE
- Font = loadFont("PressStartK-12.vlw");
- textFont(Font, 12);
- text(" A info-defender game, searching active \n for tweets containing keywords like 2012 / END \n & spawn thoose as comets. Your job as \n starfleet captain BUCK is to defend earth \n against confusion. \n \n R = restart \n arrows = move ", 410, 30);
- println("HELP");
- }
- }
KOMET CLASS
- PImage kometen;
- PImage jorden2;
- PFont Font2;
- class komet {
- int a = 15;
- int b = 15;
- float x = 0;
- float y = 0;
- float komet1, komet2;
- boolean show = true;
- komet(float _x, float _y) {
- x = _x;
- y = _y;
- float speed = 2;
- float ang = atan2(height/2-y, width/2-x);
- komet1 = cos(ang)*speed;
- komet2 = sin(ang)*speed;
- }
- void movement() {
- x +=komet1;
- y +=komet2;
- }
- void kometer() {
- if (show) {
- kometen = loadImage("komet5.png");
- imageMode(CENTER);
- image(kometen, x, y);
- }
- }
- void collision() {
- if (show) {
- if ( dist(x, y, i1, i2) < i3) {
- groove = minim.loadFile("hithit_earth.mp3", 512);
- groove.loop(0);
- show = false;
- println("HIT"); //Räknar träffar
- hp--;
- rx--;
- kometen = loadImage("testar3.png");
- imageMode(CENTER);
- image(kometen, x, y);
- }
- if ( dist(x, y, sqx, sqy) < sqr) {
- groove = minim.loadFile("hit_comet.mp3", 512);
- groove.loop(0);
- show = false;
- kills++;
- kometen = loadImage("testar3.png");
- imageMode(CENTER);
- image(kometen, x, y);
- }
- }
- }
- void smart() {
- movement();
- kometer();
- collision();
- }
- }
>>>>
<<<<>>>>
<<<<
erase all that belong so minim lib and all mp3's and change font, if you want to test it and the speedyshare timed out... all images found above
1