Computer Science
Gilmour AcademyLancerTech
  • Our Curriculum and Department
  • Intro to Programming
    • 1: Parts of a Computer
    • 2: Parts of Python
    • 3: DRY Turtle
    • 4: Turtle Design App
    • Wordle with Turtles
    • 5: Interactive Turtles
    • OLD 5: Replit, GitHub, and repositories (Oh my!)
    • 6: Raspberry Pi / GoPiGo
    • 7: Kivy
  • Intro to Web Design
    • 1: Internet?
    • 2: Websites?
    • 3: Bootstrap Template
    • 4: Graphics and Branding
    • 5: Collaboration
    • 6: Advanced Editing
    • Publish Static HTML
  • AP Computer Science
    • 1: Logic & Instances
    • 2: How Java Works
    • 3: Data Types & Flow
    • 4: Strings
    • 5: Objects & References
    • 6: Inheritance & Algorithms
    • 7: Data Structures
    • 8: Sorting
    • 9: Review
    • Data Science
  • Web App Dev
    • 1: Core Concepts
    • 2: MVT Pattern
    • 3: Hello Flask
    • 4: Install Flaskinni
    • 5: Tour Flaskinni
    • 6: Visualize Your App
    • 7: Theme & Blueprint
    • 8: Standup Your DB
    • 9: Advanced Topics
    • 10: Deployment
  • 2D Game Design
    • Class Overview
    • Gamemaker Studio 2 and Github Setup
    • Game 1: Bouncing Ball
    • Turning in your games
    • Game 2: Maze
    • Game 3: Ping Pong
    • Game 4: Breakout
    • Game 5: Tank Battle
    • Game 6 Highlights
    • DO NOT DO:
    • Game 7: Final Project
    • Publish to Opera
    • FAQ
  • 3D Game Design
    • 1: Class Overview
    • 2: Installation
    • 3: Exploring the Unity UI
    • Game 1: Rolling Ball
    • Game 2: Tanks
    • Game 3: Third Person Platformer
    • Game 4: Final project
    • FAQs
    • OLD: Distance Learning Setup
    • OLD: GIT
  • 3D Modeling & Fabrication
    • Installation
    • Fusion 360 Interface and Sketch Modeling
    • Primitive Modeling
    • Patterns
    • Appearances and Rendering
    • Building Community Gallery Page 2023
    • Parametric Modeling
    • 3D Printing Concerns
    • Assemblies and Mechanical Design
    • Laser Cutting
    • Sculpt Tools
    • Milling Concerns
  • Robotics 7
    • Software Installation
    • Python basics (trinket.io)
    • Python Turtle
    • Programming for the Ev3
    • Setting up for clarity
  • Robotics 8
    • Replit
    • Python review
    • Kivy Basics
    • Calculator
  • Competitive Robotics
    • Hardware Team
      • CAD Examples
      • Elevators
    • Software Team
      • Command Pattern
      • Example Command
      • Subsystem
      • Running Your Code
      • Under the Hood
      • RoadRunner
      • Vision Processing
  • Archives
    • Adiletta Archives
      • Old Web
        • Ex: WordPress CMS
      • ItP
        • OLD: Parts of Python (old -- Mr. A)
        • OLD: 5: Raspberry Pi
        • OLD: 6: Deploying Code
        • OLD 7: Nav Algorithm
    • Vanek Archives
      • OLD Robotics 8
        • OLD: End of Class Project
      • OLD Competitive Robotics
        • Untitled
        • Webots Videos
      • OLD Robotics 7
        • Trinket Introduction
        • Lists: x/y position
        • Functions: Math program
        • Lists: Grocery List
        • Study Guide Program
        • Tic Tac Toe Game
        • Dice Roller Program
        • Visualization
        • Dice Roller + Visualization
        • OpenSCAD: Installation
        • OpenSCAD: Command Sheet and Intro
        • OpenSCAD: Difference
        • OpenSCAD: Variables
        • OpenSCAD: Union
        • OpenSCAD: For Loops
        • OpenSCAD: Final Project
      • OLD Art I - Blender Sculpting
        • Class Overview
        • Installation
        • Lesson 1 - Tools
        • Lesson 2 - Detail
        • Lesson 3 - Base Mesh: Metaballs
        • Lesson 4: Converting metaballs and adding detail
        • Lesson 5: Masking, Hiding, and Working with Multiple Objects
        • Lesson 6: Joining Objects & Basing
        • Lesson 7: Sculpture Painting
        • Student Gallery: Animal Sculpts
        • Lesson 8: 3D Compositon
        • Lesson 9: The Project - Putting it all together
        • Lesson 10: Developing the image further
        • Lesson 11: Layout the base metaball mesh.
        • Lesson 12: Final Detail
        • Lesson 13: Basing and Painting
        • Final Project Gallery
      • OLD Fab
        • OLD Building Community Project Gallery
        • Copy of Building Community Project Gallery
        • old Building Community Project Gallery
      • OLD: Turtle Design App
      • OLD Arduino Robotics 8
        • Arduino Basic Commands Cheat Sheet
        • Logging into Tinkercad
        • Arduino, Circuits, LEDs and Resistors
        • Functions and Variables
        • Serial Monitor
        • Buttons and Interrupts
        • Traffic Light Project
        • Potentiometers + Servos
        • Piezo Buzzer and Tone();
        • Sequencer Project
        • Arrays and for loops
        • Extra Loop Practice
        • Refining the Sequencer
        • Servos
        • Ultrasonic Sensors
        • Final Project
