Jump to content
  • Advertisement

Leaderboard


Popular Content

Showing content with the highest reputation on 02/09/19 in all areas

  1. 4 points
    Ray Tracing Gems, a book with the goal of educating developers at all levels about important concepts and the state of the art in ray tracing, is due to be released mid-March in hardback form, but the contents are being made available at no cost as the chapters reached a finished state in the weeks leading up to the hardbook release. Today NVIDIA Developer Zone posted Part II of the book here. Keep an eye on the book's page as the schedule shows new parts released every few days until February 25, 2019.
  2. 2 points
    Step-by-step instruction of Snake 2D using C#, WinForms, GDI+ Let's make a very simple classic snake game. For example, if we have a snake head with 10x10 pixels then we will move our snake by a step with 10 pixels using timer. This is the result of our work: Note. I take ideas from this tutorial: Python Snake Game We can set a game field size like this: // Set a game field size ClientSize = new Size(200, 200); Let's create a method for drawing of a rectangle: private void DrawRect(int x, int y, Color color, int size = 10) { Graphics g = CreateGraphics(); SolidBrush brush = new SolidBrush(color); g.FillRectangle(brush, new Rectangle(x, y, size, size)); brush.Dispose(); g.Dispose(); } Each game must have a game loop that will be called by timer. I created the GameLoop method that just prints "Hello, World!" to the debug console every 500 ms: public Form1() { InitializeComponent(); // Set a game field size ClientSize = new Size(200, 200); // Create a timer for the GameLoop method var timer = new Timer(); timer.Tick += GameLoop; timer.Interval = 500; timer.Start(); } private void GameLoop(object sender, System.EventArgs e) { System.Console.WriteLine("Hello, World!"); } For a while our GameLoop will have only two called methods Update() and Draw(). The Update() method will have updates for snake cell coordinates and etc. The Draw() method will have only draw methods for game entities. For example: private void GameLoop(object sender, System.EventArgs e) { Update(); Draw(); } private void Update() { Console.WriteLine("Game entities coords was updated"); } private void Draw() { DrawFood(); DrawSnake(); } private void DrawSnake() { Console.WriteLine("Snake was drawn"); } private void DrawFood() { Console.WriteLine("Food was drawn"); } List data structure is ideal for keeping snake cells coordinates: // Snake list of (x, y) positions private List<Point> _snake = new List<Point>() { new Point(10, 10) }; Point (10, 10) - it is position of the head. It is better to move a general Draw() method call to Form1_Paint() and add Invalidate() call to GameLoop: private void Form1_Paint(object sender, PaintEventArgs e) { Draw(); } private void GameLoop(object sender, System.EventArgs e) { Update(); Invalidate(); } Method for drawing the snake: private void DrawSnake() { foreach (var cell in _snake) { DrawRect(cell.X, cell.Y, Color.Green); } } For moving the snake we need to create the "snakeDir" variable: / Snake movement direction private Point _snakeDir = new Point(10, 0); The snake moving is very simple: you need to add two vectors: the snake head vector position and the snake direction. You add a new vector positions intead of head and remove last element. Please, read comments: private void Update() { // Calc a new position of the head Point newHeadPosition = new Point( _snake[0].X + _snakeDir.X, _snake[0].Y + _snakeDir.Y ); // Insert new position in the beginning of the snake list _snake.Insert(0, newHeadPosition); // Remove the last element _snake.RemoveAt(_snake.Count - 1); } I will explain eating food later. But you can read comments in the code. This is a result code: using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; namespace Snake { public partial class Form1 : Form { // Snake list of (x, y) positions private List<Point> _snake = new List<Point>() { new Point(10, 10) }; // Snake movement direction private Point _snakeDir = new Point(10, 0); // Food private Point _food = new Point(); // Random generator private Random _rnd = new Random(); // Game field size private int _fieldWidth = 200; private int _fieldHeight = 200; // Snake step private int _snakeStep = 10; public Form1() { InitializeComponent(); // Centers the form on the current screen CenterToScreen(); // Set a game field size ClientSize = new Size(_fieldWidth, _fieldHeight); // Generate an initial random position for the food GenerateFood(); // Create a timer for the GameLoop method var timer = new Timer(); timer.Tick += GameLoop; timer.Interval = 200; timer.Start(); } private void Form1_Paint(object sender, PaintEventArgs e) { Draw(); } private void GameLoop(object sender, System.EventArgs e) { Update(); Invalidate(); } private void Update() { // Calc a new position of the head Point newHeadPosition = new Point( _snake[0].X + _snakeDir.X, _snake[0].Y + _snakeDir.Y ); // Insert new position in the beginning of the snake list _snake.Insert(0, newHeadPosition); // Remove the last element _snake.RemoveAt(_snake.Count - 1); // Check collision with the food if (_snake[0].X == _food.X && _snake[0].Y == _food.Y) { // Add new element in the snake _snake.Add(new Point(_food.X, _food.Y)); // Generate a new food position GenerateFood(); } } private void Draw() { DrawFood(); DrawSnake(); } private void DrawSnake() { foreach (var cell in _snake) { DrawRect(cell.X, cell.Y, Color.Green); } } private void DrawFood() { DrawRect(_food.X, _food.Y, Color.OrangeRed); } private void DrawRect(int x, int y, Color color, int size = 10) { Graphics g = CreateGraphics(); SolidBrush brush = new SolidBrush(color); g.FillRectangle(brush, new Rectangle(x, y, size, size)); brush.Dispose(); g.Dispose(); } private void GenerateFood() { _food.X = 10 * _rnd.Next(0, _fieldHeight / 10 - 1); _food.Y = 10 * _rnd.Next(0, _fieldHeight / 10 - 1); } private void Form1_KeyPress(object sender, KeyPressEventArgs e) { switch (e.KeyChar) { case 'w': _snakeDir.X = 0; _snakeDir.Y = -_snakeStep; break; case 'a': _snakeDir.X = -_snakeStep; _snakeDir.Y = 0; break; case 's': _snakeDir.X = 0; _snakeDir.Y = _snakeStep; break; case 'd': _snakeDir.X = _snakeStep; _snakeDir.Y = 0; break; } } } }
  3. 1 point
    I've been slowly progressing on my boating game over the past few weeks, it's been great that I seem to have a few people interested on youtube, despite me having no firm idea on a game design. I guess once you have water and land and boats you can use it for everything from racing to pirates / trading type games. Physics Physics has (allegedly) improved since my last blog post, instead of taking just one height sample at the centre of a boat I now use 3 samples in a triangle, to get an idea of the normal at the sea surface. This means that boats can now more closely match the surface instead of just up / down. The up / down motion is now working through the physics, rather than my previous approach of running the physics on a level ocean, then applying wave height to the displayed model only. There are disadvantages and advantages to this and it is subject to change. On the plus side it should eventually interact correctly with things like land masses, but currently the impulses to push the boats to sea level cause mad jitter on beaches! Boats also can take off now if you drive them over waves over a certain speed. Skybox First I tried using the world environment to create a skybox in godot, but had very mixed success. It was easy to create a procedural sky but because of the PBR shaders, the boat models etc ended up having a horrible blue colour cast. I tried various methods to get rid of the cast but failed miserably. In the end as I'm not really interested in PBR for this game I changed the world environment just to clear to a blue colour without a skybox, and I created a quick manual skybox in blender which I move around as the camera moves (needs a little tweaking). This looks good enough for my purposes and it means it doesn't get used in the PBR lighting so no colour cast (in fact I suspect it is defaulting to simpler shaders). Moving Origin As I was thinking of maybe having large worlds with a lot of sea to cover, I decided to have a 'moving origin' system to prevent floating point error in physics etc. It is quite easy to put in at an early stage, but more of a nightmare if you leave it till later, so I put it in early. The third person camera is focused on a particular boat at any time (e.g. player), and if that boat moves more than a certain distance from the origin, the whole world resyncs so that the boat is now centred on the origin, and the objects around are all teleported to their offsets from the player. This seems to work fine providing it is done at the correct time in the physics. Land Originally I was thinking of a simple game at sea only, but then realised it would be a lot more flexible to have land too. First I experimented with a simple plane for a beach, with a static collision box underneath it for the physics. I was planning on having a few different variations of beach geography, then stitching them together. The more I experimented the more I got dissatisfied with this approach, as it looked very inorganic, so I brainstormed for some other techniques. The difficulty was as well as looking right the approach had to work efficiently with the physics (and the moving origin). I wondered about using Delauney triangulation with some random points to get some land masses, but having a nice c++ implementation already in my library, I couldn't quite face translating this to gdscript. Plus, how would I handle the physics? Maybe Godot handles some polygon soup, but it would probably not be pretty. Next stop was a heightmap, but again I was worried about the efficiency of the physics and lots of special cases. Then this morning in bed I had a brainwave. Yesterday I had been experimenting and Godot has the ability to automatically build a convex hull physics rep around a mesh. I know from previous experience convex hulls work pretty good with physics, so instead of making e.g. a beach with this technique, why not create an entire island? Maybe I could just place islands on top of each other, interpenetrating, to create more complex coastline? It probably will look awful on the joins but given the ease of implementation this is my current winning technique. I made a quick low poly island in blender this morning, used the 'convex hull' operator in blender to ensure it was convex, UV mapped it and then did a quick texture paint in 3d paint. Whapped it in the game, added a convex hull static collider, and it's working great! Usually in these situations I'd also do procedural texturing but gdscript is a little slow for that, when I tried it in my frogger game, so probably just some manual textures for a few island types will do the trick. Anyway the final result is shown in the video. There might be some physics jiggle on the beach in this, I have to work on the boat physics on land, there seems to be some crazy interpenetration physics bug even in simple circumstances with a box against convex hull, maybe it is a bullet bug or some scaling or epsilon that is wrong.
  4. 1 point
    well done, I am working on a console based snake game.
  5. 1 point
    Look at issue 9: So if you have both EXT_texture_sRGB and EXT_texture_compression_s3tc you should have support for compressed sRGB textures. Looking in glext.h it looks like GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT is the one you want.
  6. 1 point
    LOD can also be used on animated characters, where skinning might be expensive and the cost per vertex higher than with static meshes, and dropping the tri count can be especially beneficial. In addition you can also drop the max bones / vertex at a distance, and even the number of bones (e.g. no need for finger bones if they are 1 pixel on screen). Another totally different type of LOD is imposters, which are awesome if you can get them working. You can also use level of detail schemes on other processing besides graphics (AI / physics).
  7. 1 point
  8. 1 point
    If you expect all your clients to use the same computer architecture, which is often the case, then you really don't need to worry.
  9. 1 point
    Hey Zombie, I'm a big fan of the way newer Mario games are designed. Each level has 4 phases: - Introduction of a new mechanic in a safe area - Learn the mechanic where there is danger - A "Twist" on the mechanic to make it interesting - A tough challenge to test your mastery Check out Game Maker's Toolkit for a better explanation:
  10. 1 point
    That’s fine, and perfectly reasonable, especially if you do a lot of dev without consistent internet. But the OP actually specified “not on his machine” (paraphrased). I’m just pointing out that $7 a month is a trivial expense for something so vital to the development process.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!