GithubHelp home page GithubHelp logo

gdquest-demos / godot-3-beginner-2d-platformer Goto Github PK

View Code? Open in Web Editor NEW
357.0 25.0 96.0 442 KB

Learn to create a 2d platform game with the Godot game engine. This is a beginner programming tutorial.

License: MIT License

GDScript 59.16% C# 40.84%
godot-game-engine 2d-platform-game programming-tutorial gdscript godot godot-engine

godot-3-beginner-2d-platformer's Introduction

Your First Game Godot 2d Platformer

This is the complete Open Source Project for our upcoming free beginner Godot 2D Platformer course. It will show you how to create your first Godot game from start to finish.

➡ Follow us on Twitter and YouTube for free game creation tutorials, tips, and news! Get one of our Godot game creation courses to support our work on Free Software.

The game you'll create

What you'll learn

  • Build a platform game with connected levels, pass through platforms, coins, enemies…
  • Design a title screen, pause menu, and score counter
  • Learn some good Godot programming practices to keep your projects organized

Prerequisites

  • You will need some basic understanding of GDScript, which we cover in our introduction to GDScript. GDScript is the programming language you will use in Godot to code your games.

We also recommend reading the great step-by-step guide in the official Godot docs, if you haven't already.

Godot 4

This course was originally made with Godot 3. Since then, there have been several changes to the engine code. If you'd like to run this project with Godot 4, a port is available in the godot4-game folder.

Currently, this port only exists for the GDScript version of the project. The C# version has yet to be ported.

How to get this free course

The course will come out on our YouTube channel at the end of September. To get it, subscribe to the GDQuest channel and click the notification bell to know when it is out.

We will also release a free introduction to steering behaviours soon, designed to be beginner-friendly as well!

Support gdquest

This free series is sponsored by our platformer game creation course.

GDQuest is a social company focused on education and bringing people together around Free Software.

We share the techniques professionals use to make games and open source the code for most of our projects on our GitHub page.

You can:

godot-3-beginner-2d-platformer's People

Contributors

brno32 avatar cuong0993 avatar henriiquecampos avatar nathanlovato avatar rkinson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

godot-3-beginner-2d-platformer's Issues

Play and Quit button bug after returning to Main Menu

@NathanLovato
Play a new game.
Get killed.
Click MainScreenButton - Note MainScreenButton didn't work until I set the Next Scene Path to "res://src/Screens/MainScreen.tscn") See #28
The Play and Quit buttons don't do anything.

This bug (minus #28) exists in the free Youtube tutorial if you follow along coding as you go.

Add Basic Enemies

Enemies will have a basic physics implementation, moving left or right and changing their movement direction when they hit a wall, no AI whatsoever.

  • Gravity
  • Walking
  • Bouncing when hitting a wall
  • Kill Player

@NathanLovato can we add support for VisibilityEnabler on them, so they only start moving when they are inside the screen?

This bug

I'm submitting a bug

E 0:00:18.391 emit_signal: Error calling method from signal 'body_entered': 'KinematicBody2D(Player.gd)::_on_Area2D_body_entered': Method not found..

<C++ Source> core/object.cpp:1260 @ emit_signal()

Fix Level transition

Currently the way we change between one level to another is by freeing the current and loading the next level manually, as mentioned in #1 we could simply just call get_tree().change_scene instead, like Portal2Ds were designed to do.

Regarding the interface we just need to add it to have it on both scenes, currently PlayScreen has the Levels, but we can invert this relationship somehow.

That was what I was talking about Friday, @razcore-art

Add Mario Stomp

When the Player jumps on enemies' heads, they should die.

  • Player's StompArea2D
  • Enemies' StompableArea2D

These Area2Ds will be both One way collisions, Player's will be rotated 180 degrees to make sure the collision only happens from a Vector2(0, -1) collision normal

Godot 4

Would you accept a PR that updates this project for Godot 4?

MainScreen paused and Score persists on Play Again

When entering the MainScreen from the Pause Menu Main Screen Button, the MainScreen is paused. I fixed this by adding the same script present in the Retry Button (get_tree().paused = false)

When you click Play Again on the EndScreen, the Score of the ended game persists on the new game. I fixed this by adding the script "PlayerData.score = 0"

Not Really a bug...

Hi, Thanks for sharing ur tutorial :)
I think there is a little issue with the game, if u have a score and then u go to the level 2,when u select retry in the pause menu, ur score will reset to zero and not to the start score of the level.
so may be the retry button have to point at the first scene and not reload the current scene Or
we can implement a variable. But it's not really a bug but a way of thinking the retry function.

