Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Game Play & Game Design / Developing a new free roam 2D game (Team needed) on: 2013-03-17 12:28:26
I am looking for a dev team to help make a new type of free roam game that the player can play for hours unlocking new items, quests and arias, at the minute i have only just started working on 2D games and have came up with this mock up:



the graphics are going to be made by 2 artists that i have known for the past year.

In java i have a good knowledge of 2D rendering and 2D Gui interfaces so we should be covered there.

If you have any questions just drop me a Pm or a comment.
2  Game Development / Newbie & Debugging Questions / Block colision detection problems(off centered) on: 2013-03-16 16:14:52
The problem i am having is when making the games block colliton center onto the blocks and for some reason the colision box is a few blocks NW from where it should be.
Player file:
package com.AdamWalters.com.zain.mob;

import com.AdamWalters.com.zain.Level.Level;
import com.AdamWalters.com.zain.Level.tiles.Tile;
import com.AdamWalters.com.zain.graphics.Screen;
import com.AdamWalters.com.zain.graphics.Sprite;
import com.AdamWalters.com.zain.input.InputHandler;

public class Player extends Mob {

   private InputHandler input;
   private Sprite sprite;
   private int anim = 0;
   private boolean walking = false;
   
   static final int maxHealth = 2000;
   static int health = 2000;

   int speed = 40;
   
   public Player(Level level, int x, int y, InputHandler input) {
        super(level, "Player", x, y, 1);
        this.input = input;
        sprite = Sprite.player_forward;
    }


   public void update() {
      boolean running;
      int xa = 0, ya = 0;
      if (anim < 7500)
         anim++;
      else
         anim = 0;
      if (input.shift){
         running = true;
         speed  = 20;
      }else{
         running = false;
         speed  = 40;
      }
      if (input.up&&running)
         ya--;
      if (input.down&&running)
         ya++;
      if (input.left&&running)
         xa--;
      if (input.right&&running)
         xa++;
      
      if (input.up)
         ya--;
      if (input.down)
         ya++;
      if (input.left)
         xa--;
      if (input.right)
         xa++;

      if (xa != 0 || ya != 0) {
         move(xa, ya);
         walking = true;
      } else {
         walking = false;
      }
   }

   public void render(Screen screen) {
      int flip = 0;
      if (dir == 2) {
         sprite = Sprite.player_forward;
         if (walking) {
            if (anim % speed > speed/2) {
               sprite = Sprite.player_forward_1;
            } else {
               sprite = Sprite.player_forward_2;

            }
         }
      }
      if (dir == 1) {
         sprite = Sprite.player_side;
         if (walking) {
            if (anim % speed > speed/2) {
               sprite = Sprite.player_side_1;
            } else {
               sprite = Sprite.player_side_2;
            }
         }
      }
      if (dir == 0) {
         sprite = Sprite.player_back;
         if (walking) {
            if (anim % speed > speed/2) {
               sprite = Sprite.player_back_1;
            } else {
               sprite = Sprite.player_back_2;
            }
         }
      }

      if (dir == 3) {
         sprite = Sprite.player_side;
         if (walking) {
            if (anim % speed > speed/2) {
               sprite = Sprite.player_side_1;
            } else {
               sprite = Sprite.player_side_2;
            }

         }
         flip = 1;
      }//this has to be changed for the player sprite. e.g. 16 for 32 * 32 sprites and 32 for 16 * 16 sprites.
      screen.renderPlayer(x - 16, y - 16, sprite, flip);
   }
   
   public boolean hasCollided(int xa, int ya) {
        int xMin = 0;
        int xMax = 15;
        int yMin = 7;
        int yMax = 15;
        for (int x = xMin; x < xMax; x++) {
            if (isSolidTile(xa, ya, x, yMin)) {
                return true;
            }
        }
        for (int x = xMin; x < xMax; x++) {
            if (isSolidTile(xa, ya, x, yMax)) {
                return true;
            }
        }
        for (int y = yMin; y < yMax; y++) {
            if (isSolidTile(xa, ya, xMin, y)) {
                return true;
            }
        }
        for (int y = yMin; y < yMax; y++) {
            if (isSolidTile(xa, ya, xMax, y)) {
                return true;
            }
        }
        return false;
    }

   public static int getHealthPersentage() {
      int persentage;
      persentage = (health/100)/maxHealth;
      return persentage;
   }
   public static int maxHealth(){
      return maxHealth;
   }
   public static int health(){
      return health;
   }
   public static void addDamage(int damage){
      health = health - damage;
   }

}

mob file:
package com.AdamWalters.com.zain.mob;

