Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Simple ORPG


unknown
 Share

Recommended Posts

Hah yes. Thank you XKCD.

Alright [here's the latest build](http://www.raymondcox.net/simple-orpg-win.zip) for Windows (for [mac](http://www.raymondcox.net/simple-orpg-mac.zip)). I'm including the server in this build.. To run it just double click run-server.bat. If you have a cool server post the link to download.

* Fixed a bug where if you were at the bottom part of a map without an exit you would freeze
* Added an entry for startmap in server.properties
* PropertiesLoader.java now lazily loads properties
* Added a BSD License
* Moved shared package to common
* Added in some new maps that aren't quite ready yet and fixed the tavern map
* Fixed a bug in resource factory where not all resource refs were case insensitive
Link to comment
Share on other sites

  • Replies 105
  • Created
  • Last Reply

Top Posters In This Topic

Nothing much, but if you replace the current InputSystem.java with the following code you will have a chat toggle and wasd movement. You press enter to start chatting and enter again to stop chatting/send your message. When you are not in the chatting mode then pressing the arrow keys or the wasd keys will cause your player to move in the direction selected.

```
package com.openorpg.simpleorpg.client.systems;
import java.util.concurrent.ArrayBlockingQueue;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;
import org.newdawn.slick.KeyListener;

import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.utils.ImmutableBag;
import com.openorpg.simpleorpg.client.components.ColorComponent;
import com.openorpg.simpleorpg.client.components.DrawableText;
import com.openorpg.simpleorpg.client.components.Location;
import com.openorpg.simpleorpg.client.components.Movement;
import com.openorpg.simpleorpg.client.components.Networking;
import com.openorpg.simpleorpg.client.components.ResourceRef;
import com.openorpg.simpleorpg.client.components.ChatBubble;
import com.openorpg.simpleorpg.client.components.Timer;
import com.openorpg.simpleorpg.client.components.Visibility;
import com.openorpg.simpleorpg.common.NewTiledMap;
import com.openorpg.simpleorpg.common.ResourceManager;

public class InputSystem extends BaseEntitySystem implements KeyListener {
private GameContainer container;
private ComponentMapper drawableTextMapper;
private ComponentMapper timerMapper;
private ComponentMapper networkingMapper;
private ComponentMapper locationMapper;
private Character c = null;
private ComponentMapper movementMapper;
private ComponentMapper resourceRefMapper;
private ComponentMapper visibilityMapper;

private boolean key_back = false,
key_enter = false,
key_tab = false,
key_up = false,
key_down = false,
key_left = false,
key_right = false,
key_esc = false,
isChatting = false;

@SuppressWarnings("unchecked")
public InputSystem(GameContainer container) {
super(ResourceRef.class, Location.class);
this.container = container;
}

@Override
protected void initialize() {
drawableTextMapper = new ComponentMapper(DrawableText.class, world);
timerMapper = new ComponentMapper(Timer.class, world);
networkingMapper = new ComponentMapper(Networking.class, world);
locationMapper = new ComponentMapper(Location.class, world);
movementMapper = new ComponentMapper(Movement.class, world);
resourceRefMapper = new ComponentMapper(ResourceRef.class, world);
visibilityMapper = new ComponentMapper(Visibility.class, world);
container.getInput().addKeyListener(this);
}

@Override
protected boolean checkProcessing() {
return true;
}

@Override
protected void processEntities(ImmutableBag entities) {
Entity input = world.getTagManager().getEntity("INPUT");
Entity yourEntity = world.getTagManager().getEntity("YOU");
Location yourLocation = locationMapper.get(yourEntity);
Movement yourMovement = movementMapper.get(yourEntity);
Networking net = networkingMapper.get(yourEntity);
ArrayBlockingQueue sendMessages = net.getSendMessages();

// Alphanumeric input interface (when you press enter chat shows up)
if (key_enter && isChatting) {
DrawableText drawableText = drawableTextMapper.get(input);
String sendText = drawableText.getText();

if (!sendText.equals("") && visibilityMapper.get(input).isVisible()) {
// Commands
if (sendText.startsWith("/")) {
String cmd = sendText.substring(1).toUpperCase().split(" ")[0];
String cmdMsg = sendText.substring(sendText.indexOf(cmd) + cmd.length() + 2).replace(",", "").trim();

// who
if (cmd.equals("WHO")) {
sendMessages.add("WHO");
// setname } else if (cmd.equals("SETNAME")) {
String name = cmdMsg;

if (name.length() > 0 && name.length() <= 20) {
if (isAlpha(name)) {
sendMessages.add("SET_NAME:" + name);
drawableTextMapper.get(yourEntity).setText(name);
}
}
// broadcast } else if (cmd.equals("BROADCAST")) {
String broadcast = cmdMsg;

if (broadcast.length() > 0) {
sendMessages.add("CHAT:BROADCAST," + broadcast);
}
} else if (cmd.equals("SEND")) {
String msg =  sendText.substring(sendText.indexOf(cmd) + cmd.length() + 2).trim();
sendMessages.add(msg);
}
// Normal chat
} else {
Entity chatEntity = world.createEntity();
chatEntity.setGroup("CHAT");
chatEntity.addComponent(new DrawableText("You: " + sendText));
yourEntity.addComponent(new ChatBubble(sendText, 15 * 1000));
chatEntity.addComponent(new ColorComponent(Color.white));
chatEntity.refresh();
sendMessages.add("CHAT:SAY," + sendText);
}
drawableText.setText("");
isChatting = false;
}
} else if (key_enter && !isChatting) {
isChatting = true;
}

// Add to the input text
if (c != null && visibilityMapper.get(input).isVisible() && isChatting) {
DrawableText drawableText = drawableTextMapper.get(input);
if (drawableText.getText().length() < 150)
drawableText.setText(drawableText.getText() + c);
}

// Backspace
if (key_back && visibilityMapper.get(input).isVisible()  && isChatting) {
Timer timer = timerMapper.get(input);

if (timer != null) {
if (timer.isFinished()) {
String txt = drawableTextMapper.get(input).getText();
if (timer.isFinished() && txt.length() > 0) {
timer.reset();
drawableTextMapper.get(input).setText(txt.substring(0, txt.length()-1));
}
input.removeComponent(timer);
}
} else {
input.addComponent(new Timer(75));
}
}

// Hide the input & chat history
if (key_tab) {
visibilityMapper.get(input).setVisible(!visibilityMapper.get(input).isVisible());
}

/*
if (key_esc) {
container.exit();
}
*/

// Your movement
if (yourLocation != null) {
int newX = (int)yourLocation.getPosition().x, newY = (int)yourLocation.getPosition().y;
int oldX = (int)yourLocation.getPosition().x, oldY = (int)yourLocation.getPosition().y;
String moveMessage = "";
// Check for collision & move the player
ImmutableBag maps = world.getGroupManager().getEntities("MAP");
ResourceManager manager = ResourceManager.getInstance();
if (maps.get(0) != null) {

String mapResName = resourceRefMapper.get(maps.get(0)).getResourceName();
NewTiledMap map = (NewTiledMap)manager.getResource(mapResName).getObject();
String up = map.getMapProperty("Up", "");
String down = map.getMapProperty("Down", "");
String left = map.getMapProperty("Left", "");
String right = map.getMapProperty("Right", "");

if (key_up) {
moveMessage = "MOVE:UP";
newY -= 1;
} else if (key_down) {
moveMessage = "MOVE:DOWN";
newY += 1;
} else if (key_left) {
moveMessage = "MOVE:LEFT";
newX -= 1;
} else if (key_right) {
moveMessage = "MOVE:RIGHT";
newX += 1;
}

if ( (key_up || key_down || key_left || key_right) && !isChatting ) {
// Bounds Check
// If you're at an edge only allow you to go further if you're warping
if (newX < map.getWidth() && newY < map.getHeight() &&
newX > -1 && newY > -1 ||
newX == map.getWidth() && !right.equals("") ||
newY == map.getHeight() && !down.equals("") ||
newY == -1 && !up.equals("") ||
newX == -1 && !left.equals("")) {
// Collision Check
int collisionId;
try {
collisionId = map.getTileId(newX, newY, 3);
} catch (Exception ex) { collisionId = 0; }
if (collisionId == 0) {
yourMovement = movementMapper.get(yourEntity);
if (yourMovement.isFinished()) {
// Prevent desyncing issues by 'freezing' the player at the warp/edge of map
if (oldX != -1 && oldY != -1 && oldX != map.getWidth() && oldY != map.getHeight()) {
if (map.getMapObjects()[oldX][oldY] == -1) {
sendMessages.add(moveMessage);
yourLocation.getPosition().set(newX, newY);
yourMovement.reset();
}
}
}
}
}
}
}
}

// You can't hold down a letter or enter for input
key_enter = false;
key_tab = false;
c = null;

}

boolean isAlpha(String st) {
for (char c : st.toCharArray()) {
if (!isAlpha(c)) {
return false;
}
}

return true;
}

boolean isAlpha(char c) {
// If alphanumeric
if (c > 31 && c < 127) {
return true;
}
return false;
}

@Override
public void keyPressed(int key, char c) {
if (isAlpha(c)) this.c = c;
switch (key) {
case Input.KEY_A:
case Input.KEY_LEFT:
key_left = true;
break;
case Input.KEY_D:
case Input.KEY_RIGHT:
key_right = true;
break;
case Input.KEY_W:
case Input.KEY_UP:
key_up = true;
break;
case Input.KEY_S:
case Input.KEY_DOWN:
key_down = true;
break;
case Input.KEY_DELETE:
case Input.KEY_BACK:
key_back = true;
break;
case Input.KEY_ENTER:
key_enter = true;
break;
case Input.KEY_TAB:
key_tab = true;
break;
case Input.KEY_CAPITAL:
case Input.KEY_INSERT:
case Input.KEY_LSHIFT:
case Input.KEY_RSHIFT:
case Input.KEY_LCONTROL:
case Input.KEY_RCONTROL:
case Input.KEY_LALT:
case Input.KEY_RALT:
break;
case Input.KEY_ESCAPE:
key_esc = true;
break;
}
}

@Override
public void keyReleased(int key, char c) {
switch (key) {
case Input.KEY_A:
case Input.KEY_LEFT:
key_left = false;
break;
case Input.KEY_D:
case Input.KEY_RIGHT:
key_right = false;
break;
case Input.KEY_W:
case Input.KEY_UP:
key_up = false;
break;
case Input.KEY_S:
case Input.KEY_DOWN:
key_down = false;
break;
case Input.KEY_DELETE:
case Input.KEY_BACK:
key_back = false;
break;
case Input.KEY_TAB:
key_tab = false;
break;
case Input.KEY_ENTER:
key_enter = false;
break;
case Input.KEY_ESCAPE:
key_esc = false;
break;
}

}
@Override
public void setInput(Input input) {
}

@Override
public boolean isAcceptingInput() {
return true;
}

@Override
public void inputEnded() {
}

@Override
public void inputStarted() {

}
}

```
Link to comment
Share on other sites

Cool, very nice. It would be good if you could get that up on github, so everyone can pull your repo and see the change.

Currently I'm working on the login and character creation system. I want it to be correct structurally and easy to understand. It's difficult to write because it was not part of my initial 24 hour design. My goal is to have it all done by Tuesday.
Link to comment
Share on other sites

I found another little bug thats nothing major but can get a little annoying. When you are talking, if you just type in / and press enter so no command is sent after the /, it causes the client to shutdown. I assume this is to do with the way the game checks what comes after the / for /who, /send, /setname, /broadcast and when it finds none of those it doesn't know wtf is going on and crashes.
Link to comment
Share on other sites

Ok, I finally got all the code over to my PC and setup github on it. I've uploaded the WASD version to my git which can be found [here.](https://github.com/JamesWilsonCom/myORPG) I'll keep that repo updated with any changes I make to the source and will keep it up to date with unknown's version.
Link to comment
Share on other sites

@Ertzel I tried your fork out, it works well. The / bug you described will be fixed in my next push.

I'm currently finishing up finals. One of my final projects is in an IT elective called client side web development where we have to design a site with certain requirements. I decided to kill two birds with one stone and create the Simple ORPG site. [Here](http://96.126.127.107/client_dev/final/) is the initial version I made tonight (only news and screenshots works). Any suggestions?

Also I have been working on the login system. It's coming along slowly.
Link to comment
Share on other sites

Thanks for the comments. The code is really great and modular which allows me to update/fix things easily. I think this is rapidly becoming a great project. I'll have a lot more time to devote soon, which should further it's awesomeness.

I got a lot done today. Expect a new release soon.

* Moved the client over to a state based system
* Created password text field
* Created a fixed size database pool
* New user creation creates the appropriate entries in the database
* Logging in checks to make sure the user has the correct password
* In use user database flag gets set and checked
* Flexible database schema allows for multiple players per user
* Added database connection URL to server.properties
* Fixed / and / bug
* Changed startmap=map to startlocation=map,x,y

There are two branches on GitHub, login and master.. If you checkout the master branch it contains the last two updates.

I have a little bit more to do, like salt the passwords. Currently I'm testing on a MySQL database. I want the server to be able to run without any configuration, which means it will work with embedded databases too.
Link to comment
Share on other sites

Nice Java ORPG Engine :)
First, You should never given up this engine because I'm so glad that a person invent a java online rpg engine *_*
Second, I hope you can add a better movement, a simple show and hide map stats (like fps, x=location, y=location, map=name), server log4j to textarea (appender) because consoles are so mainstream and a gui?
Link to comment
Share on other sites

