Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Mage Wars (Complete)  (Read 6592 times)
0 Members and 1 Guest are viewing this topic.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Posted 2010-12-01 00:45:41 »

I think this is now complete:

* Fireball your opponents into oblivion to take all four castles
* Up to 4 players (on same LAN segment) - so this is a signed applet and generates network traffic

You can test multiplayer using multiple tabs in Internet Explorer if you only have one machine.  Dual CPU fast machine highly recommended as this is much more CPU intensive than my previous entries.

Controls:
* Cursor Keys: Movement (or WASD)
* Mouse: Targeting

http://www.java4k.com/index.php?action=games&method=view&gid=311

Update:

Final

Bugs

Minor bugfix uploaded to Java4k 22/02/11

Time flies like a bird. Fruit flies like a banana.
Offline me

Senior Duke


Projects: 4


Java games rock!


« Reply #1 - Posted 2010-12-01 08:19:49 »

Hi Allan,

Compliments of getting this far with network and cool graphics!
I was experimenting / thinking of doing some network things too so I will
be watching this with great interest!

Best regards from

M.E.

M.E.
--------
Offline fruitmaze
« Reply #2 - Posted 2010-12-01 08:25:00 »

Looks really nice! It runs very smooth.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #3 - Posted 2010-12-02 07:32:32 »

Thanks for the kind comments.

Progress:
- Improved framerate when there are lots of objects on screen by improving object culling.
- Discovered that multiple instances of applets share static variables (which was causing side effects when running multiple instances on the same machine - seems to happen with Plugin 1)
   -- This actually has some interesting applications
- Started on fireball/wizard collision logic.   I'm hoping it will all fit in within 4k.

Adding sideways movement (strafing) would be nice.  Perhaps add WASD movement control and then put strafe left/right on Q and E.  This would work for QWERTY and QWERTZ keyboard layouts (so the Germans will be Ok), but not for the AZERTY keyboard which I believe is used in France.  Maybe leave cursor key control in as well if there is room, which would give easy access to movement (except strafing) in most countries.  Views on the best keyboard controls are welcomed.

Progress will be a bit slower for the next few days as I'm going out quite a bit as my social calendar picks up as we head towards christmas.

Time flies like a bird. Fruit flies like a banana.
Offline pjt33
« Reply #4 - Posted 2010-12-02 10:50:36 »

RDFG with strafe on E and T? I think that's the same for QWERTY, QWERTZ and AZERTY.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #5 - Posted 2010-12-04 20:30:06 »

Updated - see first post.

However doing the multiplayer collision detection has taken up most of the remaining space.  It still needs to be optimised but I think it's not going to fit in 4k - It's still missing enemy AI, Player damage display and logic to keep track of which castles have been taken.  The plan now is to add the remaining bits to get a playable version and then look to see if anything can be taken out.

The collision detection is a little basic, and relies on interpolating player movement (which also smooths the screen movement of remote players).

Time flies like a bird. Fruit flies like a banana.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #6 - Posted 2010-12-05 09:04:13 »

Things I'll probably have to take out to gain some bytes back:

1) There's some debug code still in there for printing frame rate and creating initial object positions

Removing this will gain a dozen or two bytes. No pain.

2) Removal of cursor key control

This just leaves ESDF keys plus WR for strafing.  This is unlikely to save more than 10 bytes (if that), so will leave this until I get really desperate.

1) Tagging of players with their login names during multiplayer

There's several library calls that only apply in this code including System.getProperties("user,name") and a couple of string functions to convert strings back and forth between byte arrays of "UTF-8". I probably can also lose graphics.drawString if I don't use it on the overlay. There is also dedicated code to work out where to draw the names on the screen.

Players will still appear in white, so there is no real loss in 2-player.  It's a bit more annoying for 3-player.
I like this feature as it gives a real online multiplayer feel, but the reality is that most people will only try it as single player, so it will have to go.  I think this could save 100 bytes, maybe even more.

2) Removal of mouse targeting control

I really don't want to do this.  At the moment, the player can only fire one fireball at a time.  If I allocated more slots in the network code, it wouldn't be difficult to allow more than one at a time, which would give a better player feel.  However that would generate more code, not less, so park that thought.

