Game Programming - Episode 12 - Negative Bounds

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

Key Takeaways

Handles negative bounds in a Java-based game development project

Full Transcript

yo what's going on guys my name is the welcome to episode 12 of game programming one more thing before I begin yesterday's video episode 11 didn't really publish correctly like at all I don't know what happened to YouTube I wasn't the only problem I mean obviously I was not the problem let me just try that again I wasn't the only um I guess content creator who actually experienced issues it was like sitewide um people's videos um didn't actually publish to the homepage they did publish so in other words they were live on the channel page and they were live in the actual um let me just show you guys actually just open YouTube real quick I go over here if you go to like I don't know like let's just say Hut right um they they wouldn't be on the front page but they would be on the actual like over here so if you did click on my name here and you uh you checked it out you know you'd see um you'd see my video but you wouldn't see it on your actual subscriptions page so you might have missed it if you did it it did actually come out yesterday last night as usual um and just go to my channel check it out it'll be like right there on my channel so just keep that in mind okay um and in the future if you see like a video that doesn't come out that that's actually why I ask you guys to follow me on Twitter and Facebook in case something something like like this happens I always link it so in other words um a lot of people actually see it before it even publishes to any anything on YouTube so a lot of people actually catch the video while it's still processing and sort of catch it before YouTube fully publishes it so if you do follow me on Twitter and Facebook you will never miss a video that I put out so that's just a Pro tip for you okay anyway back to this so yesterday we took a look at actually um managing you know getting off the screen now there is a problem I'm going to quickly reset this back and we're going to deal with with another part of Ray index out of bounds and that is the opposite of this so if I just put it like this so you guys can see it properly we'll make it like 50/50 oh even like 150 or something okay so we're tring slowly now there time to there time for me to talk we manag this problem when it gets off the screen now the problem is if we actually r vers this so I'm just going to come in here and change this to minus minus um one more thing actually a lot of people ask if they should take this code down including y time you don't have to okay I'm literally showing this to demonstrate to you how it works I will I will be getting rid of this code I will be getting rid of these two variables um and I will be replacing these back with X and Y in the for Loop okay I'm just literally just taking the time to actually explain to you guys how this works because that is the point of the series to take it nice and slow and to teach you guys how and why everything works so if I reverse it like I did here right so what's going to happen is this variable starts at50 respectively but it's going to get smaller so we're going to go the opposite way now what's going to happen is oh we've hit it there we go crash now why is there a crash because again it's still out of bounds remember we range uh if I go to variables we range from 0 to 9 uh to 0 to 503995 tried to access a negative um index that does not exist that is still out of bounds okay if it's over if it's too much or if it's too little so in other words negative then that causes an array index out of bounds exception how do we deal with that pretty simple okay what we've got here is if y time is greater than or equal to height we break it's pretty simple to fix this all we need to do is say that if y time is actually less than zero or if it's greater than height let's break okay okay simple as that we've done greater than height so in other words that's when it gets out of the screen going down when it gets out of the screen going up it's going to be less than zero and we can say that if it is less than zero let's break and we we need to do the exact same thing for X I assume you guys know how um how this uh Works in terms of um the actual if statement obviously we've got if x time is less than zero and then this this little double pipe thing um means or so in other words if the statement is true all this statement is true do this so break okay and um I think I explained break last time but now we can uh we can run this and you'll see that um we're fine we don't crash so that's the basis that that's the basics of um or the basis of of how this is going to work and if we just get rid of why you can see that the X works as well so here we are traveling nicely and then we're gone so um that is how that works um all we got now is uh probably next time so tomorrow we'll take a look at what are we going to do next no clue um H probably next time H what's next I have no idea what's next uh we'll probably move on to beginning um ooh I know um before we begin building tiles um we'll actually um probably add like a um like a an FPS counter as well as a timer to actually control um this and make sure that update only happens 60 times a second okay so we'll add of time tomorrow um but until then guys make sure to like the video if you did like the video and I will see you guys uh see you guys tomorrow bye [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
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from The Cherno · The Cherno · 53 of 60

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
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

Related Reads

📰
Why I Built a Trading Marketplace for Monopoly GO Players
Learn how a entrepreneur built a trading marketplace for Monopoly GO players to facilitate sticker trading, a crucial aspect of the game.
Medium · Startup
📰
How to Launch Your Own Custom Headwear Line in Europe
Learn how to launch a custom headwear line in Europe with key steps and considerations for entrepreneurs and startup founders
Medium · Startup
📰
Why Kenya’s revived golden visa matters for venture investors and founders
Kenya's revived golden visa program offers residency to investors who commit capital and create jobs, impacting venture investors and founders
TechCabal
📰
How I Went From Employee to Founder — What Nobody Tells You
Learn what it takes to transition from employee to founder, including unexpected challenges and lessons learned
Medium · Startup
Up next
Watch this before applying for jobs as a developer.
Tech With Tim
Watch →