import com.AdamWalters.com.zain.Level.Level;
import com.AdamWalters.com.zain.Level.tiles.Tile;
import com.AdamWalters.com.zain.entity.Entity;
import com.AdamWalters.com.zain.graphics.Sprite;

public abstract class Mob extends Entity {

   protected Sprite sprite;
   protected int dir = 0;   // 0 = north, 1 = east, 2 = south, 3 = west
   protected boolean moving = false;
   int speed;
   
   public Mob(Level level, String name, int x, int y, int speed) {
        super(level);
        this.x = x;
        this.y = y;
        this.speed = speed;
    }
   
   
   public void move(int xa, int ya) {
      if (xa > 0) dir = 1;
      if (xa < 0) dir = 3;
      if (ya > 0) dir = 2;
      if (ya < 0) dir = 0;
      
        if (!hasCollided(xa, ya)) {
            if (ya < 0)
                dir = 0;
            if (ya > 0)
               dir = 2;
            if (xa < 0)
               dir = 3;
            if (xa > 0)
               dir = 1;
            x += xa * 1;
            y += ya * 1;
        }
   }
    public abstract boolean hasCollided(int xa, int ya);
   protected boolean isSolidTile(int xa, int ya, int x, int y) {
        if (level == null) {
            return false;
        }
        Tile lastTile = level.getTile((this.x + x) >> 7, (this.y + y) >> 7);
        Tile newTile = level.getTile((this.x + x + xa) >> 7, (this.y + y + ya) >> 7);
        if (!lastTile.equals(newTile) && newTile.isSolid()) {
            return true;
        }
        return false;
    }

   public void update() {
   }
   
   public void render() {
   }
   
}

level file:
package com.AdamWalters.com.zain.Level;

import com.AdamWalters.com.zain.graphics.Screen;
import com.AdamWalters.com.zain.Level.tiles.Tile;

public class Level {
   
   protected static int width;
   protected static int height;
   protected int[] tilesInt;
   protected static int[] tiles;
   
   public static Level spawn = new SpawnLevel ("/levels/level.png");
   
   public Level(int width, int height) {
      this.width = width;
      this.height = height;
      tilesInt = new int [width * height];
      generateLevel();
   }
   
   public Level(String path) {
      loadLevel(path);
      generateLevel();
   }

   protected void generateLevel() {
   }
   
   protected void loadLevel(String path) {
   }

   public void tick() {
   }
   
   @SuppressWarnings
   ("unused") private void time() {
   }
   
   public void render(int xScroll, int yScroll, Screen screen) {
      
        if (xScroll < 0)
           xScroll = 0;
        if (xScroll > ((width << 3) - screen.width))
           xScroll = ((width << 3) - screen.width);
        if (yScroll < 0)
           yScroll = 0;
        if (yScroll > ((height << 3) - screen.height))
           yScroll = ((height << 3) - screen.height);
      
      screen.setOffset(xScroll, yScroll);
      /** >> 4 = /16 **/
      int x0 = xScroll >> 4;
      int x1 = (xScroll + screen.width + 16) >> 4;
      int y0 = yScroll >> 4;
      int y1 = (yScroll + screen.height + 16) >> 4;
      for (int y = y0; y < y1; y++) {
         for (int x = x0; x < x1; x++) {
            getTile(x, y).render(x, y, screen);
         }
      }
   }
   //Grass = 0xFF00 / 0x00FF00
   //Flower = 0xFFFF00
   //Rock = 0x878787
   //first two ff = 100% opaque & first two 00 = 100% transparent.
   public Tile getTile(int x, int y) {
      if (x < 0 || y < 0 || x >= width || y >= height){
         return Tile.voidTile;
      }
      if (tiles[x + y * width] == Tile.col_spawn_grass){
         return Tile.grass;
      }
      if (tiles[x + y * width] == Tile.col_spawn_log){
         return Tile.log;
      }
      if (tiles[x + y * width] == Tile.col_spawn_leaves){
         return Tile.leaves;
      }
      return Tile.voidTile;
   }
   public static int getTileID(int x, int y) {
      if (x < 0 || y < 0 || x >= width || y >= height){
         return 1;
      }
      if (tiles[x + y * width] == Tile.col_spawn_grass){
         return 2;
      }
      if (tiles[x + y * width] == Tile.col_spawn_log){
         return 3;
      }
      if (tiles[x + y * width] == Tile.col_spawn_leaves){
         return 4;
      }
      return 1;
   }
   

}
if anyone has  a solution to this it would be  appreciated if you left me a message or drop me a skype PM at :mythirdleg35
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (14 views)
2014-07-24 01:59:36

Riven (14 views)
2014-07-23 21:16:32

Riven (13 views)
2014-07-23 21:07:15

Riven (15 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!