This site requires JavaScript, please enable it in your browser!
Greenfoot back
zerhot
zerhot wrote ...

2013/11/6

i need help on my pong game

zerhot zerhot

2013/11/6

#
this is my pongworld but i have to get it in to classes but it's not working. Not everything must be in a subclass but as many as possible. how do i do that? import greenfoot.Greenfoot; import greenfoot.GreenfootImage; import greenfoot.World; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; /** * @author Coen & Kaj * @version 1.0 */ public class PongWorld extends World { /**Buttons*/ private static final int pointA = { 350, 175, 470, 235 }, pointB = { 550, 175, 670, 235 }; /**De midi muziek speler*/ private static final MidiPlayer midi = new MidiPlayer(); /**De achtergrond*/ private static final GreenfootImage BG = new GreenfootImage(1000, 500); /** * Teken de achtergrond. */ static { BG.setColor(Color.BLACK); BG.fill(); BG.setColor(Color.WHITE); BG.drawRect(490, 0, 510, 500); BG.setColor(Color.WHITE); BG.drawRect(0, 0, 999, 499); BG.drawRect(1, 1, 997, 497); BG.drawRect(2, 2, 995, 495); } /**Menu achtergrond*/ private static final GreenfootImage MENU = new GreenfootImage(1000, 500); /** * Teken het menu. */ static { MENU.setColor(Color.BLACK); MENU.fill(); MENU.setColor(Color.DARK_GRAY); MENU.drawRect(350, 175, 120, 40); MENU.drawRect(550, 175, 120, 40); MENU.setColor(Color.LIGHT_GRAY); MENU.setFont(new Font(null, Font.BOLD, 24)); MENU.drawString("1-Speler", 360, 200); MENU.drawString("2-Speler", 560, 200); } /**De puntentelling*/ private int score = new int; /**De positie van de muis.*/ private int mx, my; /**De menu boolean*/ private boolean menu = true; /**Moeilijkheidsgraad en de muziek volume*/ static int dif = 1, ins = 8; /** * De wereld. */ public PongWorld() { super(1000, 500, 1); Greenfoot.setSpeed(70); setBackground(MENU); addObject(new Button("Difficulty: ", 0), 500, 300); addObject(new Button(" Music: ", 1), 500, 350); } public void act() { if(score>= 10|| score>= 10) endGame(); if(!menu) return; if(clickedAt(pointA)) newGame(true); if(clickedAt(pointB)) newGame(false); } private void updateImage() { GreenfootImage bg = getBackground(); bg.drawImage(BG, 0, 0); bg.drawString("SPELER 1 "+ score, 250, 32); bg.drawString("SPELER 2 "+ score, 500, 32); } /** * Puntentelling. */ public void scoreUp(int player) { score++; updateImage(); removeObjects(getObjects(Ball.class)); addObject(new Ball(), 200, 120); greenfoot.Greenfoot.delay(32); if (score == 1) { if (Greenfoot.getRandomNumber(100)<60) { addObject(new PowerUp(40, 40, Color.RED), Greenfoot.getRandomNumber(200)+400, Greenfoot.getRandomNumber(200)+100); } } if (score == 4) { if (Greenfoot.getRandomNumber(100)<60) { addObject(new PowerUp(40, 40, Color.RED), Greenfoot.getRandomNumber(200)+400, Greenfoot.getRandomNumber(200)+100); } } if (score == 7) { if (Greenfoot.getRandomNumber(100)<60) { addObject(new PowerUp(40, 40, Color.RED), Greenfoot.getRandomNumber(200)+400, Greenfoot.getRandomNumber(200)+100); } } if (score == 8) { if (Greenfoot.getRandomNumber(100)<60) { addObject(new PowerUp(40, 40, Color.RED), Greenfoot.getRandomNumber(200)+400, Greenfoot.getRandomNumber(200)+100); } } if (score == 1) { if (Greenfoot.getRandomNumber(100)<60) { addObject(new PowerUp(40, 40, Color.RED), Greenfoot.getRandomNumber(200)+400, Greenfoot.getRandomNumber(200)+100); } } if (score == 4) { if (Greenfoot.getRandomNumber(100)<60) { addObject(new PowerUp(40, 40, Color.RED), Greenfoot.getRandomNumber(200)+400, Greenfoot.getRandomNumber(200)+100); } } if (score == 7) { if (Greenfoot.getRandomNumber(100)<60) { addObject(new PowerUp(40, 40, Color.RED), Greenfoot.getRandomNumber(200)+400, Greenfoot.getRandomNumber(200)+100); } } if (score == 8) { if (Greenfoot.getRandomNumber(100)<60) { addObject(new PowerUp(40, 40, Color.RED), Greenfoot.getRandomNumber(200)+400, Greenfoot.getRandomNumber(200)+100); } } } /** * Hoe een nieuw spel gestart word */ private void newGame(boolean cpu) { removeObjects(getObjects(null)); menu = false; setBackground(new GreenfootImage(1000, 500)); getBackground().setColor(Color.LIGHT_GRAY); getBackground().setFont(new Font(null, Font.BOLD, 24)); if(cpu) { addObject(new Player(new String {"up", "down"}), 50, 250); addObject(new Computer(), 950, 250); } else { addObject(new Player(new String {"up", "down"}), 50, 250); addObject(new Player(new String {"w", "s"}), 950, 250); } addObject(new Ball(), 500, 250); updateImage(); greenfoot.Greenfoot.delay(32); } /** * De GAME OVER. */ private void endGame() { removeObjects(getObjects(null)); GreenfootImage bg = getBackground(); bg.setColor(Color.BLACK); bg.fill(); bg.setColor(Color.LIGHT_GRAY); bg.setFont(new Font(null, Font.BOLD, 48)); bg.drawString("GAME OVER", 400, 250); } /** * De radius van de muis en/of hij klikt. */ private boolean clickedAt(int location) { if(Greenfoot.getMouseInfo()!= null) { mx = Greenfoot.getMouseInfo().getX(); my = Greenfoot.getMouseInfo().getY(); } return Greenfoot.mousePressed(this) && mx > location && mx < location && my > location && my < location; } /** * Een geluidje. */ public static void play(int pitch) { midi.play(pitch, 10); } /** * De moeilijksheids graad omhoog. */ public static void difUp() { dif++; } /** * De moeilijksheids graad omlaag. */ public static void difDown() { dif--; } /** * Geluid omhoog. */ public static void insUp() { ins++; midi.setChannel(ins); } /** * Geluid omlaag. */ public static void insDown() { ins--; midi.setChannel(ins); } } that is my pongworld code
zerhot zerhot

2013/11/6

#
there are some dutch words in it, don't bother them
PentValleyIsGay PentValleyIsGay

2013/11/6

#
i shall help u brother brother just shout my name and i shall reply
zerhot zerhot

2013/11/10

#
PentValleyIsGay please help me brother
You need to login to post a reply.