Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  Sheeps4k  (Read 3657 times)
0 Members and 1 Guest are viewing this topic.
Offline f.l.x

Senior Member


Projects: 3


there is no place like 127.0.0.1


« Posted 2005-12-29 14:44:08 »

Here is my 2nd submision to the contest:


In this game, you are a shepherd dog in charge of a flock of sheeps and you have to guide them to the stable door before the time runs while you mantain the wolves away from them.

In fact, the game more a prototype than a full game yet, but it's still playable Roll Eyes . I tried to implements some steering behaviors patterns, but i had to cut out many things to fit in  Undecided

however, there are some bytes left, and is litle optimized, so any feature request / bug report is apreciated.

size 3853 bytes. 3 levels. 3825B. unlimited levels. tested on linux and winxp.


[size=12pt]play the game Smiley (server)[/size]

Litterarum radices amaras, fructus dulces
http://flx.proyectoanonimo.com
figth spam!
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 742
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2005-12-29 15:13:15 »

Nice game!

The wolves are no match really, you just hunt 'em down and you're safe.  Wolves should be faster than the player, and to compensate they should keep a larger distance from the player.

You can save 1 byte by changing "enought" to "enough" Tongue

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

Senior Member


Projects: 3


there is no place like 127.0.0.1


« Reply #2 - Posted 2005-12-29 16:57:08 »

ok, updated

now the wolves are quite a challenge, they are imortal, but they will flee you more effectively if you pursuit them, and they can go out of the screen bounds, so they might be there even if you can't see them  Roll Eyes

added generated levels, not as fun, but it saved some bits.

Litterarum radices amaras, fructus dulces
http://flx.proyectoanonimo.com
figth spam!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #3 - Posted 2005-12-29 17:01:47 »

Very cool game!  I got through the first two levels, but the 3rd level I tried multiple times and never even got close hahaha.  There was always one wolf I couldn't get near.  If I was near one, or maybe 2, the 3rd one was free to play.  So essentially I had a constant decrease in sheep and if I dealt with wolves, I was wasting my time and sheep ended up scattered all over the screen.  If I tried to herd and minimally scare off wolves, I wasn't fast enough to get the % of sheep I needed by a long shot.  Maybe I just stink, but between levels 2 and 3 that's quite a difficult learning curve Smiley

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #4 - Posted 2005-12-29 18:03:11 »

Neat game.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #5 - Posted 2005-12-29 18:39:53 »

Yeah, neat!

Though with 400 sheep it really slowed down.  I suspect you haven't done anything to try to optimize the number of sheep-to-sheep "attraction" calculations.  Not that you have a lot of options with 4k.

Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #6 - Posted 2005-12-29 20:36:55 »

I ran it on my computer at home and the game is slow like hell, which is weird because my home pc is more powerful than my work pc.

P4 2.6ghz, 1 gig ram
ATI 9600xt 256mb ram
windows xp

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline f.l.x

Senior Member


Projects: 3


there is no place like 127.0.0.1


« Reply #7 - Posted 2005-12-29 22:25:03 »

i noticed that on some windows boxes, it becomes slow win more than 400 sheeps. In linux ran fine with >750 sheeps

i'll trade drawing the actors with something more ellaborated than ovals for some optimization Smiley

Litterarum radices amaras, fructus dulces
http://flx.proyectoanonimo.com
figth spam!
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 74
Projects: 15


★★★★★


« Reply #8 - Posted 2005-12-29 23:19:36 »

great game i enjoyed it alot, as for performance you may want to try
1  
<property name="sun.java2d.noddraw" value="true"/>

flag, usually helps improve the performance by a little.
Offline f.l.x

Senior Member


Projects: 3


there is no place like 127.0.0.1


« Reply #9 - Posted 2005-12-29 23:59:27 »

ok, updated the jnlp with the noddraw property and the -server vm argument, see if it makes it playable with >400 sheeps

i'll upload now a easier version (less sheeps required to pass)

Litterarum radices amaras, fructus dulces
http://flx.proyectoanonimo.com
figth spam!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline noblemaster

JGO Ninja


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #10 - Posted 2005-12-30 00:07:31 »

The game requires the "server" JVM, but I only have the "client" installed here (i.e. the JRE only). You might want to change the jnlp to start in client mode.

I just get an error message! Cannot run the game.  Sad

Offline f.l.x

Senior Member


Projects: 3


there is no place like 127.0.0.1