The space bar could be used to generate a forward firing fireball.  However it's hard to target accurately without reducing the player turn rate.  There is also a problem with Y-targeting because the ground is variable height.  I could make the fireballs follow the ground contour.  This isn't hard as the game already works out the ground height under the fireball to detect terrain collisions.  This would need modifying to override fireball height.  It would also need to override the height of other players fireballs as the game linearly interpolates remote object positions.  It may no longer be required to synchronise object Y coordinates across the network at all, which is a wider reaching change, although it probably wouldn't save many bytes as that code is mostly generic in the way it handles the 3 axes.

Definitely a retrograde step, but it might save 50 to 100 bytes.

Time flies like a bird. Fruit flies like a banana.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #7 - Posted 2010-12-23 16:51:13 »

Almost there now.  Had to remove the display of player names to fit within 4K.

Currently 100 bytes over, but the AI code is yet to be optimised and the overlay can be rewritten without library calls, so it looks likely to get there!

Time flies like a bird. Fruit flies like a banana.
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Reply #8 - Posted 2010-12-23 18:33:29 »

looks good, but it's really difficult to dodge the other mages fireballs (?) without strafing . Any chances of strafing ?

edit : ops, should have read the description Smiley

Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #9 - Posted 2010-12-23 19:28:47 »

looks good, but it's really difficult to dodge the other mages fireballs (?) without strafing . Any chances of strafing ?

edit : ops, should have read the description Smiley

Actually, it's a bit too easy with strafing.  I can wipe out the enemies by strafing left and right firing continually as the enemies don't compensate for your lateral movement when they are targeting.  While the maths for targeting lead isn't that hard, the need to reduce byte count may mean that strafing might have to come out again to preserve game balance.  Undecided

Time flies like a bird. Fruit flies like a banana.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #10 - Posted 2010-12-23 19:35:54 »

Like 1 FPS on Mac, unfortunately. Sad

See my work:
OTC Software
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #11 - Posted 2010-12-23 20:47:45 »

Like 1 FPS on Mac, unfortunately. Sad

Thanks for your comment.  It's slow on my Powerbook A4 - About 5fps.  On my PC I get about 30fps.  My Mac is old which accounts for some of it. Which Mac and Java version do you have?

I've just changed the overlay so it's generated by bit-bashing rather than OS calls, which might help a bit.
Probably not much through.  I'll go and try my current version on the Powerbook.

I can fiddle with the depth granularity a bit, but overall, I this is just a very CPU intensive programme.

Edit: I tried making the screen quarter size and got about a factor of 3 speed increase.  At this point the AI starts to make an appreciable dent in the timing. I was getting about 14fps on the powerbook and 100fps on the PC.  I tried using createCompatible Image, but didn't gain anything significant.  The processor load goes up by a factor of two, when the screen gets busy.  However I'm already using two stages of object culling. 

Still 100 bytes over the limit - changing the overlay coding didn't seem to help much.  The code needs a tidy up, but getting those bytes back is looking increasingly difficult.  At least the program is essentially all there now.

Time flies like a bird. Fruit flies like a banana.
Offline Nmb910

Senior Newbie





« Reply #12 - Posted 2010-12-23 22:51:11 »

I'm having no lag at all.

However, as I play, I can only see if im moving, and even then the screen is constantly flashing black, if I stop it just stays black until I move again.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 817
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #13 - Posted 2010-12-23 22:59:34 »

That's because the app draws your own model, hence you are watching from within his head.

Just walk quickly to some point, turn around, see yourself catch up, and see the screen go black.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #14 - Posted 2010-12-23 23:35:25 »

I'm having no lag at all.

However, as I play, I can only see if im moving, and even then the screen is constantly flashing black, if I stop it just stays black until I move again.

That's odd.  That happened with my very early versions if you opened two windows for multiplayer on the same machine, due to a bug revolving around shared static variables.  This resulted in both players being slaved to each other.  It might be worth forcing a refresh and/or clearing the cache.  If it's still doing it, then let me know which browser, OS etc. and I'll see if I can nail it.

Edit:  Something just occurred to me.  The game receives network packets from all the players (including yourself) but disgards any with the same IP address (& process ID) as the local machine.  This might not work properly on machines with more than one IP address, or maybe there's some translation issue between localhost IP address and the real IP address.  I made some assumptions in this area  persecutioncomplex

