The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > The PokéCommunity Archives > Game Development Archive
Sign Up Rules/FAQ Live Battle Blogs Mark Forums Read

Notices

Game Development Archive Locked games or old games, look for the old games that were in Game Development before November 20, 2005 or were locked before January 19, 2006.


Advertise here

 
Click here to go to the first staff post in this thread.  
Thread Tools
  #1    
Old October 18th, 2011, 10:47 AM
Derelict
Beginning Trainer
 
Join Date: Oct 2011
Gender: Male

Advertise here
Hi all,

My friend and I have recently started a bit of a project regarding Pokémon. We are recreating one of the Pokémon games (Fire Red, specifically) in Java but making it work online, simply put. I'm not a really experienced developer and so this is a great learning experience for me.

Anyway, I've already come across my first problem, and it's with the movement of the main character. I'll link to a jar (I think that's allowed?) which you can download. It's basically a simple map with the character allowed to move around (no collision or anything). It looks kind of juttery and I'm not really sure how to make it look "legit".

If you think it's a virus or something, you don't need to download it - I'll also link to a pastebin of the code, and hopefully that should be enough on it's own to tell you what's wrong.

Oh and I apologize for the code being messy, I was literally just experimenting (lots of deletions/insertions) and I didn't really want to recomment what I was doing over and over again. Please bear with it

I also understand that the .zip file containing the .jar is quite big, but that's because of the game framework I'm using (libgdx). You can view the contents of the jar in your archive program if you don't believe me

Thanks in advance if any of you are able to help me

Ah, damn - I can't post any links until 15 posts. The code is in the spoiler below, can't get around the .jar one though.

Spoiler:

Code:
/**
 *   PokéNation, a free to play online Pokémon Game
 *   Copyright (C) 2011-2012 Keywork Studios
 *
 *   This program is free software: you can redistribute it and / or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (At your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see (link removed).
 *   
 *  Any media presented to you by this game (such as graphics, sounds or GUI)
 *  was created by and is the property of Nintendo. The only thing Nintendo
 *  did not create was the source code, which belongs to Keywork Studios.
 *  
 */

package org.keyworkstudios.pokenation.screens;

import org.keyworkstudios.pokenation.framework.Screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.tiled.TiledLayer;
import com.badlogic.gdx.graphics.g2d.tiled.TiledLoader;
import com.badlogic.gdx.graphics.g2d.tiled.TiledMap;
import com.badlogic.gdx.math.Vector2;

public class SplashScreen extends Screen {
	
	TiledMap mapData;
	TiledLayer map;
	
	Texture tileTexture;
	TextureRegion[] tileGraphics;
	
	Texture charactersTexture;
	TextureRegion[] cSprites;
	
	Sprite character;
	
	@Override
	public void create() {
		mapData = TiledLoader.createMap(Gdx.files.internal("map.tmx"));
		map = mapData.layers.get(0);
		
		tileTexture = new Texture("tiles.png");
		tileGraphics = new TextureRegion[(tileTexture.getWidth() / 16) * (tileTexture.getHeight() / 16)];
		
		int i = 0;
		for (int y = 0; y <= (tileTexture.getHeight() / 16) - 1; y++) {
			for (int x = 0; x <= (tileTexture.getWidth() / 16) - 1; x++) {
				tileGraphics[i] = new TextureRegion(tileTexture, x * 16, y * 16, 16, 16);
				tileGraphics[i].flip(false, true);
				i++;
			}
		}
		
		charactersTexture = new Texture("characters.png");
		
		cSprites = new TextureRegion[(charactersTexture.getWidth() / 20) * (charactersTexture.getHeight() / 25)];
		i = 0;
		for (int y = 0; y <= (charactersTexture.getHeight() / 25) - 1; y++) {
			for (int x = 0; x <= (charactersTexture.getWidth() / 20) - 1; x++) {
				cSprites[i] = new TextureRegion(charactersTexture, x * 20, y * 25, 20, 25);
				cSprites[i].flip(false, true);
				i++;
			}
		}
		
		character = new Sprite(cSprites[0]);
		
		sCharDownWalk = new int[] {1, 2};
		sCharUpWalk = new int[] {4, 5};
		sCharRightWalk = new int[] {7, 8};
		sCharLeftWalk = new int[] {10, 11};
	}
	
	Vector2 charPos = new Vector2(24, 33);
	
	int[] sCharDownWalk;
	int [] sCharUpWalk;
	int[] sCharRightWalk;
	int[] sCharLeftWalk;
	
	int sCharDown = 0;
	int sCharUp = 3;
	int sCharRight = 6;
	int sCharLeft = 9;
	
	boolean step = false;
	int cStep = 0;
	
	boolean moving = false;

	final int direction_up = 0;
	final int direction_left = 1;
	final int direction_down = 2;
	final int direction_right = 3;
	
