Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  I need help with upgrading a game  (Read 794 times)
0 Members and 1 Guest are viewing this topic.
Offline tdchk

Junior Newbie





« Posted 2012-05-20 23:11:42 »

Hello everybody. In my country its 2:12 am so be ready to find some unlogic sentences and misspelled words in my post Smiley

Java is my friend for already a year. I guess I`ve got the basic skills for programming at the moment.
But I have no experience in game development.

I began reading this forum and understood that I`m ready to ask you, guys, for help.
For the beginning I searched for open source project games and compiled them, studied them and wrote additional stuff.

Eventually the problem:
I have a little bit changed version of the game from http://cokeandcode.com/index.html?page=tutorials.


The Main idea of my topic:
1. I want to add methods of picking a key (the yellow block) and exiting the level (by standing on the white block)
2. It seems a shame to ask, but I dont know where to place the right code. Smiley
3. I have the logic implemented in methods, so check out what I`m going to show you.

1. The methods for picking the key:
• I added and boolean variable hasKey in class Entity.java.
• I added a getter and setter method for this variable
• I added an boolean keyValidation() method
1  
2  
3  
4  
5  
6  
public boolean keyValidation(){
if(hasKey == true)
                return true;
            else
                return false;
}

• I guess that i need to set the key true when the entities location (coordinates) are the same as the keys Huh
1  
2  
if(???player???[x][y] == map[13][13])
setKey(true);


and if at this moment I`ll reach an true state of the hasKey variable it would be already a good step for me.
2. Method for opening the door.
1  
2  
3  
4  
public void openDoor(){
  if(keyValidation() == true)
  System.out.println("GameOver");  
        }


Really the problem doesn`t sound very hard, especially for u, madskilled java man)
But I stopped at this point and I would be very pleased if somebody looks through the project or code and helps me.
Thank you.

The project source:
https://docs.google.com/open?id=0B8BBSI9JDFc4YXpST2hQOXNpdHc

Sincerely yours, tdchk
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2012-05-20 23:48:38 »

Don't you have somewhere that updates the player on every move? The most logical place to put the code is at the end of the move method.

Concerning your code, there is no need to compare a boolean with another boolean to get a boolean. You could change all your code blocks to:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public boolean keyValidation() {
    return hasKey;
}

//put this after the player moves
setKey(player.x == 13 && player.y == 13);

//put this also after the player moves
public void openDoor() {
   if(keyValidation())
       SOP("GameOver");
}

Offline ReBirth
« Reply #2 - Posted 2012-05-20 23:54:24 »

As I remember that tutorial uses interpolated movement, so I doubt your ==map[13][13] would work.

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

Junior Newbie





« Reply #3 - Posted 2012-05-21 08:31:04 »

I supposed to place the open door method at the end of the move(). And changed the setKey() because unfortunatelly and dont know "whom i need to ask for my coordinates", so I just did like this:

1  
2  
3  
4  
5  
6  
7  
public boolean keyValidation(){
                return hasKey;
        }
public void openDoor(){
            if(keyValidation())
            System.out.println("GameOver");
        }

And the method that should manage all this stuff:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public boolean move(float dx, float dy) {
      float nx = x + dx;
      float ny = y + dy;
      if (validLocation(nx, ny)) {
         x = nx;
         y = ny;
         ang = (float) (Math.atan2(dy, dx) - (Math.PI / 2));
         return true;
      }
    setKey(dx, dy);
    openDoor();
      return false;
   }

Till this stage everything is clear, the problem is with the setKey().
Here are several ways i`ve tried handling this problem, but still no success.
1.
1  
2  
3  
4  
5  
6  
7  
8  
public void setKey(float dx, float dy){
            if(dx == 13 && dy == 13){
System.out.println("The key has been picked");              
hasKey = true;
            }
            else
               hasKey = false;
        }

2. I guess this is the best one, but i need to change map.key(nx,ny) to some sort of player(nx,ny), but i dont have such stuff in this app Sad
1  
2  
3  
4  
5  
6  
7  
8  
9  
public void setKey(float nx, float ny){
            if (map.key(nx,ny) == map.key(13,13))
               System.out.println("The key has been picked");
                hasKey = true;
        }

//public boolean key(float x, float y) {
//return map[(int) x][(int) y] == KEY;
//}
Offline ReBirth
« Reply #4 - Posted 2012-05-21 12:25:45 »

Interpolated move doesn't guarantee you that player will stand exactly on 13,13, which result false on the check. Use rectangle's contains().

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.

BurntPizza (10 views)
2014-09-19 03:14:18

Dwinin (29 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (79 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (60 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (30 views)
2014-09-07 01:12:14

Longarmx (36 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
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!