Recent posts by Ace_Blue on Kongregate

Subscribe to Recent posts by Ace_Blue on Kongregate

avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Design / [Feedback] Control scheme

I’d like to get people’s opinion about how comfortable they feel with a top-down shooter ship yawing as it moves around. Specifically, do you find it difficult/troublesome to aim at the top ship in this toy and how do you feel it compares to aiming/leading when the ship always shoots straight up?

Additionally, do you think the experience would be enhanced if the player could hold their ship still (but still rotating to follow the mouse) by pressing a key or the left mouse button?

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Kongregate / Why "N" is not on Kongregate

I think the biggest problem is that it has crappy controls. I know it’s the main reason I downrated it. I remember the original’s controls not being all that great all those years ago, but this is beyond the pale. Six years to get a control scheme that’s almost unusable, someone is not taking their players seriously.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Show us a screenshot of what you're working on!

Oh Feffers, don’t insult your players. Not only it’s not nice, but it hasn’t been edgy for decades!

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Kongregate / Directory of Kongregate Chat Rooms

Don’t remove the labeling on the x-axis, but change it to a time unit rather than a sample number (if that’s what it is now?), because at this point it’s kind of hard to tell if I’m looking at minute-by-minute changes or seasonal variations. And yes, the data points could go without the graph losing anything.

Edit: I just realized I didn’t make it clear but yes, it is an awesomely cool chart.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

I’d have to think about it. I don’t see what components I’d want to attach to the pool off the top of my head, but it’s worth thinking about. I think it also converges toward Drakim’s talk of having components that can contain entities, in that the pooling aspect could be handled by a component, but I had some wine with dinner and the concept is too recursive for my diminished mental faculties right now…

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

It’s funny because they do end up simply walking into Mordor…

Anyway, here’s the entity pool class, comments below.

package 
{
	public class EntityPool
	{
		private var inuse:Vector.<Entity>;
		private var reserve:Vector.<Entity>;
		private var template:Vector.<Class>;
		private var size:int;
		
		public function EntityPool(poolSize:int):void
		{
			size = poolSize;
		}
		
		public function setTemplate(componentList:Vector.<Class>):void
		{
			template = componentList;
			inuse = new Vector.<Entity>;
			reserve = new Vector.<Entity>;
			for (var i:int = 0; i < size; i++) reserve[reserve.length] = generateEntity();
		}
		
		private function generateEntity():Entity
		{
			var entity:Entity = new Entity();
			for (var i:int = 0; i < template.length; ++i)
			{
				entity.attachComponent(new template[i]() as ComponentInterface);
				entity.attachComponent(new PoolHandlerComponent() as ComponentInterface);
				(entity.getComponent(PoolHandlerComponent) 
as PoolHandlerComponent).setup(this);
			}
			return entity;
		}
		
		public function add():Boolean
		{
			if (reserve.length == 0) return false;
			inuse[inuse.length] = reserve[reserve.length - 1];
			reserve.length--;
			return true;
		}
		
		public function removeAt(index:int):Boolean
		{
			if (index < 0 || index >= inuse.length) return false;
			reserve[reserve.length] = inuse[index];
			inuse[index] = inuse[inuse.length - 1];
			inuse.length--;
			return true;
		}
		
		public function remove(entity:Entity):Boolean
		{
			for (var i:int = inuse.length - 1; i >= 0; --i) if (inuse[i] == entity)
			{
				reserve[reserve.length] = entity;
				inuse[i] = inuse[inuse.length - 1];
				inuse.length--;
				return true;
			}
			return false;
		}
		
		public function get last():Entity
		{
			if (!inuse.length) return null;
			return inuse[inuse.length - 1];
		}
		
		public function applyEvent(keyword:String, data:Object):void
		{
			var takeout:Boolean;
			for (var i:int = inuse.length - 1; i >= 0; --i)
 inuse[i].dispatchEvent(keyword, data);
		}
	}	
}

Overall it should look pretty straightforward. The idea is to create the pool and give it a template (a list of component classes that all entities in the pool have) at game start. The pool has two vectors of entities: the reserve, which is where all entities start, and where they hang out when they are not holding game information, and the in-use vector where they go when they need to be considered as part of the game. When a component that has access to the pool wants to introduce an entity into the game they add() one (take it from the reserve and put it in the inuse pile), which goes at the end of the inuse vector, then get last() to obtain a handle on it. Then they can initialize all of its components that are part of the template, and from then on they lose track of having ever introduced it. The game can introduce events to the pool through the applyEvent() function, which targets only those entities which are currently in use, thus avoiding wasted CPU cycles. Note that entities in both vectors are unsorted, allowing fast splicing.

