Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Zuzanno

Pages: [1]
1
General / Re: Where am I meant to change protection level?
« on: April 27, 2020, 05:46:15 am »
It'd be great if you do, A documentation would come handy for those who have no clue on what they're doing, like me LOL thank you

2
DotNet / Re: How do I use pollEvent Method with C#
« on: April 25, 2020, 06:17:40 am »
May you please give some more detailed information on how to do it? I started with sfml soon so I barely understand, and with no documentation, things come to be very difficult

3
DotNet / How do I use pollEvent Method with C#
« on: April 24, 2020, 06:41:00 am »
I'm trying to convert this
while (app.isOpen())
    {
        Event e;
        while (app.pollEvent(e))
        {
            if (e.type == Event::Closed)
                app.close();
        }
From C++ to C#, However, When I'm trying to do the pollevent part I dont see such method, and this is basically the heart of the game I'm making, may someone please tell me what would be a proper way to translate this into C#

4
General / Re: Where am I meant to change protection level?
« on: April 24, 2020, 03:57:05 am »
Do you know where can I find the SMFL Documentation for C#?

5
General / Where am I meant to change protection level?
« on: April 17, 2020, 08:02:53 pm »
Hello everyone, I'm trying to translate the cars game from the "Lets make 16 games in c++" video, form c++ to c# since I'm trying to learn how to and get familiarized with it, however, I've encountered a major problem and it is, My console is saying that  "Program.Car.move() is not accessible due to protection level", however I already made sure that everything is public so I don't know what really is going on here, I'd like to get some help with that and also with the last part of the code which is saying that "you cant convert the type 'double' to 'int' (check if you're missing a conversion)" or something like that /*Sorry I'm using VS in Spanish*/

I'd be really thankful if someone could tell me what's going on asap, friendly reminder, this is my first time using SFML in general and I knew c++ as well as c# so I'm trying to translate it, if something is wrong please point it out too so I can fix it or at least try to! thank you all

using System;
using SFML.Graphics;
using SFML.Window;
using SFML.Audio;
using SFML.System;

namespace SFMLCars
{
    class Program
    {
        const int num = 8;
        static int[,] points = new int[num, 2] {{300, 610},
                      { 1270, 430},
                      {1380,2380},
                      {1900,2460},
                      {1970,1700},
                      {2550,1680},
                      {2560,3150},
                      {500, 3300}};

        public struct Car
        {
            public double x, y, speed, angle;
            public int n;

            public Car(double speed,double angle, int n)
                : this()
            {  
                speed = 2;
                angle = 0;
                n = 0;
            }

            void move()
            {
                x += Math.Sin(angle) * speed;
                y -= Math.Cos(angle) * speed;
            }

            void findTarget()
            {
                double tx = points[n, 0];
                double ty = points[n, 1];
                double beta = angle - Math.Atan2(tx - x, -ty + y);
                if (Math.Sin(beta) < 0)
                {
                    angle += 0.005 * speed;
                }
                else
                {
                    angle -= 0.005 * speed;
                }
                if ((x - tx) * (x - tx) + (y - ty) * (y - ty) < 25 * 25)
                {
                    n = (n + 1) % num;
                }
            }


        };
        static void OnClose(object sender, EventArgs e)
        {
            RenderWindow window = (RenderWindow)sender;
            window.Close();
        }
        static void Main(string[] args)
        {
            RenderWindow app = new RenderWindow(new VideoMode(640,480), "Car Racing Game", Styles.Default);
            app.SetFramerateLimit(60);
            app.SetVerticalSyncEnabled(true);
            app.DispatchEvents();
            app.Clear();
            Texture t1 = new Texture("c://images/background.png");
            Texture t2 = new Texture("c://images/car.png");
            t1.Smooth = true;
            t2.Smooth = true;

           Sprite sBackground = new Sprite (t1);
           Sprite sCar = new Sprite (t2);
           sBackground.Scale = new Vector2f(2, 2);

           sCar.Origin = new Vector2f(22, 22);
           float R = 22f;

            const int N = 5;
            Car[] car = new Car[N];

            for (int i = 0; 0 < N; ++i)
            {
                car[i].x = 300 + (i * 50);
                car[i].y = 1700 + i * 80;
                car[i].speed = 7 + i;
            }

            float speed = 0f;
            float angle = 0f;
            float maxSpeed = 12.0f;
            float acc = 0.2f;
            float dec = 0.03f;
            float turnSpeed = 0.08f;

           int offsetX = 0;
           int offsetY = 0;

            while (app.IsOpen)
            {
                Event e;
                app.Closed += new EventHandler(OnClose);

                app.Display();
            }

            bool up = false;
            bool down = false;
            bool right = false;
            bool left = false;

            if (Keyboard.IsKeyPressed(Keyboard.Key.Up))
            {
                up = true;
            }
            if (Keyboard.IsKeyPressed(Keyboard.Key.Right))
            {
                right = true;
            }
            if (Keyboard.IsKeyPressed(Keyboard.Key.Down))
            {
                down = true;
            }
            if (Keyboard.IsKeyPressed(Keyboard.Key.Left))
            {
                left = true;
            }

            //movement

            if (up && speed < maxSpeed)
            {
                if (speed < 0)
                {
                    speed += dec;
                }
                else
                {
                    speed -= acc;
                }
            }
            if (down && speed >- maxSpeed)
            {
                if (speed > 0)  
                {
                    speed -= dec;
                }
                else
                {
                    speed -= acc;
                }
            }
            if (!up && !down)
            {
                if (speed - dec > 0)
                {
                    speed -= dec;
                }
                else if(speed + dec < 0)
                {
                    speed += dec;
                }
                else
                {
                    speed = 0;
                }
            }
            if (right && speed != 0)
            {
                angle += turnSpeed * speed / maxSpeed;
            }
            if (left && speed != 0)
            {
                angle -= turnSpeed * speed / maxSpeed;
            }

            car[0].speed = speed;
            car[0].angle = angle;

            for (int i = 0; i < N; ++i)
            {
                car[i].move();
            }
            for (int i = 0; i < N; ++i)
            {
                car[i].findTarget();
            }

            for (int i = 0; i < N; ++i)
            {
                for(int j = 0; i < N; ++j)
                {
                    int dx = 0;
                    int dy = 0;
                    while (dx * dx + dy * dy < 4 * R * R)
                    {
                        car[i].x += dx / 10.0;
                        car[i].x += dy / 10.0;
                        car[j].x += dx / 10.0;
                        car[j].x += dy / 10.0;
                        dx = car[i].x - car[j].x;
                        dy = car[i].y - car[j].y;
                    }
                }
            }
        }
    }  
}

Pages: [1]