Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 224 225 [226] 227 228 ... 796

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

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #3375 on: November 04, 2012, 07:08:03 pm »

@DrKillPatient:  The first method that I can think of is to do an check of each and every point within each subregion to those within another subregion to find the closest points. This can be very slow though if the subregions compared are large. Another method is to first store within each subregion the containing wall coordinates and just check those in a way similar to the first method. It can still be quite costly if one or both of the subregions are very large or have curvy walls. I haven't really done anything similar though, so my suggestions may be wildly off mark.
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3376 on: November 04, 2012, 08:12:51 pm »

http://www.test.glyphgryph.com/main.html
("a" to interact, "p" to pause)

Made some serious improvements to dialogue handling and switching between modes (here, demonstrated with the ability to layer the regular game mode, dialogue behaviour, and pause behaviour). The dialogue boxes themselves are still hacks - need to come up with a way to generalize that, but I think I'll come back to this later. The whole thing could use a lot of efficiency improvements too, lots of full-screen clears and every-frame redraws in there... anywho. Enough of that for now.

Next I can either work on the completely separate map editor application, OR the battle mode... either way, probably as much work again as everything I've done so far. Assuming anyone is actually interested and following my progress here, which would you prefer? Bigger, varied maps with ways to move between them? Or the ability to actually fight something?
Logged

fergus

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3377 on: November 05, 2012, 01:36:40 am »

If I want to ensure that each subregion is connected to, say, all other subregions within 20 tiles (IFF those subregions can be reached with a straight line), what's the best way to compute that? All I need is to find one point on the edge of one subregion, then find a reasonably close point on the nearest subregion. With that data, I can begin to draw tunnels.
I'd do something like:
  • Select a point p1 from Region1
  • Loop through Region2 to find p2, the closest point to p1
  • Loop through Region1 to find p3, the closest point to p2
  • Calculate the distance between p2 and p3
This isn't guaranteed to find the two closest points but it should get close if the regions are approximately convex.
Logged
BY THE GODS! THIS QUOTE MADE MY SIG BOX HAVE A SCROLL BAR! HAPPY DAYS INDEED!
BY THE GODS! YOU HAVE TOO MANY SIGS!

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3378 on: November 05, 2012, 06:02:01 am »

HELP Dx
Code: (Display.cpp) [Select]
plantpointer = & map.consoletoplant(cursor.getX(), cursor.getY());
My guess is that map.consoletoplant(x, y) returns a local variable by reference, so the string gets wiped when this local variable goes out of scope.

Code: (SoilMap.h) [Select]
if (y*             h                + x < plantmap.size()) return plantmap.at(y*             w             + x);
This is another thing that is very probably wrong.

Also, your Soilmap::generateGrass() method fills Soilmap::plantmap with lots of pointers, but they all point to the same object. You should probably put the temp = new plants() inside the for loops.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3379 on: November 05, 2012, 06:16:09 am »

Doesn't plantmap.push_back(*temp); mean that I push_back the values of temp, not the pointer? '*' should dereference it. I know that it works fine with the tile class, and it seems to work fine right now ...

For the if(y*h + x < plantmap.size()) thing, it's a read-only interface, so it shouldn't matter: the writing is done with the temp object, which is pushed onto the vector. I suppose it will matter when I try to make a pointer to that object, like what just happened. Dx

On the other hand, your point that the map.consoletoplant(x,y) returns a local variable, then is immediately wiped is very valid. I changed the receptor to accept the value (using a variable which is assigned the return of the consoletoplant() function instead of a pointer) and it works perfectly. Thanks for looking over my code. :D
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3380 on: November 05, 2012, 08:45:42 am »

Doesn't plantmap.push_back(*temp); mean that I push_back the values of temp, not the pointer? '*' should dereference it. I know that it works fine with the tile class, and it seems to work fine right now ...
Yeah, I misread that.

Quote
On the other hand, your point that the map.consoletoplant(x,y) returns a local variable, then is immediately wiped is very valid. I changed the receptor to accept the value (using a variable which is assigned the return of the consoletoplant() function instead of a pointer) and it works perfectly. Thanks for looking over my code. :D
GLaD to help you.
Logged

Kirbypowered

  • Bay Watcher
  • Proficient Dabbler
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3381 on: November 05, 2012, 11:23:38 am »

Next I can either work on the completely separate map editor application, OR the battle mode... either way, probably as much work again as everything I've done so far. Assuming anyone is actually interested and following my progress here, which would you prefer? Bigger, varied maps with ways to move between them? Or the ability to actually fight something?
I myself enjoy big, diverse maps, but they tend to be more interesting when littered with random enemies out to murder you...I'll say maps first, though. You'll need both eventually, right?

In other news, whilst learning C++ I've been getting annoyed at AVG. Whenever I compile a program using the MinGW console that returns 0 without actually doing anything AVG will flip out and put the newly created file on quarantine and say it's a virus. When I do the process using Code::Blocks it'll work fine. Thankfully this hasn't been happening to potentially useful programs, but it's still pretty annoying.
Logged
THE WINTER MEN COME DOWN THE VALLEY AND KILL KILL KILL.
I'm voting for the Plaid Acre up next on COLORS AND MEASUREMENTS weekly.

darkflagrance

  • Bay Watcher
  • Carry on, carry on
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3382 on: November 05, 2012, 02:00:31 pm »

Let's assume I already know Java, and that is the only programming experience I currently have.

If I want to make a 4x or turn based strategy game, would it be better to use Java and Java packages to program it, or to learn to use Game Maker or some other game-making program?
Logged
...as if nothing really matters...
   
The Legend of Tholtig Cryptbrain: 8000 dead elves and a cyclops

Tired of going decades without goblin sieges? Try The Fortress Defense Mod

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3383 on: November 05, 2012, 02:08:09 pm »

Depends on a lot. At least let us know the sort of result you're hoping for.

Using Java would probably mean more control over details, and a better end project IF you have the time and ability.

Gamemaker, even learning it from scratch, would probably be quicker and easier, thus making you more likely to actually finish. But you also lose out on the learning potential of working with a proper language, if you are somewhat inexperienced, and on the fine-grained detailed level of polish you can add with a proper language.

For a standard 4x or turn-based strategy, though, the difference between those could well not be meaningful, depending (again) on your end product.

Also, Java works with Linux, I don't think GameMaker does.
Logged

darkflagrance

  • Bay Watcher
  • Carry on, carry on
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3384 on: November 05, 2012, 10:18:11 pm »

Depends on a lot. At least let us know the sort of result you're hoping for.

Using Java would probably mean more control over details, and a better end project IF you have the time and ability.

Gamemaker, even learning it from scratch, would probably be quicker and easier, thus making you more likely to actually finish. But you also lose out on the learning potential of working with a proper language, if you are somewhat inexperienced, and on the fine-grained detailed level of polish you can add with a proper language.

For a standard 4x or turn-based strategy, though, the difference between those could well not be meaningful, depending (again) on your end product.

Also, Java works with Linux, I don't think GameMaker does.

In Java I would probably be able to produce a pretty simple and basic user interface with the in-built packages, and am planning to get something about as complex as, say, one of Koei's Romance of the Three Kingdom or TBS games in terms of mechanics. It would probably resemble Aurora in terms of appearance. If anyone has heard of the SNES/Genesis game Gemfire, it would probably be about as simple/complex as that.

I have no idea how easy a Game Maker game is to prettify compared to a Java game.
Logged
...as if nothing really matters...
   
The Legend of Tholtig Cryptbrain: 8000 dead elves and a cyclops

Tired of going decades without goblin sieges? Try The Fortress Defense Mod

TSTwizby

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3385 on: November 06, 2012, 03:12:18 am »

Trying to override (overwrite?) a function in python, doesn't seem to be working.

in Animate class...

def update(self):
   do stuff...


in Player(Anmiate) class...

def update(self, param):
   if param:
      do something
   else:
      Animate.update(self)



When I call Player.update(param), I get an error message saying that update() takes 1 positional argument. I've checked for some examples online, and they all seem to do basically what I'm doing. Moving the 'Animate.update(self)' to outside the conditional had no effect.
Logged
I got a female and male dragon on my embark. I got cagetraps on the exits but im struggling to find a way to make them path into it.
Live bait.
3 dwarfs out of 7 dead so far

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3386 on: November 06, 2012, 09:58:12 am »

Trying to override (overwrite?) a function in python, doesn't seem to be working.

in Animate class...

def update(self):
   do stuff...


in Player(Anmiate) class...

def update(self, param):
   if param:
      do something
   else:
      Animate.update(self)



When I call Player.update(param), I get an error message saying that update() takes 1 positional argument. I've checked for some examples online, and they all seem to do basically what I'm doing. Moving the 'Animate.update(self)' to outside the conditional had no effect.

The issue may not be with the theory of overwriting, but with the code itself. More complete code, please?

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3387 on: November 06, 2012, 10:10:15 am »

Ok, quick lesson on Method Overloading and Method Overriding in OOP when using inheritance.

Method overriding is when you redefine the method of a superclass in a subclass.
Method overloading is when you have multiple methods with the same name, but different signatures. The method signature is the parameter types and their order.

Now lets say I have
Code: [Select]
class Employee
{
money salery;

public money GetPay()
{
return salery;
}
}

class CasualEmployee extends Employee
{
public money GetPay(integer hoursWorked)
{
return salery * hoursWorked;
}
}

Is this an example of overloading, overriding, or both?
This is method overloading, and not overriding, because the methods both have different signatures. One takes a parameter 'hoursWorked' and the other has an empty signature. As such, if I made a CasualEmployee and called .GetPay() then it would call the method as defined in the Employee class. Using similar logic, we should know that for most languages (Python being the obvious exception) trying to call .GetPay(hoursWorked) for an object treated as an Employee would cause a compile error, because that method isn't defined for an Employee, and you would need to try and cast down to its subclass.

Make sense?

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3388 on: November 06, 2012, 10:56:04 am »

Note well: Many OO languages do NOT support method overloading. This especially true in message-based languages like Python, where a concept like "method overloading" doesn't actually make a whole lot of sense.

The question was about Python, right?

If you're programming Python in the Python-way, overloading should never be an issue. Override properly, by originally defining the method in a way that handles your override, or by giving the subclass a different method name.
« Last Edit: November 06, 2012, 11:00:07 am by GlyphGryph »
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3389 on: November 06, 2012, 10:59:03 am »

If I recall, I think you might be right.
If Player inherits the Update(self) method from Animate, then tries to overload it with Update(self, params) that would most likely be the cause of the error.

Solution is to rename the method for the player. Call it Tick(self, params) or something.
Pages: 1 ... 224 225 [226] 227 228 ... 796