Cookie Consent by Free Privacy Policy Generator 📌 Tetris Development 2 - Intro to Godot and Basic Tetris Setup


✅ Tetris Development 2 - Intro to Godot and Basic Tetris Setup


💡 Newskategorie: Programmierung
🔗 Quelle: dev.to

Time to start developing in Godot!

Having watched a few quick tutorial videos on how Godot worked, I began setting up my first scene.

Image description

Since the Tetris game is played in a grid, my scene began with a TileMap, which allows me to set a 10x20 tilemap (essentially a grid) for the game. I followed a beginner's guide to Tetris in Godot video to complete this step.

The tutorial video then proceeded to create Tetris blocks for the game. In the video, the developer used individual variables for the vertex positions for each of the 7 different blocks, and the code looks something like this:
Image description

And this piece of code is repeated 7 times with minimal changes! ("How horrendous!" is what my software engineering module professors would say, if they ever see this coding style)

Therefore, as something of a Software Engineer myself, I decided to embrace the Object Oriented Programming Principles, and re-implement this code using inheritance and polymorphism. Thus began the long research into OOP in Godot...

OOP for Tetris in Godot

First of all, there has to be a Base Tetris class. This class declares (only the names, without values) a few variables, including the current vertice positions of the Tetris block, the 4 possible orientations of this block, as well as the current rotation angle. Each child class (e.g. Tetris_L for L-shaped Tetris blocks) will then define their own values for these variables when they are instantiated with _ready().

The base class also has a function rotate(), which rotates the Tetris block clockwise by updating its vertices and angle accordingly.

With the classes set up, I implemented a function to draw Tetris blocks on the tilemap. It is surprisingly simple: Simply instantiate a Tetris child class, grab its coordinates variable, and set the corresponding coordinates on the TileMap to a random color!

With the blocks ready, the next step is to make them start moving!

Lessons Learned

  1. Instantiating a class in Godot: I have encountered two types of files in Godot so far. One is the .tscn files, which are for scenes, and another is the .gd files, which are for GD scripts. The classes are in .gd files, which must be instantiated with .new(), instead of with .load() and instantiate() which is for scenes.

  2. The _ready() function: In the GDScript, there exists a _ready() function. Initially, I treated it as an equivalent function to __init__() in Python and Java, though after some debugging I found that there exist some subtle differences. In Python for instance, the init() functions for classes are called immediately when the class objects are instantiated. On the other hand, for GDScript objects, _ready() is only called when the object enters the scene tree, so you have to get the scene tree and add_child() to it before your instantiated object is fully instanced. I was stuck on this for a while wondering why my instanced objects did not have the updated variable values I defined in their _ready() functions, but now we know!

...

✅ Tetris Development 3 - Simple Tetris Game in Godot


📈 50.02 Punkte

✅ Godot Engine - Godot 3.1 is out, improving usability and features


📈 37.47 Punkte

✅ Godot Engine - Godot 3.1 is out, improving usability and features


📈 37.47 Punkte

✅ Godot’s Graduation: Godot moves to a new Foundation


📈 35.95 Punkte

✅ Game Development and Multimedia: Godot Engine, A Game-Changer in Game Development


📈 32.66 Punkte

✅ Tetris Effect: Sony bringt das Hypno-Tetris


📈 25.46 Punkte

✅ As Tetris Turns 35, Here’s How to Play Tetris in the Terminal


📈 25.46 Punkte

✅ Erster Tetris-Trailer: Apple zeigt die Geschichte von Tetris als Spionage-Thriller


📈 25.46 Punkte

✅ »Tetris«-Rekord: 13-Jähriger stellt mit der Trommelmethode »Tetris«-Rekord auf


📈 25.46 Punkte

✅ Godot Game Development – Crash Course for Beginners


📈 24.56 Punkte

✅ Learn Godot for Game Development


📈 24.56 Punkte

✅ W4 Games raises $15M to drive video game development inflection with Godot Engine


📈 24.56 Punkte

✅ Why Godot is a Game Changer in Game Development


📈 24.56 Punkte

✅ This week in Open Source - Linux Tablet and mini PC, Godot 4, FFmpeg 6, and more


📈 21 Punkte

✅ Tetris Development #4 - Stop, Drop (and Roll?)


📈 20.83 Punkte

✅ Tetris Development #6 - Risk and Reward


📈 20.83 Punkte

✅ How to setup Wifi Pineapple Tetra and Basic Attack


📈 20.67 Punkte

✅ How to setup Wifi Pineapple Tetra and Basic Attack


📈 20.67 Punkte

✅ An Introduction to the Go Programming Language: Setup, Syntax, and Basic Concepts


📈 20.67 Punkte

✅ Creator of Ruby on Rails shows off his new Ubuntu setup, and lets you copy his setup with one command.


📈 19.97 Punkte

✅ Medium CVE-2017-17600: Basic b2b script project Basic b2b script


📈 19.84 Punkte

✅ Medium CVE-2017-17642: Basic job site script project Basic job site script


📈 19.84 Punkte

✅ Could We Fund a Universal Basic Income with Universal Basic Assets?


📈 19.84 Punkte

✅ Low CVE-2012-5570: Basic webmail project Basic webmail


📈 19.84 Punkte

✅ Basic Reverse Engineering | TryHackMe Basic Malware RE


📈 19.84 Punkte

✅ Chipmunk Basic 1.368.22 - BASIC interpreter.


📈 19.84 Punkte

✅ Godot Engine up to 3.2 TGA Image File and/or load_image stack-based overflow


📈 19.49 Punkte

✅ Conquest - An open source strategy game similar to Risk and written in Godot.


📈 19.49 Punkte

✅ Godot 3.5.1 - Free and open-source game engine.


📈 19.49 Punkte

✅ I tried Godot for few days and this is why I like it!


📈 19.49 Punkte

✅ Top five Godot games and source code from Game Off 2022


📈 19.49 Punkte

✅ Godot Tutorial for Unity Developers (and other beginners)


📈 19.49 Punkte











matomo

Datei nicht gefunden!