What do you mean; detecting the colour of a pixel around the player to decide what to do?
Exactry
So to do this I'd have to store the image's data in an array and read it back out again, or more specifically read out the pixel at the destined width/height and if it's colour matches a certain colour complete an action?
[QUOTE='[ApS] Elf;23770134']So to do this I'd have to store the image's data in an array and read it back out again, or more specifically read out the pixel at the destined width/height and if it's colour matches a certain colour complete an action?[/QUOTE]
Or just fuck the array part and read the pixel when you need it.
Yeah!
[cpp] public void checkCollision( )
{
int[] pixels = new int[ 800 * 600 ];
PixelGrabber pg = new PixelGrabber( still, 0, 0, 800, 600, pixels, 0, 800 );
try
{
pg.grabPixels( );
}
catch ( InterruptedException e )
{
}
int c = pixels[ x * 800 + y ];
int red = ( c & 0x00ff0000 ) >> 16;
int green = ( c & 0x0000ff00 ) >> 8;
int blue = c & 0x000000ff;
System.out.println( red + " | " + green + " | " + blue );
if ( red == 200 && green == 200 && blue == 200 )
{
y += 1;
}
}[/cpp]
I ended up with this, however it's just reading red, green and blue as 0 where ever I go; any ideas?
Found this on the API page for PixelGrabber
[cpp]
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel ) & 0xff;
[/cpp]
how do i make a message pop up for a website like facebook. Where if i get a like or someone comments on my post it tells me what they said. Im making a facebook dock application.
[I]Uhh.. My dumb. Can't find the delete button either.[/I]
I am working on a custom sized map based on the map info in the map file. Each tile spot has it's own member of a class called tile. I know what the map's minimum sizes are so I declared them during the deceleration of the class. I declared them like so: tiles[16][12];. The program reads the map at a later time. How can I add new members to the existing array? I can't declare the tiles at a later time, because the program relies on the tiles.
Confused on how to get started parsing and working with JSON in C++. Cannot find anything well documented.
[b]Edit:[/b]
Screw this, I think I'm gonna try out XML.
[QUOTE=WTF Nuke;23772114]I am working on a custom sized map based on the map info in the map file. Each tile spot has it's own member of a class called tile. I know what the map's minimum sizes are so I declared them during the deceleration of the class. I declared them like so: tiles[16][12];. The program reads the map at a later time. How can I add new members to the existing array? I can't declare the tiles at a later time, because the program relies on the tiles.[/QUOTE]
What do you mean? You want to expand the size of the array later, or do you want to edit the members of the array?
Also, what language?
Okay, this is a quick little question I have.
For the sake of curiosity, I'm trying to modify the models on Minecraft. I've found where they are stored, they're just hard-coded rects with angles for each rect.
So I decompiled the code, and I'm going to try commenting out some of the rects to modify the model, to start with.
But currently I'm getting a fuckton of dependency errors, because I'd prefer not to decompile the entire jar. So what I'm curious about is if there is any way to merely compile it and get the .class file while ignoring whatever errors it is reading out.
Of course, I feel like I'm completely ignoring how the compilation process is working.
Either way, is it possible or not?
[b]EDIT:[/b]
Nevermind, that wasn't the latest version. That was before he started alpha.
Now I look in the alpha jar, let's try to find i-
OBFUSCATION, OBFUSCATION EVERYWHERE. ALL IN THE ROOT OF THE JAR.
Every single class file that isn't borrowed from another source is in the root of the jar, and they're all obfuscated. I'm talking from a-z, probably at least two hundred or three hundred class files.
So basically, nevermind, it doesn't matter, I'll need another three hours to figure out where the model is, when it's this badly obfuscated.
[QUOTE=ralle105;23770583]Found this on the API page for PixelGrabber
[cpp]
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel ) & 0xff;
[/cpp][/QUOTE]
Thanks, but I realised I was actually getting the RGB values from the sprite rather than the background :v:
Well I constructed the loop:
[cpp] public void checkGroundCollision( )
{
ImageIcon b = new ImageIcon( "D:/PW/Java/background.png" );
background = b.getImage( );
pw = still.getWidth( null ) + this.getX( );
ph = still.getHeight( null ) + this.getY( );
int[] pixels = new int[ 800 * 600 ];
for ( int i = 0; i < still.getWidth( null ); i++ )
{
int nextPixel = ( still.getWidth( null ) + this.getX( ) ) - i;
PixelGrabber pg = new PixelGrabber( background, ph, nextPixel, 800, 600, pixels, 0, 800 );
try
{
pg.grabPixels( );
}
catch ( InterruptedException e )
{
System.err.println( "Image fetch aborted or error'd!" );
}
int c = pixels[ pw * 800 + ph ];
int red = ( c & 0x00ff0000 ) >> 16;
int green = ( c & 0x0000ff00 ) >> 8;
int blue = c & 0x000000ff;
//System.out.println( red + " | " + green + " | " + blue );
//System.out.println( pw + " : " + ph );
if ( red == 200 && green == 200 && blue == 200 )
{
y += 1;
}
}
}[/cpp]
And the values change depending on where you move, but wherever I call the function just causes the game to lag. How can I fix this terrible problem of lag everyone hates? :v:
[QUOTE='[ApS] Elf;23776226']Well I constructed the loop:
-snip-
And the values change depending on where you move, but wherever I call the function just causes the game to lag. How can I fix this terrible problem of lag everyone hates? :v:[/QUOTE]
The key is to not grab all the pixels, but only the ones needed:wink:
I was trying to grab the 13 or so under the player, but I guess that wasn't really necessary. I tried the code from the PixelGrabber API and it works perfectly now that I've modified it a bit :v: Now to return that there is a collision and stop the movement... :v:
Thanks for all your help!
[editline]12:32PM[/editline]
Turns out it doesn't work so perfectly; it seems to always equal 200, 200, 200.. yet when I put in a system.out.println() for the values they return 0, 0, 0 or some other weird number combinations instead - and the sprite doesn't move up.
[cpp] public void handlesinglepixel( int x, int y, int pixel )
{
//int alpha = ( pixel >> 24 ) & 0xff;
int red = ( pixel >> 16 ) & 0xff;
int green = ( pixel >> 8 ) & 0xff;
int blue = ( pixel ) & 0xff;
//System.out.println( red + " | " + green + " | " + blue );
if ( red == 200 && green == 200 && blue == 200 )
{
System.out.println( "MOVE UP DAMMIT" );
dy = -1;
}
}[/cpp]
If I uncomment that line the Sprite doesn't move up, the game lags heavily, and the console prints 0, 0, 0 or 111, 86, 53 (the colour of the dirt).
[editline]12:44PM[/editline]
Perhaps it may be much easier to just convert to a tile system and remake all the maps? Then again, the tile system would be hard to tile due to the varying sizes of everything...
Suite yourself, but I like to use pixel data:v:
I'd rather use pixel data too, tiles would be too hard, but this is just confusing me. How the hell does a System.out.println change the values of red, green and blue - and if it doesn't, how does the if statement think they are 200, 200, 200..?
[editline]02:22PM[/editline]
I found out why the statement was working and not outputting. It was just running faster without the printing (well duh printing 800 * 600 pixels constantly is going to get a bit haywire).
However, I replaced all the x and y values in the code for the PixelGrabber to 50, 50. This should mean that the pixel at 50, 50 is chosen and the colour of it outputted. But for some reason it's taking the pixel at 100, 100 instead. Any ideas? :raise:
[QUOTE=quincy18;23767464]Need some help with my perlin noise generator
[IMG]http://www.cubeupload.com/files/537721debug1.png[/IMG]
I followed some of the guidelines of this website :
[url]http://freespace.virgin.net/hugo.elias/models/m_perlin.htm[/url]
as you see the difference is very small and I have no idea on how to like zoom in. Anyone ?[/QUOTE]
Still no answer can anyone look at it ?
edit :
Map generating :
[cpp]
public float Noise1D(int x)
{
int octaves = Int32.Parse(octTextBox.Text);
float frequency = float.Parse(freqTextBox.Text);
float persistance = float.Parse(persTextBox.Text);
float total = 0;
frequency = float.Parse(freqTextBox.Text);
for (int i = 0; i < octaves; i++)
{
frequency = (float)Math.Pow(frequency, i); ;
float amplitude = (float)Math.Pow(persistance, i);
float xt = frequency * x;
float a = PerlinNoise.SmoothNoiseOne((int)xt);
float b = PerlinNoise.SmoothNoiseOne((int)xt + 1);
total += (PerlinNoise.CosineInterpolation(a, b, xt - (int)xt) * amplitude);
}
return total;
}
public void GenerateMap()
{
Bitmap map = new Bitmap(mainCanvas.Width, mainCanvas.Height);
int mapWidth = map.Width;
int mapHeight = map.Height;
int deltaHeight = map.Height / 2;
for (int x = 0; x < mapWidth; x++)
{
for (int y = 0; y < mapHeight; y++)
{
map.SetPixel(x, y, Color.Green);
}
}
for (int x = 0; x < mapWidth; x++)
{
map.SetPixel(x, (int)Math.Round(Noise1D(x)) + deltaHeight, Color.Black);
}
mainCanvas.Image = map;
}
[/cpp]
Perlin noise returns a float within [1..0], so you need to scale it by map.Height before rounding.
[editline]04:51PM[/editline]
Also, Simplex Noise.
I just started with SFML and want to know if I can draw a single pixel with some function?
-snip got it-
[QUOTE=sim642;23779744]I just started with SFML and want to know if I can draw a single pixel with some function?[/QUOTE]
I believe you need to create a sf::Image and then use SetPixel on it:
C++:
[cpp]
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
int main( )
{
sf::RenderWindow App( sf::VideoMode( 800, 600, 32 ), "pixel window" ); //create window
sf::Image image( 800, 600, sf::Color::Black ); //create image with same resolution as window, all black
image.SetPixel( 400, 300, sf::Color::Red ); //set pixel at 400,300 (in the centre of "image") to red
image.SetSmooth( false ); //turn off smoothing on image so it looks sharp
sf::Sprite sprite( image ); //make a sprite we can draw from the image
sf::Event Event;
while ( App.IsOpened( ) ) //main sfml loop
{
while ( App.GetEvent( Event ) )
{
if ( Event.Type == sf::Event::Closed )
App.Close( );
}
App.Draw( sprite ); //draw the sprite we made above, this function can't draw "image" directly
App.Display( );
}
return EXIT_SUCCESS;
}
[/cpp]
That's the only way I know how to do it.
It's hilarious to use high level classes to accomplish something really low level. I even looked at the docs of SFML and couldn't find a class for point or anything. I could draw a line from a point to the same point with thickness of 1, but that seems like overdoing it too.
That's because SFML is a high-level graphics library and setting individual pixels is more something for SDL.
You need to use downCol.equals( "200 | 200 | 200" ), else you are comparing references.
Ah, thanks.
[QUOTE=Inside;23772295]What do you mean? You want to expand the size of the array later, or do you want to edit the members of the array?
Also, what language?[/QUOTE]
C++, and I want to expand the array. At the start I declare the minimum amount of tiles (16 by 12) and then when I read the map, it might increase by one column or one row, so how would I expand it to do that?
Sorry, you need to Log In to post a reply to this thread.