Intro to GML.

Slides:



Advertisements
Similar presentations
GAME:IT Junior Learning Game Maker: The Control Tab.
Advertisements

Create a Simple Game in Scratch
Mike Scott University of Texas at Austin
Create a Simple Game in Scratch
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
GAME:IT Junior Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game.
First create a folder with your pictures/ images needed to create the story Then open Photostory 3. Click on begin a new story and click next.
Visual Basic Chapter 1 Mr. Wangler.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 8 Fall 2010.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
IE 411/511: Visual Programming for Industrial Applications
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
University of Sunderland CDM105 Session 6 Dreamweaver and Multimedia Fireworks MX 2004 Creating Menus and Button images.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Creating Buttons – Lesson 51 Creating Buttons Lesson 5.
Learning Unity. Getting Unity
GAME:IT Pinball Objectives: Review skills from Introduction Introduce gravity and friction Introduce GML coding into programming.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Game Maker – Getting Started What is Game Maker?.
Shooters in GameMaker J Parker.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
Game Maker Tutorial.
Learning PowerPoint Presenting your ideas as a slide show… …on the computer!
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Computer Programming Modeling a Passive Solar Home.
Video in Macromedia Flash (Optional) – Lesson 121 Video in Macromedia Flash (Optional) Lesson 12.
Open a new Flash File Action Script 2.0. Create a button like you did last lesson and name it Click to Play.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Unit 3: Text, Fields & Tables DT2510: Advanced CAD Methods.
Galactic Mail Part 2. Winning and Losing Exploding Asteroids Including Scoring Adding Levels And more.
Tank Game Part 3 of 6. Secondary Weapons and Pick ups Pick ups will appear randomly in the battle area and can be collected by driving into them. Each.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
GAME:IT Junior Paddle Ball Objectives: Review skills from Introduction Create a background Add simple object control (up and down) Add how to create a.
ICT/COMPUTING RULES Only use software allowed by the teacher
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
GAME:IT Mario Creating Platform Games Level 4 with GML Game Maker Language (GML) allows users more flexibility in game design. GML is similar to how real.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Dive Into® Visual Basic 2010 Express
Visual Basic.NET Windows Programming
Create a Halloween Computer Game in Scratch
MOM! Phineas and Ferb are … Aims:
PYGAME.
Chapter 1: An Introduction to Visual Basic 2015
The Smarter Balanced Assessment Consortium
Scratch Unit Overview We are going to look at computer programming and how to create your very own computer game The piece of software we will be using.
Chapter 2 – Introduction to the Visual Studio .NET IDE
The Smarter Balanced Assessment Consortium
Microsoft Excel 2003 Illustrated Complete
••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Introduction to.
The Smarter Balanced Assessment Consortium
Chapter 2 – Introduction to the Visual Studio .NET IDE
Getting Started with Scratch
The Smarter Balanced Assessment Consortium
Tank Game Part 6 of 6.
Tank Game Part 2 of 6.
Moodle Training — Advanced Topics —
Image #1 Getting Started
Game Over Module 4 Lesson 2.
Tank Game Int 10 Unit 3 – Game Maker.
Drawing OSA charts. Once Synops have been downloaded and ingested.
The Smarter Balanced Assessment Consortium
Creating a Simple Game in Scratch
CSC 221: Introduction to Programming Fall 2018
The Smarter Balanced Assessment Consortium
Presentation transcript:

Intro to GML

What is GML? A proprietary interpreted programming language called the GameMaker Language (abbreviated to GML). Gives you much more flexibility and control than the standard actions that are available through the Drag'n'Drop interface. Can be used in: Scripts: A script is a (usually) short snippet of code in GML that you write to create your own functions. Events: You can use code within object events to control the behaviour and interactions of instances of those objects. You can even mix Drag'n'Drop with code! Room Creation Code: Each room can have a special "create event" specific for that room. Here you can add the code you need and it will be run when every time the room is entered. Instance Creation Code: As well as the code you insert into the events of an object, you can also add code to individual instances when you place them in the room. Can be turned to compiled code when ran through one of the export modules.

Gamemaker Langugage Using Gamemaker Language we will create a simple click-the-object game. There will be an object that appears at random positions and the aim of the game is to click it before the timer runs out. Each time you successfully click the object the timer will get faster. If you don’t click the object before the time runs out, the game ends.

Download the sprites as instructed by your tutor. Load in the sprites for this game. There are five of them, spr_logo , spr_start_game , spr_target , spr_exit , and spr_lives . Set the origin of all sprites to center. The origin is point in the sprite where it will be positioned in the room.

Creating rooms Create two rooms; name them room_menu and room_game. Set the room size for each as 800 by 400.

Sounds Create and load two sounds: snd_yeah and snd_you_are_dead .

Fonts If you want to display text or variables on screen in your game, you’re going to need to define and name some fonts. Set the font name as font_hud and the size as 20 Arial as shown in Figure

Objects Next we’ll create the objects. There are five of them: obj_logo , obj_start_game , obj_target , obj_exit , and obj_hud . Assign the relevant sprites to the objects. NO SPRITE FOR OBJ_HUD

Events Within obj_start_game add the create event. Click on the control tab, and click and drag Execute Code to the actions window

Add code In the open window, enter the following code: //see if ini file exists and load saved score Ini_open("savedata.ini"); //open file savedata.ini global.highscore = ini-read_real("score", "highscore", 0); //set global.highscore to value or set as 0 if no value present Ini_close(); //close ini file - always do this after loading or saving data //set starting values for game: score=0; lives=5;    This code will load any high score from a previous play of the game to the variable global.highscore , set current score to 0 , and lives to 5 .

Your code should look like this

Mouse Left Button Released Event Now create the new the event shown:

Mouse Left Button Released Event - Code Again drag over the Execute Code action and add the following code room_goto(room_game); //goto the room room_game

Add a draw event Next add a Draw Event by clicking Add Event followed by Draw Event , then drag across the Execute Code . Add the following GML to this: draw_self(); //draws sprite assigned to this object draw_set_font(font_hud); //set font draw_set_halign(fa_center); //set horizontal alignment for drawn text draw_set_colour(c_black); //sets drawing colour as black draw_text(250,280, "Highscore: "+ string(global.highscore)); //draw Highscore: plus value  of global.highscore

Draw event explained A Draw Event is where you place your code, or D&D, to place text and images on the screen. Drawing functions, such as draw_text and draw_self , must be placed in Draw Event. Explanation of this code: draw_text(250,280, "Highscore: "+ string(global.highscore)); //draw Highscore: plus value  of global.highscore This draws the text at position 250 across the screen and 280 down, in pixels. global.highscore has a numerical value. Because we are drawing it with a string, " Highscore: ", we need to convert it also to a string. The code string(global.highscore) does this conversion.

Obj_exit For this object create a Left Mouse Button Released Event and add this code: game_end(); //closes game and returns to windows

obj_target Next we’ll use a Create Event to set up some initial variables. A Create Event is only run once when the object is created, or when a room starts if the object is already placed in it. We’ll use this event to create at a random position across the screen, X, and down the screen Y between 100 and 700. We’ll then start an Alarm with a value of 100 minus the score. This makes the alarm quicker as the score increases, making it get progressively harder to click in time.

obj_target continued In a Create Event put this code, which will choose a whole integer between 100 and 700, sets timer to 100 less the score, with a minimum value of 5, and then sets an alarm with the timer: x=irandom_range(100,700); //sets x position at random between 100 & 700 y=irandom_range(100,300); //sets y position at random between 100 & 300 timer=100-score; //set timer as 100 less score - so it gets faster if timer<=5 timer=5; //check if less than 5, set as 5 if it is alarm[0]=timer; x=irandom_range(100,700); //sets x position at random between 100 & 700 y=irandom_range(100,300); //sets y position at random between 100 & 300 timer=100-score; //set timer as 100 less score - so it gets faster if timer<=5 timer=5; //check if less than 5, set as 5 if it is alarm[0]=timer;

obj_target continued Next create an Alarm Event0 as shown. This will activate if the player hasn’t clicked the object in time. The GML will play a sound first, reduce the player’s lives by 1, and create a new object, then destroy itself.

obj_target continued Drag across Execute Code and add the following code: audio_play_sound(snd_you_are_dead,1,false);//plays a sound lives-=1; //reduce lives instance_create(50,50,obj_target); // create a target instance_destroy(); //destroy self

obj_target continued Create a Left Mouse Button Released Event into the same object, obj_target and put the following code in it: score+=1; //add 1 to score audio_play_sound(snd_yeah,1,false); //play sound yeah instance_create(50,50,obj_target); //create new skull instance_destroy(); //removes self from screen

obj_target continued In a Draw Event of obj_target put: draw_self(); // draws assigned sprite draw_set_colour(c_red); //sets drawing colour draw_rectangle(x-(alarm[0]/2), y-30, x+(alarm[0]/2), y-25,0); //draws a rectangle that reduces size based on alarm[0] value The above code will draw the sprite for the object, set the drawing colour to red, and then draw a rectangle based on the current value of the alarm – this will serve as visual so the player knows how long they have to click the object.

obj_hud There is no sprite for this object. This object will be used as a control object that will be used to draw a HUD of the player’s lives and score . It will also monitor how many lives the player has, and if the player has lost all of their lives it will update the high score if the player has a new high score and then restart the game. You do not need to create this file; it will be created automatically upon saving if it doesn’t already exist.

obj_hud – Creating a ini file Click Add Event and then Step Event . Add the following code to the Step Event : if (lives<0) {   if (score>global.highscore)   {         ini-open("savedata.ini");         ini-write_real( "score", "highscore", score);         ini-close(); //closes  ini file   }  game_restart(); //restarts game }

obj_hud – Score, font, alignment, and drawing colour Create a Draw GUI Event, under the draw tab. This code sets up the font, alignment, and drawing colour. Then it draws the score and as a high score if bigger than previous global.highscore . draw_set_font(font_hud); //sets the font draw_set_halign(fa_left); //sets alignment draw_set_colour(c_blue); //sets drawing colour draw_text(25, 25, "Score: "+string(score)); //draws score: + score draw_set_colour(c_blue); if score>global.highscore //executes following if score is bigger { draw_text(300, 25, "Highscore: "+string(score)); } else //other wise just draw previous highscore draw_set_colour(c_red); draw_text(300, 25, "Highscore: "+ string (global.highscore));

obj_hud – drawing lives Next is to draw the lives as images. There is a Drag & Drop action for this in the Score section. Drag this across and set to draw at 500,25 using the sprite spr_lives as shown

room_menu Open room room_menu for editing by clicking on it in the resource tree. Use the object tab to select objects and then place one each of obj_logo , obj_start and obj_exit . Select the object then click in the room to place it.

room_game Next open room_game . Place one instance of obj_target and one of obj_hud in the room. It doesn’t matter where you place them. Save and test the game

Comments explained The first type is using the double // . Anything written after the // on a single line is commented out and will not be processed.

Comments explained The next type uses the triple /// . When placed at the top of code block it changes the default Execute a piece of code to the comment.

Comments explained The third type allows you to comment out multiple lines. Any lines commented out will not be executed when the game is run. You start this section with /* and end with */ .