Skip to content
Snippets Groups Projects
Commit a46c1104 authored by Vesa Lappalainen's avatar Vesa Lappalainen :bicyclist:
Browse files

pong private

parent 9b4a6a61
No related branches found
No related tags found
No related merge requests found
using System; using System;
using System.Collections.Generic;
using Jypeli; using Jypeli;
using Jypeli.Assets;
using Jypeli.Controls;
using Jypeli.Widgets;
namespace Pong; namespace Pong;
public class Pong : PhysicsGame public class Pong : PhysicsGame
{ {
Vector nopeusYlos = new Vector(0, 200); private readonly Vector nopeusYlos = new Vector(0, 200);
Vector nopeusAlas = new Vector(0, -200); private readonly Vector nopeusAlas = new Vector(0, -200);
PhysicsObject pallo; private PhysicsObject pallo;
PhysicsObject maila1; private PhysicsObject maila1;
PhysicsObject maila2; private PhysicsObject maila2;
PhysicsObject vasenReuna; private PhysicsObject vasenReuna;
PhysicsObject oikeaReuna; private PhysicsObject oikeaReuna;
IntMeter pelaajan1Pisteet; private IntMeter pelaajan1Pisteet;
IntMeter pelaajan2Pisteet; private IntMeter pelaajan2Pisteet;
public override void Begin() public override void Begin()
{ {
LuoKentta(); LuoKentta();
...@@ -30,7 +27,8 @@ public class Pong : PhysicsGame ...@@ -30,7 +27,8 @@ public class Pong : PhysicsGame
AloitaPeli(); AloitaPeli();
} }
void LuoKentta()
private void LuoKentta()
{ {
pallo = new PhysicsObject(40.0, 40.0); pallo = new PhysicsObject(40.0, 40.0);
pallo.Shape = Shape.Circle; pallo.Shape = Shape.Circle;
...@@ -70,7 +68,8 @@ public class Pong : PhysicsGame ...@@ -70,7 +68,8 @@ public class Pong : PhysicsGame
Camera.ZoomToLevel(); Camera.ZoomToLevel();
} }
PhysicsObject LuoMaila(double x, double y)
private PhysicsObject LuoMaila(double x, double y)
{ {
PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);
maila.Shape = Shape.Rectangle; maila.Shape = Shape.Rectangle;
...@@ -82,13 +81,15 @@ public class Pong : PhysicsGame ...@@ -82,13 +81,15 @@ public class Pong : PhysicsGame
return maila; return maila;
} }
void LisaaLaskurit()
private void LisaaLaskurit()
{ {
pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0);
pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0);
} }
IntMeter LuoPisteLaskuri(double x, double y)
private IntMeter LuoPisteLaskuri(double x, double y)
{ {
IntMeter laskuri = new IntMeter(0); IntMeter laskuri = new IntMeter(0);
laskuri.MaxValue = 10; laskuri.MaxValue = 10;
...@@ -105,7 +106,8 @@ public class Pong : PhysicsGame ...@@ -105,7 +106,8 @@ public class Pong : PhysicsGame
return laskuri; return laskuri;
} }
void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde)
private void KasittelePallonTormays(PhysicsObject p, PhysicsObject kohde)
{ {
if (kohde == oikeaReuna) if (kohde == oikeaReuna)
{ {
...@@ -117,13 +119,15 @@ public class Pong : PhysicsGame ...@@ -117,13 +119,15 @@ public class Pong : PhysicsGame
} }
} }
void AloitaPeli()
private void AloitaPeli()
{ {
Vector impulssi = new Vector(500.0, 0.0); Vector impulssi = new Vector(500.0, 0.0);
pallo.Hit(impulssi * pallo.Mass); pallo.Hit(impulssi * pallo.Mass);
} }
void AsetaOhjaimet()
private void AsetaOhjaimet()
{ {
Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos);
Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero);
...@@ -152,7 +156,8 @@ public class Pong : PhysicsGame ...@@ -152,7 +156,8 @@ public class Pong : PhysicsGame
ControllerTwo.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); ControllerTwo.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
} }
void AsetaNopeus(PhysicsObject maila, Vector nopeus)
private void AsetaNopeus(PhysicsObject maila, Vector nopeus)
{ {
if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom))
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment