• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

PsychotikRabbit

Members
  • Content count

    21
  • Joined

  • Last visited

Community Reputation

175 Neutral

About PsychotikRabbit

  • Rank
    Member
  1. Yes you are right you need to call close. Another approach:   public class InputManager { private final Scanner scanner; public InputManager() { scanner = new Scanner(System.in); } //This should be called when you don't want to read input anymore. public void shutdown() { scanner.close(); } public String menu(){ String menuoption = scanner.next(); //Do some stuff... return menuoption; } public void info(){ String info = scanner.next(); //Do some stuff... } } You could then use your class like this:   public static void main(String[] args) { InputManager inputManager = new InputManager(); //Do whatever you want with the user input. String option = inputManager.menu(); System.out.println("Option: " + option); //Before exiting the application you free resources inputManager.shutdown(); }
  2. Best practice would be to re-use the same scanner instance. If the menu() and info() method must remain static then you can do something like this:   private static final Scanner scanner = new Scanner(System.in); //You should specify either if the method is public or private. private static String menu(){ String menuoption = scanner.next(); //Do some stuff... return menuoption; } //You should specify either if the method is public or private. private static void info(){ String info = scanner.next(); //Do some stuff... }
  3. I don't think it's bad to use instanceof for this part of the code. Storing a string for the name would be perfect if it would be used as an unique Identifiant. Though, all your paddles will be name "paddle" and all your walls will be named "wall". I think you must adjust your code with the functionnalities that you are looking for. Therefore, as you don't need 1000 different entities and you have to implement collision detection differently on each of your entity, it is a good way to do it.
  4. It's not a bad way, but you can improve it. Instead of adding an entityName, when you check collision you can verify the type of the obstacle instance:   //If there is an obstacle if(obstacle != null) { if(obstacle instanceof Paddle) { this.invGoingLeft(); } if(obstacle instanceof Wall) { this.invGoingDown(); } }   Also in the second snippet of code your posted you have two if   if(obstacle.entityName == "Wall")   and   if(obstacle.entityName != "Wall")   Consider using "else" instead of the second condition. Also if you don't want to get lost in your code and follow standards go read about Indentation at  http://en.wikipedia.org/wiki/Indent_style . It is a simple game, I think this collision detection is good for a pong game, though if you start making bigger projects, you might consider more advanced techniques which will fits your needs. As for now it's very good to start somewhere less complicated to get more experience.
  5. Since this is a ball specific collision implementation, you could add in the ball's update method some code to manage it.   //ball update method public void update() { //Check collision Entity obstacle = CollisionDetection.collidesWith(this); //If there is an obstacle if(obstacle != null) { if(obstacle.getX() < getX()) { //Bouce Right; } else { //Bounce Left; } if(obstacle.getY() < getY() { //Bounce Bottom } else { //Bounce Top } } }   Of course you can adapt this code to your needs.
  6. OperatingRoom[] rooms = new OperatingRoom[3]; for(int i = 0; i < rooms.length; i++) { System.out.println("Op room #" + i); rooms[i] = new OperatingRoom(); rooms[i].fillRoom(opRoom); //What is opRoom ? I guess you have a variabe not included in your snippet. rooms[i].display(); }
  7. It's simple, you can use Entity as the base class. Entity is anything that has a position,a size and is renderable in the game. Then for your "living things" you can create a MovingEntity class which extends from Entity. Now with that, all your entities/obstacles descend from Entity.   Entity.java --------------------------- public class Entity { int position x; int position y; int width; int height; //Here go your getters/setters and contructors }   MovableEntity.java --------------------------------------- public class MovableEntity extends Entity { int speed; //Here goes your setters/getters/constructors public void update() { //Detect collision and move } } Now your walls can now extends from Entity or directly be directly a Entity. Your ball/paddle/ai can extends from MovableEntity or be directly a MovableEntity.
  8. You can change your CollisionDetection class to an utility class, with static-only methods and therefore you could access it from anywhere. As CJ_COIMBRA said, you could create a new collection of Entity object and store them in the CollisionDetection class.   public class CollisionDetection { private static ArrayList<Entity> entities = new ArrayList<Entity>(); public static boolean collides(Entity e) { return collidesWith(e) != null; } public static Entity collidesWith(Entity e) { Entity obstacle = null; for(Entity entity: entities) { //If its not the same entity if(entity!= e) { if(e.getRect().intersects(entity.getRect()) { obstacle = entity; } } } return obstacle; } //Add obstacle to detect public static void addEntity(Entity entity) { entities.add(entity); } //Remove obstacle to detect public static void removeEntity(Entity entity) { entities.remove(entity); } } You could consider your walls and other obstacles as Entity. With this utility class you can initialize the detection in your init method like this:   CollisionDetection.addEntity(ball); CollisionDetection.addEntity(topWall); etc... Then in the entities that you need to manage collision (like the ball) in the update method, after updating the position of the ball you can detect collision with any other entities and handle it.   //Detect if the ball (this) collides with any other entities boolean collision = CollisionDetection.collides(this); //Detect with which entity the ball collides //If its not colliding with anything it will return null. //Its your job to ensure that it will not collide with more than one entity at the time //by reacting on collision. Entity obstacle = CollisionDetection.collidesWith(this);    
  9. Slick does provide a render, update and init method in the BasicGame class. In the render method there is two given parameters (GameContainer gc, Graphics g). The Graphics object seems to provides similar drawing method as java2d graphics. I beleive you can adapt easily your rendering class to use Slick 2D engine with that Graphics. Here's an example of how to draw a rectangle in the Slick2D engine :   public void render(GameContainer gc, Graphics g) throws SlickException { g.drawRect(0,0,20,20); }
  10. Instead of creating a screenshot with a timer can't you just use the original image and scale it when its painted ? I did not write this code, it seems to do what you need to do by scaling the image with AffineTransform on its paint. Of course you would adjust the scaling depending on the zoom of your magnifier. [CODE] protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); int w = getWidth(); int h = getHeight(); int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); double x = (w - scale * imageWidth)/2; double y = (h - scale * imageHeight)/2; AffineTransform at = AffineTransform.getTranslateInstance(x,y); at.scale(scale, scale); g2.drawRenderedImage(image, at); } [/CODE] With this it won't flicker anymore because you won't need to use setVisible and to take a bunch of screenshots every second.
  11. I've already worked on something similar, it's just mathematics. MouseEvent can provide you the mouse position of the click (MouseEvent.getX(), MouseEvent.getY()). We're lucky that you are making a chess game because of chessboard. To get the selected square location you can simply loop through all rows and column and check if the position of the mouse is within the square. I wrote a little method which would find a square , I didn't test it but I think it can help you out. [CODE] private final int NUMBER_OF_ROWS = 8; private final int NUMBER_OF_COLUMNS = 8; private final int SQUARE_SIZE = 32; public Square getSquareAt(int x, int y) { for(int col = 0; col < NUMBER_OF_COLUMNS ; ++col ) { for(int row = 0; row < NUMBER_OF_ROWS; ++row ) { int squareX = row * SQUARE_SIZE; int squareY = col * SQUARE_SIZE; Rectangle rectangle = new Rectangle(squareX,squareY, SQUARE_SIZE, SQUARE_SIZE); if(rectangle.contains(x, y)) { return chessBoard[col][row]; } } } return null; } [/CODE] I let java.awt detect if the coordinate of the mouse is within the bounds of the square. Edit: That will work if there is one unique mouse listener listening on the chessboard panel. (container of all squares).
  12. You are calling the method to highlight solution squares on the mouseReleased event instead of the mousePressed. MousePressed is the trigger for your "drag" and MouseReleased is the trigger for your "drop". What do you need to know exactly about mouse listeners ?
  13. I didn't test it but I'm pretty sure it would improve the network time. You won't need to open an output stream on the socket to write a string and to open an input stream on the socket to read a string. It would improve both CPU and network time. You could write a small unit test to test out the time sending and receiving a string by streams and another test for the time sending deserialized object and receiving the byte array.
  14. You could also send/receive a byte array instead of using character stream as you seems to be only sending Numbers. I know it prolly won't improve a lot the speed but optimization is always good. Go read about java object serialization/deserialization. You will save time by not creating a String and parsing it as you just want to send numbers.
  15. For the timer you can try differents values to test the stability of your games but as I said 25 frames per [b]second[/b] should be enough. And is the repaint() method call is really necessary in your paintComponent method ? [CODE] @Override public void paintComponent(Graphics g){ super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; if(Map.redLevel == true){ g2d.drawImage(background, himmelX, himmelY, null); g2d.drawImage(background2, himmelX2, himmelY2, null); g2d.drawImage(lava, grassX+80, grassY+355, null); g2d.drawImage(lava, grassX+680, grassY+130, null); repaint(); } } [/CODE]