Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Using a Text file for collision help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Robotkubo




PostPosted: Fri Apr 08, 2016 8:45 am   Post subject: Using a Text file for collision help

So I've seen in a few games people using a txt file for their walls and floors and such. filling it with stuff like
0000000000
1110000000
1110000000
1100000000
1111000000
1111111110
1111111110


How does this work? any tutorials on it? My game is due Friday and I need to make it so my character can jump on boxes to move around the screen, please help
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Fri Apr 08, 2016 10:54 am   Post subject: Re: Using a Text file for collision help

The idea is that if your game uses a grid for the map or game area, then every square of the grid can be represented by one entry of an array. This array can get quite large and writing all of its contents into your program directly is ugly, inefficient and difficult to modify or extend (what if you suddenly want multiple maps). To solve this problem, people write the contents of the array to a text file, using different characters for different values that each entry of the array may have. When your program loads, it can then read the file and populate the array with the correct data.
Robotkubo




PostPosted: Tue Apr 12, 2016 9:18 am   Post subject: RE:Using a Text file for collision help

Can anyone even help me?
Zren




PostPosted: Tue Apr 12, 2016 8:39 pm   Post subject: RE:Using a Text file for collision help

It sound's like you're trying to make a 2d platformer game. Which is usually is done with rectangular collision detection, but you can also do the collision detection with whatdotcolor and a picture in a similar manner that dreadnought spoke of. In this case, instead of a text document to store the 2d array, you're using the grid of pixels in the picture.

Here's some homework for getting it completed. Also be sure to read parts of The Turing Walkthrough.

1. Draw a rectangle based on 2 variables called playerX, playerY.
2. You'll need to learn how to do a game loop by putting the draw command inside a loop, and incrementing the playerX variable to move the rectangle right. Be sure to clear the screen before drawing to erase the previous "frame" and set a delay with Time.DelaySinceLast(1000 div 60) after drawing limit the game to 60FPS.
3. Learn how to move the rectangle (the player) by learning how to capture input from the keyboard with Input.KeyDown(). Check the Turing Walkthrough.
4. Draw a rectangle along the bottom of the screen in a certain color to act as the ground.
5. To do collision detection so your player doesn't move through the ground/platforms, you'll need to draw the background first after clearing the screen. Then when you do the movement logic for the player, instead of doing playerX += 1 to move right, assign the destination like playerDestinationX = playerX + 1 and use whatdotcolor(playerDestinationX, playerDestinationY) to check if the pixel in the background the player is "walking" into is the same color as the ground/platform. If so, do not move to the destination.
6. Add gravity (playerY -= 1) and use the same collision detection so you don't move into the ground.
7. Use acceleration to move and for gravity.
8. To jump, set a large positive y acceleration when you hit space. The negative gravity acceleration will brind you back down.
9. You'll need to learn how to draw pictures. First draw a picture for you're player instead of the rectangle.
10. Then draw a picture for you're background. Make sure the ground and platforms are the same color as the one you previously used for the ground.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: