Week 1 - Introduction and Objects Game Design Week 1 - Introduction and Objects
Competition! Your Hero Broad theme, be creative The more creative and interesting your take, the better Focus will be on design and ideas, not programming
What is a game?
What is a game? A game is an activity played using a sets of rules There are many types of games Board games Video games Card games Word games Sports General concepts apply across the board for games We’ll be focusing on mechanics as we start out
Game General Concepts Games (especially video games and board games) can be made up of any number of a few different elements: Mechanics Visuals Narrative Games will ALWAYS have mechanics, but not always visuals or narrative, and are always interactive in some way We’ll be focusing on mechanics as we start out
Game Mechanics So let’s talk about game mechanics Can someone give me an example of a game mechanic?
What are mechanics? Rules that together form the constraints and functionality of the game Defines how things like combat, interactions, etc work Mechanics are the absolute core of any game
What games do you play? What mechanics does the game have? Your examples? What games do you play? What mechanics does the game have? So let’s talk about game mechanics Can someone give me an example of a game mechanic?
Breaking down mechanics Breaking blocks in Minecraft
Breaking down mechanics Breaking blocks in Minecraft Player clicks the left mouse button (click event) Character’s arm punches (animation) Character’s arm checks to see if it’s hitting a block (collision detection) If block is being hit, it starts to break (damage) When click is held down, this repeats until the block takes enough damage to break Let’s break down breaking down So what does this rely on? Tamara talked about events in web
Let’s look at the elements Player Character Character skin Animations Interactions from events Movement, punching, placing blocks Block Type Texture Damage limit How do we define these things in code? These have loads of parameters associated with them. There are loads of block types with different textures, uses and damage limits We can’t define those with the code we know right now, so how do we do it?
Objects
What is an Object? In real life, an object can be anything! (seriously) All objects in the world have properties - for example, a car has a color, weight, max speed, and loads of other stuff Some objects have methods - like functions or actions - for example, a car can start, drive, break, etc Lets think about what our car object needs as an example
The Base Object We use objects in games when we want to create a sort of “model” of how something should be described For example, a “car” is made up of a main body with 4 wheels that can drive, stop, and change directions These details remain the same, regardless of the car, but other things like the color, size, speed etc can change Lets think about what our car object needs as an example
The Base Object A JavaScript object is essentially a collection of: Properties; variables with values that describe aspects of the object, and Methods; functions which describe what actions the object can take, or what it can do Lets think about what our car object needs as an example
Object Properties Name: Tesla Roadster Color: Red Year: 2019 Top Speed: 250+mph Name: FIAT 500 Color: White Year: 2008 Top Speed: 120mph Now we can use our new constructor function to create different cars, using the same properties! We just add in the values we want to use in the arguement list for the constructor
Objects can be written like variables, but use { } Each property take the form of ⇒ property : value Lets think about what our car object needs as an example
Working with Properties The values of properties can be accessed using object.property What will the following give us: car.name car.weight Lets think about what our car object needs as an example
Adding an object Method Lets think about what our car object needs as an example
Working with Methods Methods can be easily run from objects using object.method() So what do you think will happen if we say car.drive()? HINT: In JavaScript, the thing called this, is the object that "owns" the method/property. Lets think about what our car object needs as an example
Other ways of creating objects Lets think about what our car object needs as an example
Other ways of creating objects Lets think about what our car object needs as an example
Other ways of creating objects Lets think about what our car object needs as an example
Useful Links W3Schools Javascript Objects https://www.w3schools.com/js/js_objects.asp W3Schools Javascript Object Constructors https://www.w3schools.com/js/js_object_constructors.asp