Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Making Slopes for a Platformer Game

  1. #1
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Making Slopes for a Platformer Game

    Hi, I'm having trouble making slopes for a 2D platformer game in Java. How would I go about making them? Do I just subtract 1 pixel from y for every x pixel moved (and tweak it for other angles) or what, cause I haven't been able to find any tutorials on YouTube.
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Making Slopes for a Platformer Game

    Depends on how you are creating graphics. The Graphics class has a drawLine method.
    Improving the world one idiot at a time!

  3. #3
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Making Slopes for a Platformer Game

    I'm using an object based system heavily inspired by the tile based systems of retro platformers, is there a way to make an objects collision size a triangle instead of only squares like I'm doing now?
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Making Slopes for a Platformer Game

    is there a way to make an objects collision size a triangle instead of only squares
    Sure there is. Any class that (correctly) implements the interface Shape, (like the Polygon class), could be used to detect collisions. Pretty much any shape you can draw.

  5. #5
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Making Slopes for a Platformer Game

    Well, I'm still having trouble with this, so I thought I would bump this thread instead of making a new one. Here's the code I'm using:

    In the method that checks if the character is colliding with the floor
    	if (Frame.dir>=0){
    						tiley=Level.tile.get(f).y;
    						isTouchingFloor=true;
    						y=slopetemp;
    						return false;
    						}
    						if (Frame.dir<0){
    							//y=slopetemp;
    							return false;
    							}
    						if (Frame.dir==0){
    							//y=slopetemp;
    							return true;
    							}

    and the one for walls
    if (Frame.dir>0){
    					slopex=Level.tile.get(g).x;
    					System.out.println(slopex);
    					//slopey=y;
    					System.out.println(x+16);
    					slopetemp=y-(x+16-slopex);
    					//System.out.println(slopetemp);
    					y=slopetemp;
    					return false;
    					}
    					if (Frame.dir<0){
    						slopex=Level.tile.get(g).x;
    						//slopey=y;
    						//x-=Frame.dir;
    						//slopetemp=y+(x-slopex);
    						System.out.println(slopetemp);
    						//y+=Frame.dir;
    						return false;
    						}
    					if (Frame.dir==0){
     
    					}
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)

Similar Threads

  1. Making Game, Need 1-3 People That Know JAVA
    By Stilez in forum Paid Java Projects
    Replies: 2
    Last Post: August 27th, 2012, 02:51 PM
  2. help making war card game
    By thephipster in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 25th, 2012, 01:39 PM
  3. Making a Craps game.
    By SOK in forum Object Oriented Programming
    Replies: 1
    Last Post: March 6th, 2010, 08:23 PM
  4. Theory behind 2d Game making?
    By DarrenReeder in forum Java Theory & Questions
    Replies: 3
    Last Post: January 28th, 2010, 02:54 AM
  5. [SOLVED] How to start writing java mobile application?
    By Koâk in forum Java ME (Mobile Edition)
    Replies: 15
    Last Post: July 30th, 2009, 01:52 AM