Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By SurfMan

Thread: What I noticed about successful Games

  1. #1
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default What I noticed about successful Games

    I noticed it is a huge success to have the backgrounds of games move and the character just move up and down and dodge obstacles. I would love to do that. How Do I make a background that scrolls horizontally to the left? I know how to keep the character in place with up and down to move, but not sure how to go about making the background move with obstacles. Perfect example: Flappy Bird

    Thanks

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: What I noticed about successful Games

    What have you tried?

    It's not exactly rocket surgery- start with a rectangle that moves up and down based on the arrow keys (like a pong paddle). Then add shapes that come in from the right side and go to the left. There isn't one "correct" way to do this, so you'll have to experiment a little to figure out a way that makes sense to you.

    There are tutorials on this type of thing in the Static Void Games link in my signature if you want to check them out.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: What I noticed about successful Games

    Quote Originally Posted by KevinWorkman View Post
    rocket surgery
    I believe the expression is rocket science. Back to the question, you would need a seamless image, so when you scroll, you can repeat the image over and over and it seems like it never stops. But since you're talking about flappy bird, the tubes are not part of the background, the game has two background images, one that stays still (far in the distance) and the ground that moves. The tubes are added over top of the still background and they just move to the left. Not too hard, they would just be objects with an x, y, and height variable.
    1000011 1100001 1101110 100000 1111001 1101111 1110101 100000 1110010 1100101 1100001 1100100 100000 1000010 1101001 1101110 1100001 1110010 1111001 111111

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: What I noticed about successful Games

    Quote Originally Posted by zFollette View Post
    I believe the expression is rocket science.
    There are two sayings: "this isn't rocket science" and "this isn't brain surgery". I combined them for maximum hilarity. Laugh, you pedant!

    Main/This Ain't Rocket Surgery - Television Tropes & Idioms
    Urban Dictionary: rocket surgery
    https://www.google.com/search?q=rocket+surgery


    Quote Originally Posted by zFollette View Post
    Back to the question, you would need a seamless image, so when you scroll, you can repeat the image over and over and it seems like it never stops. But since you're talking about flappy bird, the tubes are not part of the background, the game has two background images, one that stays still (far in the distance) and the ground that moves. The tubes are added over top of the still background and they just move to the left. Not too hard, they would just be objects with an x, y, and height variable.
    I have an open-source example of this here: The Briny Depths by Kevin - Static Void Games
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: What I noticed about successful Games

    Quote Originally Posted by KevinWorkman View Post
    There are two sayings: "this isn't rocket science" and "this isn't brain surgery". I combined them for maximum hilarity. Laugh, you pedant!
    Stolen! http://www.amazon.co.uk/Rocket-Surge...178294&sr=8-1&

    Awesome book by the way.
    KevinWorkman likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  6. #6
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: What I noticed about successful Games

    Question: I fixed this issue, and I do not want to start another thread to waste thread space. Can someone tell me why my game is going crazy with the ball...? It is a pong game with one player vs AI. The ball is just moving crazily. Does anyone know a fix? Thanks


    Main Class:
    Java Code:
    import javax.swing.*;
    public class Main {
    
    	public Main(){
    		JFrame frame = new JFrame("Table Hockey");
    		frame.setSize(500,500);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		Pong pong = new Pong();
    		frame.add(pong);
    		MyListener listener = new MyListener(pong);
    		Timer timer = new Timer(10,listener);
    		frame.addKeyListener(pong.k);
    		timer.start();
    		frame.repaint();
    		frame.setVisible(true);
    		
    	}
    	public static void main(String[] args) {
        new Main();
    	}
    
    }
    My listener class
    Java Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    
    public class MyListener implements ActionListener {
    private Pong pong;
    	
    	public MyListener(Pong pong){
    		this.pong = pong;
    	}
    
    	@Override
    	public void actionPerformed(ActionEvent e) {
         pong.MoveBall();		
    	}
    
    }
    Pong Class
    Java Code:
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class Pong extends JComponent{
    int pongX=200;
    int pongY=200;
    int pongXspeed = 3;
    int pongYspeed = 3;
    int pongDiameter = 60;
    int SliderOneX = 5;
    int SliderOneY = 200;
    int SliderTwoX = 465;
    int SliderTwoY = 200;
    int p1points;
    int p2points;
    private BufferedImage image;
    private BufferedImage pongball;
    
    public Pong(){
    	try{
    		image = ImageIO.read(new File(
    				"/Users/MW/Downloads/formatter.jpg"));
    		pongball = ImageIO.read(new File(
    				"/Users/MW/Downloads/pongball.png"));
    	}catch(Exception e){System.out.print("Could not load image");}
    }
    	public void paintComponent(Graphics g){
    		super.paintComponent(g);
    		g.setColor(Color.black);
    		g.drawImage(image,0,0,null);
    		g.drawString("Copyright MW",50,450);
    		g.setColor(Color.white);
    		g.drawString("Player 1 Score: "+p1points, 50, 20);
    		g.drawString("Player 2 Score: "+p2points, 350, 20);
    		g.setColor(Color.black);
    		g.drawImage(pongball, pongX, pongY, null);
    		g.setColor(Color.blue);
    		g.fillRect(SliderOneX, SliderOneY, 30, 120);
    		g.fillRect(SliderTwoX, SliderTwoY, 30, 120);
    		
    	}
    public void MoveBall(){
    	pongX += pongXspeed;
    	if(pongX>=SliderOneX-30  && pongY>=SliderOneY-80 && pongY<=SliderOneY+120){
    		pongXspeed *= -1;
    	}
    	if(pongX+150==SliderTwoX && pongY>=SliderTwoY-80 && pongY<=SliderTwoY+120){
    		pongXspeed *= -1;
    	}
    	pongY += pongYspeed;
    	if(pongY > getHeight()-pongDiameter || pongY < 0){
    		pongYspeed *= -1;
    	}
    	if(pongX>500){
    		pongX = 200;
    		pongY = 200;
    		p1points++;
    	}
    	if(pongX<-30){
    		pongX = 200;
    		pongY = 200;
    		p2points++;
    	}
    	if(SliderOneY<=-15){
    		SliderOneY=SliderOneY+15;
    	}
    	if(SliderOneY>360){
    		SliderOneY=SliderOneY-15;
    	}
    	if(SliderTwoY <=-15){
    		SliderTwoY=SliderTwoY+15;
    	}
    	if(SliderTwoY>360){
    		SliderTwoY=SliderTwoY-15;
    	}
    	if(pongY>SliderTwoY){
    	SliderTwoY=SliderTwoY+10;	
    	repaint();
    	}
    	if(pongY<SliderTwoY){
    		SliderTwoY=SliderTwoY-10;
    	}
    	repaint();
    }
    KeyListener k = new KeyListener(){
    @Override
    public void keyTyped(KeyEvent e) {	
    }
    @Override
    public void keyPressed(KeyEvent e) {
    	int k = e.getKeyCode();
    	if (k == KeyEvent.VK_UP) {
    		SliderOneY -= 15;
    	}
    	if (k == KeyEvent.VK_DOWN){
    		SliderOneY += 15;
    	}
    	repaint();
    }
    @Override
    public void keyReleased(KeyEvent e) {
    	// TODO Auto-generated method stub
    }
    };
    }
    Last edited by MW130; 01-31-2014 at 03:39 PM.

  7. #7
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: What I noticed about successful Games

    What do you mean by "moving crazy"? Can you post an SSCCE instead of your whole program? What happened when you stepped through your program with a debugger, or simply added print statements, or better yet stepped through it with a piece of paper and a pencil?

    Judging from the type of questions you keep asking, I highly suggest you learn how to properly debug your code. It's going to take you forever to get anything done if you come to a forum every time something strange happens.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: What I noticed about successful Games

    Never mind, got it fixed; was totally confusing two variables. Thanks for the reply though

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: What I noticed about successful Games

    Quote Originally Posted by MW130 View Post
    Never mind, got it fixed; was totally confusing two variables. Thanks for the reply though
    And that's my point: it's awesome that you're trying to learn, and I think creating a Pong game is a perfect way to do that. But one of the most important things you need to learn is how to debug your code. You should add print statements or step through your code with a debugger or even just a piece of paper and a pencil before you think about posting to a forum. And when you do post to a forum, you should isolate the problem as much as possible instead of posting your entire program. Nine times out of ten, you figure out what the problem is during the process of isolating the problem!
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    165
    Rep Power
    2

    Default Re: What I noticed about successful Games

    You could just have offset variables and add or subtract to them. Then have the offset variables added to the map objects you have. So, when you change the xOffset and yOffset, the position of all of your objects will change accordingly.

Similar Threads

  1. JTable update only partially successful
    By assel in forum AWT / Swing
    Replies: 0
    Last Post: 12-02-2010, 11:37 PM
  2. specert-successful pass any it exams
    By specert in forum Reviews / Advertising
    Replies: 0
    Last Post: 07-11-2009, 09:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •