2D Game design Intro to Html 5

Similar documents
JavaScript: Introduction, Types

Introduction to Programming Using Java (98-388)

CGS 3066: Spring 2015 JavaScript Reference

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

JavaScript: Sort of a Big Deal,

Why Discuss JavaScript? CS312: Programming Languages. Lecture 21: JavaScript. JavaScript Target. What s a Scripting Language?

CS312: Programming Languages. Lecture 21: JavaScript

BEFORE CLASS. If you haven t already installed the Firebug extension for Firefox, download it now from

Intro. Scheme Basics. scm> 5 5. scm>

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

Client-Side Web Technologies. JavaScript Part I

CSC Web Programming. Introduction to JavaScript

Beginning HTML. The Nuts and Bolts of building Web pages.

Mul$media im Netz (Online Mul$media) Wintersemester 2014/15. Übung 03 (Haup9ach)

Semantic Processing. Semantic Errors. Semantics - Part 1. Semantics - Part 1

Cascading Style Sheets for layout II CS7026

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

Session 3: JavaScript - Structured Programming

CMSC 330: Organization of Programming Languages

LAST WEEK ON IO LAB. Install Firebug and Greasemonkey. Complete the online skills assessment. Join the mailing list.

CSCI 1061U Programming Workshop 2. C++ Basics

PHP. Interactive Web Systems

JavaScript. What s wrong with JavaScript?

Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

COMP519 Practical 5 JavaScript (1)

Working with JavaScript

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Semantic Analysis. Lecture 9. February 7, 2018

Clojure. The Revenge of Data. by Vjeran Marcinko Kapsch CarrierCom

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

JavaScript Lecture 1

Internet & World Wide Web How to Program, 5/e by Pearson Education, Inc. All Rights Reserved.

These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without

Pierce Ch. 3, 8, 11, 15. Type Systems

Chapter 3 Data Types and Variables

Principles of Programming Languages

Computer Components. Software{ User Programs. Operating System. Hardware

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Fundamentals of Programming (Python) Getting Started with Programming

JavaScript Syntax. Web Authoring and Design. Benjamin Kenwright

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT

Getting Started with Python

Repetition Structures

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Chapter 2 Working with Data Types and Operators

Introduction to Programming with Python. By: Victoria Kahian and Kyla Boswell

Object-Oriented Programming in Java

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Flow Control. CSC215 Lecture

SCoLang - Language Reference Manual

Functions & First Class Function Values

JavaScript for PHP Developers

Project 2: Scheme Interpreter


Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

Quick.JS Documentation

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Decision Making in C

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

CS558 Programming Languages

The role of semantic analysis in a compiler

JavaScript Fundamentals_

Programming In Java Prof. Debasis Samanta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

FRAC: Language Reference Manual

2. First Program Stuff

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective-

CSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8

CS 31: Intro to Systems C Programming. Kevin Webb Swarthmore College September 13, 2018

JavaScript. Training Offer for JavaScript Introduction JavaScript. JavaScript Objects

CS558 Programming Languages

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

Programming language components

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Motivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018

T H E I N T E R A C T I V E S H E L L

Chapter 1 Getting Started

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.)

Lecture 2: Variables & Assignments

(Not Quite) Minijava

Fullscreen API. Quick Guides for Masterminds. J.D Gauchat Cover Illustration by Patrice Garden

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

COMP520 - GoLite Type Checking Specification

The PCAT Programming Language Reference Manual

Python The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT

Comp 151. Control structures.

CS 320: Concepts of Programming Languages

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

<script type="text/javascript"> script commands </script>

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

COMP520 - GoLite Type Checking Specification

The Pyth Language. Administrivia

JavaScript: The Good Parts. Douglas Crockford Yahoo! Inc.

All India Council For Research & Training

Transcription:

2D Game design Intro to Html 5

Javascript Javascript: Dynamic untyped Object Oriented interpreted language Typecast as a web language Could be used for a variety of tasks Dymanic?

Javascript Javascript: Dynamic untyped Object Oriented interpreted language Typecast as a web language Dynamic? Could be used for a variety of tasks Can add functions/etc at runtime Untyped?

Javascript Javascript: Dynamic untyped Object Oriented interpreted language Typecast as a web language Dynamic? Could be used for a variety of tasks Can add functions/etc at runtime Untyped? Like assembler, no notion of you can t do that exception/compiler error Green/5 returns NaN rather than error

Javascript Douglas Crockford: Lisp in C s clothing C-like syntax while acting like a functional language

Basic Types Even though the language is untyped there still have to be types to interpret the bits Numbers Strings string or string str + ing Typeof operator 64 bit ints and floats Usual arithmetic (including % mod) and precedence rules Unary operator returns type All immutable types

Logic Usual c-like boolean and logical operators == equality with type conversion ( 50 == 50)!= inequality w/ type conversion <, >, <=, >= inequality with type conversion === equality without type conversion!== inequality without type conversion!,, && Or/and are short-circuit operators null and false are false, everything else is true carl false => carl which evals to true Ternary (instantaneous if) exists 3>4? makes no sense : makes sense

Variables No typing Declare variable with keyword var var holder; var holder2 = 5;

Conditionals I Conditional if(boolean) else if (boolean) //optional statement executed if elseif is true else //optional statement executed if true statement executed if false

Conditionals II Also switch switch( value){ case posibility1: Statement1;... StatementN; Break case posibility2: } And so on

loops Indefinite loop while (boolean) Statement do while also works Definite loop Same as java/c/c++ for(initialize; check; update) Statement Usual loop keywords work Break continue

Functions Two ways to declare a function 1st)The way everyone else does it (declaration notation) function foo (n){ //Do stuff here. } Works a lot like c++ and or python now call Foo(200); Functions cannot be nested using declaration notation

Functions II Two ways to declare a function 2nd) Set a function as a value of a variable. Eg: (example from Eloquent Java) var launchmissiles = function(value) { missilesystem.launch("now"); }; if (safemode) launchmissiles = function(value) {/* do nothing */};

Function Closures Javascript supports function closures Local variables in outer function still available to inner function later See example from developer.mozilla.org below function makefunc() { var name = "Mozilla"; function displayname() { alert(name); } return displayname; } var myfunc = makefunc(); myfunc();

Fun with Functions Since functions are often values for variables Can do great things passing them as params Example from Eloquent JavaScrip function foreach(array, action) { for (var i = 0; i < array.length; i++) action(array[i]); } (we ll formally talk about arrays in a couple of slides)

Scope Javascript supports: Local variables Parameter variables Global variables (be very very careful with these.)

Data Structures Javascript s built in data structures. Arrays var names = [ Ed, Ann, Jo, Bo, Fe ]; names[2]; names.lenght; vs names[ length ]; Arrays are zero-based names.push( Zoe );

Objects Objects in javascript kinda like structs in C++ With some python/lisp-que stuff stirred in Defined as {property:value, property1:value1, } eg. var student = {bannerid:12345, name: Stu Dent, Gpa:3.4}; console.log(student.name); But we can do fun funky things too Can add properties any time Student.classlist=[ comp350, comp426, comp399 ];

Ok but you said html5 So that is javascript what about html5? So lets look at a really tiny stripped down html5 program Just html and javascript no CSS this time.

The HTML part <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>first Demo Game</title> </head> <body> <div id="gamespace"> <div id='canvasspace'> <canvas id="game-area" width="800" height="450">if you can see this you need a better browser</canvas> </div> <!-- we'll put more here later--> </div> <script src="firstgame.js"></script> </body> </html> Simple HTML html5 canvas and link to javascript

Javascript var canvas = document.getelementbyid('game-area'); var graphicscontext = canvas.getcontext('2d'); var background = new Image(); function loadimages(){ background.src = 'images/scrolling_background.png' ; } function drawbackground(){ graphicscontext.drawimage(background,0,0); } function drawcomponents() { drawbackground(); } function startgame(){ loadimages(); background.onload= function(param){ drawcomponents(); } } startgame(); onload is really important

Using Webstorm We ll use webstorm ide from jetbrains for development in class If you use something else in your own development fine so long as it all works Webstorm runs a localhost webserver to test projects To debug, you ll need to install the jetbrains chrome extension First time you try to debug webstorm will prompt you to install If you have another browser again fine

Good start Assignment: read chapters 1-2 in core html5 Project: lets see where we are for this