So i've implemented the retry button like this:

extends Button

onready var start_score: = PlayerData.score

func _on_button_up():
PlayerData.score = start_score
get_tree().paused = false
get_tree().reload_current_scene()

what do u think?
(srry for my bad english)

Best regards,
Kyo

Project goal and scope

This is a game demo and tutorial series for programming beginners. The goal is to guide the viewer through the process of creating a simple 2d platform game, and creating their first game.

The viewer should have some tiny programming foundations. You can assume they went through scripting in the official docs, and/or our gdscript intro

The demo should feature a complete game loop with:

  • A playable character that can move, jump, and walk on slopes, with a basic camera
  • A single enemy type like Mario's goombas, that moves forward and turns around when it hits a wall, the player can jump on it to kill it or die otherwise
  • Collectible coins, with a counter on screen
  • Two tiny, tile-based level, using change_scene to move between them
  • Static start and game over screen

And no extras. You can use debug scripts or anything for yourself, but please don't add any extra autoload or utilities to the final game. This is going to be a complete step-by-step series.

Target audience

Programming beginners, from ~13 years old. People who have little to no programming experience and experience with Godot.

Game feel

Keep it simple. No input recording, no physics manipulations on walls. Decent controls in hand: the character should move well, offer a bit of air control, but that's about it.

Code style

The code should be well-structured and clean as usual, using clear variable and method names, splitting the content of physics process into several methods to make it easy to read. But try to keep the code dead simple.

We're still going with typed gdscript and the code order we use in our style guide, so it's consistent with the rest of our projects. But you should not use programming patterns like state, command, etc.

Issue: lose all score when retry level

Not sure if this has been addressed but I notice in my game after completing a couple of levels and I die and retry, all score is lost from previous levels, I fixed this by adding another variable to PlayerData "level_score" with a setget and make ememys and coins add there score to this, then I add the level score to the total score in the portal and make the user interface add the scores for display "score.text = "Score: %s" % str(PlayerData.score+PlayerData.level_score)"

now when I die I only lose the score for that level.

Fantastic tutorial BTW

Bug if back main menu and click button play

func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("pause") and pause_title.text != DIED_MESSAGE:
self.paused = not paused
scene_tree.set_input_as_handled()

Portal Interrupted by Enemy Collision

Bug report

What is the current behavior?
The Player enters the Portal and the scene begins to fade out / change to the next scene. This process is interrupted, however, if an Enemy collides with the Player during the fade out, resulting in the Player's death. Since the Portal scene transition is relatively slow, there is a decent window of time in which the Enemy can collide with you.

You can (barely) see the Pause/Player Died menu overlay through the mostly-opaque ColorRect that was fading in-- screenshot attached.

What is the expected behavior?
Ideally, entering the Portal should pause any enemies on the current level.

Tell us the steps to reproduce the bug, and if possible share a minimal demo of the problem.

  1. Position your Player near the level's Portal.
  2. Wait for an Enemy to approach, and enter the Portal shortly before collision with the Enemy
  3. Watch as chaos ensues ;)

I coded along step-by-step with the Youtube series, just FYI

Screen Shot 2020-01-19 at 10 49 13 AM

Add Coins

Coins are Area2D and serve as a reward for the player. When the player collides with them they will be freed and the player will score.

  • Add Coins Area2D
  • Add support for scoring
  • Add Player's CoinPickupArea2d, an Area2D dedicated to detect collisions with Coins

@NathanLovato can we add a PopLabel to them, so that when the player picks one, they pop a label on the screen with how much the player scored?

