AI & 2D Development COSC 315 Fall 2014 Bridget M. Blodgett.

Slides:



Advertisements
Similar presentations
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Advertisements

Constructor and New Fields // Don't synch draw() with vertical retrace of monitor graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = true;
Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
Static Methods Static methods are those methods that are not called on objects. In other words, they don’t have an implicit parameter. Random number generation.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
12 Pontoon1May Pontoon program CE : Fundamental Programming Techniques.
10-Jun-15 Fibonacci Numbers A simple example of program design.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Lesson 3 Variables – How our Brains Work - Variables in Python.
Games and Simulations O-O Programming in Java The Walker School
GAME:IT Junior Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Finishing 2D COSC 315 Fall 2014 Bridget M. Blodgett.
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
GAME:IT Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game.
VIDEO GAME PROGRAMMING Video Game Programming Junior – DigiPutt INSTRUCTOR TEACHER’S ASSISTANT.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
Artificial Intelligence in Game Design Behavior Trees.
1 CSC 221: Computer Programming I Spring 2010 interaction & design  modular design: roulette game  constants, static fields  % operator, string equals.
Developing the Game User Interface (UI) Lesson 5.
Art 315 Lecture 5 Dr. J. Parker AB 606. Last time … We wrote our first program. We used a tool called GameMaker. The program we wrote causes a ball to.
(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci.
User Input and Collisions COSC 315 Fall 2014 Bridget M. Blodgett.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 3 More About Classes Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
Learning Unity. Getting Unity
Object Oriented Design COSC 315 Fall 2014 Bridget M. Blodgett.
XNA Game Studio 4.0 Keyboard and Mouse Controls + more on Animated Sprites.
Programming Video Games
Jumping, Climbing, and Tactical Reasoning Section 2.5 Tom Schaible CSE 497 – AI & Game Programming.
1 The Stack Class Final Review Fall 2005 CS 101 Aaron Bloomfield.
Game Programming Patterns Event Queue From the book by Robert Nystrom
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Guide to Programming with Python Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game.
Georgia Institute of Technology More on Creating Classes part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
Research Topics in Computational Science. Agenda Survey Overview.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
3D Cameras COSC 315 Fall 2014 Bridget M. Blodgett.
Session 13 Pinball Game Construction Kit (Version 3):
XNA Basic Displaying Image & Collision Detect. What’s format image that XNA support? XNA support only.bmp.png and.jpg image..PNG have transparent region.
Arrays An array is a data object that can hold multiple objects, all of the same type. We can think of an array as a storage box which has multiple compartments.
CHAPTER 14 Classes, Objects, and Games XNA Game Studio 4.0.
Game Project 1 Homage to Pong. Project Rules: The primary project is Pong, the design and development of which will be discussed in detail here. If you.
Written by: Dr. JJ Shepherd
GameDevClub CODE CHEAT SHEET NOTE: ALL OF THE CODE IS CASE-SENSITIVE AND THE SYNTAX IS STRICT SO A LOT OF YOUR ERRORS WILL PROBABLY COME FROM TYPOS If.
Controlling Program Flow with Decision Structures.
11 Adding a Bread Bat Session Session Overview  We have created a cheese sprite that bounces around the display  We now need to create a bread.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
XNA Tutorial 1 For CS134 Lecture. Overview Some of the hard work has already been done for you. If you build and run your game now, the GraphicsDeviceManager.
Artificial Intelligence in Game Design Lecture 20: Hill Climbing and N-Grams.
3D Cameras and Enemies COSC 315 Fall 2014 Bridget M. Blodgett.
Making a Flappy Birds Game PART 2 – MAKING THE BIRD FLAP AND FALL – AND DEVELOPING THE GAME FURTHER (ADDING ADDITIONAL CHARACTERS, GOODIES, ENEMIES AND.
CONDITIONALS CITS1001. Scope of this lecture if statements switch statements Source ppts: Objects First with Java - A Practical Introduction using BlueJ,
The Stingray Example Program CMT3311. Stingray - an example 2D game May be useful as a simple case study Most 2D games need to solve generic problems.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Shlomo Hershkop Basics overview. Shlomo Hershkop Basic Review - Overview Practice coding Practice coding finger guessing game finger guessing.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
Values vs. References Lecture 13.
Background Shapes & Collision Resolution (Top-down and Side-scrolling)
CS 4/527: Artificial Intelligence
Lesson Objectives Aims
slides created by Ethan Apter
C# Basics These slides are designed for Game Design Class
We’re moving on to more recap from other programming languages
slides created by Ethan Apter
Explaining issues with DCremoval( )
A list-size member variable
Chapter 10 Algorithms.
slides created by Ethan Apter and Marty Stepp
CIS125GA Week 4 Logical Beginnings
Presentation transcript:

AI & 2D Development COSC 315 Fall 2014 Bridget M. Blodgett

Artificial Intelligence Why the Turing Test is BS What is the goal of including AI in games? Although genuine AI would be nice we need to start small Making sprites appear randomly is a good first step towards a more natural AI

Random XNA has a built in Random number function – It isn’t great but it works for what we need to do It is a good idea to create a single random variable and then call it for all your randomization needs If you make multiple variables and call them too quickly you could end up making numbers off the same seed – This defeats the purpose of randomness

Making Random Variables The first step is to create some placeholder variables to hold your randomly generated number and initialize it in your game1 class constructor public Random rnd{get; private set;} rnd = new Random(); We also need some class variables to define the frequency of enemy spawns int enemySpawnMinMilliseconds = 1000; int enemySpawnMaxmillisends = 2000; int enemyMinSpeed = 2; int enemyMaxSpeed = 6;

Using SpriteManager Remove the code that makes the stationary sprites from LoadContent The method should only have the player variable now Make a class variable called: – int nextSpawnTime = 0; Make a new method in SpriteManager private void ResetSpawnTime() { nextSpawnTime = ((Game1)Game).rnd.Next( enemySpawnMinMilliseconds, enemySpawnMaxMilliseconds); }

ResetSpawnTimer() Now call your new method in Initialize() This will set up the spawner but adding code to the Update method will get it running nextSpawnTime -= gameTime.ElapsedGameTime.Milliseconds; if(nextSpawnTime < 0) { SpawnEnemy(); ResetSpawnTime(); } Right now this makes a call to a function that doesn’t exist but that will be added next

Spawn Enemy There are several things that need to be done: – The enemy needs a starting position, starting speed, added to the spriteList private void SpawnEnemy(){ Vector2 speed = Vector2.Zero; Vector2 position = Vector2.Zero; Point frameSize = new Point(75,75); } After declaring these variables you need to write code to set them

switch (((Game1)Game).rnd.Next(4)){ case 0: position = new Vector2(-frameSize.X, ((Game1)Game).rnd.Next(0,Game.GraphicsDevice.Present ationParameters.BackBufferHeight – frameSize.Y)); speed = new Vector2(((Game1)Game).rnd(Next(enemyMinSpeed, enemyMaxSpeed), 0); break; case 1: position = new Vector2( Game.GraphicsDevice.PresentationParameters.BackBuffe rWidth, ((Game1)Game).rnd.Next(0,Game.GraphicsDevice.Present ationParameters.BackBufferHeight – frameSize.Y)); speed = new Vector2(- ((Game1)Game).rnd(Next(enemyMinSpeed, enemyMaxSpeed), 0); break;

case 2: position = new Vector2(((Game1)Game).rnd.Next(0,Game.GraphicsDevice.PresentationParameters.BackBufferWidth – frameSize.X), Game.GraphicsDevice.PresentationParameters.BackBuffe rHeight); speed = new Vector2(0, - ((Game1)Game).rnd(Next(enemyMinSpeed, enemyMaxSpeed)); break; case 3: position = new Vector2(((Game1)Game).rnd.Next(0,Game.GraphicsDevice.PresentationParameters.BackBufferWidth – frameSize.X), -frameSize.Y); speed = new Vector2(0,((Game1)Game).rnd(Next(enemyMinSpeed, enemyMaxSpeed)); break; }

spriteList.Add(new AutomatedSprite(Game.Content.Load kullball”), position, new Point(75,75), 10, new Point(0,0), new Point (6,8), speed, “skullcollision”)); } //this closes the method!

Irrelevant Objects Right now if a sprite passes outside the boundary they just keep going This means that the game will get slower the longer it’s played – Why? There are a number of different solutions to this issue

Boundary Rectangles Just like for collisions we can use a rectangle to determine when an object goes outside the window bounds In the sprite class add the following method public bool IsOutOfBounds(Rectangle clientRect) { if(position.X clientRect.Width || position.Y clientRect.Height) { return true; } return false; } Now you need to fix update to check the sprites each call

for (int I = 0; I < spriteList.Count; ++i){ Sprite s = spriteList[i]; s.Update(gameTime, Game.Window.ClientBounds); if (s.collisionRect.Intersects(player.collisionRect)) { spriteList.RemoveAt(i); --i; } if (s.IsOutOfBounds(Game.Window.ClientBounds)) { spriteList.RemoveAt(i); --i; }

Player Aware Sprites So our enemies are still pretty basic and don’t really react to the player Using a simple algorithm that determines the player’s position and moves the sprites accordingly you can make two new types of enemies: chasers and evaders Both of these require making a small modification to the Sprite base class to accept the player’s location