Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - NateTheGreatt

Pages: [1] 2 3 ... 5
1
I returneth to you, Flixel Help Forums, for another challenge I have been posed with: leveling and experience rates & calculations.

Does anyone have any tips/suggestions/examples they can give me that might make my venture into this scary world of maths a bit easier? Not only the math, but the structure of the calculations within my player class.

Really just any tips anyone could give would be greatly appreciated.

Also, if anyone has any experience with damage calculations taking stuff like armor and magic resistance into account, I'd love some input on that, too.

2
Ahh that makes sense. I didn't even realize there was another length variable. Thank you!

3
When I add two objects to an FlxGroup and I log members.length, it returns 2. If I add a third object, members.length logs to 4. Is this a bug?

I thought it was Flixel 2.50 so I tried updating to 2.55 and the bug persisted. Also, I noticed that when I logged FlxGroup.members it would log a list of objects to the console. After updating to 2.55, it logs nothing for FlxGroup.members.

Are these bugs?

4
help / Re: Dynamic graphic class name from XML
« on: Thu, Sep 1, 2011 »
That's probably too involved for what you need though.  For your particular situation you can probably use something like:

Code: [Select]
loadGraphic(getDefinitionByName(xml.prodblock.graphClass) as Class);
Again, I haven't tested this.  It's just a guess but I think it should work.  Please let me know how it goes... like I said, I'll be doing something very similar in a couple days so any useful information would be appreciated.

more info: http://thillerson.wordpress.com/2007/03/01/runtime-class-instantiation-in-actionscript-30/

I attempted this. It was not successful and resulted in frozen code after the loadGraphic() call :C

Edit:

I talked to strega_ on the flixel forums and he explained a very neat way to do this!!

Define your embedded image variable as a public static variable (preferably in a registry) and then do the following:

Code: [Select]
loadGraphic(Registry["NameOfImageClass"]);
E.g. with XML:

Code: [Select]
object.loadGraphic(Registry[node.@imgName]);

5
help / Re: Dynamic graphic class name from XML
« on: Sat, Aug 27, 2011 »
I'm still learning dynamic programming methods. How about a nice switch statement instead :D?

Code: [Select]
var image:String = xml.obj.img;
switch(image) {
case 'ImgBlock01':
loadGraphic(imgBlock01);
        break;
case 'ImgBlock02':
loadGraphic(imgBlock02);
        break;
}

Something like that?

6
help / Re: Entity ID system implementation
« on: Fri, Aug 26, 2011 »
There are a lot of options for this.

You could create an object registry. Make a dictionary of strings and associated classes, so you can parse in a string and get an class back (which you can then new() to make a new instance). Something like this:

The big annoying downside if that you have to have a register all the strings somewhere when the application starts. But it does mean giving the player an item is going to be readable since you can just write.

giveItem(new registry.getClass("LASER_SWORD"))

This whole solution is a little isn't that elegent and would be a strain on the processor if you gave the player a lot of stuff at once since it's fabricating every single object.

The 'neat' alternative is to extend FlxSprite with some sort of InventoryObject class and make an inventory manager. InventoryObject have their own int variable that tracks the number of that item that is stacked, a boolean to track if they are stackable objects or not and a unique string key that lets you identify the object without needing the class (which could just be a string of the class name, for simplicity).

When the player picks up an object the manager looks in the list of items to see if the player is carrying a stackable version of them same item. If not it just creates adds that item under the key defined in the object. Keep in mind that it's a reference to the same object so if you kill() it somewhere else it might have strange effects. If it -does- find an identical item with the same key it just increases it's stack variable by the amount of the object being added (rather than 50 bullet objects the player has 1 bullet object with a stack value of 50) and trashes the old object.

You could of course combine both to keep the amount of objects created down. So you could store item 'drops' as a list of registry key names and stack counts. Then when the player uses an interaction that requires them to pick up the drops you could created them and parse them into the players inventory manager.

I tried implementing this but when I do spawnItem(new itemRegistry.getClass("redSquare")) it throws an error saying that the method cannot be used as a constructor :c. Anyone know the proper way to implement this?

7
help / More discreet collisions?
« on: Thu, Aug 18, 2011 »
I'm setting up an inventory system that works by literally fitting as many items as you can into the designated inventory zone. Right now for testing purposes I have created a bunch of sprites with random width and heights and added them into this zone. I call collide with that group of sprites on itself so they all collide with each other.

My problem is that sometimes the sprites get stuck inside of one another. How can I prevent this from happening?

8
help / Re: Entity ID system implementation
« on: Mon, Aug 15, 2011 »
Wow Titch, phenominal suggestions!

Seriously! Can't thank you enough, Titch. My game owes you two!

9
To keep the offset just use a point storing the distance between the mouse and the object when it's clicked on and then add it back to the position whilst you are dragging it around.

Psuedo code ahead:-
(I've probably screwed up the +/- signs for working out the offset distances)
Code: [Select]
var m_mouseOffset:FlxPoint = new FlxPoint()
var m_isDragged:Boolean

private function onDragInit ():void
{
m_mouseOffset.x = mouse.x - this.x;
m_mouseOffset.y = mouse.y - this.y;
}

public function onDrag()
{
if (m_isDragged)
{
x = mouse.x + mouse_offset.x;
y = mouse.y + mouse_offset.y;
}
else
{
onDragInit()
m_isDragged = true;
}
}

public function onDragRelease():void
{
m_isDragged = false;
m_mouseOffset.x = 0;
m_mouseOffset.y = 0;
}

If you are only dragging on thing at a time you'll only need one instances of offset. Although adding it to every draggable object isn't a massive overhead.

I tried doing exactly that a little earlier. For some odd reason it wouldn't drag the box at all when I added the offset :C. I guess I'll have to tinker with it

10
Yes it's actually very simple, this is what I did where mySprite global sprite I want to move around that I defined earlier. And myBox is the box containing the sprite.
Make sure to enableDrag and whatnot. Parameters for the mouseSnap function were useless in my case, not sure if they are necessary.

Code: [Select]

myBox.mousePressedCallback = mouseSnap;
myBox.mouseReleasedCallback = mouseRelease;

private function mouseSnap(spritetosnap:FlxExtendedSprite, x:int, y:int):void
{
mySprite.x = FlxG.mouse.x - mySprite.width / 2;
                        mySprite.y = FlxG.mouse.y - mySprite.height / 2;
mySprite.startDrag();
}

private function mouseRelease(spritetosnap:FlxExtendedSprite, x:int, y:int):void
{
mySprite.stopDrag();
}

I'm confused, it looks like your code sets it to drag from the middle of the sprite, as well. I'm trying to achieve a drag that doesn't snap to the center.

11
help / Re: Entity ID system implementation
« on: Sun, Aug 14, 2011 »
There are a lot of options for this.

You could create an object registry. Make a dictionary of strings and associated classes, so you can parse in a string and get an class back (which you can then new() to make a new instance). Something like this:

The big annoying downside if that you have to have a register all the strings somewhere when the application starts. But it does mean giving the player an item is going to be readable since you can just write.

giveItem(new registry.getClass("LASER_SWORD"))

This whole solution is a little isn't that elegent and would be a strain on the processor if you gave the player a lot of stuff at once since it's fabricating every single object.

The 'neat' alternative is to extend FlxSprite with some sort of InventoryObject class and make an inventory manager. InventoryObject have their own int variable that tracks the number of that item that is stacked, a boolean to track if they are stackable objects or not and a unique string key that lets you identify the object without needing the class (which could just be a string of the class name, for simplicity).

When the player picks up an object the manager looks in the list of items to see if the player is carrying a stackable version of them same item. If not it just creates adds that item under the key defined in the object. Keep in mind that it's a reference to the same object so if you kill() it somewhere else it might have strange effects. If it -does- find an identical item with the same key it just increases it's stack variable by the amount of the object being added (rather than 50 bullet objects the player has 1 bullet object with a stack value of 50) and trashes the old object.

You could of course combine both to keep the amount of objects created down. So you could store item 'drops' as a list of registry key names and stack counts. Then when the player uses an interaction that requires them to pick up the drops you could created them and parse them into the players inventory manager.

This sounds brilliant. I'm gonna give my hand at combining these methods, because I do want drop tables :D. Your posts are wonderfully helpful, can't thank you enough

12
Extends FlxGroup. Add the following.

Code: [Select]
public function get x():int { return _x; }

public function set x(value:int):void
{
var diff:int = value - _x;
for each (var item:* in members)
{
if (item is FlxObject)item.x += diff
}
_x = value;
}

public function get y():int { return _y; }

public function set y(value:int):void
{
var diff:int = value - _y;
for each (var item:* in members)
{
if (item is FlxObject)item.y += diff
}
_y = value;
}

It -might- start to lag with a lots of objects since it has to iterate through all the items in members.

You are so helpful. This looks great, thank you!

Another question: I made the GUI for this draggable, but I can only make it work when the GUI.x = mouse.screenX - GUI.width/2 and same with Y. Is there a way I can drag the item from where I clicked it?

13
help / Re: Entity ID system implementation
« on: Sat, Aug 13, 2011 »
You could have an array somewhere with references to the classes of your items. So when you call giveitem(23) it looks in entities[23] and instantiates that.

Personally, the way I've been doing things in my current game is to use getDefinitionByName() in flash.utils to get a reference to a class definition from a string. That way, I can just put a 'Bat' into my game, rather than '124' or something, which I'll probably forget.

For instance:
Code: [Select]
entity = new (getDefinitionByName("enemies." + Monster) as Class)(X, Y);
You do have to remember to actually declare a variable somewhere in your source code so that the class gets added to your project. So, like,
Code: [Select]
private var __bat:Bat;

That is useful! Thank you

14
How can I create a floating inventory GUI that maintains the X and Y positions of all objects inside of it locally? Meaning if I click and drag the inventory GUI, all of the sprites will go with it. I thought of using an FlxGroup but wasn't sure how to maintain the local coordinates of the contained objects :S

15
help / Entity ID system implementation
« on: Wed, Aug 10, 2011 »
I want to implement an entity ID system into my game because I am going to have quite a bit of of items and pickups. I wasn't sure of the best way to go about this. I would like to be able to call a function like player.giveItem(itemID) and have it sort out what type of item it is and put it in my player's inventory. For now the items are just weapons and ammo, but I plan to have a lot more items like tools, parts, accessories, food, etc.

Are there any standard ways to implement a system like this?

16
Why not model a bullet as a line segment?

You'll probably need to insert your own collision check for that, but I can't think of a better way.

Yeah, that'll be my next move I guess.

17
I've been at this for the past few days now. I'm making a top-down zombie shooter and I wanted realistic behaving bullets. I achieved this by iterating a small 1x1px sprite down a line when the mouse is clicked and checking for collisions on each loop-around. This worked beautifully for single-shot weapons and even automatic weapons. The problem I'm running into is shotgun-like behavior. What I did for that was send out this sprite to iterate down 6 different lines. The problem with this is that it lags before every shot, and lags to HELL if spammed. The cleanup is pristine, though, because the FPS goes back up when the shot is done iterating.

I tried something called tunneling, graciously suggested by someone on #flixel, which is basically splitting up the loop into different frames so it doesn't do it all in one frame while retaining most of the bullets instantaneous behavior. I had high hopes for this method, but alas: it still lags when the shotgun bullets go off, this time the lag is a bit more choppy instead of pushing one solid lag spike.

So: Can anyone suggest a way I could get some realistic shotgun shells off? Preferably with this technique but other techniques are perfectly welcome :]

18
help / Re: Flash Game Dev Tips
« on: Sun, Jul 31, 2011 »
Haha I like that your reply said how do you donate, edited to a mere coffee ;)

(just messing, I don't need donations or coffee, just like to see people make/learn stuff)

C: You are a good person.

I WILL buy you a coffee someday...

19
When you press ~ and look at the console, the U is the number of updates being called per frame, and D is the number of draws, and as you shoot, you can see the number of updates just keeps going up, so they must not be getting killed.

There should be some good tutorials on google about colliding in different ways. I can't imagine colliding against a line wouldn't have any tutorials. I've never actually done it, but I would assume you could get the equation of the line, and for each enemy's x, you can find out the corresponding y on the line, and check if that y is within the bounding box. Though there's probably better ways.

Ah, I had no idea what the U and D meant. Thank you! That is extremely helpful. I'm rewriting my engine of current, it was too spaghetti anyway.

20
help / Re: Flash Game Dev Tips
« on: Sat, Jul 30, 2011 »
You are beauty. How do I buy you a coffee??

Pages: [1] 2 3 ... 5