Powered by GitBook
On this page
  • Due to time, we will cover the following:
  • Platformer Movement Script
  • Animation Control
  • Enemy Move
  • Jump Attack
  • Resources

Was this helpful?

Export as PDF
  1. 2D Game Design

Game 6 Highlights

PreviousGame 5: Tank BattleNextDO NOT DO:

Last updated 6 months ago

Was this helpful?

Due to time, we will cover the following:

  • Platformer Movement (Video 1)

  • Importing Sprite Sheets (Video 1)

  • Enemy Movement & Paths (Video 2)

  • Tile Sets (class and video 3)

  • Big Room with a follow view (class and video 3)

Platformer Movement Script

// Run This Function in END STEP event
/*
 INSTRUCTIONS: 
 This function requires passing in arguments playerSpeed (not hspeed or speed) 
 and a gravity value.
 
 You should also make an optional argument maxFall with a value of 15
 
 In addition, you need to have two variables in the create event
 of your object:
 
     jumpSpeed = 0
     canJump = true
	 
optional:  Jumping variable (needed in create if you are going to have
		   a jumping animation (controlled in step).

*/



/*********************/
/*Horizontal Movement*/
/*********************/

var move = -keyboard_check(vk_left) + keyboard_check(vk_right);
var collision = instance_place(x+playerSpeed, y+vspeed, all);

// You are moving right
if (move == 1){
	
	if (collision < 0 or !object_get_solid(collision.object_index)){
		x += playerSpeed;
	}
	
	// Move to wall, if there is a SOLID wall to your right
	else{  
		move_contact_solid(0, playerSpeed);
	}
}

// You are moving left
else if (move == -1){
	collision = instance_place(x-playerSpeed, y+vspeed, all)
	if ( collision < 0 or !object_get_solid(collision.object_index)){
		x -= playerSpeed;
	}
	
	// Move to wall, if there is a solid wall to your left
	else{
		move_contact_solid(180, playerSpeed);		
	}
}



/*******************/
/*Vertical Movement*/
/*******************/

jumping = false;
collision = instance_place(x, y - jumpSpeed, all);
// Check to see if you are in the air or are about to jump.
if (place_empty(x, y + 1) or jumpSpeed > 0 or (collision > 0 and !object_get_solid(collision.object_index))){
	jumping = true;
}

// if you are jumping...
if (jumping){
	
	
	// Move up or down if there is no collision this frame.
	if (collision < 0 or !object_get_solid(collision.object_index)){
		y -= jumpSpeed;
	}
	
	// Check for a SOLID object below you
	else if (jumpSpeed < 0  and  object_get_solid(collision.object_index)){
		move_contact_solid(270, jumpSpeed)
		jumpSpeed = 0
	}
	
	// Check for a SOLID object above you
	else if (jumpSpeed > 0  and  object_get_solid(collision.object_index)){
		move_contact_solid(90, jumpSpeed)
		jumpSpeed = -0.1
	}
	jumpSpeed -= grav;
	if (jumpSpeed < -maxFall){
		jumpSpeed = -maxFall;
	}
}

// If you are on SOLID ground, allow the player to jump again.
if (!place_empty(x, y+1) and instance_place(x, y + 1, all) > 0 and object_get_solid( instance_place(x, y + 1, all).object_index)){
	canJump = true;
}

Animation Control

var dir = -keyboard_check(vk_left) + keyboard_check(vk_right)

//put your sprite names here:
var jump_right = sMario_jumpR
var walk_right = sMario_right
var jump_left = sMario_jumpL
var walk_left = sMario_left

image_speed = 3
if (dir == 1){
	if (jumping){
		sprite_index = jump_right;
	}
	else {
		sprite_index = walk_right;
	}
}
else if (dir == -1){
	if (jumping){
		sprite_index = jump_left;
	}
	else {
		sprite_index = walk_left;
	}
}
else {
	if (!jumping and sprite_index = jump_right){
		sprite_index = walk_right;
	} else if (!jumping and sprite_index = jump_left){
		sprite_index = walk_left;
	} else if (jumping and sprite_index = walk_right) {
		sprite_index = jump_right;
	} else if (jumping and sprite_index = walk_left) {
		sprite_index = jump_left;
	}
	image_speed = 0;
	image_index = 0;
}
	

Enemy Move

var collision = instance_place(x+hspeed, y+vspeed, all);
var collisionBelowRight = instance_place(x+hspeed+sprite_width, y+1, all)
var collisionBelowLeft = instance_place(x+hspeed-sprite_width, y+1, all)

if (hspeed > 0){
	if (place_empty(x+hspeed+sprite_width, y+1) or
	   (collision >-0 and object_get_solid(collision.object_index)) or
	   (!place_empty(x+hspeed+sprite_width, y+1) and collisionBelowRight > 0 and object_get_solid(collisionBelowRight.object_index) == false )){
		hspeed = -hspeed;
	}
}
else if (hspeed < 0){
	if (place_empty(x+hspeed-sprite_width, y+1) or 
	   (collision >-0 and object_get_solid(collision.object_index)) or
	   (!place_empty(x+hspeed-sprite_width, y+1) and collisionBelowLeft > 0 and object_get_solid(collisionBelowLeft.object_index) == false )){
		hspeed = -hspeed;
	}
}

Jump Attack

if (y < other.y and jumpSpeed <= 0){
	instance_destroy(other)
} 
else {
	instance_destroy(self)	
}

Resources

Mario Sprite Sheet
Enemy Sprite Sheet
Flying Enemy Sprite Sheet
Mario Tileset