@Ryujin:

> Nice Java ORPG Engine :)
> First, You should never given up this engine because I'm so glad that a person invent a java online rpg engine *_*
> Second, I hope you can add a better movement, a simple show and hide map stats (like fps, x=location, y=location, map=name), server log4j to textarea (appender) because consoles are so mainstream and a gui?
> **And Third i hope you can make a new eclipse engine using java.**

I fixed that for you couse you were missing the Third part.Also he will add what ever he feels like this engine is a good source base alwready that beginners and even more advanced people can find very usefull.Also you are doing a great job Unknown ;]
Link to comment
Share on other sites

I worked on it a lot today and there is a new client build. To login to my server, choose a username that hasn't been used before and it will automatically create a player for you. You can then walk around, chat, exit and your player will be saved in the same location with the same name and sprite.

There will be a server build in the future, I want it to work with an emedded database that automatically creates tables on first run so that you just have to click run-server.bat to run. If you're feeling adventurous the server code is on [github](http://www.github.com/coxry/simpleorpg) under my login branch

the tables are:

```

simpleorpg

users: username, password, created

userplayers: id, username, playerid

players: playerid, playername, x, y, mapref, spriteref

```
Link to comment
Share on other sites

Minor server update today. Also I graduated from college!

* Passwords are now individually salted and hashed with SHA-256 1000 times
* The created field now displays a timestamp
* Fixed a bug with bad database connections corrupting the entire pool

