Add project files.

master
BuildTools 5 years ago
parent 304a858324
commit f161ed3b85
  1. 47
      Program.cs
  2. 69
      ball.cs
  3. 39
      callbacks.cs
  4. 22
      collisionHandler.cs
  5. 12
      game.csproj
  6. 25
      game.sln
  7. 17
      globals.cs
  8. 23
      mouse.cs

@ -0,0 +1,47 @@
using System;
using SFML.Audio;
using SFML.Graphics;
using SFML.Window;
using SFML.System;
using System.Net;
using System.Threading;
using System.Collections.Generic;
namespace game
{
class Program
{
static void Main(string[] args)
{
RenderWindow window = new RenderWindow(new VideoMode(1280, 720), "test", Styles.Default);
callbacks.registerCallbacks(window);
CircleShape cursor = new CircleShape(25f);
cursor.FillColor = Color.Green;
ball_t ball = new ball_t(50f);
ball_t ball2 = new ball_t(50f, new Vector2f(100, 100), new Vector2f(1f, .5f));
// main loop
while (window.IsOpen)
{
window.DispatchEvents();
cursor.Position = new Vector2f(g.mouse.position.X - (cursor.GetLocalBounds().Width / 2), g.mouse.position.Y - (cursor.GetLocalBounds().Height / 2));
if (g.mouse.button == Mouse.Button.Left && g.mouse.buttonState)
cursor.FillColor = Color.Red;
else
cursor.FillColor = Color.Green;
window.Clear();
// add stuff to drawing surface
window.Draw(cursor);
ball.Run(window);
ball2.Run(window);
window.Display();
}
}
}
}

@ -0,0 +1,69 @@
using System;
using SFML.Audio;
using SFML.Graphics;
using SFML.Window;
using SFML.System;
using System.Net;
using System.Threading;
namespace game
{
class ball_t
{
public CircleShape shape;
public Vector2f velocity;
public ball_t(float radius)
{
this.shape = new CircleShape(radius);
this.shape.Position = new Vector2f(1280 / 2, 720 / 2);
this.velocity = new Vector2f(.5f, .5f);
collisionHandler.registry.Add(this);
}
public ball_t(float radius, Vector2f position)
{
this.shape = new CircleShape(radius);
this.shape.Position = position;
this.velocity = new Vector2f(.5f, .5f);
collisionHandler.registry.Add(this);
}
public ball_t(float radius, Vector2f position, Vector2f velocity)
{
this.shape = new CircleShape(radius);
this.shape.Position = position;
this.velocity = velocity;
collisionHandler.registry.Add(this);
}
private void RunPhysics(Vector2f forces)
{
//temp place for collision stuff
Vector2f center = new Vector2f(this.shape.Position.X + (this.shape.GetLocalBounds().Width / 2), this.shape.Position.Y + (this.shape.GetLocalBounds().Height / 2));
bool isValidPosition = ((center.X > (1280 - (this.shape.GetLocalBounds().Width / 2)) || center.Y > (720 - (this.shape.GetLocalBounds().Height / 2))) || (center.X < (0 + (this.shape.GetLocalBounds().Width / 2)) || center.Y < (0 + (this.shape.GetLocalBounds().Height / 2))));
if (isValidPosition || collisionHandler.isColliding(this))
{
//this.shape.Position = new Vector2f(1280 / 2, 720 / 2);
this.velocity *= -1;
this.velocity /= 2f;
this.shape.Position += new Vector2f(0, -1F);
this.shape.Position = new Vector2f(Math.Clamp(this.shape.Position.X, 0, 1280), Math.Clamp(this.shape.Position.Y, 0, 720));
Console.WriteLine("COLLISION: "+this.velocity.Y.ToString());
}
Vector2f oldPosition = this.shape.Position;
this.shape.Position += this.velocity;
ball_t dummy = this;
dummy.shape.Position = this.shape.Position;
if (collisionHandler.isColliding(dummy))
{
this.shape.Position = oldPosition;
this.velocity *= -1;
this.velocity /= 2f;
}
if ((Math.Abs(this.velocity.X) < 1 ) && (Math.Abs(this.velocity.Y) < 1))
this.velocity += forces;
}
public void Run(RenderWindow window)
{
RunPhysics(new Vector2f(0f, 0.000002f * this.shape.Radius));
window.Draw(this.shape);
}
}
}

@ -0,0 +1,39 @@
using System;
using SFML.Audio;
using SFML.Graphics;
using SFML.Window;
using SFML.System;
using System.Net;
using System.Threading;
namespace game
{
class callbacks
{
public static void CallbackClose(object sender, EventArgs e)
{
RenderWindow window = (RenderWindow)sender;
window.Close();
}
public static void CallbackMouseMoved(object sender, MouseMoveEventArgs e)
{
g.mouse.position = new Vector2f(e.X, e.Y);
}
public static void CallbackMousePressed(object sender, MouseButtonEventArgs e)
{
g.mouse.button = e.Button;
g.mouse.buttonState = true;
}
public static void CallbackMouseReleased(object sender, MouseButtonEventArgs e)
{
g.mouse.buttonState = false;
}
public static void registerCallbacks(RenderWindow window)
{
window.Closed += new EventHandler(callbacks.CallbackClose);
window.MouseMoved += new EventHandler<MouseMoveEventArgs>(callbacks.CallbackMouseMoved);
window.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(callbacks.CallbackMousePressed);
window.MouseButtonReleased += new EventHandler<MouseButtonEventArgs>(callbacks.CallbackMouseReleased);
}
}
}

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
namespace game
{
static class collisionHandler
{
public static List<ball_t> registry = new List<ball_t>();
public static bool isColliding(ball_t ball)
{
foreach (ball_t registeredBall in registry)
{
if (registeredBall != ball && registeredBall.shape.GetGlobalBounds().Intersects(ball.shape.GetGlobalBounds()))
return true;
}
return false;
}
}
}

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SFML.Net" Version="2.5.0" />
</ItemGroup>
</Project>

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29926.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "game", "game.csproj", "{315B7D3F-46D7-4E12-A2A0-32A24994F484}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{315B7D3F-46D7-4E12-A2A0-32A24994F484}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{315B7D3F-46D7-4E12-A2A0-32A24994F484}.Debug|Any CPU.Build.0 = Debug|Any CPU
{315B7D3F-46D7-4E12-A2A0-32A24994F484}.Release|Any CPU.ActiveCfg = Release|Any CPU
{315B7D3F-46D7-4E12-A2A0-32A24994F484}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6A2AEA8E-88AD-41C2-8550-2ADCE8FD5E98}
EndGlobalSection
EndGlobal

@ -0,0 +1,17 @@
using System;
using SFML.Audio;
using SFML.Graphics;
using SFML.Window;
using SFML.System;
using System.Net;
using System.Threading;
namespace game
{
static class g// a5 moment// ok thats not funny
{
public static mouse_t mouse = new mouse_t();
public static Random rand = new Random();
}
}

@ -0,0 +1,23 @@
using System;
using SFML.Audio;
using SFML.Graphics;
using SFML.Window;
using SFML.System;
using System.Net;
using System.Threading;
namespace game
{
class mouse_t
{
public Vector2f position;
public Mouse.Button button;
public bool buttonState;
public mouse_t()
{
this.position = new Vector2f(0, 0);
this.button = Mouse.Button.Left;
this.buttonState = false;
}
}
}
Loading…
Cancel
Save