Add Main Menu, Play and Game Over Screens

Two basic screens to close the game loop. The Main Menu Scene will have 2 buttons, play and quit, the Game Over Screen will have a label with the player's score and two buttons: retry and quit. The Play Screen is a combination of #8 and #7.

  • Add Main Menu Screen
  • Add Play Screen
  • Add Game Over Screen
  • Add support for scene transition

Add Level's Goal

The Level's Goal is an Area2d the player must reach to finish a level, it will then trigger the transition to the next screen

  • Add Transition
  • Add Area2D Goal

MainScreen Menu Not Working

I'm submitting a...

  • Bug report.
  • Feature request.

Bug report

What is the current behavior?
MainScreen menu not working when the player pauses de game clicks MainScreen then the buttons on that screen don't work.

What is the expected behavior?
To be able to play the game or quit

Tell us the steps to reproduce the bug, and if possible share a minimal demo of the problem.

  1. Start the game
  2. Click play.
  3. Pause the game
  4. Click MainScreen
  5. Click play or quit

Sometimes Enemy doesn't die after player bounce

I'm submitting a...

  • Bug report.
  • Feature request.

Bug report

What is the current behavior?
At times, when you jump on the enemy, the enemy doesn't die but you still bounce off of them.

What is the expected behavior?
When you bounce off an enemy, it should die all the time.

Tell us the steps to reproduce the bug, and if possible share a minimal demo of the problem.

  1. Jump towards enemy
  2. Try to clip the top left part of the enemies area2d box with the bottom right corner of the player

Another way you can trigger this is if the enemy is falling (not sure if falling enemy does anything extra)

Add Player Movement

Player character will move with instant acceleration, e.g. going from zero to max speed instantly. Player can also jump and cancel the jump, i.e. the longer the player holds the jump button the higher the jump, still limited by the initial impulse.

  • Gravity
  • Walk
  • Jump

Consider how coin scoring is done

At the moment the coins have a set score value and enemies also have a score on kill.

My proposal would be to make it more Mario-like where the enemies drop coins and instead of a general score board we could use the number of coins collected.

What do you think?

Add Levels

Levels are build up of Tilemaps, and as such of Tilesets. We will have support for One Way Collision platforms, to introduce this feature and later use it in #4

  • Create Tileset with an One Way Collision Tile
  • Create First Level
  • Create Second Level
  • Assemble areas, actors and objects

EndScreen wont Expand

You forgot to turn on "Expand" to true and to set "Strech Mode" to Scale on Expand(compact) in the EndScreen scene.

Add Interface

A very simple Interface to display how many Coins (#6) the player collected, how many are still missing, and the player's current score.

  • Add Basic Interface
  • Link Interface with player and level's data

Bug

Bug: When I'm playing a game, I pause the game, click the home screen, and I'm on the home screen, but the buttons don't work
Zrzut ekranu 2022-11-13 161859
Zrzut ekranu 2022-11-13 162001

Back to the menu does not work

When I playing the game and then pause the game - button "Back to main screen" didn't working.

And thanks for awesome tutorial - it helped me a lot! :)

Death counts reset when retrying

Since we have the reload_scene logic on the RetryButton now, always calling PlayerData.reset() the player's death count is always reset, making so that at the End Screen the player always has 0 deaths.

Previously only the End Screen made a full PlayerData.reset(), while the UserInterface' just set the PlayerData.score = 0 when its RetryButton was pressed

Sometimes the player "stomps" but the enemy doesn't die

For some reason _on_Area2D_area_entered() gets (correctly) triggered when the Player stomps on the Enemy while _on_StompArea2D_body_entered() doesn't get triggered at all. This seems like a Godot bug, but we'll need to find a workaround anyway. Might have to do with the fact that we're using SegmentShape as the collision shape resource. Will have to investigate.

This can be reproduced easily in my fork: https://github.com/razcore-art/Your-First-Game-Godot-2d-Platformer/tree/feature-artwork, the "artwork" branch by having the player always move to right & jump on the platform falling on the enemy. We can see that the player correctly jumps up but the enemy doesn't die.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.