Edit: What I would like instead of the pool handler would be the ability for a component to dispatch an event that bubbles up to the entity first, and then to the pool, with a mention of which entity’s component dispatched it, so I could remove entities from the pool at the pool level. Right now I need a component to know what entity it’s on and in which pool that entity is, and to call pool.remove(entity). It’s inelegant.

Edit2: How do you get ‘pre’ formatted code to not screw up the text when it exceeds the width of the page?

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

I’ve finally gotten object pooling to work in a way I am (marginally) satisfied with. Here’s a toy example of a ship firing two different guns. There are 103 entities (the ship, both guns, and 100 bullets in a single pool) in total, never more, never less, and both guns share the same pool.

Current issues:
Pooled entities are given a PoolHandler component that keeps track of what pool they’re in and catches removal-type events (currently OUTOFBOUNDS and EXPIRE, but I can add other events as I introduce them.) I would much rather dispatch an event that the pool would catch and remove the entity, but unlike Flash Events these do not bubble. So I’m stuck with this system.
The Spawner component does not simply spawn new entities in the pool it keeps track of, it has the whole bullet setup, spread and speed and all, hard-coded into it. Ugh… I really need to do something about that, probably a function call in the component that will pass the entity that holds the spawner, the entity to be set up, and its burst index, although that feels like a lot of bouncing parameters around.

If anyone’s interested I can post the source, otherwise I won’t clog the thread with it.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / GiTD [#32] Voting finished! [imp2]

Congratulations to imp2, his very close runner-ups, and all other entrants. Pretty nice crop of games this time around, I hope many of them will be perfected and go on to great fates.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 3): Events to the rescue!

Regarding velocity, you don’t need to set myEntity to null in the constructor, it’s already null. In fact, you don’t need myEntity at all in this component, you are not using it anywhere (just pass the entity as an argument in detach() as you do in attach().)

Other than that I just can’t decide if it’s better to use velocity as a simple repository like position and handle motion in a separate module or to combine value storage and linear uniform motion in one package like you do. I guess if you don’t need anything more complex than a straight trajectory at constant speed your way saves a component. If you do need more complex motion though you have an extra function call compared to handling all motion in a separate component.

For the player, I still haven’t looked at Keyboard handling with components, so I can’t really offer much advice, and I have hard-coded application-specific stuff in components too so I really shouldn’t comment on that either, but I’m still wondering what you’ll do if you want to allow WASD as an alternate control scheme and let the player configure to their keyboard preferences (IJKL, ZQSD, etc…).

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / rotation on a slope

Please format your code with ‘pre’ tags, your underscores are screwing formatting up.

Also please explain what you mean by ‘rotation on a slope’, what you are trying to achieve, and what is not working.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

You know what? No. A few days ago I thought the hierarchical way I was doing OOP was just peachy, and when Drakim started this series about component-based design I thought it was impractical and pretentious and I already had a perfectly serviceable paradigm and who was he to come in and tell me I was doing it wrong? But I read what he had to say, and I gave it some thought, and I started tinkering with it to see if it could bring me something new.

Less than a week later it’s transformed the way I look at OOP. I am very grateful to Drakim for sharing his knowledge and his experience, and for answering my questions. But at the same time I also know that if I had just dismissed everything he had to say without giving it any consideration I would have learned nothing. And this part, this intellectual curiosity that made me abandon the safety of my paradigm to try out Drakim’s, that’s something that he couldn’t give me, it had to come from me.

So if you’re happy with throwing everything in one bag and do not have even an ounce of curiosity for other people’s ways and what they can bring you, then keep on trucking. I can’t reach you where you are and I won’t try.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

You said it yourself: “each game must be designed completely uniquely.” If you want to create a different game with some similar parts (like a title screen, or custom keybindings, for instance) you’d have to dig through the unique class to find the relevant code parts, extract them, plug them into your new project, redo all the connections that you broke when you extracted it and that aren’t quite the same in the new project, and finally debug it until you’ve ironed out all the bugs this transplant introduced.

Having separate classes that work as independently as possible helps with every single step of this process.

Additionally, inside a single project, every time you add a component it can interact with any piece that is already there, so interferences grow as the square of the number of components. If you separate your components into different classes they can no longer interfere with others and only the interactions you want can happen, because you have to enable them specifically. It reduces your Advil consumption drastically in the long term.

So whether it’s expanding an existing project or creating a new one, things work better when you don’t throw everything into one big class.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 3): Events to the rescue!

It certainly doesn’t look as stilted and cumbersome as my own, so I think you must be doing something right.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 3): Events to the rescue!