« Reply #11 - Posted 2005-12-30 00:24:32 »

ok, that was a random shot uploaded another jnlp. However, the one with the -server argument is here

Litterarum radices amaras, fructus dulces
http://flx.proyectoanonimo.com
figth spam!
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 74
Projects: 15


★★★★★


« Reply #12 - Posted 2005-12-30 02:50:48 »

the -server arguement isn't really a good idea to use with games as it won't really give a performance enhancement instead it usually does the opposite for games. since it takes a few minutes for the optimisations to kick in.
Offline f.l.x

Senior Member


Projects: 3


there is no place like 127.0.0.1


« Reply #13 - Posted 2005-12-30 14:12:24 »

I'm having problems to optimize the sheep to sheep loop due the data structures i chosen to use.
the loop looks like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
for(int i = 0; i < sheep.length; i += 4){
   if(sheep[i] == -1)
      continue;
   desired_vx = desired_vy = avg_x = avg_y = num_on_range = 0;
   // fetch data from the nearby sheep
  for (int o = 0; o < sheep.length; o += 4) {
      dist = (float) Point.distance(sheep[o], sheep[o + 1], sheep[i], sheep[i + 1]) + 0.1f;
      if (dist < SHEEP_VIEW_RANGE && (o != i) && sheep[o] != -1) {
         num_on_range++;
         //cumulate the repeling force for this sheep
        desired_vx -= ((sheep[o] - sheep[i]) / dist);
         desired_vy -= ((sheep[o + 1] - sheep[i + 1]) / dist);
         //cumulate the average center of the nearby crowd
        avg_x += sheep[o];
         avg_y += sheep[o + 1];
      }
   }
   [...]
}


I tried to loop only for some sheeps before and after the 'i' sheep, but without ordering the array it doesn't work, and ordering each frame kills the game.

I also tried to check if the distance on the x or y was too much but it seems that any checking kills the performance if there are more than 1000 sheeps Sad

any idea

Litterarum radices amaras, fructus dulces
http://flx.proyectoanonimo.com
figth spam!
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #14 - Posted 2005-12-30 15:37:38 »

Restructuring the data would be necessary to get any big benefit.. though there are some minor opimization that can be done with your existing loop.

Computing the distances is one of the more expensive operations.  There are ways to speed it up:

1  
2  
dist = (float) Point.distance(sheep[o], sheep[o + 1], sheep[i], sheep[i + 1]) + 0.1f;
if (dist < SHEEP_VIEW_RANGE && (o != i) && sheep[o] != -1) {


First check o!=i and sheep
  • != -1  BEFORE computing the distance.

Instead of using Point.distance  do your own computation.. but leave off the sqrt  just compute (dx^2 + dy^2).  Then compare to squared  SHEEP_VIEW_RANGE^2 instead.

Then only inside the if block do you need the sqrt, AND you can save the dx &  dy values in local vars so they don't need to be recalculated when computing desired_vx & desired_vy.

Offline nva225

Junior Member





« Reply #15 - Posted 2005-12-30 18:11:39 »

Hmm nice game, but very ambitous with the (very cool) gravitational pull aspect. The giant "sheep balls" are interesting to watch. Too bad it begins running slowly around 500 sheep, as you're already aware.

Sorry I can't really think of anything else to help out besides what swpalmer already said.

Only thing that crosses my mind, though you're probably already doing this, is to make sure you're not drawing two circles for each sheep, and you're just pasting a pregenerated image where needed. Java circles are pretty slow.
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #16 - Posted 2005-12-30 18:34:29 »

Runs fine on my machine.  I only made it to the 4th level.  750 sheep I think.  Too hard with 3 wolves.  Maybe you could have the wolves fight each other a little bit as a distraction for them.  Overall well done.  Especially like the flocking.


AMD  Athlon64 3000+
512MB Dual channel
Radeon 9600PRO

Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #17 - Posted 2005-12-30 19:33:10 »

I'm having problems to optimize the sheep to sheep loop due the data structures i chosen to use.
the loop looks like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
for(int i = 0; i < sheep.length; i += 4){
   if(sheep[i] == -1)
      continue;
   desired_vx = desired_vy = avg_x = avg_y = num_on_range = 0;
   // fetch data from the nearby sheep
  for (int o = 0; o < sheep.length; o += 4) {
      dist = (float) Point.distance(sheep[o], sheep[o + 1], sheep[i], sheep[i + 1]) + 0.1f;
      if (dist < SHEEP_VIEW_RANGE && (o != i) && sheep[o] != -1) {
         num_on_range++;
         //cumulate the repeling force for this sheep
        desired_vx -= ((sheep[o] - sheep[i]) / dist);
         desired_vy -= ((sheep[o + 1] - sheep[i + 1]) / dist);
         //cumulate the average center of the nearby crowd
        avg_x += sheep[o];
         avg_y += sheep[o + 1];
      }
   }
   [...]
}


I tried to loop only for some sheeps before and after the 'i' sheep, but without ordering the array it doesn't work, and ordering each frame kills the game.

I also tried to check if the distance on the x or y was too much but it seems that any checking kills the performance if there are more than 1000 sheeps Sad

any idea

1) you don't need to sort the entire array every frame, only about 1x a second I'd guess
2) you could use another array with indexes into the sheep array to implement a quad tree or something like that....

