Jump to content

chrissx

Member
  • Posts

    2
  • Joined

  • Last visited

Posts posted by chrissx

  1. 23 hours ago, Kamjam66xx said:

    Personally i stay away from python and java and would recommend c/c++ for the simple reason that it is cross platform, low level (so you actually learn important concepts and how everything works), very easy to read syntax (ignoring numerical anamolies and the like), its functional/procedural/object-oriented all in one, it is used in a lot of high paying fields further down the line, concepts from other languages translate to c++ given the different types of programming it can be, and it can be entirely learned by using everything to move around and work with numbers and variables.

     

    I just think that dealing with others prewritten high level stuff is very complex compared to writting it yourself. But you could be very different from me in that aspect. 

     

     

    Well...I think C and C++ might be too hard for beginners, I think C# is a better coice because it combines syntax that is really similar to C with a few high level and concepts, basically it's a better mix between C and Java, the only problems are the forced object-orientation and the - compared to C/C++ - bad performance, but both should not be that big of a concern for a beginner.

  2. using System;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    namespace PokeballBot
    {
        public partial class Form1 : Form
        {
            bool running = false;
    
            public Form1() => InitializeComponent();
    
            void button1_Click(object sender, EventArgs e)
            {
                running = !running;
                button1.Text = running ? "Stop" : "Start";
            }
    
            void Form1_Paint(object sender, PaintEventArgs e)
            {
                if (running)
                {
                    Bitmap screenshot = ScreenshotPokeball;
                    Point ball = GetLoc(Color.FromArgb(201, 60, 76), screenshot);
                    Point pika = GetLoc(Color.FromArgb(248, 208, 80), screenshot);
                    pictureBox1.Image = screenshot;
                    if (ball.X != -1 && ball.Y != -1 && pika.X != -1 && pika.Y != -1)
                        if (pika.X < ball.X)
                            KeyboardPress(68, 7);
                        else if (pika.Y > ball.Y)
                            KeyboardPress(87, 26);
                        else if (pika.X > ball.X)
                            KeyboardPress(65, 4);
                        else if (pika.Y < ball.Y)
                            KeyboardPress(83, 22);
                }
                Invalidate(false);
                Update();
            }
    
            Point GetLoc(Color c, Bitmap croppedGameScreen)
            {
                for (int x = 0; x < croppedGameScreen.Width; x++)
                    for (int y = 0; y < croppedGameScreen.Height; y++)
                        if (AreAboutEqual(c, croppedGameScreen.GetPixel(x, y)))
                            return new Point(x / 16, y / 16);
                return new Point(-1, -1);
            }
    
            bool AreAboutEqual(Color f, Color s) => f.R - 10 < s.R && f.R + 10 > s.R && f.G - 10 < s.G && f.G + 10 > s.G && f.B - 10 < s.B && f.B + 10 > s.B;
    
            static Bitmap ScreenshotPokeball
            {
                get
                {
                    Rect rect = new Rect();
                    GetWindowRect(Process.GetProcessesByName("Pokeball").ToArray()[0].MainWindowHandle, ref rect);
                    Bitmap bmp = new Bitmap(160, 160, PixelFormat.Format24bppRgb);
                    Graphics.FromImage(bmp).CopyFromScreen(rect.left + 19, rect.top + 42, 0, 0, new Size(160, 160), CopyPixelOperation.SourceCopy);
                    return bmp;
                }
            }
    
            [StructLayout(LayoutKind.Sequential)]
            struct Rect
            {
                public int left;
                public int top;
                public int right;
                public int bottom;
            }
    
            static void KeyboardPress(byte vk, byte sc)
            {
                keybd_event(vk, sc, 0, 0);
                keybd_event(vk, sc, 2, 0);
            }
    
            [DllImport("user32.dll")]
            static extern IntPtr GetWindowRect(IntPtr hWnd, ref Rect rect);
    
            [DllImport("user32.dll")]
            static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
        }
    }

    Combined with some some windows forms its a pretty nice bot for this game.

    PokeballBot.exe

×