Game Programming - Episode 18 - Controlling The Map

The Cherno · Intermediate ·🚀 Entrepreneurship & Startups ·13y ago

Key Takeaways

Game programming using Java, implementing keyboard controls for map movement and discussing game development plans.

Full Transcript

hey what's up guys my name is the Cho and welcome to episode 18 of game programming so yesterday we took a look at actually implementing the key Handler class or the keyboard class um which actually uh um we were able to print out true when we pressed the up arrow and false if it was released if it wasn't pressed so um today we're actually going to take a look at actually I guess putting this to use so now obviously we've got a way to actually um gather ke Inus and we can record them but how do we actually use this to animate our our tile our map um and what we'll do first is actually get rid of this um printing thing so we uh we don't we don't do that one one thing that you can actually do is um is actually do this right what you can do is you can actually scan through every single one um so like keys. length right every single one of this keys and what you can do is say if you know keys I uh is true right then what you can actually do is print um system.out do print line you can print the key that is press and this is just like for fun so we can see um which one we print so if we just type this real quick um and and do this what you'll get is oh make sure you print um the we won't exactly know which key but if you actually just print I you'll actually know what which key ID it is so if we print if we go uh up you can see that's key number 38 uh if we had if we hit W that's k87 a is 65 D is 68 s is 83 down is 40 left is 37 39 38 so 37 38 39 so left up right down is how it's rolling but yeah that's just like a little fun little thing um that you can do to actually find out the IDS of the Kee so in other words how this does as you can see we didn't actually get anything if I just open the console here we didn't actually get anything higher than 87 so in other words what I'm saying is 120 should probably be fine now notice if we had put this to 85 and we tried I think it was the wky right well first of all it crashed straight away and the reason it crashed was the up key the WK was simply above that as you can say it's the wky here is 87 and we limited it to 85 so that's a little more in- depth understanding onto why we put 120 here it yeah we just want to we just want to have enough enough variables here enough bullings in this array to actually store in for every every key on our keyboard okay now actually applying this now is um relatively simple all right if we go back into our game. Java class we see that we actually have access to the key class of course through our little um keyboard key uh declaration here now what we can do is we've currently got it moving through this and to actually have it move when we press the appropriate key we can simply type if key do up for our up key equals true right if ky. up um then let's just Yus minus right because that'll actually drag our map up and similarly if I just get rid of this we can do the same thing for all of our other little controls so key. down will be y ++ ky. left will be um x-- and k. WR will be x++ so if we uh if we launch this you'll see um that I'm just pressing the arrow keys now and you can see that our map is indeed moving now it looks like it's actually I can I can see it on my computer it's lagging like crazy even though we're at 2,000 FPS that's because of my screen recorder so if this turns out laggy if this if this turns out laggy for you guys on the video that's uh that's the screen recorder fa okay if you do it yourselves on your computer you should get no lag obviously we're 2,000 frames per second here um but yeah you can see that I'm actually able to uh move myself around the map to my pleasing um simply by adding you know a few lines of code so um so yeah and we can actually uh we can actually start to do something with this now so yeah um I hope you enjoyed this episode of game programming guys if you did please hit the like button and I'll see you guys tomorrow where we'll move on into creating our game actually one quick thing I want to address a lot of people seem to be asking if this game will be multiplayer now I did mention that this game will be like Realm of the Mad good and as you know Realm of the Mad God is multiplayer so yes this game that we're making here rain will be multiplayer okay the idea of the series is to create Realm of the Mad God from scratch simple as that I'm not even going to say a game like Realm of the Mad God because what we're going to do at first is basically create Realm of the Mad God from scratch then from there then from there you know we'll obviously modify it and and um do whatever whatever it is we need to do but one thing that I really wanted to stress real quick guys is that um I really want to involve you guys in this series so when we actually come to designing things and actually you know making core gameplay decisions I'll definitely um get you guys into this and make sure that you guys have a have a say in what you get taught I guess and what what this series really becomes so um yeah anyway that's that's episode which what episode was this uh 18 yep that's episode 18 of game programming guys hope you enjoyed if you did add it to your favorites hit the like button and I'll see you guys see you guys tomorrow with a brand new episode later guys [Music]

Original Description

Support this series and get rewards! ► http://www.patreon.com/thecherno 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
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from The Cherno · The Cherno · 60 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
Game Programming - Episode 18 - Controlling The Map
Game Programming - Episode 18 - Controlling The Map
The Cherno

This video teaches how to implement keyboard controls for map movement in a game using Java and discusses plans for developing a multiplayer game.

Key Takeaways
  1. Implement the KeyHandler class to record keyboard input
  2. Use the keyboard input to animate the game map
  3. Apply keyboard controls to move the map
  4. Plan game development and design
💡 Implementing keyboard controls is a crucial step in game development, and understanding how to record and apply keyboard input is essential for creating interactive games.

Related Reads

📰
How a Gen-X Entrepreneur Built a “Millionaire Playbook” That Generated $250,000 in a Month
Learn how a Gen-X entrepreneur created a millionaire playbook that generated $250,000 in a month by understanding long-term business profitability
Medium · Startup
📰
My Team Had Twelve Engineers in January. It Has Seven Now. There Has Been No Layoff Announcement.
Learn how to identify and address silent layoffs in your team, and why it matters for team morale and productivity
Medium · AI
📰
White Label vs In-House Hiring: Which Model Fits Your Business?
Learn how to decide between white label and in-house hiring models based on cost, speed, and control to fit your business needs
Dev.to AI
📰
Moctale Wants to Be More Than an IMDb Alternative. But Is Its Creator-Led Model Enough?
Moctale aims to be a creator-led alternative to IMDb, but its success depends on its unique model
Medium · Startup
Up next
How to Build a $1 Million Business (Without Selling Your Time)
Chris Donnelly
Watch →