Edit2:  I think the problem definitely relates to loopback.  If I change my code to use InetAddress.isLoopBackAddress(), it exhibits the same problem you are seeing.  It looks like there is some inconsistancy in java  implementation in this area,.

Time flies like a bird. Fruit flies like a banana.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #15 - Posted 2010-12-24 01:17:27 »

I have a workaround to the loopback problem.  Currently using both IP address and a processID fabricated from applet start up time, to determine which incoming packets are loopbacks and should be ignored.  Could just use the processID and rely on it being very unlikely that two are the same.  Alternatively I could store the IP address in the body of the message.  That would avoid issues with multi-homed machines.  I'll thing about it more tommorow.  Probably just rely on the processID being different, even though it isn't a robust solution

I have uploaded a version that ignores the loopback address and just uses processID.  See if that works  Smiley

Time flies like a bird. Fruit flies like a banana.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #16 - Posted 2010-12-24 06:29:46 »

Still laggy on the best Mac laptop you can buy right now with that latest Java version. Sad I think it's safe to say Mac applets are borked right now.

See my work:
OTC Software
Offline Nmb910

Senior Newbie





« Reply #17 - Posted 2010-12-24 08:10:09 »

It works fine now.  Thanks.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #18 - Posted 2010-12-24 10:28:49 »

Still laggy on the best Mac laptop you can buy right now with that latest Java version. Sad I think it's safe to say Mac applets are borked right now.

I had hoped that performance would be better on the new intel macs (:sigh:).  This game bit-bashes the entire scene and then drawImage()'s the result to the graphics context, which doesn't play to the mac's strengths.  Doing more in Java2D tends to level the playing field as most macs have reasonable graphics cards.  I'll look at something a bit more mac friendly for my second entry.

It works fine now.  Thanks.

Great stuff.  I'll go with just using processID.  It'll save a few bytes as well.


Time flies like a bird. Fruit flies like a banana.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #19 - Posted 2010-12-25 15:00:21 »

Release Candidate posted. 4092 bytes

I have taken strafing out, but probably could put it back if I removed cursor control.
However I think it's too easy with strafing, so I'll see how the current version goes.

Time flies like a bird. Fruit flies like a banana.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #20 - Posted 2010-12-26 14:15:00 »

Final (I hope)  Grin

-Sky now changes to dusk to herald your impending death.

Unsigned pack200 file is 4093 bytes.
http://homepage.ntlworld.com/alan.d.waddington/java/competitions/java4k/2011/MageWars4k_kzip128.jar.pack.gz
The unsigned version can be played (if you set up a suitable web page), but multiplayer doesn't work.

If you want to see the source, here it is:
http://homepage.ntlworld.com/alan.d.waddington/java/competitions/java4k/2011/M.java

Time flies like a bird. Fruit flies like a banana.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #21 - Posted 2010-12-27 16:05:14 »

Like 1 FPS on Mac, unfortunately. Sad

Just tested this on my Dad's iMac (2.66GHz Intel Core i5 OSX 10.6.5) where it works fine.  Also Java4k.com also works on this machine.

Time flies like a bird. Fruit flies like a banana.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #22 - Posted 2011-02-22 10:44:46 »

Minor bugfix uploaded to Java4k

(If you collided with a wall, while you appeared to stop, the velocity information transmitted over the network wasn't zero'd and you appeared to continue moving to all other players.  Now fixed)

Unsigned Pack200 4087 bytes (Actually a bit smaller than the previous release!)

Time flies like a bird. Fruit flies like a banana.
Offline zeroone
« Reply #23 - Posted 2011-03-28 20:17:08 »

How does the 3D rendering algorithm work?
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #24 - Posted 2011-05-09 18:58:36 »

How does the 3D rendering algorithm work?

It's been a month (sorry), but in case you still are interested...

It's raycasting through a terrain height-map sampled for a non-linear set of Z-depths, resulting in an effect a bit like stage scenery.  i.e. there is a set of flat scenery for a range of discrete depths.   This results in drastic undersampling at long distance, but in practice it isn't really distinguishable from the 'normal' X-Y undersampling you get at long distance, so it works better than one would think.  Oh and there's a second set of height-map sampling through any objects that are in view.  This allows for rotation of objects around the vertical axis, with the result that players and enemies can turn around.  The fireballs are overlayed on afterwards, using a Z-buffer.

Time flies like a bird. Fruit flies like a banana.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (67 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!