Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.24 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using SdlDotNet.Graphics;
  5. using SdlDotNet.Input;
  6. using SdlDotNet.Graphics.Primitives;
  7. using SdlDotNet.Core;
  8. using System.Collections.Generic;
  9. using System.IO;
  10.  
  11. namespace Shmup
  12. {
  13.    
  14.     public abstract class Entity
  15.     {
  16.         public static Random rnd = new Random();
  17.  
  18.         public float x;
  19.         public float y;
  20.         public int sprite;
  21.         public int rotation;
  22.  
  23.         public Entity(float X, float Y, int Sprite, int Rotation)
  24.         {
  25.             x = X;
  26.             y = Y;
  27.             sprite = Sprite;
  28.             rotation = Rotation;
  29.         }
  30.        
  31.         public void draw(Surface sprites, SpriteSheet ss, Surface video)
  32.         {
  33.             Surface temp1 = sprites.CreateSurfaceFromClipRectangle(ss.getRectangle(sprite));
  34.             Surface temp2 = temp1.CreateRotatedSurface(rotation, false);
  35.             Surface temp3 = temp2.Convert(video, false, false);
  36.             temp3.SourceColorKey = temp3.GetPixel(new Point(0, 0));
  37.             video.Blit(temp3, new Point((int)(x - (temp3.Width / 2)), (int)(y - (temp3.Height / 2))));
  38.             temp3.Dispose();
  39.             temp2.Dispose();
  40.             temp1.Dispose();
  41.         }
  42.  
  43.         public abstract void move();
  44.     }
  45.    
  46.     // -- Stars --
  47.  
  48.     public class stars: Entity
  49.     {
  50.  
  51.         public stars(int X, int Y, int Sprite, int Rotation) : base(X, Y, Sprite, Rotation) {}
  52.  
  53.         public override void move() { }
  54.     }
  55.  
  56.     // -- Ships --
  57.  
  58.     public class Ship : Entity
  59.     {
  60.         private int direction;
  61.         private float acceleration;
  62.         private float velocity;
  63.         private int maxvelocity;
  64.  
  65.         // constructors
  66.  
  67.         public Ship(float X, float Y, int Sprite, int Rotation, int Direction, float Velocity, float Acceleration, int Maxvelocity) : base(X, Y, Sprite, Rotation)
  68.         {
  69.             direction = Direction;
  70.             velocity = Velocity;
  71.             acceleration = Acceleration;
  72.             maxvelocity = Maxvelocity;
  73.         }
  74.         // behaviour
  75.  
  76.         public override void move()
  77.         {
  78.             if (Keyboard.IsKeyPressed(Key.UpArrow)) { thrust(); }
  79.             if (Keyboard.IsKeyPressed(Key.RightArrow)) { rotation -= 4; }
  80.             if (Keyboard.IsKeyPressed(Key.DownArrow)) { minusthrust(); }
  81.             if (Keyboard.IsKeyPressed(Key.LeftArrow)) { rotation += 4; }
  82.  
  83.             double rad = (double)(rotation + 90) * Math.PI / 180.0;
  84.             double dx = (velocity * Math.Cos(rad));
  85.             double dy = -(velocity * Math.Sin(rad));
  86.  
  87.             x += (float)(dx);
  88.             y += (float)(dy);
  89.  
  90.  
  91.         }
  92.  
  93.         public void thrust()
  94.         {
  95.             velocity += acceleration;
  96.             if (velocity > maxvelocity) { velocity = maxvelocity; }
  97.         }
  98.  
  99.         public void minusthrust()
  100.         {
  101.             velocity -= acceleration;
  102.             if (velocity < 0) { velocity = 0; }
  103.         }
  104.     }
  105.  
  106.     // -- Asteroid --
  107.  
  108.     public class Asteroid : Entity
  109.     {
  110.  
  111.         // state
  112.        
  113.         public float dx;
  114.         public float dy;
  115.         public int direction;
  116.         public int dr;
  117.  
  118.         // constructors
  119.  
  120.         public Asteroid(float X, float Y, int Sprite, int Rotation, int Direction, float Dx, float Dy, int Dr) : base(X, Y, Sprite, Rotation)
  121.         {
  122.             dx = Dx / 2f;
  123.             dy = Dy / 2f;
  124.             direction = Direction;
  125.             dr = Dr;
  126.          
  127.         }
  128.         public override void move()
  129.         {
  130.             {
  131.                 rotation += dr;
  132.                 x += dx;
  133.                 y += dy;
  134.  
  135.                 if (rotation != 0)
  136.                 {
  137.                     direction = (direction + rotation) % 360;
  138.                 }
  139.  
  140.  
  141.                 if (x < 0)
  142.                 {
  143.                     x = Program.FRAME_WIDTH;
  144.                 }
  145.                 else if (x > Program.FRAME_WIDTH)
  146.                 {
  147.                     x = 0;
  148.                 }
  149.  
  150.                 if (y < 0)
  151.                 {
  152.                     y = Program.FRAME_HEIGHT;
  153.                 }
  154.                 else if (y > Program.FRAME_HEIGHT)
  155.                 {
  156.                     y = 0;
  157.                 }
  158.             }
  159.         }
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement