Game Programming - Episode 41 - Player

The Cherno · Intermediate ·🧒 Coding for Kids ·13y ago

Key Takeaways

The video covers the creation of a player class in Java, extending the mob class, and implementing constructors, update, and render methods for game development.

Full Transcript

hey what up guys My Name Is AO welcome to episode 41 of game programming so this time we're going to take a look at a very simple episode just taking a look at what the player class is what it does and how it works so um we've sort of created this like this framework of um this hierarchy really of of all these sub classes and they they all sort of get back from entity right entity is like the the root the mother of all freaking things entities I guess um but yeah so the entity is like it's like the head right it's the top and then we sort of go down to mob and then from Mob We Branch off to you know mobs so in other words a mob I said last time was basically a character or you know like a character yeah so it could be the player it could be other players it could be animals anything basically anything that moves um something something that's mobile so if we're actually on over here in our Navigator uh right on the folder if we right click hit new in class we can actually create a new player class we're going to call this player and it would probably just be in the mob um we could probably put it in its own package but I'm just thinking right now I don't think I will though just because um just because you know there's probably not going to be any sub classes to player there's not going to be any anything related to player that's going to be in the player folder so if there's nothing in it might as well just createit it in the mob folder so we'll just hit finish and here we go so public class player first thing we need to do is make sure that it extends mob um and because it's in the same class we won't even have to import that and we need a few things here but I'm just thinking I might save them for another episode so that I sort of you know so that I sort of cover um each Episode by a subject not multiple subjects um so what I will do though is probably uh well it need a Constructor first of all there is going to be a Constructor with X and Y um there's we're going to be a another Constructor with nothing and that's going to be it for Constructors now um X and Y why is there a Constructor with X and Y um the reason is sometimes players need to be created at a specific location so public player might just create a player at um at a default location like a spawning location but sometimes you know for whatever reason um the reason I'm thinking of right now is like in Realm of the Mad God when do you enter a different realm you actually you know you appear at a specific like spawn point right and what happens is you know I obviously I don't know the actual code to Realm of the Mad guard um but I would imagine what happens is you as you play a unit it despawns from the previous realm it loads the new realm into the game and then it finally it creates a new player object for you um at a particular location because obviously you basically know that every time you spawn you sort of spawn in at a different location so as a Creator set new location um it this created at X and Y y so um if we go back to our entity thing that is really the place that has X and Y so in other words we obviously don't need to create int X and int y we don't actually need to create those variables in the player class we can simply just say that this dox = x and this. y = y and that's it because this.x if we actually control click on it on that it'll take us back to to The Entity class so we can see where the variable is actually defined so that's brilliant um the other thing is for this thing um we'll talk about that in another episode because again I don't want to you know deal with half a subject in one video and then you know come back to the same subject in another video I sort of want to cover one subject matter in one in in in one video so that I'm not you know sort of confusing people and being like all right well we're going to be covering inputs today but um to do that you should watch the previous episode cuz I thought did half of it then no i s of want to do it all in one video okay so um the other things we need is the update method so when whenever we actually hit um whoops public void update when whenever we sort of hit um I don't know an arrow key I don't know basically basically when we move when we hit something on our keyboard we want to play to move so yeah we need an update method and finally a rendom method so yeah um and the render method of course will render our game now few things you can see here here that uh update actually overrides another update um it just put a breakpoint there it actually overrides um if we go to here if we um if we actually control click on this override thing it'll actually take us to it till its rout so update and of course update then overrides the update in our entity thing that's wonderful right what that tells me right away is that we don't actually need to call player. update to update the player however render doesn't override anything and the primary reason is we don't actually have random method in our mob class now whether we will or won't I'm not 100% sure if I actually want to have um a random method in the mob class let me just think quickly mob well all mobs need to random so to be honest I probably will put it here and I'll make it public obviously random method needs to be public so does update just because we will be accessing them um in other in other classes so if we go back here you'll see that a green arrow has appeared meaning that we are actually overriding it from Mob that's brilliant all right so that is the basic structure for our player class um next time we'll probably cover inputs so in other words you can see that if we go back to our game class the way that our player moves you know sort of works over here s of Scrolls the map and it's sort of in in in the game. Java update method um it's not actually moving the player it's sort of just scrolling the screen and you know obviously we're not keeping track of where the player is we're just you know keeping track of X and Y variables we'll move all that into our player class and we will actually probably you know finish up input for the player object so that any any players in our game can actually move you know using the arrow kease for their individual instances but yeah anyway guys I hope you enjoyed this episode of game programming if you did please hit that like button and I will see you guys next time goodbye [Music]

Original Description

Welcome to Game Programming, a series in which we take an in depth look at how to make a game from scratch, in Java. ---------------------------------------------------------------------------------------------------------------- Website: http://www.thecherno.com Twitter: http://www.twitter.com/thecherno Facebook: http://www.facebook.com/thecherno Subreddit: http://www.reddit.com/r/thecherno/ Steam Group: http://www.steamcommunity.com/groups/thecherno ---------------------------------------------------------------------------------------------------------------- Outro music is by Approaching Nirvana: http://www.youtube.com/approachingnirvana
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from The Cherno · The Cherno · 0 of 60

← Previous Next →
1 3D Game Programming - Episode 1 - Window
3D Game Programming - Episode 1 - Window
The Cherno
2 3D Game Programming - Episode 2 - Game Loop
3D Game Programming - Episode 2 - Game Loop
The Cherno
3 3D Game Programming - Episode 3 - Arrays
3D Game Programming - Episode 3 - Arrays
The Cherno
4 3D Game Programming - Episode 4 - Drawing Pixels!
3D Game Programming - Episode 4 - Drawing Pixels!
The Cherno
5 3D Game Programming - Episode 4.5 - How Rendering Works
3D Game Programming - Episode 4.5 - How Rendering Works
The Cherno
6 3D Game Programming - Episode 5 - Playing with Pixels!
3D Game Programming - Episode 5 - Playing with Pixels!
The Cherno
7 3D Game Programming - Episode 6 - Performance Boosting
3D Game Programming - Episode 6 - Performance Boosting
The Cherno
8 3D Game Programming - Episode 7 - FPS Counter
3D Game Programming - Episode 7 - FPS Counter
The Cherno
9 3D Game Programming - Episode 8 - Alpha Support and More
3D Game Programming - Episode 8 - Alpha Support and More
The Cherno
10 3D Game Programming - Episode 9 - Beginning 3D
3D Game Programming - Episode 9 - Beginning 3D
The Cherno
11 3D Game Programming - Episode 10 - Floors and Animation
3D Game Programming - Episode 10 - Floors and Animation
The Cherno
12 3D Game Programming - Episode 11 - Rotation
3D Game Programming - Episode 11 - Rotation
The Cherno
13 3D Game Programming - Episode 12 - User Input
3D Game Programming - Episode 12 - User Input
The Cherno
14 3D Game Programming - Episode 13 - Render Distance Limiter!
3D Game Programming - Episode 13 - Render Distance Limiter!
The Cherno
15 3D Game Programming - Episode 14 - Basic Mouse Movement
3D Game Programming - Episode 14 - Basic Mouse Movement
The Cherno
16 3D Game Programming - Episode 15 - Textures + More!
3D Game Programming - Episode 15 - Textures + More!
The Cherno
17 3D Game Programming - Episode 16 - Walking, Crouching, Sprinting + More
3D Game Programming - Episode 16 - Walking, Crouching, Sprinting + More
The Cherno
18 3D Game Programming - Episode 16.5 - Exporting Runnable Jars
3D Game Programming - Episode 16.5 - Exporting Runnable Jars
The Cherno
19 3D Game Programming - Episode 17 - Small Adjustments + Birthday!
3D Game Programming - Episode 17 - Small Adjustments + Birthday!
The Cherno
20 3D Game Programming - Episode 17.5 - Creating an Applet
3D Game Programming - Episode 17.5 - Creating an Applet
The Cherno
21 3D Game Programming - Episode 18 - The Beginning of Walls
3D Game Programming - Episode 18 - The Beginning of Walls
The Cherno
22 3D Game Programming - Episode 18.1 - A Few More Things
3D Game Programming - Episode 18.1 - A Few More Things
The Cherno
23 Episode 18.5 - Creating an EXE File in Java
Episode 18.5 - Creating an EXE File in Java
The Cherno
24 3D Game Programming - Episode 19 - Rendering Walls
3D Game Programming - Episode 19 - Rendering Walls
The Cherno
25 3D Game Programming - Episode 20 - Continuing Walls, Fixing Bugs, and Managing Crashes
3D Game Programming - Episode 20 - Continuing Walls, Fixing Bugs, and Managing Crashes
The Cherno
26 3D Game Programming - Episode 21 - Texturing Walls, Fixing Clipping, and Fixing the Mouse
3D Game Programming - Episode 21 - Texturing Walls, Fixing Clipping, and Fixing the Mouse
The Cherno
27 3D Game Programming - Episode 22 - Random Level Generator + Properly Fixing Clipping
3D Game Programming - Episode 22 - Random Level Generator + Properly Fixing Clipping
The Cherno
28 3D Game Programming - Episode 23 - Graphical User Interface (GUI) Launcher
3D Game Programming - Episode 23 - Graphical User Interface (GUI) Launcher
The Cherno
29 3D Game Programming - Episode 24 - Making Our Launcher Work
3D Game Programming - Episode 24 - Making Our Launcher Work
The Cherno
30 3D Game Programming - Episode 25 - Writing and Reading Files
3D Game Programming - Episode 25 - Writing and Reading Files
The Cherno
31 3D Game Programming - Episode 26 - Custom Resolutions
3D Game Programming - Episode 26 - Custom Resolutions
The Cherno
32 3D Game Programming - Episode 27 - Decorating the Launcher
3D Game Programming - Episode 27 - Decorating the Launcher
The Cherno
33 3D Game Programming - Episode 28 - Continuing our Custom Launcher!
3D Game Programming - Episode 28 - Continuing our Custom Launcher!
The Cherno
34 3D Game Programming - Episode 29 - Launching The Game
3D Game Programming - Episode 29 - Launching The Game
The Cherno
35 3D Game Programming - Episode 30 - Colour Processing In-Depth
3D Game Programming - Episode 30 - Colour Processing In-Depth
The Cherno
36 3D Game Programming - Episode 31 - Sprites!
3D Game Programming - Episode 31 - Sprites!
The Cherno
37 3D Game Programming - Episode 32 - Sprite Mapping
3D Game Programming - Episode 32 - Sprite Mapping
The Cherno
38 3D Game Programming - Episode 33 - High Resolution Rendering
3D Game Programming - Episode 33 - High Resolution Rendering
The Cherno
39 3D Game Programming - Episode 34 - Entities
3D Game Programming - Episode 34 - Entities
The Cherno
40 Genesis - My Game for Ludum Dare 24
Genesis - My Game for Ludum Dare 24
The Cherno
41 Vlog + Ludum Dare Results
Vlog + Ludum Dare Results
The Cherno
42 Game Programming - Episode 1 - Resolution
Game Programming - Episode 1 - Resolution
The Cherno
43 Game Programming - Episode 2 - Threads
Game Programming - Episode 2 - Threads
The Cherno
44 Game Programming - Episode 3 - Game Loop
Game Programming - Episode 3 - Game Loop
The Cherno
45 Game Programming - Episode 4 - Window
Game Programming - Episode 4 - Window
The Cherno
46 Episode 5 - Buffer Strategy
Episode 5 - Buffer Strategy
The Cherno
47 Game Programming - Episode 6 - Graphics Initialized
Game Programming - Episode 6 - Graphics Initialized
The Cherno
48 Game Programming - Episode 7 - Buffered Image and Rasters
Game Programming - Episode 7 - Buffered Image and Rasters
The Cherno
49 Game Programming - Episode 8 - The Screen Class
Game Programming - Episode 8 - The Screen Class
The Cherno
50 Game Programming - Episode 9 - Rendering Pixels
Game Programming - Episode 9 - Rendering Pixels
The Cherno
51 Game Programming - Episode 10 - Clearing the Screen
Game Programming - Episode 10 - Clearing the Screen
The Cherno
52 Game Programming - Episode 11 - "Out of Bounds, Baby!"
Game Programming - Episode 11 - "Out of Bounds, Baby!"
The Cherno
53 Game Programming - Episode 12 - Negative Bounds
Game Programming - Episode 12 - Negative Bounds
The Cherno
54 Game Programming - Episode 13 - Timer
Game Programming - Episode 13 - Timer
The Cherno
55 Game Programming - Episode 14 - FPS Counter
Game Programming - Episode 14 - FPS Counter
The Cherno
56 Episode 15 - Tiles
Episode 15 - Tiles
The Cherno
57 Game Programming - Episode 16 - The Map
Game Programming - Episode 16 - The Map
The Cherno
58 The Walls 2 - Minecraft PvP Survival Map
The Walls 2 - Minecraft PvP Survival Map
The Cherno
59 Game Programming - Episode 17 - Key Input
Game Programming - Episode 17 - Key Input
The Cherno
60 Game Programming - Episode 18 - Controlling The Map
Game Programming - Episode 18 - Controlling The Map
The Cherno

This video teaches how to create a player class in Java for game development, covering constructors, update, and render methods. It's part of a series on game programming from scratch.

Key Takeaways
  1. Create a new player class extending the mob class
  2. Implement constructors with X and Y coordinates
  3. Override the update method to handle player movement
  4. Implement a render method to display the player
  5. Use the player class in the game loop
💡 The player class should extend the mob class and override the update method to handle player-specific movement and rendering.

Related AI Lessons

Up next
Man Builds a Backyard Tiny House and Turns It into a Home Office | Start to Finish by @Elseweyr
AKLA GELEN
Watch →