Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 75 76 [77] 78 79 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 909066 times)

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1140 on: February 02, 2012, 04:45:09 pm »

JAVA, Y U SO COMPLICATED WITH PICTURES?

Sorry, I'm just really worked up over this. For a substantial amount of time now, I have been trying to understand how to insert image graphics into a plain old frame. However, there seems to be nobody at all who can explain this in an Errol-understandable format. Moreover, most solutions have been with a JLabel. I fear that this wouldn't be practical for me, as it would entail setting up at least 450 JLabels (tile based graphics, yeah)

So, please, how do I make a program where I can insert an image from a file and get a nice little image object for Graphics to use?

I wrote a quick Java app that reads in an image and displays it to a panel.  The ImagePanel class is more or less generic.  You can drop it directly into your own code if you change the package line.  This is just a (well documented) example.  If you have any further questions after reading this, please ask.

Jar file containing source, image, and javadoc.
Spoiler: Main.java (click to show/hide)
Spoiler: ImagePanel.java (click to show/hide)

Hey, for Java compiling from the console (cmd), what am I supposed to set the path to? I remember doing this in Java class, but I can't get it to work on my home pc.

You want to use this.
Code: [Select]
set path=%path%;path\to\jdk\bin
For example.
Code: [Select]
set path=%path%;C:\Program Files\Java\jdk1.5.0_09\bin
I pulled that from this website.
Logged

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1141 on: February 02, 2012, 05:02:12 pm »

I looked all over that site, or so I thought. Grazi.
Logged
  
Holy crap, why did I not start watching One Punch Man earlier? This is the best thing.
probably figured an autobiography wouldn't be interesting

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #1142 on: February 02, 2012, 05:06:58 pm »

Hmph. The roadblock I keep hitting every time I try to write a roguelike engine is one of scheduling turns. If I have discrete turns that increment a counter on each NPC that determines when their next turn is, I get the problem of differences in speed not being a flat slope (speed 2 is half as fast as speed 1, but speed 10 is only 9/10ths as fast as speed 9). This could cause problems.

Has anyone gotten one of these damned things to work?
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1143 on: February 02, 2012, 05:19:28 pm »

Why would you do speed that way? And how are you even implementing it? I mean, there's lots of ways to do speed, and that just seems... odd. Wouldn't it be simpler to think of more speed as better anyways?

If you want a simple system with a bit more granularity with speed being higher=better, you could use something like this:
Each turn, on the creatures "take action" code
Code: [Select]
new_ap = old_ap + speed
  if new_ap > 10
     new_ap - 10
     this.takes_turn
  end
  old_ap = new_ap
end
 

Obviously there's lots of ways to implement something like that. It easily allows you to make modifications for more time consuming moves and such as well (since your values can go negative, implying recoil), and lets you easily apply speed effects and stuff.
« Last Edit: February 02, 2012, 05:22:52 pm by GlyphGryph »
Logged

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #1144 on: February 02, 2012, 05:36:22 pm »

*facepalm* God, I was doing that completely backwards. I can't believe I didn't think of that. I even used an almost identical system to that in a different engine.

So if there were a more time-consuming action, it would look something like this:
Code: [Select]
new_ap = old_ap + speed
  if new_ap > 10
     new_ap - 20
     this.takes_turn
  end
  old_ap = new_ap
end
And the opposite for faster actions, right?
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1145 on: February 02, 2012, 05:50:55 pm »

Basically, yeah! Though instead of changing it directly there, I'd put the -10 as the 'minimum' reduction and then have any action take more. Otherwise you'd get issues with people repeatedly doing quick actions to save up a bunch of "ap" allowing them to follow them up with a BIG action every single turn.

Rather, what I'd do as have a "single turn" be the minimum cost for actions and only go up from there (with a smart implementation, this could be handled from within the action, obviously)

That was really just a tossed out thing - there are much better ways to achieve the same effect, it was just to give you an idea of how to think about it.

Code: [Select]
ap = 0
speed = 4
speed_cap = 20

def go
  ap+=speed
  while ap > 0
    ap-=speed_cap
    take_turn
  end
end

def take_turn
  #whatever
end

There's a slightly improved implementation of the same concept.
« Last Edit: February 02, 2012, 05:55:20 pm by GlyphGryph »
Logged

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #1146 on: February 02, 2012, 05:55:07 pm »

But even that system seems to have the same problem I was talking about. On a scale from 1 to 100, speed 2 is twice as fast as speed 1. But the same goes for 100 and 50. The higher on the scale you go, the less incrementing by one means. It just seems like such a system would be heavily skewed. Am I wrong in thinking that?
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1147 on: February 02, 2012, 05:56:27 pm »

Hmm... Well, that's because two IS twice one, though. So of course it's twice as fast.

Are you saying you want some non-flat growth rate?

Speed is linear, and if I move at 1mph and you move at 2mph, you are moving twice as fast as me. That's just how speed works in real life.

What sort of growth system would you prefer? That each one is twice the speed of the one before it?
Because I can do one like that too.

(note: this is linear growth, I think your system before was significantly worse)
« Last Edit: February 02, 2012, 05:58:52 pm by GlyphGryph »
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1148 on: February 02, 2012, 05:58:07 pm »

