Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.sound.*;
- char[][] disp;
- int wsx = 100;
- int wsy = 100;
- int ts = 16;
- int px = 15;
- int py = 15;
- boolean right = true;
- String status = "";
- int statuschar = 0;
- SoundFile[] audio;
- boolean haskey = false;
- int spos = 0;
- int counter = 0;
- boolean gamestate = true;
- int sel = 0;
- Enemy[] e;
- int scalls = 0;
- int rooms;
- ArrayList<String> menu;
- boolean hardmode = false;
- int coins = 0;
- int[] inv; //1 = Boulders 2 = Potions
- boolean hasboulder = false;
- boolean haspotion = false;
- void setup() {
- hasboulder = false;
- haspotion = false;
- rooms = 0;
- coins = 0;
- scalls++;
- wsx = width/16;
- wsy = height/16;
- disp = new char[wsx][wsy];
- menu = new ArrayList<String>();
- for(int i = 0; i < wsx; i++) {
- for(int j = 0; j < wsy; j++) {
- disp[i][j] = ' ';
- }
- }
- menu.add("Play");
- menu.add("Options");
- menu.add("Credits");
- e = new Enemy[2];
- audio = new SoundFile[3];
- audio[0] = new SoundFile(this, "talk.wav");
- audio[1] = new SoundFile(this, "music.mp3");
- audio[2] = new SoundFile(this, "coin.wav");
- if(scalls == 1) {
- PImage titlebaricon = loadImage("icon.png");
- surface.setIcon(titlebaricon);
- }
- clearDisp();
- for(int i = 10; i < 33; i++) {
- disp[i][10] = '#';
- }
- for(int i = 10; i < 20; i++) {
- disp[10][i] = '#';
- }
- for(int i = 10; i < 33; i++) {
- disp[i][20] = '#';
- }
- for(int i = 10; i < 21; i++) {
- disp[32][i] = '#';
- }
- for(int i = 10; i < 21; i++) {
- disp[21][i] = '#';
- }
- disp[21][15] = 'D';
- changeRoom(false);
- }
- void settings() {
- size(700, 600);
- }
- void draw() {
- //println(audio[1].isPlaying());
- if((counter)%ceil(audio[1].frames()/600) == 1) {
- audio[1].play();
- }
- background(0);
- fill(255);
- textSize(ts);
- for(int i = 0; i < wsx; i++) {
- for(int j = 0; j < wsy; j++) {
- fill(255);
- if(disp[i][j] == '#') {
- fill(130, 74, 13);
- }
- if(disp[i][j] == 'D') {
- fill(191, 74, 13);
- }
- if(disp[i][j] == '▲') {
- fill(15, 255, 255);
- }
- if(disp[i][j] == '♣') {
- fill(0, 255, 0);
- }
- if(disp[i][j] == 'B') {
- fill(128);
- }
- if(disp[i][j] == '☻') {
- fill(255, 255, 0);
- }
- if(disp[i][j] == 'K') {
- fill(255, 255, 0);
- if(counter%20 >= 15) {
- fill(255);
- }
- }
- if(disp[i][j] == '♦') {
- fill(255, 255, 0);
- if(counter%20 >= 15) {
- fill(255);
- }
- }
- if(disp[i][j] == '=') {
- fill(255, 0, 0);
- disp[i+1][j] = '-';
- }
- if(disp[i][j] == '▒') {
- fill(0, 0, 255);
- }
- if(disp[i][j] == '>') {
- fill(255, 0, 0);
- }
- if(disp[i][j] == '<') {
- fill(255, 0, 0);
- }
- if(disp[i][j] == '^') {
- fill(255, 0, 0);
- }
- if(disp[i][j] == 'v') {
- fill(255, 0, 0);
- }
- if(disp[i][j] == '-') {
- fill(255, 0, 0);
- if(disp[i+1][j] != '#' && disp[i+1][j] != 'B') {
- disp[i+1][j] = '-';
- }
- int k = i;
- boolean t = false;
- while(true) {
- if(disp[k][j] == '=') {
- t = true;
- break;
- }
- if(disp[k][j] == 'B') {
- t = false;
- break;
- }
- k--;
- if(k <= 0) {
- break;
- }
- }
- if(!t) {
- disp[i][j] = ' ';
- }
- }
- if(!(i == px && j == py)) {
- text(disp[i][j], i*ts, j*ts);
- }
- }
- }
- if(!gamestate) {
- counter++;
- for(int i = 0; i < e.length; i++) {
- if(e[i] != null) {
- e[i].render();
- }
- }
- if(counter < 5) {
- clearDisp();
- for(int i = 10; i < 33; i++) {
- disp[i][10] = '#';
- }
- for(int i = 10; i < 20; i++) {
- disp[10][i] = '#';
- }
- for(int i = 10; i < 33; i++) {
- disp[i][20] = '#';
- }
- for(int i = 10; i < 21; i++) {
- disp[32][i] = '#';
- }
- for(int i = 10; i < 21; i++) {
- disp[21][i] = '#';
- }
- disp[21][15] = 'D';
- changeRoom(false);
- }
- if(counter == 80) {
- addStatus("Where am I?");
- }
- if(counter == 260) {
- addStatus("I should go to the door");
- }
- if(counter == 500) {
- addStatus("wasd or arrow keys to move");
- }
- if(statuschar < status.length()) {
- if(statuschar < wsx) {
- disp[statuschar][1] = status.charAt(statuschar);
- } else {
- disp[statuschar-wsx][2] = status.charAt(statuschar);
- }
- }
- if(counter%5 == 1) {
- statuschar++;
- if(statuschar < status.length() && !status.equals("")) {
- audio[0].play();
- }
- if(statuschar == status.length()+4) {
- if(status.equals("The door is locked") && spos == 0) {
- addStatus("Hmm... is that a key (K) over there?");
- spos = 1;
- }
- if(status.equals("You got the key") && spos == 1) {
- addStatus("That'll be useful for that door...");
- spos = 2;
- }
- if(status.equals("You used the key") && spos == 2) {
- addStatus("Is that a laser? Maybe I can block it with the boulders (B)");
- spos = 3;
- }
- }
- }
- String k = "Rooms: "+rooms;
- centerText(k,36);
- centerText("♦"+coins, 35);
- String t = "";
- if(hasboulder) t += "Boulder | ✓ "; else t += "Boulder | X ";
- if(haspotion) t += "Potion | ✓"; else t += "Potion | X";
- centerText(t, 34);
- fill(0, 255, 128);
- text('@', px*ts, py*ts);
- if(disp[px][py] == 'D') {
- if(right) {
- px++;
- right = !right;
- } else {
- px--;
- right = !right;
- }
- changeRoom(true);
- disp[px][py] = ' ';
- rooms++;
- }
- if(disp[px][py] == '-') {
- px = 15;
- py = 15;
- right = true;
- setup();
- }
- if(disp[px][py] == '>' || disp[px][py] == '^' || disp[px][py] == '<' || disp[px][py] == 'v') {
- px = 15;
- py = 15;
- right = true;
- setup();
- }
- if(disp[px][py] == '♦') {
- disp[px][py] = ' ';
- coins++;
- audio[2].play();
- }
- } else {
- clearDisp();
- centerText("TwoRoomRogue", 10);
- for(int i = 0; i < menu.size(); i++) {
- centerText(menu.get(i), 12+i);
- if(i == sel) {
- centerText("["+menu.get(i)+"]", 12+i);
- }
- }
- }
- }
- void keyPressed() {
- if(!gamestate) {
- int npx = px;
- int npy = py;
- int dir = 0; //1 = up 2 = down 3 = left 4 = right
- if(key == 'w') {
- npy--;
- dir = 1;
- }
- if(key == 's') {
- npy++;
- dir = 2;
- }
- if(key == 'a') {
- npx--;
- dir = 3;
- }
- if(key == 'd') {
- npx++;
- dir = 4;
- }
- if(keyCode == UP) {
- npy--;
- dir = 1;
- }
- if(keyCode == DOWN) {
- npy++;
- dir = 2;
- }
- if(keyCode == LEFT) {
- npx--;
- dir = 3;
- }
- if(keyCode == RIGHT) {
- npx++;
- dir = 4;
- }
- boolean say = true;
- if(key == ENTER) {
- say = false;
- if(disp[px][py] == '.') {
- if(!hasboulder) {
- if(coins >= 1) {
- coins -= 1;
- addStatus("You bought the boulder. Press B to deploy");
- hasboulder = true;
- } else {
- addStatus("Not enough coins");
- }
- } else {
- addStatus("You already have a boulder");
- }
- }
- if(disp[px][py] == ',') {
- if(!haspotion) {
- if(coins >= 4) {
- coins -= 4;
- addStatus("You bought the potion. Press P to deploy");
- haspotion = true;
- } else {
- addStatus("Not enough coins");
- }
- } else {
- addStatus("You already have a boulder");
- }
- }
- }
- if(key == 'b') {
- if(hasboulder) {
- if(disp[px-1][py] == ' ') {
- disp[px-1][py] = 'B';
- addStatus("You placed the boulder");
- hasboulder = false;
- }
- }
- }
- if(key == 'p') {
- if(haspotion) {
- if(disp[px-1][py] == '^' || disp[px-1][py] == 'v' || disp[px-1][py] == '>' || disp[px-1][py] == '<') {
- disp[px-1][py] = ' ';
- addStatus("You used the potion.");
- haspotion = false;
- }
- }
- }
- if(key == 'f') {
- counter += 500;
- }
- if(counter < 500) {
- npx = px;
- npy = py;
- }
- if(disp[npx][npy] != '#' && disp[npx][npy] != '♣' && disp[npx][npy] != 'D' && disp[npx][npy] != '▲' && disp[npx][npy] != 'B' && disp[npx][npy] != '=' && disp[npx][npy] != '▒') {
- px = npx;
- py = npy;
- }
- if(disp[npx][npy] == 'K') {
- haskey = true;
- disp[npx][npy] = ' ';
- addStatus("You got the key");
- }
- if(disp[npx][npy] == 'D') {
- if(haskey == false) {
- addStatus("The door is locked");
- } else {
- px = npx;
- py = npy;
- addStatus("You used the key");
- haskey = false;
- }
- }
- if(disp[npx][npy] == '.') {
- if(say) addStatus("Boulder. They cost 1♦ each. Press B to deploy [They're always placed to the left]");
- }
- if(disp[npx][npy] == ',') {
- if(say) addStatus("Death Potion. They cost 4♦ each. Press P to deploy [Kills enemy to the left]");
- }
- if(disp[npx][npy] == 'B') {
- boolean k = false;
- switch(dir) {
- case 1:
- if(disp[npx][npy-1] == ' ' || disp[npx][npy-1] == '-') {
- disp[npx][npy-1] = 'B';
- k = true;
- }
- break;
- case 2:
- if(disp[npx][npy+1] == ' ' || disp[npx][npy+1] == '-') {
- disp[npx][npy+1] = 'B';
- k = true;
- }
- break;
- case 3:
- if(disp[npx-1][npy] == ' ' || disp[npx-1][npy] == '-') {
- disp[npx-1][npy] = 'B';
- k = true;
- }
- break;
- case 4:
- if(disp[npx+1][npy] == ' ' || disp[npx+1][npy] == '-') {
- disp[npx+1][npy] = 'B';
- k = true;
- }
- break;
- }
- if(k == true) {
- px = npx;
- py = npy;
- }
- disp[px][py] = ' ';
- if(k == true) {
- disp[npx][npy] = ' ';
- }
- }
- } else {
- if(keyCode == UP) {
- sel--;
- if(sel < 0) {
- sel = 0;
- }
- }
- if(keyCode == DOWN) {
- sel++;
- if(sel > menu.size()-1) {
- sel = 1;
- }
- }
- if(key == ENTER) {
- if(menu.get(sel).equals("Play")) {
- gamestate = !gamestate;
- }
- if(menu.get(sel).equals("Back")) {
- String[] m = {"Play","Options","Credits"};
- setMenu(m);
- }
- if(menu.get(sel).equals("Options")) {
- String[] m = {"???", "Warning: Hardmode is buggy", "Back"};
- if(hardmode) {
- m[0] = "Disable hardmode";
- } else {
- m[0] = "Enable hardmode";
- }
- setMenu(m);
- } else
- if(menu.get(sel).equals("Enable hardmode")) {
- hardmode = true;
- String[] m = {"Play","Options","Credits"};
- setMenu(m);
- } else
- if(menu.get(sel).equals("Disable hardmode")) {
- hardmode = false;
- String[] m = {"Play","Options","Credits"};
- setMenu(m);
- } else
- if(menu.get(sel).equals("Credits")) {
- String[] m = {"TheZipCreator | Coding","Gil H. Steinberg | Music", "Back"};
- setMenu(m);
- }
- }
- }
- }
- void changeRoom(boolean lasers) {
- int rx = 0;
- int ry = 0;
- if(right) {
- rx = 11;
- ry = 10;
- } else {
- rx = 22;
- ry = 10;
- }
- if(random(10) < 9) {
- int roomType = floor(random(3));
- if(roomType == 0) {
- for(int i = rx; i < rx+9; i++) {
- for(int j = ry+1; j < ry+10; j++) {
- disp[i][j] = ' ';
- if(random(1) < 0.1) {
- disp[i][j] = '♣';
- }
- }
- }
- }
- if(roomType == 1) {
- for(int i = rx; i < rx+9; i++) {
- for(int j = ry+1; j < ry+10; j++) {
- disp[i][j] = ' ';
- if(random(1) < 0.1) {
- disp[i][j] = '▲';
- }
- }
- }
- }
- if(roomType == 2) {
- for(int i = rx; i < rx+9; i++) {
- for(int j = ry+1; j < ry+10; j++) {
- disp[i][j] = ' ';
- if(random(1) < 0.1) {
- disp[i][j] = '▒';
- }
- }
- }
- }
- if(lasers) {
- int ly = floor(random(ry+1,ry+10));
- while(ly == 15) {
- ly = floor(random(ry+1,ry+10));
- }
- int l2y = 0;
- if(hardmode) {
- l2y = floor(random(ry+1,ry+10));
- while(l2y == 15) {
- ly = floor(random(ry+1,ry+10));
- }
- disp[rx][l2y] = '=';
- }
- disp[rx][ly] = '=';
- disp[floor(random(rx+1,rx+9))][floor(random(ry+1,ry+10))] = 'B';
- disp[floor(random(rx+1,rx+9))][floor(random(ry+1,ry+10))] = 'B';
- e[0] = new Enemy(floor(random(rx+1,rx+9)),floor(random(ry+1,ry+10)),1);
- e[1] = new Enemy(floor(random(rx+1,rx+9)),floor(random(ry+1,ry+10)),2);
- int ky = floor(random(ry+1,ry+10));
- if(!hardmode) {
- while(ky == ly) {
- ky = floor(random(ry+1,ry+10));
- println("d"+random(1));
- }
- } else {
- while(ky == ly || ky == l2y) {
- ky = floor(random(ry+1,ry+10));
- println("d"+random(1));
- }
- }
- disp[floor(random(rx+1,rx+9))][ky] = 'K';
- } else {
- disp[floor(random(rx+1,rx+9))][floor(random(ry+1,ry+10))] = 'K';
- }
- if(rooms%2 == 1) {
- int numcoins = floor(random(1,4));
- for(int i = 0; i < numcoins; i++) {
- disp[floor(random(rx+1,rx+9))][floor(random(ry+1,ry+10))] = '♦';
- }
- }
- } else {
- if(lasers) {
- println("ttt");
- addStatus("You have entered a shop. Press ENTER to order an item while under it");
- for(int i = rx; i < rx+9; i++) {
- for(int j = ry+1; j < ry+10; j++) {
- disp[i][j] = ' ';
- }
- }
- disp[rx][ry+3] = '=';
- disp[rx+4][ry+1] = '☻';
- disp[rx][ry+4] = 'K';
- disp[rx+2][ry+2] = 'B';
- disp[rx+6][ry+2] = '▲';
- disp[rx+2][ry+4] = '.';
- disp[rx+6][ry+4] = ',';
- for(int i = 0; i < e.length; i++) {
- e[i] = null;
- }
- } else {
- disp[rx][ry+4] = 'K';
- }
- }
- }
- void addStatus(String t) {
- for(int i = 0; i < wsx; i++) {
- disp[i][1] = ' ';
- }
- for(int i = 0; i < wsx; i++) {
- disp[i][2] = ' ';
- }
- status = t;
- statuschar = 0;
- }
- void centerText(String c, int o) {
- int i = (43/2)-(c.length()/2);
- for(int j = 0; j < c.length(); j++) {
- disp[i+j][o] = c.charAt(j);
- }
- }
- void clearDisp() {
- for(int i = 0; i < wsx; i++) {
- for(int j = 0; j < wsy; j++) {
- disp[i][j] = ' ';
- }
- }
- }
- void setMenu(String[] m) {
- sel = 0;
- menu = new ArrayList<String>();
- for(int i = 0; i < m.length; i++) {
- menu.add(m[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement