Recent posts by OctaBech on Kongregate

Flag Post

Topic: Game Programming / Is it possible to "inherit" an interface from a type?

Originally posted by Draco18s:
Originally posted by OctaBech:
Originally posted by Draco18s:
Originally posted by BobJanova:

I’m not sure the factory is the issue here, though I agree.

True, it isn’t, but the whole…factory design thing boggles my mind.

It’s meant for flexible code, where the same system branches out to multiple distributions with different demands, which calls for different strategies.

Read this:
http://discuss.joelonsoftware.com/default.asp?joel.3.219431

The problem with the analogy is that he shouldn’t be looking for a hammer-framework in the first place, unless his purpose was to make a factory which produces spice racks. He seems to be of the common misconception that frameworks and collections are the same, which they aren’t. Frameworks are not universal tools, they are highly specialized for their purpose and are in full control of everything but the hotspots used to tailor for special demands within its realm of its purpose. He shouldn’t be looking for a hammer but a rack-framework which then can be customized after his needs. In cases where it’s necessary to combine multiple frameworks they should be kept strongly separated by the facade-pattern.

What he complains about are things he shouldn’t even be touching, the factory pattern is used to make the code flexible and maintainable for the people writing the framework, not the user, for whom the code should remain a black box. The user orders something from the framework and gets it, the framework may not be able to deliver the exact product the user wanted, so the user will have to manually compensate with the decorator pattern.

 
Flag Post

Topic: Game Programming / Java out of bounds error?

Yeah, both behaviors are mathematically correct, so it’s a decision made by Oracle(Sun) that the result sign is the same as the dividend.

 
Flag Post

Topic: Game Programming / Fullscreen resolution

Originally posted by feartehstickman:

Shouldn’t the fullscreen resolution be the resolution of the monitor it’s running on?

Or does Flash do some weird scaling thing?

Nope, no weird scaling as it’s vector based, not sure if the OP means he want Flash to show more of the gameplay area.

 
Flag Post

Topic: Game Programming / Java out of bounds error?

It’s Random.nextInt(5) instead of Random.nextInt()%5. :)

EDIT: Sorry, you probably want to know why.
Random.nextInt() creates a random number using all 32bit, which includes the bit that signs the number to be positive/negative. %5 to a negative number gives a negative result.
Random.nextInt(n) only generates numbers from 0 to n-1.

 
Flag Post

Topic: Game Programming / Is it possible to "inherit" an interface from a type?

Originally posted by Draco18s:
Originally posted by BobJanova:

I’m not sure the factory is the issue here, though I agree.

True, it isn’t, but the whole…factory design thing boggles my mind.

It’s meant for flexible code, where the same system branches out to multiple distributions with different demands, which calls for different strategies.

The main code-base doesn’t contain creation of new objects (new Object), but instead calls a create function from the Factory (Factory.createObject()). This way the code-base can be compiled for different distributions by simply being feed with different factories which create the right strategies when called.

If the code-base only is meant for one game, it doesn’t make much sense to use the Factory pattern other than one got the creation of new objects neatly isolated into one class (I agree, in this case it just make things more complicated).

 
Flag Post

Topic: Game Programming / Attacking

yeah, I changed it to a function called from the weapon object instead, so the points can’t be calculated from the weapon’s position and direction before returned. :)

 
Flag Post

Topic: Game Programming / Attacking

it could be an array of points.

point = pointArray[weapon.frameNo];

or a 2D array if multiple points should be checked per frame.

EDIT:

Sorry that was awkward code :)

The weapon class could hold info on where the point(s) are for each frame of the attack animation.

point = weapon.getPoint(frameNo);

If you want multiple points to be checked per frame, the getPoint function could return an array of points. That should allow for some diversity in weapon types.

 
Flag Post

Topic: Game Programming / Attacking

Originally posted by Draco18s:

weaponRadious

Radius. R-A-D-I-U-S. Radius.

Thanks :D

 
Flag Post

Topic: Game Programming / Attacking

I’ve never made a game of this type, so take what I’m going to say with a grain of salt. :)

A guy under the alias DeanoC (If I remember correctly) from Team Ninja who did Heavenly Sword, said that only fighting games like Tekken and Street Fighter use precise hit detection because the outcome of a battle should depend on player skills. Action Adventure games like Heavenly Sword, God of War, Devil May Cry and Ninja Gaiden use hit boxes or proximity which is less process demanding and less infuriating for the player.

the hitbox is quite simple, each unit (friend and foe) is given a hitbox containing 4 points xMin, xMax, yMin and yMax. The weapon is just a point (ie the tip of a sword) and all the game does is checking if the point is within a hitbox. Depending on weapon type, the hitbox can be de/increased.

public function isHit(unit:Unit, point:Point, weaponRadious):Boolean
{
if (point.x < unit.xMin – weaponRadious)
return false;
if (point.x > unit.xMax + weaponRadious)
return false;
if (point.y < unit.yMin – weaponRadious)
return false;
if (point,y > unit.yMax + weaponRadious)
return false;
return true;
}

Originally posted by Draco18s:

weaponRadious

Radius. R-A-D-I-U-S. Radius.

For game balancing purpose, make the player’s hitbox smaller then the sprite (even with pixel perfect hit detection people will feel they got hit due to an error with the game) and make the enemy hitboxes bigger than their sprites. :)

 
Flag Post

Topic: Game Programming / Deleting sprites (How would You do it #5?)

Originally posted by alecz127:
Originally posted by OctaBech:

Watch out when using event listeners in Flash, they are not performance friendly. Look into the monitor pattern instead.

EDIT: And try to only have one Frame-listener, which loops through an array with all the units and calls a function called ‘action’ or something on them.

I’m sorry, I couldn’t find any good resources on “Monitor Pattern”, could you or someone else provide one?
On another note, searching for it led me to several books on as3 design patterns I think I’ll buy in the next couple weeks.
“Design Patterns: Elements of Reusable Object-Oriented Software” is being called a bible on the subject, any truth to that?

I’m the one who should be sorry for using the wrong name, it’s called the “Observer” and not “Monitor” pattern. :)

Never read that book, but I know one should be weary about books on the topic. Design patterns are simple, there aren’t many and they are easy to understand, the real problem is when and how to apply the patterns without getting tangled up in UML planning.
What I’m trying to say is that you should look for a book which bases its teaching on a project which it gradually evolves by applying the different patterns.

 
Flag Post

Topic: Game Programming / Deleting sprites (How would You do it #5?)

Watch out when using event listeners in Flash, they are not performance friendly. Look into the monitor pattern instead.

EDIT: And try to only have one Frame-listener, which loops through an array with all the units and calls a function called ‘action’ or something on them.

 
Flag Post

Topic: Game Programming / Deleting sprites (How would You do it #5?)

Originally posted by qwerberism:

am I the only one who doesn’t get why this is a problem? The method you use really depends on your paradigm and game strucuture.

Well the OP asked for the best way, so it’s only natural that some want to know why the other methods are better, which advantages they have.

The thread with its many different views also raises another interesting question, how weary should one be from participating in projects with more than one programmer? I’d say very.

 
Flag Post

Topic: Game Programming / Deleting sprites (How would You do it #5?)

Originally posted by player_03:
Originally posted by OctaBech:

[…] you try to see it from every single unit as if they are independent thinking beings, but that either creates a lot of duplicated code or a whole lot of cross references […]

I’ve implemented it that way, and no, it doesn’t. Why would it?

It does and you gave a rather good example of that:

Originally posted by player_03:

Soldiers of the same type would be allowed to store a reference to the same “AI” instance, if appropriate.

Your example has the AI code spread around, some being in the unit classes and other bits being shared in different ways breaking the rule of high cohesion. Having all the different unit types keep references also means that changes in the AI interface demands for changing the code in all the units, breaking the rule of low coupling.

Do not get me wrong, I’m not using your example to call you a bad programmer, it’s a well known and well studied problem caused by the model centric view, which has stalled many products, created bugs and prevented the re-use of code between projects. I’m not saying you should change your practice, I’m just pointing out that there’s sanity behind Ace’s words, his method is derived from the research done to prevent the problems caused by the model centric view and now taught at universities.

Anyway, you shouldn’t spread the AI to the individual units, you might want them to work together in the future which is easier to handle from one place, it’s also easier to optimize the code (no need for all units to do the same calculation, it saves one so much more than shifting ints instead of multiplying).

 
Flag Post

Topic: Game Programming / Deleting sprites (How would You do it #5?)

@Player_03

Encapsulation doesn’t handicap you, you are just seeing it from the wrong perspective, you try to see it from every single unit as if they are independent thinking beings, but that either creates a lot of duplicated code or a whole lot of cross references, both breaking the rules of high cohesion and low coupling. It’s not a problem as long as it’s a small code base and you are the only programmer, but it simply doesn’t work in big projects or if you want to reuse/modify the code base.

Try instead to think of it as one of those role playing games like heroes quest. The unit cards contain information, the figurines represent the movie clips and the game master is the GameLogic class which each turn/frame-even reads the cards, throw the dices and move the figurines on the board. Now you have the difference responsibilities clearly defined and can call them in an logical order. :)

 
Flag Post

Topic: Game Programming / Deleting sprites (How would You do it #5?)

Originally posted by Elyzius:

That was very existentialist, Ace, very existentialist. I like how you included a bit of epistemology in your discussion. What I find insightful is that, to you, the existence of the Controller was never in doubt. If I were to follow your arguments to their conclusion, it seems that everything is ultimately part of the Controller. Encapsulation is an illusion.

Ok, enough derailing BS from me. We now bring you back to the original topic. :P

Not derailing BS at all, your question is valid. :) There are different perspectives of how Objects should be seen, the most common but slowly dying view is the model centric where objects should copy the real world, for instance a car object encapsulates all the info about a car or sub-objects like Engine, Door, Tire and so forth.
Ace however is using the responsibility centric perspective, which means he doesn’t group after what real world object the code belongs to but what its job is, in the case with the GameLogic it encapsulates the job of handling movement and collision of all types of units. The reason for using the responsibility centric perspective is that a car can have more purposes than simple transport, for example the car’s roof shares the same responsibility as an umbrella, to keep people dry, but where should that code be written, in the car or in the umbrella object? It would generate a mess if the model centric view was to be followed, so instead the code for the “keep dry” responsibility is encapsulated into its own object which then call the car/umbrella objects which only contain their own variables.

 
Flag Post

Topic: Game Programming / Deleting sprites (How would You do it #5?)

Originally posted by Bobikas:

Let’s say we have a BattleField and Soldier movie clips (or derived from movie clip or other display object). BattleField contains a bunch of soldiers (as children). Rough truth is that soldiers sometimes die and after dying they should get removed from the BattleField.

So the (double) question is: Who should
1. detect the death of the soldier (run collision detection with bullets, check if he is out of screen, check if he starved to death or blown himself, etc.);
2. call the removeChild() function/method.

So how would you do it? Do some magic with parent reference? Event listener? Do everything in battleField? Anything else? Or maybe organize everything in some other way?

Tough question as there exist a ton of different philosophies on this topic. If you want a maintainable and flexible framework for your game which also can be used for future and even drastically different games, then you should look into agile programming.

Many have mentioned that you should have one central class named GameLogic and that’s especially true for agile programming. The job of GameLogic class is to handle all of the calculations in the game, so if you want something changed/added you go to that class. The advantage is that as soon as you have duplicated code you simply create a new function for this code and call it where there codes is needed, so you in the future only have to edit one place in the code when making alterations/extensions/bug-fixes (the code also becomes easier to read as the function name explains what that code bit does).
In sharp contrast to UnknownGuardian’s suggestion, the soldier/unit classes do not contain logic in agile programming (they do not perform the detach), their only job is to function as data containers with get and set functions for alteration of said data. Let’s say you have 3 or more different unit types which all have to detach the same way, that’s the code duplicated 3 times, but what if you during optimization of the code decide not to detach the units but instead just make them invisible for fast “re-attachment” instead of creating new units? In agile programming you would only have to make the change one place in the code (in the GameLogic class).
True, you could just make all the units extend the same super class, but what if some units only are used once and should be detached instead of made invisible for later use? The units would have to extend the detach super class but at the same time also extend another super class which hold code they still have in common with units which only are made invisible, it would be a proper mess and is the only reason why AS3, Java and C# do not allow for extension of more than one class.

Back to agile programming and the GameLogic class, when you change the detach code for units to instead make them invisible, you do not delete this code, but instead use the strategy pattern; you create an interface called DetachStrategy and then move the old detach code to a class which implements this interface and also write the new make invisible code in a class which implements the interface. This way you can in future games switch between the two methods based on your needs.

For the problem with some units using the old detach strategy one just use the state pattern. The state pattern is simply a class which extends the same strategy interface, looks on the unit’s type and then decides which of the two detach strategies should be used.

These places where the strategy pattern is used are called variability points, you should not waste time on planning them before coding but just add them as needed, it will save you many design headaches and your framework will gradually become more flexible while remaining highly maintainable.

Following the golden rule of low coupling and high cohesion, it’s important that the GameLogic class only handles game logic, things like graphics-rendering should be handled by a different class, communication through a clearly defined facade pattern (an interface with functions which only exchange immutable data), preventing a criss cross of “connections”/references and confusion about where values are being manipulated (will save hours on debugging, especially when the framework grow large). The same with the game menu and game controls, the GameLogic class should remain independent so you easily can switch control type(in game even) and menu system.

Hmm post got longer than planned and it has gotten rather late, so I won’t read it through before submitting, feel free to ask if there’s something which doesn’t make sense. :)

 
Flag Post

Topic: Game Programming / Using MovieClips to spawn npcs over time

Originally posted by Arloistale:

Okay, I think I was being a little vague. I want to know if it’s possible to use the timeline feature of movie clips to create other movie clips on a base movie clip at specific times. If this is not possible, then how would I “write code that does that?”

You can create a keyframe at the wanted time. In the “action” part of the new keyframe you then create the new movie clip and attach it to the current movieclip.

But as Draco and Amibtious are trying to tell you, this is not the way to write game code and your attempt at making a game will only fail, it’s designed for for fixed animations like an intro.

You should instead learn to write code in either AS2 or AS3 and then use timers or count frames for your purpose of introducing NPCs. :)

 
Flag Post

Topic: Swords & Potions / Casual Guild for Improvements

Sorry, forget my request. I’ve read FinalUnknown’s guide and lost the mood to continue.

Have fun with the game. :)

 
Flag Post

Topic: Swords & Potions / Casual Guild for Improvements

Thanks a lot for creating this guild.
Oh and please invite me. :)

 
Flag Post

Topic: Game Programming / bullet angle isn't accurate.

I’m glad that your problem is solved, but isn’t all that angle calculation overkill?

If you have the verctor from player to mouse calculated, then you can normalize it to a unit vector and multiply vX and vY with the wanted speed once and for all, so you won’t have to multiply again and again(* operations very expensive, especially compared to +).

var length:int = bulletArray.length;
for(i = 0; i < length; i++) {
bulletArray[i].w0rldX += vX;
bulletArray[i].w0rldY += vY;
}

also move bulletArray.length outside the loop or else flash will re-calculate it every time(at least it used to).

Only mentioning this because I liked your game snippet and want it to do well. :D

 
Flag Post

Topic: Collaborations / Want to test a game?

Where do you want us to post the issues and bugs we find? :)

 
Flag Post

Topic: Collaborations / Want to test a game?

Without knowing the game type, it’s hard to tell if my “input” will be worth anything as I’m more into casual fun than skill based games(unless the skills are slow paced planning and management). But I’d be happy to beta(?)-test for you.

 
Flag Post

Topic: Game Programming / moving all of 1 object multiple times

Tough to tell when not knowing how your background works,but even on the negative y-axis -= should work.

Is your speed a const or is it dynamically derived? could be it’s negative, so try using Math.absolute(speed).

But as said, put up the code for your background and for speed. :)