Contacts: Intro to game programming in Java (with almost-drawingpanel)

Slides:



Advertisements
Similar presentations
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
Advertisements

Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
Topic 9 more graphics Based on slides bu Marty Stepp and Stuart Reges from
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
Copyright 2008 by Pearson Education Building Java Programs Graphics Reading: Supplement 3G.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
1 Graphical objects We will draw graphics in Java using 3 kinds of objects: DrawingPanel : A window on the screen. Not part of Java; provided by the authors.
Structure of GridWorld classes Creating a GridWorld project without the jar file Modifying GridWorld classes Removing grid lines Changing the color of.
Using FangEngine The FangEngine is created by Brian C. Ladd & Jam Jenkins Presentation by Pepper With much credit to: Jenkins, Jam & Brian C. Ladd. Introductory.
Week 14 - Monday.  What did we talk about last time?  Image manipulation  Inheritance.
Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008.
Copyright 2010 by Pearson Education Building Java Programs Graphics reading: Supplement 3G.
Georgia Institute of Technology Movies part 2 Barb Ericson Georgia Institute of Technology April 2006.
CPSC1301 Computer Science 1 Chapter 14 Creating and Modifying Movies part 2.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Chapter 5: Ball Worlds Features 2 classes, constant data fields, constructors, extension through inheritance, graphics.
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 02b: Tutorial for Programming in Processing Jarek Rossignac.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
1 CSC 216 Lecture 3. 2 Unit Testing  The most basic kind of testing is called unit testing  Why is it called “unit” testing?  When should tests be.
More OOP. Extending other’s classes extend Java platform classes, e.g. class Applet public class MyApplet extends Applet { public void init() { } public.
Welcome back!. Object Oriented Programming – Encapsulation Classes encapsulate state (fields) and behavior (methods) – Polymorphism Signature Polymorphism.
Building Java Programs Graphics Reading: Supplement 3G.
CS305j Introduction to Computing Simple Graphics 1 Topic 11 Simple Graphics "What makes the situation worse is that the highest level CS course I've ever.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
CHAPTER Agenda Applets Servelets Browsers HelloWorld.
Midterm: Question 1 (35%) (30 minutes) Write an assembly program to draw a rectangle. – (5%) Show a message to ask for information of the rectangle – (5%)
Week 10 - Friday.  What did we talk about last time?  References and primitive types  Started review.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Processing  Install Processing  Learn how to edit, run, save, export,
Java With NetBeans First Project. Java Are language for this semester is Java The Development Environment is Netbeans.
CompSci 42.1Intro to Java Anatomy of a Class & Terminology Running and Modifying a Program.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Modifying GridWorld Classes.
MOM! Phineas and Ferb are … Aims:
Building Java Programs
Multimedia in Java Multimedia combines graphics, animation and sound
Eclipse Navigation & Usage.
Building Java Programs
Building Java Programs
Building Java Programs
Example: Card Game Create a class called “Card”
Week 8 - Monday CS 121.
Building Java Programs
Basic Graphics Drawing Shapes 1.
CS 106A, Lecture 14 Events and Instance Variables
Setting up Eclipse Locally
Topic 8 graphics "What makes the situation worse is that the highest level CS course I've ever taken is cs4, and quotes from the graphics group startup.
Building Java Programs
Chapter 10 Algorithms.
Drawing in Java.
Lecture 7: Introduction to Processing
CSE 142 Lecture Notes Graphics with DrawingPanel Chapter 3
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Chapter 10 Algorithms.
Topic 9 More Graphics Based on slides bu Marty Stepp and Stuart Reges from
Threads.
Building Java Programs
Building Java Programs
Building Java Programs
Graphics Reading: Supplement 3G
Building Java Programs
Presentation transcript:

Contacts: Intro to game programming in Java (with almost-drawingpanel) Shiny (mootothemax@gmail.com) Aleksander (aleksander_01@live.com)

GamePanel -Based off DrawingPanel and in Java (familiar) -Way better than any of the other Java alternatives I've used -Exports as a standalone runnable JAR file. -Download here (click download zip): https://github.com/spotco/GamePanel We're not going to use this forever, but it's a good place to learn the basics!

Setup in Eclipse New java project Give it a name Finish

Drag and drop the .java files into the “src” folder Ok Try running “SimpleGame” !

Making a new game public class MyGame extends GamePanel { public MyGame() { super(300,300); //the window will be 300 width, 300 height } And then somewhere else, add a main... public static void main(String[] args) { new MyGame(); }

Drawing Stuff import java.awt.Color; public class MyGame extends GamePanel { public MyGame() { super(300,300); /* * _g is an inherited field of type "Graphics" * (This is the same Graphics you know and love!) */ _g.setColor(Color.red); _g.fillRect(50, 50, 100, 100); }

The “Update Cycle” public class MyGame extends GamePanel { public MyGame() {...} //Do initialization stuff here! @Override public void update() { //This is a method we're overriding /* * This gets run every 20 milliseconds! */ System.out.println("test"); }

Animating something What's going on here? public class MyGame extends GamePanel { private int _x,_y; public MyGame() {...} @Override public void update() { _g.setColor(Color.red); _g.fillRect(_x, _y, 10, 10); _x++; _y++; } What's going on here?

Animating something Clear the screen before drawing. public class MyGame extends GamePanel { private int _x,_y; public MyGame() {...} @Override public void update() { this.clear(); _g.setColor(Color.red); _g.fillRect(_x, _y, 10, 10); _x++; _y++; } Clear the screen before drawing. Fill a white rectangle the size of the screen OR this.clear().

Controlling Something @Override public void update() { this.clear(); _g.setColor(Color.red); _g.fillRect(_x, _y, 10, 10); if (this.is_key_down(KEY_LEFT)) { _x--; } if (this.is_key_down(KEY_RIGHT)) { _x++; if (this.is_key_down(KEY_UP)) { _y--; if (this.is_key_down(KEY_DOWN)) { _y++;

Let's make “Snake”! You, (the red dot) want to grab the green dot. How to do this? -Store the location of the green dot -If the red dot (player) is close to the green dot, the player just “ate” the green dot -Increment the score, and move the green dot somewhere random on the screen

How to detect if the player “hits” the green dot? Here's a real easy way to do it: see if circles are colliding! Two circles are colliding if (distance between the centers) < (sum of the two radius (radii?)) public bool is_collide(int x1, int y1, int x2, int y2, int radius_sum){...}

Draw some UI _g.setColor(Color.black); _g.drawString("Score: 0", 250, 10); Make it show the “actual” score, of course!

Exporting as a Runnable JAR File -> export Select Runnable JAR file, then next

Select the class with your “main” in Launch configuration, and specify the output JAR file name. Then, Finish. Run the jar to play the game outside of eclipse.

A few ideas to get going... Easy: Implement the score functionality. Collect the dot to increment score by 1. If the player walks out of the screen, return him back to the screen. Medium: Make multiple green dots that could be collected (maybe of different size and point value). What would be the “smart” way of doing this? Hard: Make the dots run away from the player. They don't want to get eaten!