• What do you need help with? Version 1
    5,001 replies, posted
In Java, I'm using a class named Wall to generate walls on a background of a 2D side scroller type game. I have another class that represents the player: but how do I check for collisions against all of the walls generated?
[QUOTE=Overv;23758343]Try putting GL.Vertex2 before GL.TexCoord2.[/QUOTE] Didn't help.
[QUOTE='[ApS] Elf;23760738']In Java, I'm using a class named Wall to generate walls on a background of a 2D side scroller type game. I have another class that represents the player: but how do I check for collisions against all of the walls generated?[/QUOTE] If you have an object.Intersects bool, loop through walls and see if there's an intersection.
[QUOTE='[ApS] Elf;23760738']In Java, I'm using a class named Wall to generate walls on a background of a 2D side scroller type game. I have another class that represents the player: but how do I check for collisions against all of the walls generated?[/QUOTE] [cpp] bool collison = false for each wall do { if (player left < wall right OR player right > wall left) AND (player up < wall down OR player down > wall up) { collision = true break } } [/cpp] /Fugly psuedo-code.
Okay, so I'm using java, and i want to connect to a mysql database that's being hosted locally, default ports, default user accounts etc. I looked at JBDC or what ever it's called, but all the documentation i could find is all abstract, like you have to already know what you're doing, no code examples etc. Could someone explain to me exactly how to download it, where to download it, how to install it, and basically how to use it? Thanks.
[QUOTE=ralle105;23761157][cpp] bool collison = false for each wall do { if (player left < wall right OR player right > wall left) AND (player up < wall down OR player down > wall up) { collision = true break } } [/cpp] /Fugly psuedo-code.[/QUOTE] Thanks for the help, but what does "Wall" return? The class looks like this: [cpp]public class Wall { int x, y; Image wall; Wall( String type, int xpos, int ypos ) { if ( type == "glass" ) { ImageIcon i = new ImageIcon( "D:/PW/Java/glassWall.png" ); wall = i.getImage( ); x = xpos; y = ypos; } } public int getX( ) { return x; } public int getY( ) { return y; } public Image getImage( ) { return wall; } }[/cpp] [editline]07:30PM[/editline] In fact I may not have described the game correctly. It's basically a 2D game that has a side-on view, but the background doesn't scroll, where you move the sprites.
[code] wall left = wall.x wall right = wall.x+imageWidth wall up = wall.y wall down = wall.y+imageHeight [/code] Same goes for player.
I put wall into the loop but it wanted me to create a new method rather than taking the class, any ideas? Thanks for your help so far!
[QUOTE='[ApS] Elf;23762587']I put wall into the loop but it wanted me to create a new method rather than taking the class, any ideas? Thanks for your help so far![/QUOTE] :raise:You should iterate through an array/list/whatever you use of all the walls.
[QUOTE=ralle105;23762824]:raise:You should iterate through an array/list/whatever you use of all the walls.[/QUOTE] It might be because of where I'm checking the colission, should I check it in Board (added to the JFrame), the Wall class or the Player class? In the player class it seems to say it isn't defined when using: [cpp]for ( Wall w : Wall() )[/cpp] or [cpp]for ( Wall w : Wall )[/cpp] Sorry about the hassle, I'm quite new to Java.
[QUOTE='[ApS] Elf;23763253']It might be because of where I'm checking the colission, should I check it in Board (added to the JFrame), the Wall class or the Player class? In the player class it seems to say it isn't defined when using: [cpp]for ( Wall w : Wall() )[/cpp] or [cpp]for ( Wall w : Wall )[/cpp] Sorry about the hassle, I'm quite new to Java.[/QUOTE] [cpp]for ( Wall w : WhateverArrayYouHaveTheWallsStoredIn )[/cpp]
-snip- I got it, thanks for your help!
[QUOTE=iNova;23761129]If you have an object.Intersects bool, loop through walls and see if there's an intersection.[/QUOTE] Inefficiency :v: No point checking walls that the player is not near, or heading towards
Well I sure lied, I didn't get it. [cpp]ArrayList Wall; Wall[] wallList = new Wall[9]; wallList[0] = new Wall( "glass", 100, 172 ); wallList[1] = new Wall( "glass", 100, 182 ); wallList[2] = new Wall( "glass", 100, 192 ); wallList[3] = new Wall( "glass", 100, 202 ); wallList[4] = new Wall( "glass", 100, 212 ); wallList[5] = new Wall( "glass", 100, 222 ); wallList[6] = new Wall( "glass", 100, 232 ); wallList[7] = new Wall( "glass", 100, 242 ); wallList[8] = new Wall( "glass", 100, 252 ); wallList[9] = new Wall( "glass", 100, 262 );[/cpp] I used this to create the wall list array, and then put this in a for loop: [cpp]for ( Object obj : Wall ) { g2d.drawImage( obj.wall, obj.x, obj.y ); }[/cpp] But if I try the above or the functions such as getX( ), it just comes up with the error "cannot be resolved or is not a field" for wall, x and y (or when using the getX( ) etc functions "the method is undefined for the type Object"). Any ideas?
[cpp] for (int i=0;i<9;i++) { Wall wall = wallList[i]; //Do checks } [/cpp] ?
"wallList cannot be resolved to a variable" and if I declare array wallList; at the start of the class it says: "array cannot be resolved to a type"
[QUOTE='[ApS] Elf;23764555']"wallList cannot be resolved to a variable" and if I declare array wallList; at the start of the class it says: "array cannot be resolved to a type"[/QUOTE] It's pseudo-code. You need to learn what a type is.
[cpp]java.util.AbstractCollection<Wall> wallVector = new java.util.ArrayList( 10 ); for( int i = 0; i < 10; ++i ) wallVector.add( new Wall( "glass", 100, 172 + i * 10 ) ); //... for( Wall obj : wallVector ) { //obj.stuff(); }[/cpp]
[QUOTE=turb_;23755692]But I don't know the content length, and what if the boundary ends up split between chunks?[/QUOTE] /facedesk Content-Length: [b]100876[/b] Content-Type: multipart/form-data; boundary=[b]----WebKitFormBoundary9S0IBLc1TGixx3Al[/b]
[QUOTE=ZeekyHBomb;23764632][cpp]java.util.AbstractCollection<Wall> wallVector = new java.util.ArrayList( 10 ); for( int i = 0; i < 10; ++i ) wallVector.add( new Wall( "glass", 100, 172 + i * 10 ) ); //... for( Wall obj : wallVector ) { //obj.stuff(); }[/cpp][/QUOTE] Thanks, that works perfectly for the image drawing. Should I run the for loop in player class or in the board class to check for collisions?
[QUOTE=ZeekyHBomb;23756667]In SFML you can simply use the Intersects-function.[/QUOTE] How exactly do you use that function? I'm not sure how to create a sf::Rect, I get errors when I try: [cpp]sf::Rect my_rect(x, y, width, height);[/cpp]
I'm currently toying with löve, and I'm trying out advanced math with circles for the first time. Basically I've got a circle. I know the origin X and Y, and the radius. I need to know the X and Y location of points on the circle, for every 30th degree. I made a drawing while trying to get help from my friends. [URL]http://img205.imageshack.us/img205/9896/27341089.png[/URL] (ignore the inner circle for now) I'll need to know the coordinates of the intersections.(At the drawing they're only every 45th degree, just to simplify) Any help on this will be greatly appreciated.
[QUOTE=FerrisWheel;23765411]How exactly do you use that function? I'm not sure how to create a sf::Rect, I get errors when I try: [cpp]sf::Rect my_rect(x, y, width, height);[/cpp][/QUOTE] You have to do [cpp] sf::Rect<int/float/double/whatever> my_rect(x, y, width, height); [/cpp]
[QUOTE=Warsheep;23765544]I'm currently toying with löve, and I'm trying out advanced math with circles for the first time. Basically I've got a circle. I know the origin X and Y, and the radius. I need to know the X and Y location of points on the circle, for every 30th degree. I made a drawing while trying to get help from my friends. [URL]http://img205.imageshack.us/img205/9896/27341089.png[/URL] (ignore the inner circle for now) I'll need to know the coordinates of the intersections.(At the drawing they're only every 45th degree, just to simplify) Any help on this will be greatly appreciated.[/QUOTE] Construct a triangle like so: [IMG]http://mathworld.wolfram.com/images/eps-gif/Trigonometry_1001.gif[/IMG] Once you've worked out the length of the adjacent and opposite sides (radius*cos(angle) and radius*sin(angle)), add them to your origin to get the position of your point on the circle.
[QUOTE=bean_xp;23766061]Construct a triangle like so: Once you've worked out the length of the adjacent and opposite sides, add them to your origin to get the position of your point on the circle.[/QUOTE] I'm completely new to this level of math, no idea what cos and sin really is. I guess I'll read up on that before I continue. Any recommended places to read? I've quickly realised that it's a nightmare to search for things if you're not exactly sure what you're looking for. Thanks for the help though, now I've got some idea what I need to do. edit: Oh, I see you edited your post a bit, makes a lot more sense now. Thanks!
[QUOTE=Warsheep;23766174]I'm completely new to this level of math, no idea what cos and sin really is. I guess I'll read up on that before I continue. Any recommended places to read? I've quickly realised that it's a nightmare to search for things if you're not exactly sure what you're looking for.[/QUOTE] Sin and Cos are trigonometric functions, if you're completely new to them then searching for an introduction to trigonometry should help. I'm fairly sure you will be taught this in school at some point so you could ask your teacher. Otherwise any introduction to trigonometry should explain their usage, [url=http://www.youtube.com/watch?v=F21S9Wpi0y8]this video[/url] should help.
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 ?
If I need to access an interface in my entire program, is it justified to use globals? And if so, why is it better to use a GetInterface() instead of g_Interface? The problem is that I can't really not use globals, because it's impossible to pass them to a C++ function called by Lua.
I'm trying to create a 2D game version of what is known as Pixel Wars on the forum. However I'm completely unsure how to go about the concept. Most 2D games use a scrolling background and a tile system, but I'm not sure how that'd work for maps like this: [IMG]http://ooft.net/upload/14834o.png[/IMG] Yet using a full map like that would surely use too much memory? Any ideas how I'd go about creating these maps and what methods to use?
Make use of the image's pixels instead of tiles.
Sorry, you need to Log In to post a reply to this thread.