Changeset 7534


Ignore:
Timestamp:
2016-06-27 14:58:42 (3 years ago)
Author:
empaheik
Message:

valmis :#)

Location:
2016/26/HeiniI/Pong
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • 2016/26/HeiniI/Pong/Pong/Pong/Pong.cs

    r7518 r7534  
    99public class Pong : PhysicsGame 
    1010{ 
     11    Vector nopeusYlos = new Vector(0, 200); 
     12    Vector nopeusalas = new Vector(0, -200); 
     13 
    1114    PhysicsObject pallo; 
     15    PhysicsObject maila1; 
     16    PhysicsObject maila2; 
     17 
     18    PhysicsObject VasenReuna; 
     19    PhysicsObject OikeaReuna; 
     20 
     21    IntMeter Pelaajan1Pisteet; 
     22    IntMeter Pelaajan2Pisteet; 
     23 
    1224    public override void Begin() 
    1325    { 
    1426        luoKentta(); 
    1527        AsetaOhjaimet(); 
     28        LisaaLaskurit(); 
    1629        AloitaPeli(); 
    1730 
    18         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    1931    } 
    2032    void luoKentta() 
     
    2537        pallo.Y = 0.0; 
    2638        pallo.Restitution = 1.0; 
     39        pallo.KineticFriction = 0.0; 
     40        pallo.MomentOfInertia = Double.PositiveInfinity; 
    2741        Add(pallo); 
     42        AddCollisionHandler(pallo, KasittelePallonTormays); 
    2843 
    29         LuoMaila(Level.Left + 20.0, 0.0); 
    30         LuoMaila(Level.Right - 20.0, 0.0); 
     44        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     45        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3146 
    32         Level.CreateBorders(1.0, false); 
     47        VasenReuna = Level.CreateLeftBorder(); 
     48        VasenReuna.Restitution = 1.0; 
     49        VasenReuna.IsVisible = false; 
     50 
     51        OikeaReuna = Level.CreateRightBorder(); 
     52        OikeaReuna.Restitution = 1.0; 
     53        OikeaReuna.IsVisible = false; 
     54 
     55        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     56        ylaReuna.Restitution = 1.0; 
     57        ylaReuna.IsVisible = false; 
     58 
     59        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     60        alaReuna.Restitution = 1.0; 
     61        alaReuna.IsVisible = false; 
     62 
     63 
    3364        Level.Background.Color = Color.Aquamarine; 
    3465 
     
    4172        pallo.Hit(impulssi); 
    4273    } 
    43     void LuoMaila (double x, double y) 
     74    PhysicsObject LuoMaila (double x, double y) 
    4475    { 
    4576        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     
    4980        maila.Restitution = 1.0; 
    5081        Add(maila); 
     82        return maila; 
    5183    } 
    5284    void AsetaOhjaimet() 
    5385    { 
    54         Keyboard.Listen(Key.A, ButtonState.Down, LiikutaMaila1Ylös, "Pelaaja 1: liikuta mailaa ylös"); 
    55         Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila1, null); 
     86        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: liikuta mailaa ylös",maila1, nopeusYlos); 
     87        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     88        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1. liikuta mailaa alas", maila1, nopeusalas); 
     89        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    5690 
     91 
     92 
     93        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     94        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     95        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusalas); 
     96        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     97 
     98        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    5799        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     100 
     101    } 
     102    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     103        
     104{ 
     105        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     106        { 
     107            maila.Velocity = Vector.Zero; 
     108            return; 
     109        } 
     110        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     111        { 
     112            maila.Velocity = Vector.Zero; 
     113            return; 
     114        } 
     115        maila.Velocity = nopeus; 
     116} 
     117    void LisaaLaskurit() 
     118    { 
     119        Pelaajan1Pisteet = LuoPistelaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     120        Pelaajan2Pisteet = LuoPistelaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     121    } 
     122    IntMeter LuoPistelaskuri( double x, double y) 
     123    { 
     124        IntMeter laskuri = new IntMeter(0); 
     125        laskuri.MaxValue = 10; 
     126        Label naytto = new Label(); 
     127        naytto.BindTo(laskuri); 
     128        naytto.X = x; 
     129        naytto.Y = y; 
     130        naytto.TextColor = Color.HotPink; 
     131        naytto.BorderColor = Level.Background.Color; 
     132        naytto.Color = Level.Background.Color; 
     133        Add(naytto); 
     134 
     135        return laskuri; 
     136    } 
     137    void KasittelePallonTormays(PhysicsObject pallo,PhysicsObject kohde) 
     138    { 
     139        if (kohde == OikeaReuna) 
     140        { 
     141                Pelaajan1Pisteet.Value += 1; 
     142        } 
     143        else if (kohde == VasenReuna) 
     144        { 
     145            Pelaajan2Pisteet.Value += 1; 
     146        } 
    58147 
    59148    } 
  • 2016/26/HeiniI/Pong/Pong/Pong/obj/x86/Debug/ContentPipeline-{9F11FD93-1081-4299-B6D1-7923FB13FBD7}.xml

    r7518 r7534  
    99      <BuildConfiguration>Debug</BuildConfiguration> 
    1010      <CompressContent>false</CompressContent> 
    11       <RootDirectory>C:\MyTemp\HeiniI\Pong\Pong\PongContent\</RootDirectory> 
    12       <LoggerRootDirectory>C:\MyTemp\HeiniI\Pong\Pong\Pong\</LoggerRootDirectory> 
    13       <IntermediateDirectory>C:\MyTemp\HeiniI\Pong\Pong\Pong\obj\x86\Debug\</IntermediateDirectory> 
    14       <OutputDirectory>C:\MyTemp\HeiniI\Pong\Pong\Pong\bin\x86\Debug\Content\</OutputDirectory> 
     11      <RootDirectory>C:\MyTemp\HeiniI-uusin\Pong\Pong\PongContent\</RootDirectory> 
     12      <LoggerRootDirectory>C:\MyTemp\HeiniI-uusin\Pong\Pong\Pong\</LoggerRootDirectory> 
     13      <IntermediateDirectory>C:\MyTemp\HeiniI-uusin\Pong\Pong\Pong\obj\x86\Debug\</IntermediateDirectory> 
     14      <OutputDirectory>C:\MyTemp\HeiniI-uusin\Pong\Pong\Pong\bin\x86\Debug\Content\</OutputDirectory> 
    1515    </Settings> 
    1616    <Assemblies> 
  • 2016/26/HeiniI/Pong/Pong/Pong/obj/x86/Debug/Pong.csproj.FileListAbsolute.txt

    r7518 r7534  
    77C:\MyTemp\HeiniI\Pong\Pong\Pong\obj\x86\Debug\Pong.exe 
    88C:\MyTemp\HeiniI\Pong\Pong\Pong\obj\x86\Debug\Pong.pdb 
     9C:\MyTemp\HeiniI-uusin\Pong\Pong\Pong\obj\x86\Debug\Pong.csprojResolveAssemblyReference.cache 
     10C:\MyTemp\HeiniI-uusin\Pong\Pong\Pong\obj\x86\Debug\Microsoft.Xna.Framework.RuntimeProfile.txt 
     11C:\MyTemp\HeiniI-uusin\Pong\Pong\Pong\obj\x86\Debug\Pong.exe 
     12C:\MyTemp\HeiniI-uusin\Pong\Pong\Pong\obj\x86\Debug\Pong.pdb 
     13C:\MyTemp\HeiniI-uusin\Pong\Pong\Pong\bin\x86\Debug\Pong.exe 
     14C:\MyTemp\HeiniI-uusin\Pong\Pong\Pong\bin\x86\Debug\Pong.pdb 
     15C:\MyTemp\HeiniI-uusin\Pong\Pong\Pong\bin\x86\Debug\Jypeli.dll 
     16C:\MyTemp\HeiniI-uusin\Pong\Pong\Pong\bin\x86\Debug\Jypeli.xml 
  • 2016/26/HeiniI/Pong/Pong/PongContent/obj/x86/Debug/PongContent.contentproj.FileListAbsolute.txt

    r7518 r7534  
    11C:\MyTemp\HeiniI\Pong\Pong\PongContent\obj\x86\Debug\PongContent.contentprojResolveAssemblyReference.cache 
     2C:\MyTemp\HeiniI-uusin\Pong\Pong\PongContent\obj\x86\Debug\PongContent.contentprojResolveAssemblyReference.cache 
Note: See TracChangeset for help on using the changeset viewer.