By ‘fairly rare’ I meant ‘not going to happen a few hundred times every frame’. Even in a tower defense situation like gemcraft with slow, stun, poison and armor break effects being applied to / removed from a dozen or more enemies every second, splice() should not make a difference. After all, each component has at most one event listener of a given type, we’re looking at very short vectors and lists here.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 3): Events to the rescue!

Similar to the way I handle it except I also match priority.

public function detachEvent(keyword:String, callback:Function, priority:int = 0):void
{
	if (!events[keyword]) return;
	var i:int = events[keyword].length - 1;
	while (i >= 0 && callback != events[keyword][i][0] && priority != events[keyword][i][1]) i--;
	if (i >= 0) events[keyword].splice(i, 1);
}

And yes, splice() is slow, but I don’t care, you shouldn’t be removing events willy-nilly, only when removing components, and that should be a fairly rare occurrence.

I’ve also decided to not take parameters in the constructor of components, and have a setup() function for components that need starting values, options and flags set up. This way altering the behavior of a component is as simple as a call to its setup() function, and I’ll be able to spawn entities in pools based on a template.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

Actually, as I keep thinking about it (with my fingers), I’m more and more convinced I wouldn’t want either components or entities holding entities. Instead, I’d go with a flat picture where pretty much every entity is on the same level.

Take a ship with multiple weapons systems. Do the weapons really need to be on the ship? Or is it sufficient that the position of each gun is linked to the position of the hull? The only reason I can think of that you’d even want these entities grouped together is so you can originate projectiles relative to the position of the hull when drawing. Other than that, there is no need for the hull to boss the guns around. In fact, the hull should not even know if there are guns on it or not, that’s not its business.

What about enemies? Most enemies only have one firing mode, so it doesn’t hurt to attach the gun and the hull on the same entity. The only exception is bosses, but you can make those as several entities like the player ship for all their guns or, my personal favorite, as multiple enemies with shared hitpoints (or partially shared, so you can take down the boss bit by bit.)

Also, in the interest of allowing for changes in behavior after the initial setup I’ve added a function to the component interface:

package 
{
	public interface ComponentInterface 
	{
		function attached(entity:Entity):void
		function detached(entity:Entity):void
	}
}

Here’s a typical attached/detached function pair

public function attached(entity:Entity):void
{
	myentity = entity;
	currentcount = 0;
	entity.attachEvent(ComponentEvent.UPDATE, this.update, int.MAX_VALUE);
}

public function detached(entity:Entity):void
{
	entity.detachEvent(ComponentEvent.UPDATE, this.update, int.MAX_VALUE);
	myentity = null;
}

As you can see I’ve also added a function to the Entity class so they can remove their events, which allows me to fully switch components around. The only caveat is that if you add components that have dependencies and then remove the components on which they are dependent, they will keep the reference. For instance if you add a position component, then an animation component (which uses position) and remove the position component, the animation component will still know about it and it won’t be collected as garbage. If you then add a new position component, the animation component will not know about it and keep referring to the old one. That could really mess you up, but I don’t see an easy way around it.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Logical OR help

Originally posted by GameBuilder15:

Wow. Thanks for the replies, everyone.

I can’t believe there’s an error in the book. I’m not that far into it; I don’t think I’m even at page 60 yet, and there are 890 pages.

Yeah that’s unbelievable, it’s 890 pages, how could they not proofread it flawlessly cover-to-cover? They don’t make inerrant books like they did 2000 years ago anymore…

Dude, errors happen. And apparently there’s an erratum for that particular one, so chances are it will be fixed in the next edition.

As for XOR, A XOR B = (A || B) && !(A && B). Sure it’s long, but it’s there.

Edit: \/ Way to ruin the joke.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

Originally posted by jerimo:

But personally i would make it so that you could easily make a factory of these objects; Each weapon can have a “cooldown” component attached to it.

This. This is the source of most of my headaches right now. If a weapon has a component attached to it, then the weapon is an entity. Therefore it cannot also be a component of another, bigger entity, like the player’s avatar. I’d love a system where elemental parts assemble into bigger parts that combine into even more complex parts and so on, but this is not it. This system has two levels and two only: Entity and component. If you want to make a comparison to Lego blocks, in this system the component blocks don’t have prongs. (They’re more like the animals and characters in Duplo, if you have small children and know about this: their surface is smooth, you can’t build anything on top of them.)

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Logical OR help

This is something that is important when you have two tests to perform, one of which is slow: You want to put the faster test up front. If both are fast, you want to put the one most likely to result in short-circuiting first (so the test that is more often true if you have an OR operator, the one that’s more often false if it’s an AND operator.)

