PDA

View Full Version : Realm of Magic, a 2D Multiplayer RPG



Diaboli
28-09-2006, 08:06 PM
This was originally going to be named Harry Potter Online, but since that could cause some problems, i renamed it to Realm of Magic.

So far, the features are:
- you can move, and se other player move. (still a little buggy)
- use entreances (teleports you between rooms, placed in doorways etc.)
- Chat (say, yell and whisper.)
- See wich player you hold the mouse pointer over
- See ping
- See room title
- GameObjects

The only GameObject installed is a door on an entreance. walk up to it and whisper "opendoor", and it will disappear. (allowing you to enter)
(type "/whisper opendoor" in chat)

The /whisper function is not like in conventional games. it lets you speak only to people that are nearer than 30 pixles. /say can be heard up to 500 pixles distance, and /yell works up to 2000 pixles...

http://thorins.net/RoM.rar

Screenies:
http://thorins.net/1.png
http://thorins.net/2.png
http://thorins.net/3.png

To use the source, you have to have the standard Delphi6 socket components (TServerSocket and TCLientSocket) and DelphiX.

Any tips, feedback, ++ is appreciated.

EDIT: Post is updated with latest features... (01.10.2006 @ 00:34GMT)

savage
29-09-2006, 06:54 AM
(sry if my english is a little off, I'm norwegian :P)

Most norwegians I know and have worked with, speak better English than than the English.

Diaboli
29-09-2006, 07:11 AM
Have anyone tested it or looked at the source?
I'm currently working on removing some serious lag when there are more than one player in a room, and some feedback would be nice.
if you see any errors in the source that i for some reason havent cleaned, just tell me... :P

AthenaOfDelphi
29-09-2006, 10:18 AM
Hi Diaboli,

I just downloaded your game... server fired up, client fired up...

The text colours on the initial login page are a bit of a pain. The dark red is a little tricky to see.

Once I had provided my nickname and logged in, a room appeared, then I got the error message:-

'0,00 is not a valid floating point number'

I'm guessing this is reading something from an INI file or the registry and is doing the conversion based on the locale thats set in the system settings.

Huehnerschaender
29-09-2006, 10:37 AM
Hi there,

after starting the server and client I can type in my login-name. When I do so and click on start I only see a black screen and the standard Windows mouse cursor.

Starting the client a second time gives me the same error Athena encountered.

Greetings,
Dirk

AthenaOfDelphi
29-09-2006, 11:08 AM
Hi Diaboli,

Just looking through the code... I found the problem with the floating point conversion I think.

I believe its down to the function calcDistance. You are using Pythagoras for the case where the difference between the X and Y values isn't 0, but why not ditch all the comparisons and float to string (and back again) conversions? I know its all floating point, but in this day and age, I wouldn't have thought its too much of a burden.

I'm trying to get it working so I've modified the routine to this:-



Function CalcDistance(X1,Y1,X2,Y2: Integer): Integer;
begin
result:=round(sqrt(sqr(x1-x2)+sqr(y1-y2)));
end;


Based on the fact that your routine was doing a lot of float to string (and back again) conversion, this should also be faster.

You mention the fact that it seems to get laggy when there are a few people on.

Having just looked at some of the code, I would suggest that you consider changing the routines that feed information to and receive it from the server. In particular, RecPlayers and RecPlayerPos.

You are spending a lot of time locating delimiters and then manipulating the strings that contain the data. You could still move the data around with strings, but you would be better off tightly formatting the data so that a particular item is always the same length and always in the same position. Then you only need to copy the data. I've also just noticed that you are locating the delimiters twice. Once to locate the end of the data (with your leftStr routine) and then again to delete the data (with your rightStr) routine. I'm just changing the code to use standard routines, like this:-



idxpos:=pos('|',rec);
dataitem:=copy(rec,1,idxPos-1);
delete(rec,1,idxPos);


So as a complete example... this....



Function RecPlayerPos(Rec: String): Boolean;
var
i: Integer;
iPos: Integer;
IsSelf, PID, Name, X, Y, Dir, Speed, House: String;
bIsSelf: Boolean;
begin
while Length(Rec) > 0 do
begin
PID:= LeftStr(Rec,Pos('|',Rec)-1);
Rec:= RightStr(Rec,Length(Rec)-Pos('|',Rec));
X:= LeftStr(Rec,Pos('|',Rec)-1);
Rec:= RightStr(Rec,Length(Rec)-Pos('|',Rec));
Y:= LeftStr(Rec,Pos('|',Rec)-1);
Rec:= RightStr(Rec,Length(Rec)-Pos('|',Rec));
Dir:= LeftStr(Rec,Pos('|',Rec)-1);
Rec:= RightStr(Rec,Length(Rec)-Pos('|',Rec));
Speed:= LeftStr(Rec,Pos('#',Rec)-1);
Rec:= RightStr(Rec,Length(Rec)-Pos('#',Rec));
if (StrIsInt(PID)) and (StrIsInt(X)) and (StrIsInt(Y)) and (StrIsInt(Dir)) and (StrIsInt(Speed)) then
SetPlayerPos(StrToInt(PID),StrToInt(X),StrToInt(Y) ,StrToInt(Dir),StrToInt(Speed))
else
Rec:='';
end;
end;


becomes....




Function RecPlayerPos(Rec: String): Boolean;
var
i: Integer;
iPos: Integer;
IsSelf, PID, Name, X, Y, Dir, Speed, House: String;
bIsSelf: Boolean;
idxPos : integer;
begin
while Length(Rec) > 0 do
begin
idxPos:=pos('|',rec);
pid:=copy(rec,1,idxPos-1);
delete(rec,1,idxPos);

idxPos:=pos('|',rec);
x:=copy(rec,1,idxPos-1);
delete(rec,1,idxPos);

idxPos:=pos('|',rec);
y:=copy(rec,1,idxPos-1);
delete(rec,1,idxPos);

idxPos:=pos('|',rec);
dir:=copy(rec,1,idxPos-1);
delete(rec,1,idxPos);

idxPos:=pos('#',rec);
speed:=copy(rec,1,idxPos-1);
delete(rec,1,idxPos);

if (StrIsInt(PID)) and (StrIsInt(X)) and (StrIsInt(Y)) and (StrIsInt(Dir)) and (StrIsInt(Speed)) then
SetPlayerPos(StrToInt(PID),StrToInt(X),StrToInt(Y) ,StrToInt(Dir),StrToInt(Speed))
else
Rec:='';
end;
end;


This also gives you the chance of spotting bad packets, since if you don't find a delimiter when you expect one, you can simply ditch that packet and move on. Another option would be to create objects that contain the data and then use streaming to move the object data from server/client/server.

Please bear in mind, that the first client based game I worked on was our competition entry. There are many people far more experienced than me on here who may spot big problems with some of my suggestions, but I just compiled it (with Delphi 5) with the changes I made in and I can run around and move from room to room. That said, I don't have anyone else to try it with at the moment, but a bit later on, I'll give it a go.

I hope you finish it... there aren't enough old style games around. Too much emphasis is put on fancy graphics and environment which need a monster PC to play.

AthenaOfDelphi
29-09-2006, 11:10 AM
Hi there,

after starting the server and client I can type in my login-name. When I do so and click on start I only see a black screen and the standard Windows mouse cursor.

Starting the client a second time gives me the same error Athena encountered.

Greetings,
Dirk

I got that problem when I started it from within the IDE. When I run it outside the IDE it works fine.

Diaboli
30-09-2006, 12:54 PM
thanks for the MUCH simplified CalcDistance funtion! :D

as for the reading and writing of packets, i am going to rewrite it to use raw data. for instance an integer will always be 4 bytes of the package, no matter how long... i just have to write some xxxToRaw functions...
and some getXXX functions...

like:

package:= #02+IntToRaw(PID);

if OPCode = #02 then
DeletePlayer(GetInt(Rec));



after starting the server and client I can type in my login-name. When I do so and click on start I only see a black screen and the standard Windows mouse cursor.

This happens AFTER the hostname box, right?
if not, you have typed your name in the hostname box, wich would result in the client trying to connect to your name, wich prbbly wouldnt work.
It can also be a symptome of not receiving the #00 package, wich tells the game that it is logged in and wich room to load...

I have some updated code, but i'll wait with uploading it till i have fixed some of the errors you reported...

EDIT:
I have updated the download. the lag is almost entirely removed now, after using conversions to and from raw string.
the link in the first post is updated, and here is another one:
http://thorins.net/RoM.rar

EDIT2:
Sorry if you have tried to test the new features and found them not existing. my internet broke down during upload last night, but it has been uploaded now.

feel free to check it out and comment. (source is still included)

Diaboli
01-10-2006, 08:49 PM
I have managed to implement GameObjects (doors and so on)
i will upload updated RoM.rar as soon as possible (I'll edit this post)

EDIT: Update uploaded! (same link as before)

WILL
02-10-2006, 04:54 AM
How about some screenshots?

I'm quite busy these days, but I would have time to peek at a few screenies if you can whip a few up. :)

Diaboli
02-10-2006, 04:27 PM
i have updated first post with screenies. i used links, as they are quite large...

Diaboli
03-10-2006, 10:22 PM
i have uploaded an update. no new features, but hopefully some bugfixes and stuff...

i have some problems with players entering and leaving rooms. it should work fine when only one player is on, but if two players is in one room, and one of them leave, it has happened that both players disappear for one player (the one still in the first room). when the player re-enters the room, it works fine, but the player still in it is still not there. (a bit irritating, really, not seeing your character :P)

Fixed some stuff so invalid packets can be detected (only for RecPlayers and RecPlayerPos so far.
Also made so the server wont send information about players that are longer away from you than 2000 pixles (in the SendPlayerPos function, that is)

Diaboli
04-10-2006, 09:34 PM
Sorry for this third post...

Have fixed some bugs and done some stuff to remove further lag.
my own computer will be running server for a little while, just to test.
the only required login is nickname right now, so please respect eachothers nicks (if you test it)

The host is: rom.thorins.net

just download the RoM.rar (same link as ever) and test.
the door has a new password: "usedoor" it will open and close.
and i do know that the door does not reappear again after you open, then close it... im working on it...