diff --git a/.DS_Store b/.DS_Store index 62ff5c3..971b76f 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/StarterCode/Book.pde b/StarterCode/Book.pde index adaf8c1..56bc1b6 100644 --- a/StarterCode/Book.pde +++ b/StarterCode/Book.pde @@ -6,6 +6,8 @@ class Book { //current page # private int curPageN; private PImage coverImg; + private int page; + private int spot; private Page[] pages; @@ -46,5 +48,16 @@ class Book { public PImage getCoverImg() { return coverImg; } - + public void setPage(int p){ + page = p; + } + public int getPage(){ + return page; + } + public void setSpot(int s){ + spot = s; + } + public int getSpot(){ + return spot; + } } diff --git a/StarterCode/Library.pde b/StarterCode/Library.pde index 4928cee..f979d3f 100644 --- a/StarterCode/Library.pde +++ b/StarterCode/Library.pde @@ -1,11 +1,24 @@ +import java.util.TreeMap; +import java.util.Iterator; +import java.util.Map; + class Library { // is it possible to search? will be determined later but keep it in mind - ArrayList books; + //ArrayList books; + //key is title + TreeMap books; public Library() { - books = new ArrayList(); + books = new TreeMap(); + + // Add one book, which is an instructions manual, so the program doesn't throw an error when generating the library. + Page[] examplePages = {new Page("Access books in your library.", "click on books.png", color(255, 255, 255)), new Page("Switch pages by using the side arrows.", "use the side arrows.png", color(255, 255, 255)), new Page("Return to the library by clicking exit.", "click exit.png", color(255, 255, 255))}; + books.put("User Guide", new Book("User Guide", 3, examplePages, "Centered? User Guide Title.png")); + books.put("User Guide2", new Book("User Guide", 3, examplePages, "Centered? User Guide Title.png")); + books.put("User Guide3", new Book("User Guide", 3, examplePages, "Centered? User Guide Title.png")); spot = 0; columns = 2; + currentPage = 0; buttonColor = color(193, 193, 193); button2Color = color(194, 194, 194); @@ -16,6 +29,7 @@ class Library { buttonClicked = false; button2Clicked = false; + } int spot; int columns; @@ -30,7 +44,7 @@ class Library { boolean buttonClicked; boolean button2Clicked; - public Library(ArrayList books){ + public Library(TreeMap books){ this.books = books; spot = 0; columns = 2; @@ -45,52 +59,50 @@ class Library { buttonClicked = false; button2Clicked = false; } - ArrayList getBooks(){ + TreeMap getBooks(){ return books; } void addBook(Book b){ - books.add(b); + books.put(b.getTitle(), b); } - Book getBook(int bookNumber){ - return books.get(bookNumber); + Book getBook(String bookName) { + return books.get(bookName); } - Book getBookWithName(String bookName) { - for (Book b:books) { - if (b.getTitle().equals(bookName)) { - return b; - } - } - return null; + int getCurrentPage(){ + return currentPage; } //draws the library void drawLibrary(){ + clear(); boolean changed = false; - if(8*spot+80) { fill(253, 253, 253); + triangle(0.07*width, 0.45*height, 0.03*width, 0.5*height, 0.07*width, 0.55*height); if (mousePressed){ color c = get(mouseX, mouseY); if (c == color(253, 253, 253)){ fill(50, 50, 50); - spot+=-1; + spot--; + currentPage--; changed = true; } delay(50); } - triangle(0.07*width, 0.45*height, 0.03*width, 0.5*height, 0.07*width, 0.55*height); - fill(255, 255, 255); } // Your library sign @@ -103,17 +115,122 @@ class Library { // Line across screen at 10% down line(0, (int)((double)height/(double)10), width, (int)((double)height/(double)10)); // Books + int coverWidth = width*285/500; + int coverHeight = height*285/500; + float xPos = width*428/500; + float yPos = height*428/500; + int newHeight = height - (int)((double)height/(double)10); - int xOffset = (int) ((double) 1/2 * (double) (width - (double) 285/columns - (((double) (2*columns-1)*428)/columns))); - int yOffset = (int)((double)height/10) + (int) ((double) 1/2 * (double) (newHeight - (double) 285/columns - (double) (columns-1)* (double) 428/columns)); - for(int i = 0; i < 8 && 8*spot+i < books.size(); i++){ - PImage cover = books.get(8*spot+i).getCoverImg(); - cover.resize(285/columns, 285/columns); - image(cover, xOffset+(i % (2*columns)) * 428/columns, yOffset+(i - (i % (2*columns)))/(2 * columns) * 428/columns); + float xOffset = (float) width/10; + float yOffset = (float)((double)height/10) + (int) ((double) 1/2 * (double) (newHeight - (double) coverHeight/columns - (double) (columns-1)* (double) yPos/columns)); + + // Divide treeMap into 2d array so it can be iterated over. + ArrayList> libraryPages = new ArrayList>(); + ArrayList temporaryList = new ArrayList(); + int it = 0; + for(Map.Entry entry: books.entrySet()) { + temporaryList.add(entry.getValue()); + if (it == 3) { + it = 0; + libraryPages.add(temporaryList); + temporaryList = new ArrayList(); + } + else { + it++; + } + } - if(changed == true){ + if(temporaryList.size() > 0) { + libraryPages.add(temporaryList); + } + //drawing books that belong to spot/page + int bookIterator = 0; + + for(Book b:libraryPages.get(spot)) { + // iterate over treemap for each book. + PImage cover = b.getCoverImg(); + cover.resize(coverWidth/columns, coverHeight/columns); + image(cover, xOffset+(bookIterator % (2)) * xPos/columns, yOffset+(bookIterator - (bookIterator % (2)))/( columns) * yPos/columns); + bookIterator++; + } + + if(changed){ background(0,0,0); drawLibrary(); } + if (mousePressed){ + // top left corner button + ArrayList bookList = new ArrayList(books.values()); + if (mouseX > 78 && mouseX < 214 && mouseY > 99 && mouseY < 241){ + inLibrary = false; + println("top left is pressed"); + /*if (currentPage == 1){ + w.setBook(books.get(0)); + w.drawWindow(); + }*/ + ArrayList topLeftBooks = new ArrayList(); + for (int i = 0; i < bookList.size(); i++){ + if (i % 4 == 0){ + topLeftBooks.add(bookList.get(i)); + } + } + for (int i = 0; i < topLeftBooks.size(); i++){ + println(topLeftBooks.get(i).getTitle()); + } + println ("Current page: " + currentPage); + w.setBook(topLeftBooks.get(currentPage)); + println ("Book: " + topLeftBooks.get(currentPage).getTitle()); + //w.drawWindow(); + inWindow=true; + } + if (mouseX > 289 && mouseX < 427 && mouseY > 99 && mouseY < 241){ + inLibrary = false; + println("top right is pressed"); + ArrayList topRightBooks = new ArrayList(); + for (int i = 0; i < bookList.size(); i++){ + if (i % 4 == 1){ + topRightBooks.add(bookList.get(i)); + } + } + for (int i = 0; i < topRightBooks.size(); i++){ + println(topRightBooks.get(i).getTitle()); + } + w.setBook(topRightBooks.get(currentPage)); + //w.drawWindow(); + inWindow=true; + } + if (mouseX > 78 && mouseX < 214 && mouseY > 314 && mouseY < 453){ + inLibrary = false; + println("bottom left is pressed"); + ArrayList topRightBooks = new ArrayList(); + for (int i = 0; i < bookList.size(); i++){ + if (i % 4 == 2){ + topRightBooks.add(bookList.get(i)); + } + } + for (int i = 0; i < topRightBooks.size(); i++){ + println(topRightBooks.get(i).getTitle()); + } + w.setBook(topRightBooks.get(currentPage)); + //w.drawWindow(); + inWindow=true; + } + if (mouseX > 289 && mouseX < 427 && mouseY > 314 && mouseY < 453){ + inLibrary = false; + println("bottom right is pressed"); + ArrayList topRightBooks = new ArrayList(); + for (int i = 0; i < bookList.size(); i++){ + if (i % 4 == 3){ + topRightBooks.add(bookList.get(i)); + } + } + for (int i = 0; i < topRightBooks.size(); i++){ + println(topRightBooks.get(i).getTitle()); + } + w.setBook(topRightBooks.get(currentPage)); + //w.drawWindow(); + inWindow=true; + } + } } } diff --git a/StarterCode/StarterCode.pde b/StarterCode/StarterCode.pde index 1ef95bb..ac431a1 100644 --- a/StarterCode/StarterCode.pde +++ b/StarterCode/StarterCode.pde @@ -1,33 +1,58 @@ +// Instead of creating a window object with a book, you have a window object and you have a setter that puts in the book later +// Put all visual stuff inside a second method + Library l; Window w; +Book b1; +int currentPage; +public static boolean inLibrary = true; +public static boolean inWindow = false; void setup() { size(500, 500); String cover1 = "Art Example Two.png"; String cover2 = "Art Example Three.png"; - - Page[] p = {new Page("Rush is a Canadian band that averages a score of 7.500.", "pixil-frame-0.png", color(255, 255, 255), "rush.wav"), new Page("This score falls behind Taylor Swift by a full tenth.", "img2.png", color(255, 255, 255), "taylor swift.wav")}; - Book b1 = new Book("Test", 2, p, cover1); - Book b2 = new Book("Test2", 2, p, cover2); + + Page[] p = {new Page("I ran.", "pixil-frame-0.png", color(255, 255, 255)), new Page("I ran2.", "img2.png", color(255, 255, 255))}; + Page[] p2 = {new Page("Text", "Art Example One.png", color(0, 0, 0))}; + b1 = new Book("Test", 2, p, cover1); + Book b2 = new Book("Test2", 1, p2, cover2); + Book b3 = new Book("Test3", 1, p2, cover2); + + w = new Window(); l = new Library(); - w = new Window(b1); + + currentPage = l.getCurrentPage(); + background(0, 0, 0); - for(int i = 0; i<34; i++){ + /*for(int i = 0; i<34; i++){ if( (int)Math.sqrt(i)%2 ==0 ){ l.addBook(b1); }else{ l.addBook(b2); } - } + }*/ + + l.addBook(b1); + l.addBook(b2); + l.addBook(b3); + + + // For now, this is only used to launch the window because it requires a book to be launched. + // This book isn't used otherwise and is not the same as the default book + } void draw() { - if(w.getStay()) { - w.drawWindow(); - } else { - clear(); - l.drawLibrary(); - } + // 78, 99 + // 214, 100 + // 81, 241 + // 221, 239 + //draws the library + if (inLibrary) l.drawLibrary(); + // draws the book + //w.draw(); + if (inWindow) w.drawWindow(); } void mousePressed() { diff --git a/StarterCode/StarterCode7272024301000574194.autosave b/StarterCode/StarterCode7272024301000574194.autosave new file mode 100644 index 0000000..1d740d7 --- /dev/null +++ b/StarterCode/StarterCode7272024301000574194.autosave @@ -0,0 +1,15 @@ +Library l = new Library(new ArrayList()); +PImage coverImage; +PImage coverImage2; +void setup() { + background(0, 0, 0); + size(1000, 500); + coverImage = loadImage("Art Example Three.png"); + coverImage2 = loadImage("Art Example Two.png"); + l.addBook(new Book("La Edad de Oro", new ArrayList(), coverImage)); + l.addBook(new Book("El Presidio PolĂ­tico en Cuba", new ArrayList(), coverImage2)); +} + +void draw() { + l.drawLibrary(); +} diff --git a/StarterCode/Statistics.pde b/StarterCode/Statistics.pde new file mode 100644 index 0000000..64d3c9d --- /dev/null +++ b/StarterCode/Statistics.pde @@ -0,0 +1,25 @@ +class Statistics { + int numPagesRead; + int numBooksRead; + int timePassed; + public Statistics(){ + numPagesRead = 0; + numBooksRead = 0; + timePassed = 0; + } + public int PagesRead(){ + return numPagesRead; + } + public int BooksRead(){ + return numBooksRead; + } + public int TimePassed(){ + return timePassed; + } + public void incrementPages(){ + numPagesRead++; + } + public void incrementBooks(){ + numBooksRead++; + } +} diff --git a/StarterCode/Window.pde b/StarterCode/Window.pde index 45fd0d3..d70c27b 100644 --- a/StarterCode/Window.pde +++ b/StarterCode/Window.pde @@ -9,6 +9,7 @@ class Window { color button2Color; color button2Highlight; + int firstPage; float buttonWidth = width/15; float buttonHeight = height/5; float buttonX = width/50; @@ -19,7 +20,6 @@ class Window { float homeWidth = width/25; float homeHeight = height/25; - boolean hasPlayedFirstSound = false; boolean buttonOver; @@ -34,9 +34,10 @@ class Window { boolean stay; - public Window(Book b) { - l = new Library(); - cBook = b; + Statistics stat = new Statistics(); + + void initialize(Book bs){ + cBook = bs; cPage = cBook.pages[cBook.getCurPage()-1]; buttonColor = color(193, 193, 193); @@ -47,18 +48,17 @@ class Window { buttonOver = false; button2Over = false; - homeOver = false; buttonClicked = false; button2Clicked = false; - homeClicked = false; - - homeIcon = loadImage("homeicon.png"); - - stay = true; } + void drawWindow() { + + homeIcon = loadImage("homeicon.png"); + + stay = true; //displays p's data and cBook's title //p's data is the text and image //button2X-width/25 @@ -75,7 +75,9 @@ class Window { // play first sound if (!hasPlayedFirstSound) { hasPlayedFirstSound = true; - cPage.getAudio().startSound(); + if (cPage.getAudio() != null) { + cPage.getAudio().startSound(); + } } //title text surface.setTitle("Book: "+cBook.getTitle()); @@ -97,12 +99,12 @@ class Window { } if(cBook.getCurPage() == cBook.getTotalPages()) { forward = false; + stat.numBooksRead++; } - //displaying buttons stroke(0, 0, 0); fill(192, 192, 192); - if(back) { + if(back) { //<>// if(!buttonClicked) { fill(buttonColor); triangle(buttonX, buttonY+(buttonHeight/2), buttonX+buttonWidth, buttonY+buttonHeight, buttonX+buttonWidth, buttonY); @@ -132,8 +134,15 @@ class Window { update(); } + void setBook(Book book){ + cBook = book; + initialize(book); + } + Book getBook(){ + return cBook; + } - void mousePressed() { + void mousePressed() { //<>// if(buttonOver) { buttonClicked = true; } else { //<>// @@ -156,13 +165,17 @@ class Window { homeClicked = false; if(buttonOver) { updatePage(0); + stat.numPagesRead--; } if(button2Over) { updatePage(1); + stat.numPagesRead++; } if(homeOver) { //have functionality to return to library //l.drawLibrary(); + inLibrary = true; + inWindow = false; stay = false; } } @@ -187,7 +200,12 @@ class Window { cBook.pages[cBook.getCurPage() - 1].playSound(); } } - + public int ReadPages(){ + return stat.PagesRead(); + } + public int ReadBooks(){ + return stat.BooksRead(); + } void update() { if(get(mouseX, mouseY) == buttonColor || get(mouseX, mouseY) == buttonHighlight) { buttonOver = true; @@ -210,4 +228,5 @@ class Window { boolean getStay() { return stay; } + } diff --git a/StarterCode/data/Centered? User Guide Title.png b/StarterCode/data/Centered? User Guide Title.png new file mode 100644 index 0000000..1b86351 Binary files /dev/null and b/StarterCode/data/Centered? User Guide Title.png differ diff --git a/StarterCode/data/click exit.png b/StarterCode/data/click exit.png new file mode 100644 index 0000000..f843f73 Binary files /dev/null and b/StarterCode/data/click exit.png differ diff --git a/StarterCode/data/click on books.png b/StarterCode/data/click on books.png new file mode 100644 index 0000000..ec650a1 Binary files /dev/null and b/StarterCode/data/click on books.png differ diff --git a/StarterCode/data/use the side arrows.png b/StarterCode/data/use the side arrows.png new file mode 100644 index 0000000..7ffb577 Binary files /dev/null and b/StarterCode/data/use the side arrows.png differ