Simplifying fractions

It seems that you have a lot of energy, which is Good™, but you also seem to be sloppy, impatient and hurried - which is standing in your way. That might be the reason you don’t get things from abstract explanations. Take a step back and relax. Try to analyse formulars/given code step by step and try to understand the single steps. Don’t get impacient if you don’t get it right away (nobody does). Just take your time (or get your hands on some Ritalin :-X)

thx for the advice.

I will take hte advice and try and figure out the source code from riven ;).

will post back wiht my analysis.

I’d actually advise against analyzing my sourcecode.

Read that darn book first! If something is not clear, do no skip the page, ever! Because the learning curve is only UP, and every following page assumes you grasped the previous.

It’s all about discipline.

I didnt say I skipped stuff. I said I took like 2 days on each little topic.

Ok I skimmed through it to see wha tI had read before. I dont think that I had finished it.

I have covered all that the book has to offer though, through my scowering of th internet.

haha I just learned something. It will acutally fix a prolem Ihad in a game. I didnt konw how to make something gloabal to all instances. static variables. taht saved me tons of hassle.

thx for the badgering on my crappy skills, you saved me a lot of work.

Don’t skim too. And if you think you absorbed everything in the book, you might want to reread it, or buy a better book.

Besides that, the static keyword is easily abused.

If you design things properly, you might only use static in the main method, and the slingleton pattern. Steer clear of static as much as possible, it’ll bite you in the long run.

is it ok if I make my score, level, and shield static?

What if you introduce more ‘units’ with shields…

my game is at the end of its development. and If I add more units it will still work. cause the shield I am referring to is the player shield.

check out ym game: http://www.java-gaming.org/index.php/topic,19826.0.html

This may enlighten you on what I mean.

Oh eyah taht version does not have the static variables. cause I am trying to make levels. An older version of the game iwch was made with java 2d jsut re-initiated the game. but it had the gameloop so I could control it better. so I am going ot init the state (or game I am not sure wich it is doing I know it gets to the right place). The init(container) works when I am going to the menu. but it doesnt work when I am going to the next level.

This has already been explained to you, but typically when you want to handle movement you want to normalize your movement vector, which in the end produces a vector of length 1. That means, in the end, that it has direction only, but no magnitude.

You can think of it like a 1 dimensional vector. The only directions it can have are left or right, which would be represented by 1 and -1. Then no matter what you multiply by it, you end up getting the same direction, but it has the length of the multiple. Like multiplying it by 100 creates a vector going either left or right at that distance of 100. Dividing by 100 makes something going left or right that goes only 1/100 distance.

Typically you want whatever you’re moving to have a speed which is a one dimensional decimal value. Then you get the direction it should move by getting a normalized vector, and you multiply that direction by the speed.

ahh that explains a lot. I already hav eosmeting that works now. Iwill try ot use that now.

waht I realized was that I was casting my vx/100 as an int. wich cut of the decimal making it inacurate.

and since Hansdampf told me to change my x and y. It is now a decimal, and it keeps all of its accuracy, and moves at a regular rate.

thanks all for your help.

Re: the static variable thing, the point people are trying to make is that while yes, static variables are the closest thing to global variables you can get in Java, you generally want as few global variables as possible in a project. This cuts across language boundaries, and is good practice almost all the time. Generally speaking, the only statics in an ideal design would be global constants that are absolutely never going to change, or singletons (which should be used sparingly at most), which are objects that both need a global access point and there can absolutely only be one of (whether singletons are ever necessary or acceptable to use is a hotly debated topic, one which hopefully we won’t re-ignite here…).

Your example of making the player variables static is a good case to think about, because while it may work for now, suppose you eventually want to make a sequel to your game, and you want it to be multi-player, or you want competing AI units. This will be much easier if your player is a full fledged object, in which case adding another player is just a matter of instantiating another object rather than duplicating each of the life/score/ammo/etc. fields (depending on the game) as global variables.

Also, if you’re writing games that will ever run in a browser, statics are a serious problem. Sometimes (the rules are seemingly random, though Sun will tell you there is some logic to it) they don’t get reset if you leave a page and come back or reload, which means that your player’s shield/score values will be the same as they were the last time the game was played, but only sometimes, and this is almost never the behavior you want. There are workarounds, but it’s better to design around the issue in the first place.

In summary, as Riven said, static variables are a recipe for pain, and you should feel dirty every time you use one, doubly so if it’s not also final. Of course there are exceptions to the rule, but it takes a lot of experience to know when it is safe and when it’s not, so it’s best to get into the habit of avoiding them initially until you know for sure when you’re in one of the situations where they actually help.

Just to add to that: for constants we’ve always had interface fields, and enums were added ‘recently’.

ok thank you for the clarification. I may have to change some of the design inmy program. cause right now the shields are int he main game state. If I move it to the player class…

althouhg there is a problem with it though cause it will re-init it when the next level comes.

hey coulde some1 tell me how much the init()'s do, cause there are more than one.

cause I cannot find out what each does, and the discription in the class description is not very detailed.

What init()'s ?

Normally you make your player a member of your game class’ instance, so it doesn’t change and you can lookup the right instance from elsewhere. But I mean a normal member, not a static one :wink: Just pass around the objects as needed.

sorry I may not have specified this, I am using Slick.

Which class? What circumstances? How do you use it? Link to the javadoc you find not detailed enough?

Bottomline:
Make it easy to help you and don’t make us feel like we being your mom and dad to breast feed you…
You know, most of us work for our living, so we have limited time :o

wow this thread is very hostile.

the context: in a state, there are many init().

the link: I cant post now, I am at school :(. why is cokeandecode blocked and java-gaming.org isnt…

Hm… hostile? I think this is one of the most generous programmers forums on the planet (and far beyond).

I’d like to comment on ‘mom and dad breast feeding’, but I guess that would be a bit too offtopic.

H3ckboy, really, we’ve been giving you so much advice that our fingers hurt. You don’t seem to work on your basic understanding on your Java knowlegde, which unfortunately, at this stage, is NOT aquired most by trial-and-error. You really have to study, or you’ll waste (at least) your own time.

I’m not being harsh (or at least I’m not trying to be). Please take this advise seriously, and read good Java book, cover to cover, don’t miss a word. You’ll be glad you did.

[quote]this thread
[/quote]
Yes this FORUM is a very awesome forum, did I say ti wasnt? no I said this thread.

and I am not whining.

oh yeah and jsut so you know everything I have learned has been throuhg trial and I dont think I am exagerating.

This thread has long lived beyond its original purpose and is going VERY off topic. so I am gunna stop posting in it.

cya all