Changeset 7305 for 2016/24/HaseebS


Ignore:
Timestamp:
2016-06-14 14:59:24 (3 years ago)
Author:
empaheik
Message:

I completed making the game.

Location:
2016/24/HaseebS/FysiikkaPeli1
Files:
19 added
11 edited

Legend:

Unmodified
Added
Removed
  • 2016/24/HaseebS/FysiikkaPeli1/FysiikkaPeli1/FysiikkaPeli1/FysiikkaPeli1.cs

    r7279 r7305  
    99public class FysiikkaPeli1 : PhysicsGame 
    1010{ 
     11    Vector VelocityUp = new Vector(0, 200); 
     12    Vector velocityDown = new Vector(0, -200); 
     13 
    1114    PhysicsObject ball; 
     15    PhysicsObject paddle1; 
     16    PhysicsObject paddle2; 
     17 
     18    PhysicsObject leftBorder; 
     19    PhysicsObject rightBorder; 
     20 
     21    IntMeter player1Score; 
     22    IntMeter player2Score; 
     23 
    1224    public override void Begin() 
    1325    { 
    1426        CreateLevel(); 
    15         StartGame();     
     27        StartGame(); 
     28        SetControls(); 
     29        AddCounters(); 
    1630    } 
    1731    void CreateLevel() 
     
    2438        Add(ball); 
    2539 
    26         CreatePaddle(Level.Right -20, 0.0); 
    27         CreatePaddle(Level.Left +20, 0.0); 
    28         
    29              
     40        AddCollisionHandler(ball, Handleballcollison); 
     41 
     42        paddle1 =CreatePaddle(Level.Right -20, 0.0); 
     43        paddle2 =CreatePaddle(Level.Left +20, 0.0); 
    3044 
    3145 
    3246        Camera.ZoomToLevel(); 
    3347 
    34         Level.Background.Color = Color.Black; 
     48        Level.Background.Color = Color.LightGray; 
    3549        Level.CreateBorders(1.0, true); 
     50        ball.Color = Color.DarkForestGreen; 
     51 
     52        leftBorder = Level.CreateLeftBorder(); 
     53        leftBorder.Restitution = 1.0; 
     54        leftBorder.IsVisible = false; 
     55 
     56        rightBorder = Level.CreateRightBorder(); 
     57        rightBorder.Restitution = 1.0; 
     58        rightBorder.IsVisible = false; 
     59 
     60        PhysicsObject bottomBorder = Level.CreateBottomBorder(); 
     61        bottomBorder.Restitution = 1.0; 
     62        bottomBorder.IsVisible = false; 
     63 
     64        PhysicsObject topBorder = Level.CreateTopBorder(); 
     65        topBorder.Restitution = 1.0; 
     66        topBorder.IsVisible = false; 
     67 
    3668    } 
    3769    void StartGame() 
    3870    { 
    39         Vector impulse = new Vector(-400.0, 0.0); 
     71        Vector impulse = new Vector(600.0, 0.0); 
    4072        ball.Hit(impulse); 
    4173    } 
    4274 
    43     void CreatePaddle(double x, double y) 
     75    PhysicsObject CreatePaddle(double x, double y) 
    4476    { 
    4577        PhysicsObject paddle = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    4678        paddle.Shape = Shape.Rectangle; 
     79        paddle.Color = Color.DarkRed; 
    4780        paddle.X = x; 
    4881        paddle.Y = y; 
    49         paddle.Restitution = 1.0; 
     82        paddle.Restitution = 1.1; 
    5083        Add(paddle); 
     84        return paddle; 
     85 
     86    } 
     87   
     88    void SetControls() 
     89    { 
     90        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     91        Keyboard.Listen(Key.Up, ButtonState.Down, SetVelocity, "The Paddle1 will go up", paddle1, VelocityUp); 
     92        Keyboard.Listen(Key.Up, ButtonState.Released, SetVelocity, "Releasing A will stop Paddle1", paddle1, Vector.Zero); 
     93        Keyboard.Listen(Key.Down, ButtonState.Down, SetVelocity, "Paddle1 Will go down",paddle1, velocityDown); 
     94        Keyboard.Listen(Key.Down, ButtonState.Released, SetVelocity, "Paddle will stop from going down", paddle1, Vector.Zero); 
     95 
     96        Keyboard.Listen(Key.A, ButtonState.Down, SetVelocity,"Paddle2 will go up", paddle2, VelocityUp); 
     97        Keyboard.Listen(Key.A, ButtonState.Released, SetVelocity,"Paddle2 will stop moving", paddle2, Vector.Zero); 
     98        Keyboard.Listen(Key.D, ButtonState.Down, SetVelocity, "Paddle 2 will go down", paddle2, velocityDown); 
     99        Keyboard.Listen(Key.D, ButtonState.Released, SetVelocity, "Paddle 2 wills stop moving", paddle2, Vector.Zero); 
     100 
     101        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     102        Keyboard.Listen(Key.Tab,ButtonState.Pressed, ShowControlHelp, "It will show control panel"); 
     103 
     104 
     105 
     106    } 
     107    void SetVelocity(PhysicsObject paddle, Vector velocity) 
     108    { 
     109        if ((velocity.Y > 0) &&(paddle.Top > Level.Top)) 
     110        { 
     111            paddle.Velocity = Vector.Zero; 
     112            return;  
     113        } 
     114        if ((velocity.Y < 0) && (paddle.Bottom < Level.Bottom)) 
     115        { 
     116            paddle.Velocity = Vector.Zero; 
     117        } 
     118        paddle.Velocity = velocity; 
    51119    } 
    52120 
    53     void SetControls() 
     121    void AddCounters() 
    54122    { 
    55         Keyboard.Listen(Key.A, ButtonState.Down, MovePaddle1Up, "Player, When you press A, Paddle goes up" ); 
    56         Keyboard.Listen(Key.A, ButtonState.Released, StopPaddle1, "Playe When you release A, Paddle stop " ) 
    57         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     123        player1Score = CreateScoreCounter(Screen.Right -100, Screen.Top -100); 
     124        player2Score = CreateScoreCounter(Screen.Left + 100, Screen.Top -100); 
    58125    } 
     126 
     127    IntMeter CreateScoreCounter(double x, double y) 
     128    { 
     129        IntMeter counter = new IntMeter(0); 
     130        counter.MaxValue = 10; 
     131 
     132        Label display = new Label(); 
     133        display.BindTo(counter); 
     134        display.X = x; 
     135        display.Y = y; 
     136        display.TextColor = Color.GreenYellow; 
     137        display.BorderColor = Color.YellowGreen; 
     138        display.BorderColor = Level.Background.Color; 
     139        display.Color = Level.Background.Color; 
     140        Add(display); 
     141 
     142        return counter; 
     143 
     144      } 
     145    void Handleballcollison(PhysicsObject ball, PhysicsObject target) 
     146    { 
     147        if (target == rightBorder) 
     148        { 
     149            player2Score.Value += 1; 
     150        } 
     151        else if (target == leftBorder) 
     152        { 
     153            player1Score.Value += 1; 
     154        } 
     155  
     156    } 
     157 
     158 
    59159} 
  • 2016/24/HaseebS/FysiikkaPeli1/FysiikkaPeli1/FysiikkaPeli1/obj/x86/Debug/ContentPipeline-{4BE79D17-BC08-4925-A65C-910B4392E166}.xml

    r7279 r7305  
    99      <BuildConfiguration>Debug</BuildConfiguration> 
    1010      <CompressContent>false</CompressContent> 
    11       <RootDirectory>C:\MyTemp\HaseebShaikh\New folder\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1Content\</RootDirectory> 
    12       <LoggerRootDirectory>C:\MyTemp\HaseebShaikh\New folder\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\</LoggerRootDirectory> 
    13       <IntermediateDirectory>C:\MyTemp\HaseebShaikh\New folder\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\obj\x86\Debug\</IntermediateDirectory> 
    14       <OutputDirectory>C:\MyTemp\HaseebShaikh\New folder\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\bin\x86\Debug\Content\</OutputDirectory> 
     11      <RootDirectory>C:\MyTemp\HaseebS\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1Content\</RootDirectory> 
     12      <LoggerRootDirectory>C:\MyTemp\HaseebS\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\</LoggerRootDirectory> 
     13      <IntermediateDirectory>C:\MyTemp\HaseebS\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\obj\x86\Debug\</IntermediateDirectory> 
     14      <OutputDirectory>C:\MyTemp\HaseebS\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\bin\x86\Debug\Content\</OutputDirectory> 
    1515    </Settings> 
    1616    <Assemblies> 
  • 2016/24/HaseebS/FysiikkaPeli1/FysiikkaPeli1/FysiikkaPeli1/obj/x86/Debug/FysiikkaPeli1.csproj.FileListAbsolute.txt

    r7279 r7305  
    77C:\MyTemp\HaseebShaikh\New folder\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\obj\x86\Debug\FysiikkaPeli1.exe 
    88C:\MyTemp\HaseebShaikh\New folder\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\obj\x86\Debug\FysiikkaPeli1.pdb 
     9C:\MyTemp\HaseebS\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\obj\x86\Debug\FysiikkaPeli1.csprojResolveAssemblyReference.cache 
     10C:\MyTemp\HaseebS\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\obj\x86\Debug\Microsoft.Xna.Framework.RuntimeProfile.txt 
     11C:\MyTemp\HaseebS\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\obj\x86\Debug\FysiikkaPeli1.exe 
     12C:\MyTemp\HaseebS\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\obj\x86\Debug\FysiikkaPeli1.pdb 
     13C:\MyTemp\HaseebS\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\bin\x86\Debug\FysiikkaPeli1.exe 
     14C:\MyTemp\HaseebS\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\bin\x86\Debug\FysiikkaPeli1.pdb 
     15C:\MyTemp\HaseebS\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\bin\x86\Debug\Jypeli.dll 
     16C:\MyTemp\HaseebS\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1\bin\x86\Debug\Jypeli.xml 
  • 2016/24/HaseebS/FysiikkaPeli1/FysiikkaPeli1/FysiikkaPeli1Content/obj/x86/Debug/FysiikkaPeli1Content.contentproj.FileListAbsolute.txt

    r7279 r7305  
    11C:\MyTemp\HaseebShaikh\New folder\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1Content\obj\x86\Debug\FysiikkaPeli1Content.contentprojResolveAssemblyReference.cache 
     2C:\MyTemp\HaseebS\FysiikkaPeli1\FysiikkaPeli1\FysiikkaPeli1Content\obj\x86\Debug\FysiikkaPeli1Content.contentprojResolveAssemblyReference.cache 
Note: See TracChangeset for help on using the changeset viewer.