How to Make a Top Down Scroller Game

Материал из Поле цифровой дидактики

Шаблон:Wiki Standards Top down scrollers are a very common type of game in Scratch as they are generally easy to make. A top down scroller consists of a scrolling map with walls and objects. There is a player that moves around the map and can be blocked by walls and other obstacles. There can be weapons, enemies, collectables or even inventory systems.

Scrolling

First, a scrolling base is needed (please note that there will be no walls yet). It can be made by drawing levels or by uploading images. If you are drawing it, try to use vector, then convert to bitmap to trim of the edges (this is very important). Do not put any wall or obstacles as that will be for the wall sprite. (if you are uploading a picture then you can keep it. Once you have the levels, label them for easier scripting. The middle one should be 0,0, the one on the right should be 1,0, and so on. Then make a player, it should be about 50 x 50 pixels big.

Making the scripts

Make 2 variables in the player sprite and make sure that they are for all sprites.

 (scroll x) 
(scroll y) 

Then go to the map and make these local variables and this custom block:

 (x)
(y) 
 define clone at (x) (y) (costume) 
set [x v] to ((0) - ((x) * (480)))
set [y v] to ((0) - ((y) * (360)))
switch costume to (costume)
create clone of (myself v)

Then you can put the when green flag clicked block and create a clone block at the desired location and the correct costume all the way through all the map costumes. Use the labels as guides to what number to put. Make sure to put a wait 0.01 seconds block before just so the clones don't get deleted right when they are cloned (by the last script in this section)

Then make this script:

when I start as a clone
forever
 go to x: ((scroll x) - (x)) y: ((scroll y ) - (y))
 if <<(x position) = ((scroll x) - (x))> and < (y position) = ((scroll y) - (y)) >> then
  show
 else
  hide
 end
end 

Before moving on, add this script to prevent clones from stacking on top of each other:

when green flag clicked
delete this clone

Player Movement

Once you have the map, you need a movement system that has wall sensing and scrolling. To begin, duplicate the map sprite but name it wall. Then add walls and obstacles. Finally delete the map, leaving just the obstacles. If you are uploading an image, redraw the wall's shape (don't waste time drawing the insides) and set ghost effect to 100. Do not use the hide block for this. You can also make it sense the color of the walls if the image has walls of the exact color.

Making the scripts

start by making this script in the player sprite:

when green flag clicked
go to x:(0) y:(0)
forever
 if <key (up arrow v) pressed> then
  change y by (10) //or whatever you want to player speed to be (4 is slow, 8 is normal, 15 is fast)
  if <touching (wall v)> then
  change y by (-10) // or whatever you put in the top
  end
 end
 if <key (up arrow v) pressed> then
  change y by (-10) //do the negative of what you put for the up movement 
  if <touching (wall v)> then
  change y by (10) //same as previous
  end
 end
 if <key (up left arrow v) pressed> then
  change x by (10) 
  if <touching (wall v)> then
  change x by (-10)
  end
 end
 if <key (up right arrow v) pressed> then
  change x by (-10) 
  if <touching (wall v)> then
  change x by (10)
  end
 end
 change [scroll x v] by ((0) - (x position))
 change [scroll y v] by ((0) - (y position))
 go to x: (0) y: (0)
end

That is all the scripts for player movement and wall detection.

Getting Advanced

The scripts above are just to get you started, here are some advanced ways to make your game more fun.

Enemies

Enemies are things that try to kill your player. To make an enemy, you have to combine the scripts of the player and the walls, and add some more code. To do this, duplicate the player sprite, but delete the ending 3 blocks. Then you can get the cloning scripts from the walls, and the rest is up to you. There are many type of enemies, including dumb ones that glide straight to your player, smart ones the identifies a path to your player, and semi-smart ones that are a combination of both. They are harder to make, so it they are not included in this tutorial.

Achievements

Achievements are things that you have to do a specific thing or things to get. Achievements can vary greatly, so it is up to you to decide what to make. However, an achievement needs a trigger, such as getting a certain amount of coins or winning a level in hardcore.

Collectables

Collectables are things that you can collect, in most cases it is coins or currency that can be traded for items. They can also be skill points that increase your level. It can also be pieces that the player need to collect in order to win a level.

Finishing Up

Once you have everything you want in your game, you can share it with the community. Top down scrollers are very common, but they vary greatly. Before you make it official, be sure to make sure it has no obvious glitches or bugs.

Examples