public void update() { GameFigure f; synchronized (figures) { for (int i = 0; i < figures.size(); i++) { f = (GameFigure) figures.get(i); f.update(); } } }
public void gameRender() { if (dbImage == null) { dbImage = createImage(PWIDTH, PHEIGHT); if (dbImage == null) { System.out.println("dbImage is null"); return; } else { graphics = dbImage.getGraphics(); } } graphics.clearRect(0, 0, GamePanel.PWIDTH, GamePanel.PHEIGHT); synchronized (gameData.figures) { GameFigure f; for (int i = 0; i < gameData.figures.size(); i++) { f = (GameFigure) gameData.figures.get(i); f.render(graphics); } } }
public void update() { // ----------------------------------------------------------------------------- // a little collision test for the playable ship and another instance of the ship // when the ship collides the weapon level state will increment // the player ship's weapon level state 9/15/2015 // uses the figures arraylist until an item class is created // ----------------------------------------------------------------------------- // TempShip ship = (TempShip) this.figures.get(0); Ship currentShip = (Ship) this.ships.get(0); // set to 4 for the time being, make a new arraylist for the enemies // TempShip ship = (TempShip) this.figures.get(0); try { for (int i = 0; i < this.figures.size(); i++) { // Rectangle[] hit = ship.getHitBox(); Rectangle hit = currentShip.getShipHitBox(); Ship asdf = (Ship) this.figures.get(i); if (hit.intersects(asdf.getShipHitBox())) { items.add( (Item) weaponMaker.getWeapon( "KINETIC", randomize(asdf.getXofMissileShoot(), 100), randomize(asdf.getYofMissileShoot(), 100))); items.add( (Item) weaponMaker.getWeapon( "KINETIC", randomize(asdf.getXofMissileShoot(), 100), randomize(asdf.getYofMissileShoot(), 100))); items.add( (Item) weaponMaker.getWeapon( "KINETIC", randomize(asdf.getXofMissileShoot(), 100), randomize(asdf.getYofMissileShoot(), 100))); items.add( (Item) weaponMaker.getWeapon( "KINETIC", randomize(asdf.getXofMissileShoot(), 100), randomize(asdf.getYofMissileShoot(), 100))); items.add( (Item) weaponMaker.getWeapon( "KINETIC", randomize(asdf.getXofMissileShoot(), 100), randomize(asdf.getYofMissileShoot(), 100))); items.add( (Item) weaponMaker.getWeapon( "KINETIC", randomize(asdf.getXofMissileShoot(), 100), randomize(asdf.getYofMissileShoot(), 100))); items.add( (Item) weaponMaker.getWeapon( "KINETIC", randomize(asdf.getXofMissileShoot(), 100), randomize(asdf.getYofMissileShoot(), 100))); items.add( (Item) weaponMaker.getWeapon( "KINETIC", randomize(asdf.getXofMissileShoot(), 100), randomize(asdf.getYofMissileShoot(), 100))); items.add( (Item) weaponMaker.getWeapon( "KINETIC", randomize(asdf.getXofMissileShoot(), 100), randomize(asdf.getYofMissileShoot(), 100))); // asdf.x = 100000; // ship.setShipState(STATE_DONE); this.figures.remove(asdf); // currentShip.setLevelState(currentShip.getLevelState()); } } // checks for collision between items and the ship. If collision is // detected then it either changes the ships weapon in increments the // weapon level 9/23/15 for (int i = 0; i < this.items.size(); i++) { // Rectangle[] hit = currentShip.getShipHitBox(); Rectangle hit = currentShip.getShipHitBox(); // System.out.println(this.items.size()); Item item = (Item) this.items.get(i); if (hit.intersects(item.getRectangle1())) { int itemReference = item.getItemType(); int shipWeaponReference = currentShip.getWeaponState(); if (itemReference == shipWeaponReference) currentShip.setLevelState(currentShip.getLevelState()); else if (itemReference >= 0 && itemReference <= 2) { currentShip.setWeaponState(itemReference); currentShip.setLevelState(BASE_LEVEL); } this.items.remove(item); } } System.out.println("weapon state is " + currentShip.getWeaponState()); } catch (java.lang.ClassCastException e) { // System.out.println("missile"); } // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- List<GameFigure> removeGameFigures = new ArrayList<GameFigure>(); GameFigure f; synchronized (figures) { for (int i = 0; i < figures.size(); i++) { f = figures.get(i); f.update(); if (f.getState() == GameFigure.STATE_DONE) { removeGameFigures.add(f); } } figures.removeAll(removeGameFigures); } List<Ship> removeShips = new ArrayList<Ship>(); Ship s; synchronized (ships) { for (int i = 0; i < ships.size(); i++) { s = ships.get(i); s.update(); if (s.getState() == Ship.STATE_FINISHED) { removeShips.add(s); } } ships.removeAll(removeShips); } // added new items list to find and remove objects 9/23/15 List<Item> removeItems = new ArrayList<Item>(); Item it; synchronized (items) { for (int i = 0; i < items.size(); i++) { it = items.get(i); it.update(); if (it.getState() == Item.STATE_DONE) removeItems.add(it); } } items.removeAll(removeItems); }
public void update() { if (this.mode == GameData.MODE_LOAD) { if (!this.fieldLoaded) { synchronized (this.field) { this.field.loadField("Level_One"); // FieldReader reader = new FieldReader("FieldTest1"); // // Start start = reader.getStart(); // int xStart = GamePanel.SECTION_WIDTH * start.x; // int yStart = GamePanel.SECTION_HEIGHT * start.y; // this.field[start.x][start.y] = new FieldSection(xStart, yStart, // true); // // ArrayList<HorizontalRun> hRuns = reader.getHorizontalRuns(); // for(HorizontalRun run : hRuns){ // for(int i = run.xBegin; i <= run.xEnd; i++){ // int xOffset = GamePanel.SECTION_WIDTH * i; // int yOffset = GamePanel.SECTION_HEIGHT * run.y; // // this.field[i][run.y] = new FieldSection(xOffset, yOffset, // true); // } // } // // ArrayList<VerticalRun> vRuns = reader.getVerticalRuns(); // for(VerticalRun run : vRuns){ // for(int i = run.yBegin; i <= run.yEnd; i++){ // int xOffset = GamePanel.SECTION_WIDTH * run.x; // int yOffset = GamePanel.SECTION_HEIGHT * i; // // this.field[run.x][i] = new FieldSection(xOffset, yOffset, // true); // } // } // // for(int x = 0; x < this.field.length; x++){ // for(int y = 0; y < this.field[x].length; y++){ // if(this.field[x][y] == null){ // int xOffset = GamePanel.SECTION_WIDTH * x; // int yOffset = GamePanel.SECTION_HEIGHT * y; // // this.field[x][y] = new FieldSection(xOffset, yOffset, // false); // } // } // } } this.fieldLoaded = true; this.tank.setStart(this.field.getStartPoint()); } this.mode = GameData.MODE_PLAY; // synchronized (this.lines){ // int numHorizontal = GamePanel.HEIGHT / GamePanel.SECTION_HEIGHT + 1; // int numVertical = GamePanel.WIDTH / GamePanel.SECTION_WIDTH + 1; // // int linex1, linex2, liney1, liney2; // Color lineColor = Color.BLACK; // // if(this.lines.size() < numHorizontal){ // linex1 = 0; // linex2 = GamePanel.WIDTH; // liney1 = GamePanel.HEIGHT - this.lines.size() * // GamePanel.SECTION_HEIGHT; // liney2 = liney1; // // this.lines.add(new Line(linex1, liney1, linex2, liney2, lineColor)); // } // else if(this.lines.size() - numHorizontal < numVertical){ // liney1 = 0; // liney2 = GamePanel.HEIGHT; // linex1 = GamePanel.WIDTH - (this.lines.size() - numHorizontal) * // GamePanel.SECTION_WIDTH; // linex2 = linex1; // // this.lines.add(new Line(linex1, liney1, linex2, liney2, lineColor)); // } // else{ // this.mode = GameData.MODE_PLAY; // } // } } else { synchronized (this.tank) { tank.update(); } List remove = new ArrayList<GameFigure>(); GameFigure f; synchronized (figures) { for (int i = 0; i < figures.size(); i++) { f = (GameFigure) figures.get(i); f.update(); // if (f.getState() == GameFigure.STATE_DONE) { // remove.add(f); // } } figures.removeAll(remove); } } }