Also, the text you quoted is correct, but the comment in the code is not. Probably a typo.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Logical OR help

The conditional will evaluate to true if either component is true (that’s what || means), so in your case if xPosition is outside of the [0; 100] interval. The comment is very strangely worded, too. Are you sure you copied it right?

You are correct in your example of xPosition = 5.5, the conditional would evaluate to false in that case.

Edit: Ninja’d.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

Originally posted by Drakim:

I suspect a lot of people would want to include the basic ingame object properties on the Entity class (such as .x and .y) because abstracting it out wouldn’t gain them that much. You’d lose some modularity the more you add though.

I feel that would be a mistake. I’ve gotten so much mileage already out of the Position component, it’s a very convenient way to store reference coordinates for just about anything, and passing them along without having the recipient wonder about the type of what they were attached to in the first place.

I use a Position component as the target for the Tracker component, which has no clue what it’s targeting, only where to find it. And if the target moves its coordinates are updated automatically (yay pointers!) so it’s homing.
I also use it to store the mouse coordinates. Any component that needs to know about the mouse on a regular basis can get the mouse position this way. If I want to replace the mouse pointer with an entity, I can give it the mouse Position as its own Position component, for instance.
My camera is currently a Position component, and I pass it along to the draw function. This way entities that want to be drawn can check first if they’re on screen, and if so know exactly where to draw themselves.

A much bigger limitation is that an entity can only have one of each type of component. If I have a ship that fires bullets at a given rate and missiles at another, slower rate, I would need two Repeaters with different timers. I can’t have that. Maybe the way through that is a Scheduler component that keeps a list of events to fire and their frequency. Anything that changes over time (animations, auto-fire, expiring statuses and bonuses) could be routed through it. I have to think about it.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

They are because this is a toy project I’m using to try and wrap my mind around the component-based way to do things. Right now the way I’m doing it is that the ‘draw’ event is accompanied by a canvas:BitmapData and a camera:PositionComponent objects in the data, and every item draws on the canvas at the offset determined by the camera.

I don’t like this way of doing things. First the canvas gets passed around like a bottle of cheap wine at a teen party, when it should be receiving info on what to draw where and do copypixels() at a centralized location. Second, if I have an entity that needs to be drawn twice (on the main view and on a radar screen, for instance), I’m stuck because I can only have one image associated with the entity right now. In order to have two I’d need a new component that would be an exact copy of the BitmapData component, just with a different class name. That’s very inelegant.

I’m sure there are simple and elegant solutions to these problems, but I don’t understand the framework well enough to come up with them.

A question: Would it be OK to extend the Entity class in order to have pre-made entities of a certain type? Like an ‘Enemy’ class that’s an Entity to which position, speed, AI, health etc… components are automatically added in the constructor? I feel that might help with object pooling, but it might be a step back toward the hierarchy design. Obviously these classes would be project-specific.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

I’m bumping into a problem with the priority thing. Namely, the problem is that priority is fixed. If you have a view with depth you’ll want objects to be drawn from farthest to closest to the camera, but if some objects can move their depth level can vary. How do you handle that with a fixed priority list?

Here’s a simple example, I want the black ball to be drawn before the red ball when it’s going up and after when it’s going down so in first approximation it looks a bit like it’s swinging around the red ball. How would you handle it without breaking encapsulation?

The BitmapData component knows about position but not about speed, and it should not know about speed in general (because basing the drawing order on speed is an arbitrary choice that shouldn’t be hard-coded into the component, and because determining the priority order between a mobile and static object would then fail since the static object has no reason to have a speed component, and shouldn’t be given one just for this purpose.)

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Open Source Isometric Game

Do you have a road map that goes with this project? If I was to contribute I’d face two primary hurdles:
1) I’m afraid I’m going to mess up something for someone else or duplicate their effort.
2) I don’t know what the final project should look like.

I feel like I’ve been given access to the construction site for the new opera. I can use all the materials and tools that are here to help with the construction, but not consult the architect’s plans. I don’t want to start building a staircase just to be told it’s standing in the middle of the auditorium and has to be taken down, you know.

 
avatar for Ace_Blue Ace_Blue 1068 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 2): Composition over inheritance

It also raises the question of how to do object pooling. A simple bullet hell might create and destroy hundreds of bullet entities every second, but since entities only add what they need and each addition is a new object created, I could easily see object creation/destructions rising into the thousands every second, while it would be difficult to reuse spent bullets even if the new ones are just like the old ones. Not only that, but all of these new objects need to get their spots in the event list, while all the old ones need their events removed. I’m worried about performance.