Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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  
  pengo4k  (Read 9270 times)
0 Members and 1 Guest are viewing this topic.
Offline luisoft

JGO Coder


Projects: 6


Java games rock!


« Posted 2005-02-24 02:49:57 »

tell me what do u think about this game:

http://howlerbr.freecoolsite.com/files/pengo4k/pengo.jnlp

It is a 4k version of the ld classic Pengo
Offline Hansdampf

Senior Member


Projects: 3


too offending?


« Reply #1 - Posted 2005-02-24 03:28:37 »

nice!
I'd replace the breakIce g.fillOval(x, y, 1, 1);
for more speed. The game slows linearly down by the amount of broken ice for me
       

   

lots of sillystupid games: http://www.emaggame.com
Offline jojoh

JGO Knight


Medals: 5
Projects: 7


games4j.com


« Reply #2 - Posted 2005-02-24 07:50:45 »

Cool!

Pengo is a classic and this is a very worthy 4K conversion. I had some problems though. At level 4 I could not complete the level. All badies are gone and all (visible ?) coins are gone, but I can't get to next level. Also agree with Hansdampf. After two broken iceblocks, the game runs at about 1/2 speed from normal! Game should probably also be time based. So player moves same dist / sec independent of CPU speed and load. I guess that is not the case, so on a 3GHz machine this might simply be too fast to play. Badies mouth is upside-down when moving left  Cheesy Not sure if that is intentional.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline luisoft

JGO Coder


Projects: 6


Java games rock!


« Reply #3 - Posted 2005-02-24 09:03:08 »

tks for the feedback, I will try to figure out what is happing. But how can I make the player moves same dist / sec independent of CPU speed and load ?
Offline jojoh

JGO Knight


Medals: 5
Projects: 7


games4j.com


« Reply #4 - Posted 2005-02-24 09:48:28 »

Something like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
//init
     float playerX;
      long lastLoopTime = System.currentTimeMillis();

      //Main game loop
     while (true) {
            delta = System.currentTimeMillis() - lastLoopTime;
            lastLoopTime = System.currentTimeMillis();

            //Use delta for all your movement!

            //Move
           if(left){
                  playerX -= delta * 0.01f;
            }
            if(right){
                  playerX += delta * 0.01f;
            }

            //All your other gamecode
     }

Short description, but I think you get the idea

Offline luisoft

JGO Coder


Projects: 6


Java games rock!


« Reply #5 - Posted 2005-02-24 10:53:53 »

I have tried the following code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferStrategy;
import java.io.InputStream;

import javax.swing.JFrame;

public class Loop1 extends JFrame {

      private boolean[] controls = new boolean[5];
      int x=100;
      int y=100;
      double dx=0.1;
      double dy=0.1;

      public Loop1() {
   
            setSize(300,300);
            setResizable(false);
            show();
 
             enableEvents(56);
   
            createBufferStrategy(2);
            BufferStrategy strategy = getBufferStrategy();
 
            int FPS=60;
            int MILI_FRAME_LENGTH = 1000/FPS;
            long startTime = System.currentTimeMillis();
            int frameCount = 0;

            long lastLoopTime = System.currentTimeMillis();
            long lastFpsTime=0;
            long fps=0;

            while (true) {

                  long delta = System.currentTimeMillis() - lastLoopTime;
                  lastLoopTime = System.currentTimeMillis();
                   lastFpsTime += delta;
                  fps++;
 
                   if (lastFpsTime >= 1000) {
                        this.setTitle(" (FPS: " + fps + ")");
                        lastFpsTime = 0;
                        fps = 0;
                  }

                     logic(delta);
                        draw((Graphics2D) strategy.getDrawGraphics());
                        strategy.show();

                  frameCount++;
                  while((System.currentTimeMillis()-startTime)/MILI_FRAME_LENGTH <frameCount) {
                        Thread.yield();
                  }

                  //Toolkit.getDefaultToolkit().sync();

            }
      }

      private void logic(double delta) {
            if(controls[0]) {
                  x-=dx*delta;
            } else if(controls[1]) {
                  x+=dx*delta;
            } else if(controls[2]) {
                  y-=dy*delta;
            } else if(controls[3]) {
                  y+=dy*delta;
            }

            if(x>300) {
                  x=0;
            }
            if(x<0) {
                  x=300;
            }
            if(y<0) {
                  y=300;
            }
            if(y>300) {
                  y=0;
            }

      }

      private void draw(Graphics2D g) {
            g.setColor(Color.white);
            g.fillRect(0,0,300,300);

            g.setColor(Color.red);
            g.fillOval(x,y,5,5);

      }


      protected void processKeyEvent(KeyEvent e) {
            int[] keys = new int[] {KeyEvent.VK_LEFT,KeyEvent.VK_RIGHT,KeyEvent.VK_UP,KeyEvent.VK_DOWN,KeyEvent.VK_SPACE};
            for (int i=0;i<keys.length;i++) {
                  if (e.getKeyCode() == keys[i]) {
                        controls[i] = e.getID() == KeyEvent.KEY_PRESSED;
                  }
            }
            if (e.getKeyCode() == 27) {
                  System.exit(0);
            }
        }

      public static void main(String argv[]) {
            new Loop1();
      }

}


But it seems to move the dot point faster when I move up and left and slower when I move down and right... Ihave another post in the forum with the same question.

This code follows what you said to do...what is wrong?
The only difference is that I am using ints for x and y instead of floats
Offline luisoft

