Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using SdlDotNet.Graphics;
- using SdlDotNet.Input;
- using SdlDotNet.Graphics.Primitives;
- using SdlDotNet.Core;
- using System.Collections.Generic;
- using System.IO;
- namespace Shmup
- {
- public abstract class Entity
- {
- public static Random rnd = new Random();
- public float x;
- public float y;
- public int sprite;
- public int rotation;
- public Entity(float X, float Y, int Sprite, int Rotation)
- {
- x = X;
- y = Y;
- sprite = Sprite;
- rotation = Rotation;
- }
- public void draw(Surface sprites, SpriteSheet ss, Surface video)
- {
- Surface temp1 = sprites.CreateSurfaceFromClipRectangle(ss.getRectangle(sprite));
- Surface temp2 = temp1.CreateRotatedSurface(rotation, false);
- Surface temp3 = temp2.Convert(video, false, false);
- temp3.SourceColorKey = temp3.GetPixel(new Point(0, 0));
- video.Blit(temp3, new Point((int)(x - (temp3.Width / 2)), (int)(y - (temp3.Height / 2))));
- temp3.Dispose();
- temp2.Dispose();
- temp1.Dispose();
- }
- public abstract void move();
- }
- // -- Stars --
- public class stars: Entity
- {
- public stars(int X, int Y, int Sprite, int Rotation) : base(X, Y, Sprite, Rotation) {}
- public override void move() { }
- }
- // -- Ships --
- public class Ship : Entity
- {
- private int direction;
- private float acceleration;
- private float velocity;
- private int maxvelocity;
- // constructors
- public Ship(float X, float Y, int Sprite, int Rotation, int Direction, float Velocity, float Acceleration, int Maxvelocity) : base(X, Y, Sprite, Rotation)
- {
- direction = Direction;
- velocity = Velocity;
- acceleration = Acceleration;
- maxvelocity = Maxvelocity;
- }
- // behaviour
- public override void move()
- {
- if (Keyboard.IsKeyPressed(Key.UpArrow)) { thrust(); }
- if (Keyboard.IsKeyPressed(Key.RightArrow)) { rotation -= 4; }
- if (Keyboard.IsKeyPressed(Key.DownArrow)) { minusthrust(); }
- if (Keyboard.IsKeyPressed(Key.LeftArrow)) { rotation += 4; }
- double rad = (double)(rotation + 90) * Math.PI / 180.0;
- double dx = (velocity * Math.Cos(rad));
- double dy = -(velocity * Math.Sin(rad));
- x += (float)(dx);
- y += (float)(dy);
- }
- public void thrust()
- {
- velocity += acceleration;
- if (velocity > maxvelocity) { velocity = maxvelocity; }
- }
- public void minusthrust()
- {
- velocity -= acceleration;
- if (velocity < 0) { velocity = 0; }
- }
- }
- // -- Asteroid --
- public class Asteroid : Entity
- {
- // state
- public float dx;
- public float dy;
- public int direction;
- public int dr;
- // constructors
- public Asteroid(float X, float Y, int Sprite, int Rotation, int Direction, float Dx, float Dy, int Dr) : base(X, Y, Sprite, Rotation)
- {
- dx = Dx / 2f;
- dy = Dy / 2f;
- direction = Direction;
- dr = Dr;
- }
- public override void move()
- {
- {
- rotation += dr;
- x += dx;
- y += dy;
- if (rotation != 0)
- {
- direction = (direction + rotation) % 360;
- }
- if (x < 0)
- {
- x = Program.FRAME_WIDTH;
- }
- else if (x > Program.FRAME_WIDTH)
- {
- x = 0;
- }
- if (y < 0)
- {
- y = Program.FRAME_HEIGHT;
- }
- else if (y > Program.FRAME_HEIGHT)
- {
- y = 0;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement