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