Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
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  
  [SOLVED] Snake-type Game  (Read 860 times)
0 Members and 1 Guest are viewing this topic.
Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Posted 2012-01-12 01:34:09 »

I made a snake-like game based on what I had started already, and it turned out all right besides a few things.

1) The turning is very choppy and bad and horrible
2) That's it

Or at least, that's the only major thing. The code (I'm pretty sure) could be improved on a ton. The only thing I'm worried about is the turning right now, however.

Here's the source and .jar, I would appreciate anyone giving some constructive criticism or help fixing the key lag/general sloppiness.

http://www.mediafire.com/?lxk259ducle3fev

Thanks,
-Nathan

Check out my website!
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2012-01-12 03:42:21 »

Hehehe I've seen those sprites before somewhere....... Wink

Runs at 7000FPS and I quit after 2000+ points Tongue

The only bug I found was when hitting two different arrow keys semi-quickly the player stops.

Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #2 - Posted 2012-01-12 03:46:31 »

Hehehe I've seen those sprites before somewhere....... Wink

Hahaha yeah I couldn't make my own version look good! Smiley

Runs at 7000FPS and I quit after 2000+ points Tongue
Holy crap really? What kind of god-rig do you have? I get 1300 Tongue

The only bug I found was when hitting two different arrow keys semi-quickly the player stops.

I'm working on this, debugging is my least favorite part of coding when it takes this long. Even though it's only been an hour haha.


Do you have any idea what could be making the key-reading so sloppy?

Thanks by the way Smiley
-Nathan

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

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2012-01-12 04:00:44 »

Runs at 7000FPS and I quit after 2000+ points Tongue
Holy crap really? What kind of god-rig do you have? I get 1300 Tongue
Uhh an Intel Core i7 2600K overclocked to 4GHz, Nvidia GeForce GTX 580, 8GB of RAM, 60GB SSD, and 1TB HDD.........MUST..PLAY...BATTLEFIELD 3! Smiley

The only bug I found was when hitting two different arrow keys semi-quickly the player stops.

I'm working on this, debugging is my least favorite part of coding when it takes this long. Even though it's only been an hour haha.

Do you have any idea what could be making the key-reading so sloppy?
It seems like there is absolutely no point to the xxxPressed, dx, dy, and xxxWait variables, I can't see any reasonable use for them, except playing around with numbers.
The variables that control all the moving are the dirXXX variables, yet everything seems fine to me.....

I didn't do any extensive debugging because your code is way overcomplicated when you could have taken out half of it.

EDIT: Aha, I stared at it a couple more minutes and I figured it out. This only happens when you press a new key while still holding down the old key. Since my fingers are moving really fast, I couldn't really notice it but I noticed the bug in the code. I traced it down to keyReleased(int). Let's say I hold down UP, hold RIGHT, release UP, then release RIGHT: dirUp gets set to true, then dirRight gets set to true. In keyReleased(int), when I release UP: dirRight, dirLeft, and dirDown are set to false; then I release RIGHT: dirLeft, dirUp, and dirDown are set to false. In the end everything is false so nothing is moving!

I suggest using only 1 variable for direction and having 4 constants that specify what direction to move:
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  
private final int RIGHT = 0, LEFT = 1, UP = 2, DOWN = 3;
private int currentDirection = UP;

...

public void keyPressed(int key) {
    switch(key) {
        case KeyEvent.VK_RIGHT:
            currentDirection = RIGHT;
            break;
        case KeyEvent.VK_LEFT:
            currentDirection = LEFT;
            break;
        case KeyEvent.VK_UP:
            currentDirection = UP;
            break;
        case KeyEvent.VK_DOWN:
            currentDirection = DOWN;
            break;
    }
}

//forget about keyReleased

public void move() {
    //calculate timeToMove
   
    if(timeToMove) {
        switch(currentDirection) {
            case RIGHT:
                //move right;
                break;
            case LEFT:
                //move left;
                break;
            case UP:
                //move up
                break;
            case DOWN:
                //move down;
                break;
        }
    }
}


Phew....lots of typing Grin

Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #4 - Posted 2012-01-12 04:05:50 »

I didn't do any extensive debugging because your code is way overcomplicated when you could have taken out half of it.

Oh Shocked

What makes it so complicated and difficult?

It's weird because I can understand my code but I was looking through Minicraft and had NO idea what was going on :/

Check out my website!
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-01-12 04:14:01 »

Hehehe updated my post.

By "overcomplicated" I meant more like "overworked". You had lots of things going on, different variables that meant the same thing and many variables that were unused. However I was only looking at your Player class. I didn't open any of your other source files Smiley

And of course, you can understand your own code because you typed it, you know what was going on through your head when you did (at least....for the time being Grin)

Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #6 - Posted 2012-01-12 04:28:47 »

Thanks so much! Worked sooooooo well!

I am once again very pleased at your helpfullness   Grin

-Nathan

Check out my website!
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2012-01-12 04:34:12 »

Cool

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.

rwatson462 (28 views)
2014-12-15 09:26:44

Mr.CodeIt (19 views)
2014-12-14 19:50:38

BurntPizza (39 views)
2014-12-09 22:41:13

BurntPizza (74 views)
2014-12-08 04:46:31

JscottyBieshaar (36 views)
2014-12-05 12:39:02

SHC (49 views)
2014-12-03 16:27:13

CopyableCougar4 (44 views)
2014-11-29 21:32:03

toopeicgaming1999 (112 views)
2014-11-26 15:22:04

toopeicgaming1999 (98 views)
2014-11-26 15:20:36

toopeicgaming1999 (29 views)
2014-11-26 15:20:08
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!