	int direction = direction_down;
	
	int spriteIndex = 0;
	
	@Override
	public void update(float deltaTime) {
		if (currentTime == 0) currentTime = System.currentTimeMillis();
	}
	
	long currentTime = 0;
	
	public boolean hasPassed(int ms) {
		if (System.currentTimeMillis() >= currentTime + ms) {
			currentTime = 0;
			return true;
		} else {
			return false;
		}
	}
	
	boolean moveKeyPressed = false;
	int moveStage = 0;
	
	@Override
	public void renderDesktop(float deltaTime) {
		for (int x = 0; x <= map.getWidth() - 1; x++) {
			for (int y = 0; y <= map.getWidth() - 1; y++) {
				if (map.tiles[x][y] - 1 == -1) {
				} else {
					game().batch().draw(tileGraphics[map.tiles[x][y] - 1], y * 16, x * 16);
				}
			}
		}
		
//		character.draw(game().batch());
//		character.setPosition((charPos.x * 16), (charPos.y * 16) - 8);
		
		moveKeyPressed = Gdx.input.isKeyPressed(Input.Keys.UP) || Gdx.input.isKeyPressed(Input.Keys.LEFT) ||
							Gdx.input.isKeyPressed(Input.Keys.DOWN) || Gdx.input.isKeyPressed(Input.Keys.RIGHT);
		
		if (!moving && moveKeyPressed && hasPassed(50)) {
			if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
				if (direction != direction_up) {
					direction = direction_up;
				} else {
					moving = true;
				}
			}
			
			if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
				if (direction != direction_left) {
					direction = direction_left;
				} else {
					moving = true;
				}
			}
			
			if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
				if (direction != direction_down) {
					direction = direction_down;
				} else {
					moving = true;
				}
			}
			
			if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
				if (direction != direction_right) {
					direction = direction_right;
				} else {
					moving = true;
				}
			}
		}
		
		
		if (!moving) {
			switch (direction) {
			case direction_up:
				spriteIndex = sCharUp;
				break;
				
			case direction_left:
				spriteIndex = sCharLeft;
				break;
				
			case direction_down:
				spriteIndex = sCharDown;
				break;
				
			case direction_right:
				spriteIndex = sCharRight;
				break;
			}
		} else {
			if (moveStage == 0) {
				step = !step;
				if (step) 	cStep = 0;
				else		cStep = 1;
				
				if (direction == direction_up) {
					spriteIndex = sCharUpWalk[cStep];
				}
				
				if (direction == direction_left) {
					spriteIndex = sCharLeftWalk[cStep];
				}
				
				if (direction == direction_down) {
					spriteIndex = sCharDownWalk[cStep];
				}
				
				if (direction == direction_right) {
					spriteIndex = sCharRightWalk[cStep];
				}
				
				moveStage++;
			} else if (moveStage <= 11) {
				if (direction == direction_up) 		charPos.y -= 0.1f;
				if (direction == direction_left)	charPos.x -= 0.1f;
				if (direction == direction_down)	charPos.y += 0.1f;
				if (direction == direction_right)	charPos.x += 0.1f;
				
				moveStage++;
			} else if (moveStage == 12) {
				moving = false;
				moveStage = 0;
				
//				switch (direction) {
//				case direction_up:
//					spriteIndex = sCharUp;
//					break;
//					
//				case direction_left:
//					spriteIndex = sCharLeft;
//					break;
//					
//				case direction_down:
//					spriteIndex = sCharDown;
//					break;
//					
//				case direction_right:
//					spriteIndex = sCharRight;
//					break;
//				}
			}
		}
		
		game().camera().position.set(charPos.x * 16, (charPos.y * 16) - 8, 0);
		game().batch().draw(cSprites[spriteIndex], (charPos.x * 16), (charPos.y * 16) - 8);
	}

	@Override
	public void renderAndroid(float deltaTime) {
	}

	@Override
	public void pause() {
	}

	@Override
	public void resume() {
	}

	@Override
	public void onBackKey() {
		Gdx.app.exit();
		System.exit(0);
	}

	@Override
	public void dispose() {
	}
}
  #2    
Old October 18th, 2011, 11:23 AM
Cilerba
the hearts of lonely people
Community Supporter
 
Join Date: Feb 2010
Location: Massachusetts
Age: 17
Gender: Male
Nature: Quiet
I've said this before quite a few times. Despite the fact that this forum has the word "Help" in the name does not mean you come to here for help. Try posting this in the Beginner's Lounge (specifically this thread) and hopefully you'll get some responses.
__________________
A MODEST PROPOSAL
http://www.pokecommunity.com/showthread.php?p=7766537
 
Quick Reply

Sponsored Links


Advertise here
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 08:08 PM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2014 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2014 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.