JGO Coder


Projects: 6


Java games rock!


« Reply #6 - Posted 2005-02-24 10:58:41 »

I think that the problem was exactlly that. Now I am using double for x,y and delta, instead of int for x,y and long for delta. Now it seems to move at the same speed in all directions...but I did not understand why it did not work with ints....any ideas?
Offline jojoh

JGO Knight


Medals: 5
Projects: 7


games4j.com


« Reply #7 - Posted 2005-02-24 11:05:28 »

(int)(5+0.3) //this = 5
(int)(5-0.3) //this = 4

Typecasting float to int will not round off, but just take away decimals.

Offline luisoft

JGO Coder


Projects: 6


Java games rock!


« Reply #8 - Posted 2005-02-24 11:17:15 »

now I am using

double x;
double y;
double dx;
double dy;
long delta;

// updating according to delta variation
x-=dx*delta;
y-=dx*delta;

// drawing the player
g.fillOval((int)x,(int)y,5,5);

It seems to be working but I don't know if it the best practice.

I always heard that is preferred to use ints instead of double or floats to get more performance
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #9 - Posted 2005-02-24 11:24:01 »

Quote
I always heard that is preferred to use ints instead of double or floats to get more performance


Premature optimization is the root of all evil. Besides, minor optimizations at an instruction level tend to make very little difference on modern hardware. You'll do much better investing your time in finding a solution that's algorithmically faster.

Java Game Console Project
Last Journal Entry: 12/17/04
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline luisoft

JGO Coder


Projects: 6


Java games rock!


« Reply #10 - Posted 2005-02-24 15:10:52 »

jojoh and jbanes, I have just one more question:

If I do not use delta for update my movement, how can I maintain the same speed with different CPUs?

Say if I wanna move my player  3 pixels every time a press a directional key?

x+=3 if going right
x-=3 if going left
y+=3 if goinf down
y-=3 if goinf up.

How should I do that?
Offline Malohkan

Senior Member




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


« Reply #11 - Posted 2005-02-24 15:23:47 »

Then you want to have a set frame rate.  Also, you shouldn't actually make them move whenever a key is pressed as the KeyEvent Thread is not in synch with your game... so take a look at my tutorial to see a good way to manage frame based animation as you're desiring:

http://www.gamelizard.com/JavaGameProgrammingPresentation.htm

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

JGO Coder


Projects: 6


Java games rock!


« Reply #12 - Posted 2005-02-24 15:44:49 »

I am taking a look at your game loop. I did not understand this:

//Doesn't account for drag
    tick = at.getClockTicks();

//Does account for drag
  //tick += ticksPerFrame;


What exactly means "account" for drag? And when I should use one or another?
Offline luisoft

JGO Coder


Projects: 6


Java games rock!


« Reply #13 - Posted 2005-02-24 15:48:24 »

Also, was not clear to me why did you mix GageTimer with System.currentTimeMillis() ?
Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #14 - Posted 2005-02-24 15:56:20 »

umm...is webstart foobared or somethin?! Or are you lying to us telling us its 4K? huh?  Tongue



Oh yer, good game, i used to be an addict on it on www.javaonthebrain.com.

Still a cool game!

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline luisoft

JGO Coder


Projects: 6


Java games rock!


« Reply #15 - Posted 2005-02-24 16:43:46 »

the webstart jar version is bigger. The final version for 4k competition I have used proguard to shrink the size, and it is lower than 4k...

here is the url:

http://howlerbr.freecoolsite.com/files/pengo4k/pengo4k.jar

Download it and execute...

java -jar pengo4k.jar P

Offline luisoft

JGO Coder


Projects: 6


Java games rock!


« Reply #16 - Posted 2005-02-24 17:06:40 »

Malohkan, I have implemented your game loop example. It works, but please answer my previous questions for a better understanding. Tks in advance! Cheesy
Offline Malohkan

Senior Member




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


« Reply #17 - Posted 2005-02-24 23:32:30 »

As for mixing timing techniques, there's no need for that other than it's simple to show how to calculate FPS.  You can use GAGE to get the time just as easily for that purpose.

As for your timing question, drag means time lost due to the cpu working too hard on something.  The idea is that if you're unable to evaluate all of your game stuff in a single frame's time, the next frame will try to be faster to make up for it.  This can be good for when you really care about true time elapsed.

However for many of my purposes, any time I have drag, it's long lag, generally a spike from something unforseeable.  So I really don't want the next 10 frames to be really quick because I'm in an action game where you fight AI, so that gives the CPU a big advantage.  Not only does it suck to have the game freeze, but it sucks worse to see the AI get 10 shots on you when you barely have time to react.  So really it's a matter of trying both out to see which is right for your purpose.  Ideally your game won't require so much time and they'll both work the same Smiley

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

JGO Coder


Projects: 6


Java games rock!


« Reply #18 - Posted 2005-02-25 08:59:13 »

thank you Malohkan, your explanation really cleared out my questions! Grin
Offline krypto

Junior Member




while(true) { self.caffeinate (); }


« Reply #19 - Posted 2005-02-25 11:15:23 »

It ran great on my machine... Good Job.

JRPG Users -  General Users Site
JRPG Developers -  The JRPG Project's Home
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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (46 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (64 views)
2014-09-21 02:42:18

BurntPizza (36 views)
2014-09-21 01:30:30

moogie (42 views)
2014-09-21 00:26:15

UprightPath (51 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!