That's probably correct, but strict is not the same as elegant. A state manager that supports everything that you want it to be able to do will be ugly as hell, juggling with pointers and/or passing large game state objects, with extra conditions and insane amounts of extra code just to handle dynamic deallocation. It's easier and much safer to handle states decentrally.

I seriously don't see any practical application your can do, that mine can't do more easily and readably.
Did you see any such messy state manager? I don't need one. No extra conditions, that is the point of it. It is significantly more elegant than an unruly stack of random, unrelated classes.
Also, 'passing large game state objects'? You are joking right. I'm passing something very small, a reference. The size of the object is totally irrelevant when passing a reference.
And in mine, when I want to upgrade my loop to skip draw frames when you hit low FPS I can do it once in my game class, where would you implement it?

Seriously, if you know how to program, mine is significatly better. Text book answer for a text book question, and I know the book page for page.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1149 on: February 02, 2012, 06:00:03 pm »

I should also add that I think you are looking at this the wrong way

2 speed is twice 1 speed, yes.

And 50 speed is 50x 1 speed.

And 100 speed is 100x 1 speed.

Each point of speed gives you an extra turn (or other, equal value) vs someone with 1 speed.
Logged

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #1150 on: February 02, 2012, 06:09:17 pm »

Yeah, I know that's how speed should work normally, but...
Let me put it this way: in a roguelike, the map is divided into discrete areas on a grid. So while speed 100 would normally be immediately and visibly faster than speed 95, on a roguelike map it's different.

In this case, it would mean that the two entities would move together for 19 spaces, then the slower of the two (95) would skip a turn while the faster would pull ahead. What this means in practice is that, if you have two entities with speed 1 and one of them finds +5 boots of swiftness, that one will immediately be six times faster than the other and leave it in the dust.

But with two 95s, we get the situation described above. That's my reasoning.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1151 on: February 02, 2012, 06:18:11 pm »

Again, what sort of speed growth are you actually looking for, then.

What this means in practice is that, if you have two entities with speed 1 and one of them finds +5 boots of swiftness, that one will immediately be six times faster than the other and leave it in the dust.[/quote]
Again, this makes perfect sense in any terms I'm familiar with - getting a boost to 6mph walking speed in real life would still make you 6 times faster than the guy moving at 1.

If you want an alternative, I'm honestly not quite sure what alternative you're looking for. There are other valid options, but you haven't specified which ones you want. Using real life terms, maybe, describe to me the "real life" speed of a creature with in-game speed of 1 through 6, respectively.
« Last Edit: February 02, 2012, 06:22:31 pm by GlyphGryph »
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1152 on: February 02, 2012, 06:32:27 pm »

Yeah, I know that's how speed should work normally, but...
Let me put it this way: in a roguelike, the map is divided into discrete areas on a grid. So while speed 100 would normally be immediately and visibly faster than speed 95, on a roguelike map it's different.

In this case, it would mean that the two entities would move together for 19 spaces, then the slower of the two (95) would skip a turn while the faster would pull ahead. What this means in practice is that, if you have two entities with speed 1 and one of them finds +5 boots of swiftness, that one will immediately be six times faster than the other and leave it in the dust.

But with two 95s, we get the situation described above. That's my reasoning.
So you're looking for a speed system that isn't additive but multiplicative? You could use a logarithmic scale. Speed 2 is 2x as fast as speed 1, speed 3 is 2x as speed 2 et cetera. So if someone finds a +3 boots of speed, his speed is going to be 8 times as high, no mater what her base speed was (obviously you'll need to tweak the base to get sensible numbers)
Logged

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #1153 on: February 02, 2012, 06:38:03 pm »

Yeah, I know that's how speed should work normally, but...
Let me put it this way: in a roguelike, the map is divided into discrete areas on a grid. So while speed 100 would normally be immediately and visibly faster than speed 95, on a roguelike map it's different.

In this case, it would mean that the two entities would move together for 19 spaces, then the slower of the two (95) would skip a turn while the faster would pull ahead. What this means in practice is that, if you have two entities with speed 1 and one of them finds +5 boots of swiftness, that one will immediately be six times faster than the other and leave it in the dust.

But with two 95s, we get the situation described above. That's my reasoning.
So you're looking for a speed system that isn't additive but multiplicative? You could use a logarithmic scale. Speed 2 is 2x as fast as speed 1, speed 3 is 2x as speed 2 et cetera. So if someone finds a +3 boots of speed, his speed is going to be 8 times as high, no mater what her base speed was (obviously you'll need to tweak the base to get sensible numbers)
Yeah, basically. Am I wrong in thinking that would be the best way to do it? Each level of speed is equal, so adding 5 to it is just as useful whether you're at level 1 or 95. And yes, if it was log base 2 anything with speed 1 would take over 1 million turns to move one space.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1154 on: February 02, 2012, 06:45:22 pm »

Of course, that means a person at speed ... 5, say, is going to get a whopping 32 actions for each one action of someone at speed 1.
Logged
Pages: 1 ... 75 76 [77] 78 79 ... 796