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 - zez

Pages: [1] 2 3 ... 11
1
help / Handy dandy tile randomizer.
« on: Wed, Jan 5, 2011 »
I dunno about the rest of you, but I pretty much hate setting a million CSV values for tiles that basically act the same way, but have some minor difference visually too break up the 'grid'.

Thus, I made this helper class. It has two basic uses. The first is fairly simple and just generates a tile map that has a flood fill of random tiles. The later will take an embedded tile map, and randomize any tile(s) you tell it too.

Usage is fairly simple, you either flood fill like so
Code: [Select]
add(new randomtiles(tilesheet, true, a number between 0 and 1 that is the likelyhood of any given tile being random, the width in tiles, the height in tiles, the number of tiles on the sheet/ the last tile on the sheet you want too randomly show);

or you load an embedded tile map and randomize it like this
Code: [Select]
var ranmap:randomtiles = new randomtiles(tilesheet, false);
//make any changes too collideIndex or drawIndex or what have you the old fashioned way
ranmap.randomize(new embedded_map_csv, [tile, values, you, want, randomized], [range, of, tile, randomization], [chance, of, randomizing, tile]);
add(ranmap);
This bit should probably have the disclaimer that your arrays have to line up meaning tile[0] should be the first tile in whatever range of tiles the variation is for, randomrange[0] should be how many tiles away the last possible tile from tile[0] is, and variation[0] is how likely it is too change tile[0] too another tile.
Thus if tile[0] = 5, randomrange[0] = 5, and variation[0] =0.23, you have a 23% chance of changing every tile with a value of 5 too a tile with a value between 5 & 10.

Final bit of explanation, variation should be a number between 0 and 1. A value of 0 or less will NEVER randomize a tile, so you may as well just use FlxTilemap, and a value >= 1 will always randomize the tile (in the case of the second usage the tile corresponding the variation index.) You may very well want to use 1 sometimes, and in those cases there isnt really anything stopping you from using 1 billion instead of one, other then it being kind of silly.

Anyhow, heres the class in case anyone else wants it.
Code: [Select]
package com
{
import org.flixel.*;
public class randomtiles extends FlxTilemap
{
private var _tilessheet:Class;
public function randomtiles(tilesheet:Class, autogenerate:Boolean, variation:Number = 0, map_width:int = 0, map_height:int = 0, tiles:int = 0)
{
if (autogenerate == true)
{
var mapstring:String = "";
for (var i:int = 0; i < map_width * map_height; i++)
{
if (i % map_width == 0)
{
if (i > 0)
{
mapstring += "\n";
}
if (FlxU.random() < variation)
{
mapstring += (int(FlxU.random() * tiles)).toString();
}
else
{
mapstring += "0";
}
}
else if (FlxU.random() < variation)
{
mapstring += "," + (int(FlxU.random() * tiles)).toString();
}
else
{
mapstring += ",0";
}
}
drawIndex = 0;
loadMap(mapstring, tilesheet);
}
else
{
_tilessheet = tilesheet;
}
}
public function randomize(mapdata:String, tiles:Array, randomrange:Array, variation:Array):void
{
loadMap(mapdata, _tilessheet);
for (var t:int = 0; t < tiles.length; t++)
{
for (var i:int = 0; i < totalTiles; i++)
{
if (getTileByIndex(i) == tiles[t] && FlxU.random() < variation[t])
{
setTileByIndex(i, tiles[t] + int(FlxU.random() * randomrange[t]));
}
}
}

}

}

}

Should I maybe give it a user interface and make it just spit out CSV files, thus making it a "randomize tile map csv files" app instead of a flixel exclusive "make your maps randomize themselves on load" class?

It loads pretty quick and isnt particularly system intensive, even when doing the silly for loop in a for loop thing well randomizing existing maps (adds about 3ms to update on my box well doing stress tests, and doesnt change ram usage for long enough for me too read or notice the change,) so that isnt really an issue....

2
help / Re: Bloom trouble
« on: Wed, Jan 5, 2011 »
Code: [Select]
public function spritewithblurfilter(X:Number, Y:Number)
{
super(X, Y);
var blur = new BlurFilter(6, 6, 1);//or whatever
loadGraphic(sprite sheet, true, true, 32);// ditto
pixels.applyFilter(pixels, pixels.rect, _flashPoint, blur);
}
Totally works for applying a bitmap filter (in this case Blur, but it could be anything,) to the entire sprite sheet.

 You can also apply it to _framePixels the same way (I mean, you probably want to store the variable somewhere so you only make a new one once, and keep track of if you have already applied it too the frame so you dont end up re-applying the same effect 3000 times or something silly....)
If you want to have an easy way of toggling the effect.

You may or may not have to make Pixels and or _framePixels public in FlxSprite to make this work (I forget if I did that or not. Im pretty sure I did it too at least one of them, if it was _framePixels then it only matters if you want too apply it at pre set times to whatever frame the sprite is on.)

3
help / Re: Detailed water physics
« on: Wed, Jan 5, 2011 »
I could be totally off-base on this, but I think both of them happen because your player is overlapping any given water object before the eyes get a chance (and thus the only instance where _playerWater != -1 is when you press "S"). Too solve problem 1, make the bounding box of the eyes go a pixel or two higher then the top of the player, too solve problem 2, make the bounding box go a pixel or two too the left and right of the player (so tweak height, width, and offset of the eyes.)

If Im right, problem 2 is happening because the eyes arent overlapping THAT WaterObject yet, and problem 1 is just the player hitting the water before his eyes.

Note that even if the Eye object is sized too be as wide / high up as the player, if you have something like eyes.x = x; eyes.y = y; in your players update, there is still a good chance the player will overlap the water before the eyes.

You also may want to play around with putting eyes.x = x; eyes.y = y before or after the update and see if that helps any.

4
help / Re: Multi-layered Tilemap Collisions
« on: Thu, Aug 5, 2010 »
make a class, name it something, make it extend flxTilemap, then load your one way tiles in that tilemap (have it be a separate tile map) same way as normal, then adjust that code to be if Contact is (whatever you named that class.)
The custom tilemap class probable doesnt need any special code, other then extending tilemap, so you can basically make it totally empty.
Another thing you could do, is pass a tilemap to the player as a variable, and change Contact is OneWayTileBlock to Contact == the tilemap you passed as a variable, provided you only have one map of one way tiles.

5
help / Re: Block player can push
« on: Wed, Aug 4, 2010 »
drag.x is your friend in this case. You could probably even use the normal collision code, cap velocity.x at something low (maxVelocity.x = 50 or something;) set drag.x to something around the maxVelocity.x and let flixel do the rest.

6
help / Re: Bulltes disappear on old scrollbounds?
« on: Wed, Aug 4, 2010 »
flxu.setworldbounds
This is my idea.

7
how would I go about doing that? When I tried wrap.bitmapdata = pixels; draw(wrap,etcetc); I got more slowdown...

8
So umm... did I implement the fix incorrectly, or do you think somethin else is breaking it? I just want to know where to start on debugging this.

9
help / Re: moving a tileMap and collide problems
« on: Sun, Aug 1, 2010 »
this might not fix anything, but try fiddling with FlxU.worldbounds. You also could work around it by just setting FlxG.followBounds....

10
help / Re: Edge detection! IDEA!
« on: Sun, Aug 1, 2010 »
depending on sprite width, theres always
Code: [Select]
if (map.getTile(left/tilewidth, (bottom /tileheight) + 1) >= map.collideIndex && map.getTile(right/tilewidth, (bottom /tileheight) + 1 < map.collideIndex){ your left side is on an edge, do stuff}
if (map.getTile(left/tilewidth, (bottom /tileheight) + 1) < map.collideIndex && map.getTile(right/tilewidth, (bottom /tileheight) + 1 >= map.collideIndex){ your right side is on an edge, do stuff}
Of course, that breaks pretty hard in the event that the sprite in question isnt wider then the tiles, but it doesnt require any extra objects or variables.

11
help / Re: "Shadows", arrays questions
« on: Sat, Jul 31, 2010 »
The problem with the simple one you have posted here, is that
Code: [Select]
public function Light(X:Number,Y:Number,darkness:FlxSprite):void
{
super(x, y, Lite);

this.darkness = darkness;
this.blend = "screen";


}
should be
Code: [Select]
public function Light(X:Number,Y:Number,[u]D[/u]arkness:FlxSprite):void
{
super(x, y, Lite);

this.darkness = [/u]D[/u]arkness;
this.blend = "screen";


}
or something along those lines. What you have now is telling light that darkness = itself, so if you want to pass it another instance of darkness, you need to have the name of the variable you are passing be different then the variable you are passing it too.

As for the box2d bit, it looks like you just didnt import correctly, or failed to pre-load box2d.

12
help / Re: "Shadows", arrays questions
« on: Sat, Jul 31, 2010 »
Oh, my bad, the error it threw from my browser based copy was in the playstate. Post the code to the light.as file?

13
So... My current project, on a shoddy laptop from a while back (duel core amd turion @ 803 mhz, 960 megs of ram, running XP service pack 3,) is pretty much unplayable in flash player 10.1, whereas it runs kind of sort of mostly perfectly in 10.0 (I have some of the more system intensive stuff set up to only fire well FlxG.elapsed is < something, so the first thing to go is visual fluff, and it still runs most of it.)
In 10.1 it drops down to around 15 fps, and pretty much becomes unplayable.

I tried modifying FlxSprites advanced render stuff, and basicly just changed buffer.draw(_framePixels, stufffff) into buffer.draw(new Bitmap(_framePixels), that same stuff) and umm... got pretty much zero results. The game does render about twice as fast when I do it that way, but looking at the dev console, I dont really think thats whats breaking it (unless Im doing something totally bassackwards, always a possibility)

Anyhow, heres about the situation;
with "fix"
10.1
42~ ms update
8~ ms render
45~ ms flixel
60~ ms total
15~ fps
cpu - 50% ish
memory - starts at 40 megs, quickly jumps to 75, then rises to about 100 megs, idles there for a second, and then drops down too 75. It does this regardless of advanced rendering.

10.0
9~ ms update
6~ ms render
14 ~ ms flixel
20~ ms total
50~ fps
cpu - 50% ish
memory - 40 - 50 megs, fairly consistent.

without fix
10.1 mostly the same, render is about double when doing advanced rendering, frame rate is still around 15.
cpu - 50% is
memory 75 megs - 100 ish and then back.
10.0 no noticeable difference.
cpu - 50% ish
memory - 31megs - 76 ish and then back.

14
help / Re: "Shadows", arrays questions
« on: Fri, Jul 30, 2010 »
Looks like you have a null object in your render somewhere. Couple suggestions. Instead of screenXY.x and screenXY.y try getScreenXY().x and getScreenXY().y. If that solves it the problem is that you are never creating your flxpoint. You could stick screenXY = new FlxPoint(getScreenXY()); somewhere in create, and make screenXY a private var:flxpoint, then in the render stick in screenXY = getScreenXY(); to get around that as well.
If that is not the problem, it might be that you want darkness.draw(screen , screenXY.x - this.width / 2, screenXY.y - this.height / 2);
My only other thought is that you may have never created the darkness sprite, so in create darkness = new flxsprite(); darkness.creatGraphic(flxG.width,flxG.height, 0x000000); or whatever... Im not really sure if thats how the darkness object should be set up (never done this particular effect,) but you get the idea.

15
help / Re: Flixel Collisions Bug [NEED HELP]
« on: Thu, Jul 29, 2010 »
FlxU.setWorldBounds(0, 0, gameworld width, gameworld height);?

16
help / Re: "Shadows", arrays questions
« on: Thu, Jul 29, 2010 »
noooooooooooo dont add the array.
You would do it the same way you normally would make something render infront of or behind something else, using a group. So if you want the shadows infront of everything, after you have added everything else to the state, you would add(shadowgroup); then when you add the shadow, it would be shadowgroup.add(shadow); instead of add(shadow);
That, or just run the process after everything else is added....

Also, if you plan to add a 16x16 sprite to every possible area on a map, first off, you actually can bypass all the array stuff and just us this
Code: [Select]
for (var i:int = 0; i < _map.totalTiles; i ++ )
{
if (i % _map.widthInTiles == 0 && i > 0)
{
eY += 1;
}
sprite = new flxsprite ( (i - (_map.widthInTiles * eY)) * 16,eY * 16);
add(sprite);
and second off, you are probably going to just want to use a single sprite with the proportions flxg.width, flxg.height; along with some drawing stuff to get your affect.

17
games / Re: WIP Lufies Adventure
« on: Wed, Jul 28, 2010 »
My biggest issue with it is that the grass on the background wall stuffs has the same priority as the foreground, so I wanted to jump on it.

18
help / Re: "Shadows", arrays questions
« on: Wed, Jul 28, 2010 »
okay... so i is just an integer, what its doing is looping through every index within the array. (i starts at zero, wile i is less the the length of the array, add one to i.)
The bit that is if(i % map.widthinTiles == 0 && i > 0){eY += 1;} is adding 1 to your y value every time you reach a number that is perfectly divisible by the width in tiles, meaning whenever you hit the end of a row, it goes to the next columns value. You can then use these two values to get the X and Y coordinates. The y coordinate is just eY * whatever the size of the 'tile' you are using is, so 16 in this case. The X coordinate is a little bit trickier, as the value of i will be every single possible value within the array, and not just a pure X value, however, sense you know the y value (eY) you can just multiply that by the width in tiles of your map (like I did) and subtract it from i, to get the X 'tile' value. Then you just multiply your x 'tile' value by the width of a tile (16 in this case) to get the proper x coordinate in pixels.

what if(array[ i ] == a number) is doing, is just checking to see if the array value at the index i is equal to a number that theoretically represents your sprite, and if it is, creates it and places it based that equation in the paragraph above. So, the 'sprite' variable Im using there is getting passed (X coordinate, Y coordinate) just like any flxsprite should, and yes, it can be any other variable. You can infact use if(array[ i ] == 1) {goat = new goat( (i - (_map.widthInTiles * eY)) * 16,eY * 16); add(goat);} if (array[ i ] == 2) {cheese = new cheese( (i - (_map.widthInTiles * eY)) * 16,eY * 16); cheese.smell = "really smelly"; cheese.health = 23; add(cheese);} or pretty much whatever else you want using this method.

If you only have 3 positions in your grid, however, you might as well just do it manually instead of using a for loop, the way I have it set up right now, its designed to work with an array the same proportions as your worlds tilemap, and place sprites that way, so you can just edit a csv array in whatever map editor rather then having to manually plug away at sprites, or load in an xml file or some other such nonsense. In other words, this is a good way to do it if you have a large space you are filling with relatively small sprites (for example, I place my enemys and powerups this way, enemys averaging out to being around 16*32 and powerups being 16*16)

*EDIT* Good call zyxstand, I feel silly.

19
help / Re: "Shadows", arrays questions
« on: Wed, Jul 28, 2010 »
1. Yeah, you can embed it as a text file, what do you think flxtilemap is using?
and for 2
Code: [Select]
var tmpArray:Array = (embedded csv array as String).split("\n");
for (var tmpi:int = 0; tmpi < tmpArray.length; tmpi++)
{
string += tmpArray[tmpi] + ",";
}
if (tmpi == tmpArray.length)
{
array = string.split(",");
}
for (var i:int = 0; i < array.length; i ++ )
{
if (i % _map.widthInTiles == 0 && i > 0)
{
eY += 1;
}
if (array[i] == a number)//add sprite
{
sprite = new flxsprite ( (i - (_map.widthInTiles * eY)) * 16,eY * 16);
add(sprite);
}
}
That will take a string that happens to be a csv array, convert it into a 1 dimensional array, and loop through it placing sprites at the correct X & Y positions. Its basically the same code Im using to place sprites in my current project. If you are not using a csv array, but some other sort of array, you will have to modify the top bit where it converts the string into a 1 dimensional array. Also note, that this code assumes the array is the same size as your games map, as it is using the width of the games tilemap to determine the Y values.
*EDIT* Oh yeah, and eY should be var:int = 0, before the for loop starts. Its the current Y coordinate of the sprite being placed. (well, 1/16th of the current y coordinate.)

20
chat / Re: Shmup lovers!
« on: Wed, Jul 28, 2010 »
bangai-O did something kind of similar to ikaruga, but minus the defensive element that made it really shine. I wouldn't really recommend getting a gamecube just for ikaruga. EITHER get a dreamcast for around 20$ and download the iso (dreamcasts have pretty much zero copy protection, so no need to mod) as you probably wont find a hard copy, or get yourself a wii and take advantage of backwards compatibility.

Pages: [1] 2 3 ... 11