Changeset 6237


Ignore:
Timestamp:
2015-06-24 12:01:09 (8 years ago)
Author:
anlakane
Message:

Miskan ebin haxeja

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2014/30/MitjaK/Attack to Agora/Attack to Agora/Attack to Agora/Attack to Agora/Attack_to_Agora.cs

    r6192 r6237  
    99public class Attack_to_Agora : PhysicsGame 
    1010{ 
     11    private Animation chuckinkavely; 
    1112 
    12     private Animation chuckinkavely; 
    13     double nopeus = 200; 
    14     double hyppyvoima = 1000; 
     13    /// <summary> 
     14    /// Vakiot kannattaa merkitä constiksi (ei voi muuttaa). Tällöin ne kirjoitetaan isolla. 
     15    /// </summary> 
     16    const double NOPEUS = 250; 
     17    const double HYPPYVOIMA = 1500; 
    1518 
    16     //Image level1 = LoadImage("Agora_paaovi_pixelate"); 
    1719    Image level1 = LoadImage("kentta1"); 
    1820    Image taistelijanvarjo = LoadImage("varjo"); 
    19     
    20     Image taistelijaolio = LoadImage("olio"); 
     21 
     22    Image taistelijaOlio = LoadImage("olio"); 
    2123    PlatformCharacter taistelija; 
    22     
    23     int kenttanro = 4; 
    24   //  int Kenttanro = -1; 
     24 
     25    int kenttaNro = 5; 
     26 
    2527    public override void Begin() 
    26     
    27      
    2828    { 
     29        LataaContent(); 
     30        LuoKentta(); 
     31        AsetaOhjaimet(); 
     32    } 
    2933 
    30         Luokentta(); 
    31  
    32          
    33          
    34     } 
    35      
    36  
    37      void Liikuta(PlatformCharacter pelaaja, double suunta) 
     34    void Liikuta(PlatformCharacter pelaaja, double suunta) 
    3835    { 
    3936        pelaaja.Walk(suunta); 
    4037 
    4138        if (!pelaaja.Animation.IsPlaying) 
    42          
    4339            pelaaja.Animation.Resume(); 
    44      } 
    45  
    46  
    47  
    48      
     40    } 
    4941 
    5042    void LiikutaYlos(PlatformCharacter pelaaja) 
    5143    { 
    52         pelaaja.Jump(hyppyvoima); 
    53          
    54  
     44        pelaaja.Jump(HYPPYVOIMA); 
    5545    } 
    5646 
    57     void Luokentta() 
     47    void LataaContent() 
    5848    { 
    5949        chuckinkavely = LoadAnimation("pelaajaliikkuu"); 
     50    } 
     51 
     52    void LuoKentta() 
     53    { 
    6054        SmoothTextures = false; 
    61  
    62         ColorTileMap pohjaLevy = ColorTileMap.FromLevelAsset("kentta4pohja"); 
    63         pohjaLevy.SetTileMethod(Color.Gold, Luopohja); 
    64         pohjaLevy.SetTileMethod(Color.Cyan, Luotaistelija); 
    65         pohjaLevy.Execute(1, 1); 
    66  
    67  
    68          
    69         Level.Background.Image = LoadImage("kentta"+kenttanro); 
    70         //Level.Background.Image = level1; 
    71         //Level.Background.Color = Color.Black; 
    72         //Level.Width = 2000; 
    73         //Level.Height = 1200; 
    74         Level.Background.FitToLevel(); 
     55        // IsFullScreen = true; 
    7556        Gravity = new Vector(0, -2500); 
    7657 
    77        // PhysicsObject pohja = Level.CreateBottomBorder(); 
    78        // pohja.Y = Level.Bottom + 100; 
     58        SetWindowSize(1920, 1080); 
     59        // Synkataan taustakuvan ja colortilemapin pikselit 
     60        Level.Background.Image = LoadImage("kentta" + kenttaNro.ToString()); 
     61 
     62        Level.Width = Screen.Width; 
     63        double kerroin = (double)Level.Background.Image.Width / Level.Background.Image.Height; 
     64        Level.Height = Level.Width / kerroin; 
     65        Level.Background.FitToLevel(); 
     66 
     67        Image pohjaLevynKuva = LoadImage("kentta" + kenttaNro.ToString() + "pohja"); 
     68 
     69        ColorTileMap pohjaLevy = new ColorTileMap(pohjaLevynKuva); 
     70        pohjaLevy.SetTileMethod(Color.Gold, LuoPohja); 
     71        pohjaLevy.SetTileMethod(Color.Cyan, Luotaistelija); 
     72        pohjaLevy.Optimize(Color.Gold); 
     73 
     74        // oletuksena 1 pikseli = 1 unit 
     75        const double BASE_SIZE = 1.0; 
     76        double widthMultiplier = Level.Width / pohjaLevynKuva.Width; 
     77        double heightMultiplier = Level.Height / pohjaLevynKuva.Height; 
     78        pohjaLevy.Execute(BASE_SIZE * widthMultiplier, BASE_SIZE * heightMultiplier); 
     79 
     80        // PhysicsObject pohja = Level.CreateBottomBorder(); 
     81        // pohja.Y = Level.Bottom + 100; 
    7982        //pohja.IsVisible = false; 
    8083        PhysicsObject vasenreuna = Level.CreateLeftBorder(); 
     
    8588        //oikeareuna.Tag = "oikeareuna"; 
    8689 
    87  
    88       
    89         //Varjo(pohja); 
    90  
    91         IsFullScreen = true; 
    92         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    93  
    94  
    95  
    96  
     90        Varjo(); 
    9791    } 
    9892 
     
    10094    { 
    10195 
    102         taistelija = new PlatformCharacter(15, 15); 
    103         taistelija.Shape = Shape.Circle; 
     96        taistelija = new PlatformCharacter(75, 75); 
     97        taistelija.Shape = Shape.Rectangle; 
    10498        taistelija.Animation = new Animation(chuckinkavely); 
    10599        taistelija.Animation.Start(); 
    106100        taistelija.Position = paikka; 
    107101 
    108         Keyboard.Listen(Key.A, ButtonState.Down, Liikuta, null, taistelija, -nopeus); 
    109         Keyboard.Listen(Key.D, ButtonState.Down, Liikuta, null, taistelija, nopeus); 
    110         Keyboard.Listen(Key.Space, ButtonState.Pressed, LiikutaYlos, null, taistelija); 
    111         AddCollisionHandler(taistelija, "vasenreuna",Seuraavakentta); 
     102        AddCollisionHandler(taistelija, "vasenreuna", SeuraavaKentta); 
    112103 
    113104        taistelija.Mass = 10.0; 
     
    116107        Camera.StayInLevel = true; 
    117108    } 
    118     void Varjo(PhysicsObject pohja) 
     109 
     110    void Varjo() 
    119111    { 
    120112        GameObject varjo = new GameObject(70, 30); 
    121113        varjo.Image = taistelijanvarjo; 
    122         varjo.Y = pohja.Top; 
    123114        Add(varjo, -1); 
     115 
    124116        Timer ajastin = new Timer(); 
    125117        ajastin.Interval = 0.01; 
     
    127119        { 
    128120            varjo.X = taistelija.X; 
     121            varjo.Y = EtsiVarjonY(); 
    129122        }; 
    130123        ajastin.Start(); 
    131124    } 
    132125 
    133     void Seuraavakentta(PhysicsObject tormaaja, PhysicsObject tormatty) 
     126    /// <summary> 
     127    /// Etsii pelaajaa lähimpänä pelaajan alla olevan lattiapalikan huipun Y-koordinaatin. 
     128    /// </summary> 
     129    /// <returns></returns> 
     130    double EtsiVarjonY() 
     131    { 
     132        List<GameObject> possibleFloorPieces = GetObjects(x => x.Left < taistelija.X && x.Right > taistelija.X); 
     133 
     134        double highestY = double.MinValue; 
     135        int highestIndex = -1; 
     136 
     137        for (int i = 0; i < possibleFloorPieces.Count; i++) 
     138        { 
     139            double currentY = possibleFloorPieces[i].Y; 
     140 
     141            if (currentY > highestY && currentY < taistelija.Bottom)  
     142            { 
     143                highestY = currentY; 
     144                highestIndex = i; 
     145            } 
     146        } 
     147 
     148        return possibleFloorPieces[highestIndex].Top; 
     149    } 
     150 
     151    void SeuraavaKentta(PhysicsObject tormaaja, PhysicsObject tormatty) 
    134152    { 
    135153        ClearAll(); 
    136         kenttanro++; 
    137         //Kenttanro--; 
    138         Luokentta(); 
     154        kenttaNro++; 
     155        LuoKentta(); 
    139156    } 
    140157 
    141     void Luopohja(Vector paikka, double leveys, double korkeus) 
     158    void LuoPohja(Vector paikka, double leveys, double korkeus) 
    142159    { 
    143160        PhysicsObject pala = PhysicsObject.CreateStaticObject(leveys, korkeus); 
    144161        pala.Position = paikka; 
    145         pala.Color = Color.Transparent; 
     162        pala.IsVisible = false; 
    146163        Add(pala); 
    147164    } 
    148     
     165 
     166    /// <summary> 
     167    /// Asetetaan pelaajalle ohjaimet. 
     168    /// </summary> 
     169    void AsetaOhjaimet() 
     170    { 
     171        Keyboard.Listen(Key.A, ButtonState.Down, Liikuta, null, taistelija, -NOPEUS); 
     172        Keyboard.Listen(Key.D, ButtonState.Down, Liikuta, null, taistelija, NOPEUS); 
     173        Keyboard.Listen(Key.Space, ButtonState.Pressed, LiikutaYlos, null, taistelija); 
     174        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     175    } 
    149176} 
Note: See TracChangeset for help on using the changeset viewer.