Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

106 Neutral

About kevin_06s

  • Rank
  1. Hello, I am trying to create an arrow key movement system that is familiar to all gamers, but Java is not cooperating. In my program, I am using a KeyListener and keeping track of keystates with booleans, like the GameDev Wiki says to do. After some testing, I found out that if I press and hold a diagonal like up-left and release it, everything works fine. However, if I press and hold up-left, then release only left, Java will not fire a KeyEvent for left being released until up is also released! I want to be able to detect the left being released, and I have no idea how to do so.
  2. In C++ I used to use macros to do my logging: public void log(string message) { ofstream out("Log.txt"); out << __FILE__ << __LINE__ << message; out.flush(); } Unfortunately, Java does not have the __FILE__ and __LINE__ macros, so how can I rewrite log() in Java?
  3. <br /><br /><br /> Thanks, this seems like it will work just fine. I am going to go brush up on my XML.
  4. Sorry, what I meant was not that there was a variety of standard effect types, but rather that, for example, when a card is attacking, its onAttack(Card target) method might be called, or when it is being attacked, onDefend(Card attacker) might be called. This allows me to do a huge variety of logic for card effects which cannot be matched by using standard state alternations. Is there any way to retain the flexibility I want while not having to resort to making a new subclass for each card? [/quote] Template methods along the lines of onAttack(), onDefend() etc. are a good way to structure turn processing, but you should use composition rather than inheritance to describe different cards with a single class, and different assemblies of a moderate number of card effects, rather than as separate classes. For example, assuming rules more or less like Magic: the Gathering, a card (creature?) could have a list of "things that might trigger when it attacks", and the one and only Card.onAttack() implementation (there might be decorators and test ones that we don't care about) would go through the list, test whether triggers are skipped, and execute those that aren't. I am of course implying a Trigger class with methods to test whether it actually executes (e.g. "if it is an odd turn"), to tell the game which choices the player has to make (e.g. "choose target creature A controlled by you"), to execute if possible (e.g. "heal creature A"). Triggers would have no more inheritance than, maybe, variants with different contexts of known information, like CreatureAttackTrigger (with knowledge of the attacking creature) or TurnEndTrigger (with knowledge of the active player). You can get away with classes in this case because there is a small and fixed set of events that could fire a trigger. Triggers would reference elementary test, user interface and game state change operations (in the example, querying the turn number, an odd() predicate, querying who controls a creature and which player is attacking; asking for a creature; healing a creature respectively). The same organization would apply to continuous abilities, replacements, and anything else. And yes, there is "a variety of standard effect types", even if they start out as the effect of a single card. Considering the modest amount of things they can do (damage, drawing cards, etc.), they are even more standard. Can you provide examples of what you think requires arbitrary code in card subclasses? How fancy are your cards? [/quote] Please tell me if I am understanding you correctly. You are saying to have a Trigger class which has methods that check for all the different kinds of logical conditions, and then a collection with the different possible types of effects. Each card would have different values indicating which effects out of that collection it can apply, and a list of which triggers to check. The design looks something like this: Enum Effects Class Trigger and subclasses Enum TriggerTypes Class Card has TriggerTypes and Effects Is this correct?
  5. This rudimentary design is far too unstructured. Everything your cards do is actually an aggregate of standard effects (effect types implicit in your method names are destroy a card, force something to attack or not attack (or to defend or not defend), forbid some cards to be played), which should be their own classes or functions; they, in turn, will probably rely on an even more stable layer of elementary game state alterations, evaluation of predicates, selection of cards and other objects. Different cards should be defined in databases and configuration files, all instances of one Card class. I suggest you study the comprehensive rules of Magic: the Gathering; beneath a heap of complications (with whole sections required by a single troublesome card), there is a rather neat and formal definition of game entities and events, of effect types, of state based actions that take place automatically, of what players can do, of how conflicts between cards are resolved. I hope your game will be simpler, but you should strive for that level of exactness. [/quote] Sorry, what I meant was not that there was a variety of standard effect types, but rather that, for example, when a card is attacking, its onAttack(Card target) method might be called, or when it is being attacked, onDefend(Card attacker) might be called. This allows me to do a huge variety of logic for card effects which cannot be matched by using standard state alternations. Is there any way to retain the flexibility I want while not having to resort to making a new subclass for each card?
  6. I am working on a trading card game (TCG) project, and I have run into a roadblock in deciding how to implement the special effects and abilities of the cards. I am working in Java, by the way, although this is really a problem in object oriented design. As it is now, I have a sort of event based setup where there is a main Card class that has methods like onAttack(), onDefend(), onPlay(), onDestroyed(), etc... which are called as events happen. The stumbling block here is that I need to create a new subclass for every single card with an effect, which, while it would work just fine, somehow seems fundamentally wrong to me in the same way that it seems wrong to me when someone does array[0] = 0; array[1] = 0; array[2] = 0; etc., when they could just use a for loop. This approach that I am using seems like it would scale very badly as the number of cards increases, and I am wondering if there is a way to simplify this design? I am also wondering if anyone knows how some commercial TCGs get around this problem, or even if anyone has any source code from a TCG that I can study.
  7. kevin_06s

    Extract int from string in Java

    I figured it out. The problem was that I had to do: sum += Math.pow(Integer.parseInt(Character.toString(temp.charAt(n))), 4); It seems like this would be so much easier in other languages. I think C++ would just be sum = pow(temp[n] - '0', 4);
  8. Having troubles with type conversions in Java. I have a string containing some number, say, 12345, and I need to loop through the string, extracting a single digit at a time to perform operations on. Here's what I have so far. for(int i = 0; i < 10000; ++i) { String temp = Integer.toString(i); int sum = 0; for(int n = 0; n < temp.length(); ++n) { sum += Math.pow(Integer.parseInt(temp.charAt(n)), 4); } } I tried doing this: sum += Math.pow(Integer.parseInt(temp.charAt(n).toString()), 4); but it didn't work, and as I have it right now, it won't let me parse a char, so I need to convert it to string somehow. Thanks
  9. kevin_06s

    Compressing Game Music

    Right now the size of my game music is 90% of my total size. It is taking up way too much space, and it is already in .ogg format, compressed down from .wav files. Is there any way to compress it further? Are there any file formats that are more compressed than .ogg? Or are there any tools or things I could use to compress them?
  10. kevin_06s

    SDL Velocity Problem

    Ok, I think it's working now :)
  11. kevin_06s

    SDL Velocity Problem

    Yes, that is exactly what it is doing. I have already switched over to a static pixels/second speed, and given up on velocity. What I had was basically like this: #include "Include.h" //All libraries needed #define SPEED .01 #define FPS 30 int main(int argc, char* argv[]) { bool quit = false; double xVel = 0; double yVel = 0; int x = 0, y = 0; Uint32 fps = SDL_GetTicks(); SDL_Surface* screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE) //load() returns an optimized, colorkeyed image SDL_Surface* test = load("Images\\dot.png"); while(quit == false) { while(SDL_PollEvent(&events)) { if(events.type == SDL_QUIT) { quit = true; break; } } Uint8* keystates = SDL_GetKeyState(NULL); if(keystates[SDLK_UP] || keystates[SDLK_w]) { yVel -= SPEED; } if(keystates[SDLK_DOWN] || keystates[SDLK_s]) { yVel += SPEED; } if(keystates[SDLK_LEFT] || keystates[SDLK_a]) { xVel += SPEED; } if(keystates[SDLK_RIGHT] || keystates[SDLK_d]) { xVel -= SPEED; } x += xVel; y += yVel; apply(x, y, test, screen); //apply() is my blitting function if((SDL_GetTicks() - fps) < (1000 / FPS)) { SDL_Delay((1000 / FPS) - (SDL_GetTicks() - fps)); } fps = SDL_GetTicks(); SDL_Flip(screen); } If I set SPEED too low, then it becomes unresponsive and very hard to control, if I set SPEED at 1.0 or greater, then it moves too fast.
  12. kevin_06s

    SDL Velocity Problem

    I'm not sure how to do that, because the velocity is responding to the input of the arrow keys. Also, what is different in increasing velocity by 1/90th every frame from increasing velocity by 1 every 90th frame? I am not seeing the difference, I thought a velocity change in the decimals would be the same thing.
  13. kevin_06s

    SDL Velocity Problem

    Even at a velocity of 1, though, the image is moving too fast, and the cast truncates the number, so if I add +0.0001 velocity / frame, up until 0.9999 velocity, the image will sit there which is what causes the delay, then at 1.0000 velocity it goes flying off the screen. >:( This is the setup I'm using: if left/right is pressed, +- xVelocity if up/down is pressed, +- yVelocity each frame, the image moves by x-position += xVelocity y-position += yVelocity Perhaps there is a better setup?
  14. kevin_06s

    SDL Velocity Problem

    The trouble I have been having is as you say, SDL will only blit whole pixels. I tried setting the acceleration to something like .002, but because I have to convert to an integer before blitting, it only serves to cause a delay between the keypress and the image movement. The image movement itself though is still too fast.
  15. kevin_06s

    SDL Velocity Problem

    My screen size in SDL is 800 x 600, which is not really small, but whenever I try to implement velocity, the images go much too fast. I have set an image to increase velocity by 1 each frame, at 30 fps. So that becomes an arithmetic series with d = 1 and n1 = 0. Term 30 would be 29, so sum30 = 30((0 + 29) / 2) = 435 pixels per second. The image crosses the screen in under two seconds, while I need it to cross in around 10 seconds!! How can I fix this?
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!