Changeset 7298


Ignore:
Timestamp:
2016-06-14 14:57:14 (7 years ago)
Author:
koannak
Message:
 
Location:
2016/24/AnttuK/SUO
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • 2016/24/AnttuK/SUO/SUO/SUO/SUO.cs

    r7270 r7298  
    1111    Image plImg = LoadImage("Untitled"); 
    1212    PhysicsObject player; 
     13    IntMeter counter; 
     14 
     15 
    1316    public override void Begin() 
    1417    { 
     18        CreateCounter(); 
    1519        SetKeys(); 
    1620        SetLevel(); 
     21        MediaPlayer.Play("music"); 
     22        MediaPlayer.Volume = 0.5; 
     23        MediaPlayer.IsRepeating = true; 
     24    } 
     25    void CreateCounter() 
     26    { 
     27        counter = new IntMeter(0); 
     28        Label counterDisp = new Label(); 
     29        counterDisp.X = Screen.Left + 100; 
     30        counterDisp.Y = Screen.Top - 100; 
     31        counterDisp.TextColor = Color.Black; 
     32        counterDisp.BindTo(counter); 
     33        counterDisp.Title = "Stars remaining"; 
     34        Add(counterDisp); 
     35    } 
     36    void Restart(PhysicsObject obj1, PhysicsObject obj2) 
     37    { 
     38        ClearAll(); 
     39        MessageDisplay.Add("You Lose! Try Again?"); 
     40        CreateCounter(); 
     41        SetKeys(); 
     42        SetLevel(); 
     43    } 
     44    void Win(PhysicsObject obj1, PhysicsObject obj2) 
     45    { 
     46        if (counter.Value == 0) 
     47        { 
     48            ClearAll(); 
     49            MessageDisplay.Add("You Win!"); 
     50            SetLevel(); 
     51            Vector exampleMovement = new Vector(1, 0); 
     52            Mouse.IsCursorVisible = true; 
     53            Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     54        } 
    1755    } 
    1856    void SetKeys() 
    1957    { 
    2058        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    21         Keyboard.Listen(Key.Left, ButtonState.Down, MovePlayer, null, new Vector(-20, 0)); 
    22         Keyboard.Listen(Key.Right, ButtonState.Down, MovePlayer, null, new Vector(20, 0)); 
    23         Keyboard.Listen(Key.Up, ButtonState.Down, MovePlayer, null, new Vector(0, 20)); 
    24         Keyboard.Listen(Key.Down, ButtonState.Down, MovePlayer, null, new Vector(0, -20)); 
     59        Keyboard.Listen(Key.Left, ButtonState.Down, MovePlayer, null, new Vector(-50, 0)); 
     60        Keyboard.Listen(Key.Right, ButtonState.Down, MovePlayer, null, new Vector(50, 0)); 
     61        Keyboard.Listen(Key.Up, ButtonState.Down, MovePlayer, null, new Vector(0, 50)); 
     62        Keyboard.Listen(Key.Down, ButtonState.Down, MovePlayer, null, new Vector(0, -50)); 
     63        Keyboard.Listen(Key.R, ButtonState.Down, Restart, null, player,player); 
    2564    } 
    2665    void SetLevel() 
     
    3069        tiles.SetTileMethod('#', CreateRect, Color.Gray); 
    3170        tiles.SetTileMethod('P', CreatePlayer); 
    32         tiles.Execute(32,32); 
     71        tiles.SetTileMethod('!', CreateEnemy); 
     72        tiles.SetTileMethod('^', CreateFlag); 
     73        tiles.SetTileMethod('@', CreateSafe); 
     74        tiles.SetTileMethod('$', CreateStar); 
     75        tiles.Execute(50,50); 
    3376    } 
    3477    void CreateRect(Vector pos, double width, double height, Color clr) 
     
    3881        tile.Shape = Shape.Rectangle; 
    3982        tile.Color = clr; 
     83        tile.Tag = "tile"; 
    4084        Add(tile); 
    4185    } 
    4286    void CreatePlayer(Vector pos, double width, double height) 
    4387    { 
    44         player = new PhysicsObject(width/2,height/2); 
     88        player = new PhysicsObject(width*0.5,height*0.5); 
    4589        player.Position = pos; 
    4690        player.Shape = Shape.Circle; 
    4791        player.Image = plImg; 
    4892        player.Restitution = 1.0; 
    49         player.LinearDamping = 1.0; 
    50         player.CanRotate = false; 
     93        player.LinearDamping = 0.9; 
     94        //player.CanRotate = false; 
     95        player.Tag = "player"; 
     96        player.CollisionIgnoreGroup = 1; 
     97        AddCollisionHandler(player, "flag", Win); 
     98        AddCollisionHandler(player, "star", CountAndDestroy); 
    5199        Add(player); 
     100    } 
     101    void CreateEnemy(Vector pos, double width, double height) 
     102    { 
     103        RandomMoverBrain dumbEnem = new RandomMoverBrain(); 
     104        dumbEnem.Speed = 100; 
     105        dumbEnem.ChangeMovementSeconds = 1; 
     106 
     107        FollowerBrain smartEnem = new FollowerBrain("player"); 
     108        smartEnem.Speed = 100; 
     109        smartEnem.DistanceFar = 100; 
     110        smartEnem.StopWhenTargetClose = false; 
     111        smartEnem.FarBrain = dumbEnem; 
     112 
     113        PhysicsObject enem = new PhysicsObject(width*0.75, height*0.75); 
     114        enem.Position = pos; 
     115        enem.Shape = Shape.Diamond; 
     116        enem.Color = Color.Ruby; 
     117        enem.Restitution = 1.0; 
     118        enem.Tag = "enemy"; 
     119        enem.Brain = smartEnem; 
     120 
     121        AddCollisionHandler(enem, "player", Restart); 
     122        Add(enem); 
    52123    } 
    53124    void MovePlayer(Vector vect) 
     
    55126        player.Hit(vect); 
    56127    } 
     128    void CreateFlag(Vector pos, double width, double height) 
     129    { 
     130        PhysicsObject flag = PhysicsObject.CreateStaticObject(width, height); 
     131        flag.Position = pos; 
     132        flag.Shape = Shape.Triangle; 
     133        flag.Color = Color.Cyan; 
     134        flag.Tag = "flag"; 
     135        flag.CollisionIgnoreGroup = 2; 
     136        Add(flag); 
     137    } 
     138    void CreateSafe(Vector pos, double width, double height) 
     139    { 
     140        PhysicsObject safe = PhysicsObject.CreateStaticObject(width, height); 
     141        safe.Position = pos; 
     142        safe.Shape = Shape.Circle; 
     143        safe.Color = Color.Black; 
     144        safe.Tag = "safe"; 
     145        safe.CollisionIgnoreGroup = 1; 
     146        Add(safe); 
     147    } 
     148    void CreateStar(Vector pos, double width, double height) 
     149    { 
     150        PhysicsObject star = PhysicsObject.CreateStaticObject(width, height); 
     151        star.Position = pos; 
     152        star.Shape = Shape.Star; 
     153        star.Color = Color.Yellow; 
     154        star.Tag = "star"; 
     155        counter.Value ++; 
     156        Add(star); 
     157    } 
     158    void CountAndDestroy(PhysicsObject obj1, PhysicsObject obj2) 
     159    { 
     160        obj2.Destroy(); 
     161        counter.Value --; 
     162    } 
    57163} 
  • 2016/24/AnttuK/SUO/SUO/SUO/SUO.csproj.Debug.cachefile

    r7270 r7298  
    11Content\level1.xnb 
    22Content\Untitled.xnb 
     3Content\music.xnb 
     4Content\music.wma 
    35Content\level1.txt 
    46Content\Untitled.png 
     7Content\music.mp3 
  • 2016/24/AnttuK/SUO/SUO/SUO/bin/x86/Debug/Content/level1.txt

    r7270 r7298  
    1 ########## 
    2 ####    P# 
    3 ##   ## ## 
    4 ## #### ## 
    5 ####### ## 
    6 #   ##  ## 
    7 ###  ## ## 
    8 ####    ## 
    9 #######  # 
    10 ########## 
     1 
     2 
     3  #######  ####### 
     4  #$ ! $#  # !# !# ############## 
     5###     ####$##$####         !  # 
     6#P$  @  @          $        !^! # 
     7###     ###$##$#####         !  # 
     8  #$ ! $# # !# !#  ############## 
     9  ####### ####### 
  • 2016/24/AnttuK/SUO/SUO/SUO/obj/x86/Debug/ContentPipeline-{943DB61E-18B1-4023-9157-F466AB52EC42}.xml

    r7270 r7298  
    99      <Options>None</Options> 
    1010      <Output>C:\MyTemp\AnttuK\SUO\SUO\SUO\bin\x86\Debug\Content\level1.xnb</Output> 
    11       <Time>2016-06-13T14:58:57.6378337+03:00</Time> 
     11      <Time>2016-06-14T14:54:41.2542867+03:00</Time> 
    1212    </Item> 
    1313    <Item> 
     
    1919      <Output>C:\MyTemp\AnttuK\SUO\SUO\SUO\bin\x86\Debug\Content\Untitled.xnb</Output> 
    2020      <Time>2016-06-13T14:10:57.4488745+03:00</Time> 
     21    </Item> 
     22    <Item> 
     23      <Source>music.mp3</Source> 
     24      <Name>music</Name> 
     25      <Importer>Mp3Importer</Importer> 
     26      <Processor>SongProcessor</Processor> 
     27      <Options>None</Options> 
     28      <Output>C:\MyTemp\AnttuK\SUO\SUO\SUO\bin\x86\Debug\Content\music.xnb</Output> 
     29      <Extra>C:\MyTemp\AnttuK\SUO\SUO\SUO\bin\x86\Debug\Content\music.wma</Extra> 
     30      <Time>2016-06-14T14:45:05.959763+03:00</Time> 
    2131    </Item> 
    2232    <BuildSuccessful>true</BuildSuccessful> 
  • 2016/24/AnttuK/SUO/SUO/SUO/obj/x86/Debug/SUO.csproj.FileListAbsolute.txt

    r7270 r7298  
    1111C:\MyTemp\AnttuK\SUO\SUO\SUO\bin\x86\Debug\Content\Untitled.xnb 
    1212C:\MyTemp\AnttuK\SUO\SUO\SUO\bin\x86\Debug\Content\Untitled.png 
     13C:\MyTemp\AnttuK\SUO\SUO\SUO\bin\x86\Debug\Content\music.xnb 
     14C:\MyTemp\AnttuK\SUO\SUO\SUO\bin\x86\Debug\Content\music.wma 
     15C:\MyTemp\AnttuK\SUO\SUO\SUO\bin\x86\Debug\Content\music.mp3 
  • 2016/24/AnttuK/SUO/SUO/SUO/obj/x86/Debug/cachefile-{943DB61E-18B1-4023-9157-F466AB52EC42}-targetpath.txt

    r7270 r7298  
    11Content\level1.xnb 
    22Content\Untitled.xnb 
     3Content\music.xnb 
     4Content\music.wma 
    35Content\level1.txt 
    46Content\Untitled.png 
     7Content\music.mp3 
  • 2016/24/AnttuK/SUO/SUO/SUOContent/SUOContent.contentproj

    r7270 r7298  
    6161    </Compile> 
    6262  </ItemGroup> 
     63  <ItemGroup> 
     64    <Compile Include="music.mp3"> 
     65      <Name>music</Name> 
     66      <Importer>Mp3Importer</Importer> 
     67      <Processor>SongProcessor</Processor> 
     68      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 
     69    </Compile> 
     70  </ItemGroup> 
    6371  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    6472  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
  • 2016/24/AnttuK/SUO/SUO/SUOContent/level1.txt

    r7270 r7298  
    1 ########## 
    2 ####    P# 
    3 ##   ## ## 
    4 ## #### ## 
    5 ####### ## 
    6 #   ##  ## 
    7 ###  ## ## 
    8 ####    ## 
    9 #######  # 
    10 ########## 
     1 
     2 
     3  #######  ####### 
     4  #$ ! $#  # !# !# ############## 
     5###     ####$##$####         !  # 
     6#P$  @  @          $        !^! # 
     7###     ###$##$#####         !  # 
     8  #$ ! $# # !# !#  ############## 
     9  ####### ####### 
Note: See TracChangeset for help on using the changeset viewer.