Changeset 7729 for 2016


Ignore:
Timestamp:
2016-07-04 15:04:03 (3 years ago)
Author:
karkaite
Message:
 
Location:
2016/27/RuhanAnjanK/Pong
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2016/27/RuhanAnjanK/Pong/Pong/Pong/Pong.cs

    r7676 r7729  
    11using System; 
    22using System.Collections.Generic; 
     3using System.Linq; 
     4using System.Text; 
    35using Jypeli; 
    46using Jypeli.Assets; 
     
    911public class Pong : PhysicsGame 
    1012{ 
     13    Vector speedup = new Vector(0, 200); 
     14    Vector speeddown = new Vector(0, 200); 
     15 
     16    PhysicsObject ball; 
     17    PhysicsObject racket1; 
     18    PhysicsObject racket2; 
    1119    public override void Begin() 
    1220    { 
    1321        // TODO: Kirjoita ohjelmakoodisi tähän 
    14         PhysicsObject ball = new PhysicsObject(40.0, 40.0); 
    15         ball.Shape = Shape.Circle; 
    16         ball.X = -200.0; 
    17         ball.Y = 0.0; 
    18         ball.Restitution = 0.0; 
    19  
    20         Add(ball); 
    21  
    22         Level.CreateBorders(1.0, false); 
    23         Level.Background.Color = Color.Black; 
    24  
    25         Camera.ZoomToLevel(); 
     22        CreateLevel(); 
    2623 
    2724         Vector impulse = new Vector (500.0 , 0.0); 
     
    3128        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "end game"); 
    3229    } 
    33     void CreateLevel () 
     30    void CreateLevel() 
    3431    { 
    35         PhysicsObject ball = new PhysicsObject(40.0, 40.0); 
     32        ball = new PhysicsObject(40.0, 40.0); 
    3633        ball.Shape = Shape.Circle; 
    3734        ball.X = -200.0; 
    3835        ball.Y = 0.0; 
    39         ball.Restitution = 0.0; 
     36        ball.Restitution = 1.0; 
    4037 
    4138        Add(ball); 
    4239 
     40       racket1 = CreateRacket(Level.Left + 20.0, 0.0); 
     41       racket2 = CreateRacket(Level.Right - 20.0, 0.0); 
     42 
    4343        Level.CreateBorders(1.0, false); 
    44         Level.Background.Color = Color.Black; 
     44        Level.Background.Color = Color.Green; 
    4545 
    4646        Camera.ZoomToLevel(); 
     47    } 
     48    PhysicsObject CreateRacket(double x, double y) 
     49    { 
     50        PhysicsObject racket = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     51        racket.Shape = Shape.Rectangle; 
     52        racket.X = x; 
     53        racket.Y = y; 
     54        racket.Restitution = 1.0; 
     55        Add(racket); 
     56        return racket; 
     57    } 
     58 
     59    void StartGame() 
     60    { 
     61        Vector impulse = new Vector(500.0, 0.0); 
     62        ball.Hit(impulse); 
    4763    } 
    4864} 
Note: See TracChangeset for help on using the changeset viewer.