Jesperklippel

Member

13

142 Neutral

• Rank
Member
1. Tilemap collision

3pic_F4il_FTW came with a solution! Thanks! :D - Jesper
2. Tilemap collision

I've tried that too.. I've tried everything. I'm desperate... What is a game without collision? The interview I have is tomorrow..... :( I hope that it wouldn't come to this, but here is the project: https://drive.google.com/file/d/0BySRvoxEoAtlTm8wMVVsN3B3TFU/view?usp=sharing   I'd appreciate it sooo much if you would take a look, or try anything, because I don't know what to do anymore.. Thank you so much! - Jesper
3. Tilemap collision

for(int i = 0; i < HEIGHT; i++) { for(int j = 0; j < WIDTH; j++) { if(level1.level[i][j] == 1) { //Bottom, top, left and right position of the tile. int bottom, top, left, right; bottom = i*32 + 32; top = i*32; left = j*32; right = j*32 + 32; if(player.right < left || player.left > right || player.top > bottom || player.bottom < top) { } else { std::cout << "Collision!"; } } Okay so I got this working. It's outputting Collision at the right times! Now, how should I stop the player from moving? This is also something that I don't really get. Should I set the position, set the move speed to 0?   - Jesper
4. Tilemap collision

//MOVEMENT CODE if(upPressed) { velocity.x = 0; velocity.y = upSpeed; player.setRotation(90); } else if(downPressed) { velocity.x = 0; velocity.y = downSpeed; player.setRotation(270); } else velocity.y = 0; if(rightPressed) { velocity.y = 0; velocity.x = rightSpeed; player.setRotation(180); } else if(leftPressed) { velocity.y = 0; velocity.x = leftSpeed; player.setRotation(0); } else velocity.x = 0; player.move(velocity.x, velocity.y); //COLLISION CODE for(int i = 0; i < HEIGHT; i++) { for(int j = 0; j < WIDTH; j++) { if(level1.level[i][j] == 1) { //Bottom, top, left and right position of the tile. int bottom, top, left, right; bottom = i*32 + 32; top = i*32; left = j*32; right = j*32 + 32; if(player.right > left && player.right > left - 32) { player.player.setPosition(left-32, player.player.getPosition().y); } else if(player.left < right && player.left < right + 32) { player.player.setPosition(right + 1, player.player.getPosition().y); } else if(player.top < bottom && player.top < bottom + 32) { player.player.setPosition(player.player.getPosition().x, bottom + 1); } else if(player.bottom > top && player.bottom > top - 32) { player.player.setPosition(player.player.getPosition().x, top-32); } } This the the movement code and the collision code. Right now my character is just glitching and constantly changing position. I can't move, it just glitches!   Thanks again..
5. Tilemap collision

I just can't get it working... I really wanna get it done today so I can finish some other stuff up tomorrow, because like I said it needs to be done before next tuesday. I feel I've tried everything, maybe some psuedo, or actual code would help me clear things up! I'm desperate! :(   Thank you so much for your help and patience!   - Jesper
6. Tilemap collision

Thanks dude! I'm definately gonna try this out, because the game I am making is an assigment for a study I want to do, and the interview is next tuesday. So I hate wasting time on this kind of stuff. I don't understand it because I've done collision and stuff before, and I'm not a noob.. just a beginner ;) But well, I'll try this out and I'll let you know! :)   - Jesper
7. Tilemap collision

So I should only check for collision at the four corners of the player sprite?
8. Tilemap collision

Hello everybody!   I've got a bit of a problem with my tilemap collision. I've been working on this the whole afternoon, so I'm not lazy and just asking you guys.. ;) I am programming in C++, with SFML library.   Here is my main.cpp http://pastebin.com/eAUKHLRb And here is my player.cpp http://pastebin.com/kixD2MFX   At the bottom of the main.cpp you can see my collision code. The player position is getting updated every frame and is correct, also the positions of the tiles are correct. But when I compare those, to check for collision its just not working, and I'm getting tired of the fact that I spend alot of hours looking for a solution, and not finding one. So in the meanwhile when I look for more solutions, I wanted to ask you guys!   If you see any other things that shouldn't be, please also tell me! I am a beginner ;)    Thanks,   Jesper Klippel
9. Need some help...

That is called pixel perfect collision detection (iirc) but if you want that implementation, you have to check each player's pixel to the rest of the nearby pixels. This isn't really useful in platformers and is mostly used in 2D fighting games.   However there is a bit of a hacky solution to your problem. If you make sure your "playerY" is positioned at player's feet rather than the center, this implementation will work. Your player's head will not collide with roofs and things like that with this kind of implementation though, it works mostly like mario and sonic games.   [   If your "playerY" is in center, just check backgroundTexture.getPixel(PlayerX, PlayerY-(playerHeight/2))   ] I'm not sure if you have playerHeight or not, if you don't define it.   This also depends a lot on how your camera works. In my platformer game, the camera wouldn't always be centered on player, so one would have to make adjustments if that was the case. I'm not entirely sure how to help you code-wise because Im not sure if backgroundTexture is returning X and Y in regards to display or original image file.     Hmm, okay. I'm probably gonna try the tile map method because like you said, the iirc method comes with some problems..   - Jesper
10. Need some help...

Well... Thanks already for all your helpful replies! I really appreciate them! I edited my first post by the way, with some extra information. So I think I've figured out a way for the collision, since for the assignment graphics are irrelevant. I could make a level in photoshop, with white background and black objects. Then in the code I can store the top, right, bottom and left of the player in variables. Then I can compare those positions to i.e backgroundTexture.getPixel(PlayerX, PlayerY), which gets the current color of the pixel. If the pixel is black, the player is colliding with an object, if it's white it's not. I hope you get my idea. Will this work?   - Jesper
11. Need some help...

That's indeed what I tried to do. I've made pong, and some other small things. But now for the study assignment it needs to be a little bigger, classes etc.  Classes aren't the problem, the main problem I run into is the tilemap with collision. The tilemap is working, the textures are being drawn, but I don't have a clue about collision.   I've heard some people say that learning from youtube video's or something is bad, because you might learn some bad habits, so that's why I came here!   - Jesper
12. Need some help...

Hello eveybody, I'm new on this forum! So let me explain my situation here. I am 16 years old and I love programming, and I have been programming for over 5 years now. Now after my exams, I want to get into a game programming study. But that study requires that you already have a simple 2d game made, so I can show them my current skills. But I'm just getting stuck over and over again... So I need some (experienced) advice from someone! Like I said, complicated stuff I will learn in the study, now I just need to make a simple game with the theme "Jelly", so I was thinking a 2D platformer. Now I'm having trouble with loading maps and using collision with maps. I've tried it with .txt files and 1's and 0's, but haven't been quite succesful. I just can't seem to get it going alright.. I am programming in C++ with preferably SFML. If you''ve got some tips, please don't hesitate to respond! Thanks! Also, my skype is jesper_klip, if you want an one on one conversation!   Jesper Klippel
13. Game idea based around the theme "Jelly"

Hello,   First of all, I'm new to this forum. Hi everybody :)   So, I am 16 years old and my goal is to go to a Game Development school next year. I admissed, but you aren't automatically in. You get chosen. To go to the interview day I need to finish an assigment. It's nothing hard. Just a 2D single player game. But they theme of the game has to be Jelly. And for some reason I just can't think of any fun and original game ideas. I thought to post a message on this forum while I'm brainstorming, and maybe some of you could help me out.   Thanks!   - Jesper Klippel