Game 6 Highlights

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

1
// Run This Function in END STEP event
2
/*
3
INSTRUCTIONS:
4
This function requires passing in arguments playerSpeed (not hspeed or speed)
5
and a gravity value.
6
7
You should also make an optional argument maxFall with a value of 15
8
9
In addition, you need to have two variables in the create event
10
of your object:
11
12
jumpSpeed = 0
13
canJump = true
14
15
optional: Jumping variable (needed in create if you are going to have
16
a jumping animation (controlled in step).
17
18
*/
19
20
21
22
/*********************/
23
/*Horizontal Movement*/
24
/*********************/
25
26
var move = -keyboard_check(vk_left) + keyboard_check(vk_right);
27
var collision = instance_place(x+playerSpeed, y+vspeed, all);
28
29
// You are moving right
30
if (move == 1){
31
32
if (collision < 0 or !object_get_solid(collision.object_index)){
33
x += playerSpeed;
34
}
35
36
// Move to wall, if there is a SOLID wall to your right
37
else{
38
move_contact_solid(0, playerSpeed);
39
}
40
}
41
42
// You are moving left
43
else if (move == -1){
44
collision = instance_place(x-playerSpeed, y+vspeed, all)
45
if ( collision < 0 or !object_get_solid(collision.object_index)){
46
x -= playerSpeed;
47
}
48
49
// Move to wall, if there is a solid wall to your left
50
else{
51
move_contact_solid(180, playerSpeed);
52
}
53
}
54
55
56
57
/*******************/
58
/*Vertical Movement*/
59
/*******************/
60
61
jumping = false;
62
collision = instance_place(x, y - jumpSpeed, all);
63
// Check to see if you are in the air or are about to jump.
64
if (place_empty(x, y + 1) or jumpSpeed > 0 or (collision > 0 and !object_get_solid(collision.object_index))){
65
jumping = true;
66
}
67
68
// if you are jumping...
69
if (jumping){
70
71
72
// Move up or down if there is no collision this frame.
73
if (collision < 0 or !object_get_solid(collision.object_index)){
74
y -= jumpSpeed;
75
}
76
77
// Check for a SOLID object below you
78
else if (jumpSpeed < 0 and object_get_solid(collision.object_index)){
79
move_contact_solid(270, jumpSpeed)
80
jumpSpeed = 0
81
}
82
83
// Check for a SOLID object above you
84
else if (jumpSpeed > 0 and object_get_solid(collision.object_index)){
85
move_contact_solid(90, jumpSpeed)
86
jumpSpeed = -0.1
87
}
88
jumpSpeed -= grav;
89
if (jumpSpeed < -maxFall){
90
jumpSpeed = -maxFall;
91
}
92
}
93
94
// If you are on SOLID ground, allow the player to jump again.
95
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)){
96
canJump = true;
97
}
Copied!

Animation Control

1
var dir = -keyboard_check(vk_left) + keyboard_check(vk_right)
2
3
//put your sprite names here:
4
var jump_right = sMario_jumpR
5
var walk_right = sMario_right
6
var jump_left = sMario_jumpL
7
var walk_left = sMario_left
8
9
image_speed = 3
10
if (dir == 1){
11
if (jumping){
12
sprite_index = jump_right;
13
}
14
else {
15
sprite_index = walk_right;
16
}
17
}
18
else if (dir == -1){
19
if (jumping){
20
sprite_index = jump_left;
21
}
22
else {
23
sprite_index = walk_left;
24
}
25
}
26
else {
27
if (!jumping and sprite_index = jump_right){
28
sprite_index = walk_right;
29
} else if (!jumping and sprite_index = jump_left){
30
sprite_index = walk_left;
31
} else if (jumping and sprite_index = walk_right) {
32
sprite_index = jump_right;
33
} else if (jumping and sprite_index = walk_left) {
34
sprite_index = jump_left;
35
}
36
image_speed = 0;
37
image_index = 0;
38
}
39
Copied!

Enemy Move

1
var collision = instance_place(x+hspeed, y+vspeed, all);
2
var collisionBelowRight = instance_place(x+hspeed+sprite_width, y+1, all)
3
var collisionBelowLeft = instance_place(x+hspeed-sprite_width, y+1, all)
4
5
if (hspeed > 0){
6
if (place_empty(x+hspeed+sprite_width, y+1) or
7
(collision >-0 and object_get_solid(collision.object_index)) or
8
(!place_empty(x+hspeed+sprite_width, y+1) and collisionBelowRight > 0 and object_get_solid(collisionBelowRight.object_index) == false )){
9
hspeed = -hspeed;
10
}
11
}
12
else if (hspeed < 0){
13
if (place_empty(x+hspeed-sprite_width, y+1) or
14
(collision >-0 and object_get_solid(collision.object_index)) or
15
(!place_empty(x+hspeed-sprite_width, y+1) and collisionBelowLeft > 0 and object_get_solid(collisionBelowLeft.object_index) == false )){
16
hspeed = -hspeed;
17
}
18
}
Copied!

Jump Attack

1
if (y < other.y and jumpSpeed <= 0){
2
instance_destroy(other)
3
}
4
else {
5
instance_destroy(self)
6
}
Copied!

Resources