Here's the SQL needed to create the necessary tables.

>! ```
delimiter $$
>! CREATE TABLE `players` (
  `playerid` int(11) NOT NULL AUTO_INCREMENT,
  `playername` varchar(45) NOT NULL,
  `x` int(11) NOT NULL,
  `y` int(11) NOT NULL,
  `mapref` varchar(45) NOT NULL,
  `spriteref` varchar(45) NOT NULL,
  PRIMARY KEY (`playerid`)
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8$$
>! CREATE TABLE `userplayers` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(45) NOT NULL,
  `playerid` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8$$
>! CREATE TABLE `users` (
  `username` varchar(45) NOT NULL,
  `password` varchar(256) NOT NULL,
  `salt` varchar(16) DEFAULT NULL,
  `created` datetime NOT NULL,
  PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8$$
>! ```

As always, test on the latest server (accounts have been reset).

**Update 6/9/2012**

* Cleaned up login screen
* Added new account button
* Added a couple commands (/fps and /b )
* You can now tab between username and password

Download the latest client to test out these updates.

edit: I forgot to include resources.xml in the latest build causing it to not work. It's in there now.
Link to comment
Share on other sites

Minor Bug found:

At the login screen, if you click the grey area (basically anywhere except the text boxes and the buttons) and type something, then click on the text boxes and login, the last letter of what you typed will already be in the text box when you are in-game.

Example:

At login screen, I click the grey area and type 'cat'. When I login, the letter 't' will be in the textbox at the bottom of the chat screen.
Link to comment
Share on other sites

  • 1 month later...
I have a new build.

* H2 Database is now used by default. MySQL will work by editing the connection string in server.properties.
* Fixed The Alpha's bug
* Client is now a JNLP and will work on all platforms without modification
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×
×
  • Create New...