The game is pretty cool as is, do you really need more sheep?

 Grin
Offline DonaldEKnuth

Junior Member





« Reply #18 - Posted 2006-01-02 02:32:42 »

Very nice and fun game! Ran fine on my 2Ghz 512mb RAM Windows XP Pro. box.

My 4k 2006 Entry: Sokoban4k
Offline Anon666

Junior Member




aka Abuse/AbU5e/TehJumpingJawa


« Reply #19 - Posted 2006-01-02 20:04:37 »

No wonder if is slow, you are performing sheep.length*sheep.length square roots!!!

How about you change this line :-
1  
2  
dist = (float) Point.distance(sheep[o], sheep[o + 1], sheep[i], sheep[i + 1]) + 0.1f;
if (dist < SHEEP_VIEW_RANGE && (o != i) && sheep[o] != -1) {


into this :-

1  
2  
3  
dist = (float) Point.distanceSq(sheep[o], sheep[o + 1], sheep[i], sheep[i + 1]);
if (dist < (SHEEP_VIEW_RANGE-0.1f)*(SHEEP_VIEW_RANGE-0.1f) && (o != i) && sheep[o] != -1) {
   dist = Math.sqrt(dist) + 0.1f


It will remove a considerable number of sqrt's, with only a small size cost.

It'd be even better if you can change the desired_vx stuff inside the if, so it can use the square of the distance.
Offline lyeoh

Innocent Bystander





« Reply #20 - Posted 2006-01-07 15:25:03 »

The game got really slow from level 10 onwards - 2000, 2200 etc sheep!

At that point it got pretty easy to save the required 200+ sheep - the wolves just can't kill 1800+ sheep fast enough, in fact the wolves were very helpful when you need to herd bigger bunches of sheep at a faster speed Wink.

Once you have 1500+ sheep you can only herd them in small chunks unless you have have help from the wolves.

Nice game though, even though it got slow, I still continued playing Cheesy.
Offline f.l.x

Senior Member


Projects: 3


there is no place like 127.0.0.1


« Reply #21 - Posted 2006-01-07 21:36:18 »

Thanks i'm following some of those tips now, i have been intentionally away from eclipse for this seasons holidays, so there is no changes yet, but there will be.

Quote
Only thing that crosses my mind, though you're probably already doing this, is to make sure you're not drawing two circles for each sheep, and you're just pasting a pregenerated image where needed. Java circles are pretty slow.
in fact i'm drawing the ovals each cicle, it's slower, but it saves me some bytes from image variables and drawing the ovals into them for the first time, but i'll maybe do so, and put something else than ovals for all the actors

Quote
do you really need more sheep?
i'm working in a litle gameplay twist (for the levels to make some sense, and to be a litle more playable) wich implies a limited number of sheeps Smiley anyway implement a tree for the sheeps could be too mucho for the space remaining Grin

i have left that loop like this, for now

1  
2  
3  
4  
5  
dist = ((sheep[i] - sheep[o]) * (sheep[i] - sheep[o]));
dy = ((sheep[i + 1] - sheep[o + 1]) * (sheep[i + 1] - sheep[o + 1]));
if ((dist + dy) < (SHEEP_VIEW_RANGE * SHEEP_VIEW_RANGE)) {
num_on_range++;
dist = (float) Math.sqrt(dist + dy) + 0.1f;



thanks alot

Litterarum radices amaras, fructus dulces
http://flx.proyectoanonimo.com
figth spam!
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.

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

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

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

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

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

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

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

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

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

Riven (49 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!