How to Make a Basic Shooter

Материал из Поле цифровой дидактики
Версия от 11:33, 21 июля 2022; Patarakin (обсуждение | вклад) (1 версия импортирована)

Шаблон:Expand This tutorial features an endless basic shooting game.

Plan

Before starting to build the game, here's a plan that will be followed:

  • Make the player fire lasers when the left mouse button is down.
  • When a shape is destroyed, give the player a specific amount of money depending on what shape was destroyed.
  • When a laser hits an enemy (in this tutorial, a zombie), make that zombie lose some health points; when the zombie runs out of health points (has less than 0.1), delete the zombie and change the $ by an amount depending on what type of zombie it is.
  • Include multiple weapons for the player to choose from.
  • Release specific zombies at a specific rate depending on the level/wave the player is on.
  • Show all variables that need to be shown in a fancy way.

Building the Game

There are no given costumes included with this tutorial — be creative and create some!

The Player

This section will focus on the movement and direction of the player sprite. After a base costume for the PCS (player-controlled sprite) has been made, create the variables PlayerBounceback, xspeed, and yspeed for all sprites.

whenclickedsetPlayerBouncebackto0resettheplayerbouncebackforeverifPause=0andPlayerBounceback<0thenifthegameisn'tpausedandtheplayerbonuncebackislessthan0(thevariablewillbenegitavetomaketheplayergobackward)then...movePlayerBouncebackstepsmovetheplayerbackchangePlayerBouncebackby0.1increase(ordecrease,whicheverwayyou'drefertoitas)theplayerbounceback.ByaddingapositivetoanegitavemakethenumbersmallerendendwhenclickedYoucanchangethisifyouwouldliketo.switchcostumetoplayerSwitchthecostumeto"player"orwhatyounamedyourplayercostume.setxspeedto0Resetxspeed.setyspeedto0Resetyspeed.gotox-100y0Movethepcs(player-controlledsprite)tothemiddleoftheleftsideofthescreen.foreverLoopthefollowingscriptforever.ifpause=0thenifthegameisn'tpausedpointtowardsmouse-pointerMakethepcspointtowardsthemousepointer.changexbyxspeedChangexbyavariable.changeybyyspeedChangeybyavariable.ifkeywpressed?orkeyuparrowpressed?thenIfworuparrowkeypressed.changevspeedby1endifkeyspressed?orkeydownarrowpressed?thenIfsordownarrowkeypressed.changevspeedby-1endifkeyapressed?orkeyleftarrowpressed?thenIfaorleftarrowkeypressed.changexspeedby-1endifkeydpressed?orkeyrightarrowpressed?thenIfdorrightarrowkeypressed.changexspeedby1endsetyspeedto0.9*yspeedDecreasetheyvariable.setxspeedto0.9*xspeedDecreasethexvariable.createcloneofmyselfThisisoptional(O#1).ifonedge,bouncedoesn'tlettheplayergoofftheedge-goingofftheedgerestrictstheplayerfromfiringendendwhenIstartascloneDothisifyoudid(O#1).switchcostumetotrailAcostumeisneededwithoutanyplayergraphics.setsizeto90%Setthesizeto90%(9/10)oftheoriginalsize.repeat10Repeatthefollowingcode10times(10*10=100,100%ghost=invisible)changeghosteffectby10Makethetrailslightlydisappear.enddeletethiscloneDeletetheclone.

Guns and Weapons

The player needs to have some tools to defend themselves. In this tutorial, there will be eight weapons that one can use.

  • Daggers (move forward and back when mouse is down).
  • Sword (turns when mouse is down).
  • Flank swords (turns when mouse is down).
  • Gun (points towards mouse pointer & fires a projectile when the mouse is down).
  • Machine Gun (same characteristics as a gun, but fires rapidly, and isn't very accurate).
  • Twin guns (like a machine gun, but it is accurate).
  • Hunter (fires two fast and piercing projectiles).
  • Destroyer (fires a projectile that can go through many zombies and shapes while dealing excessive damage).

Enemies

In this game, the enemies will be zombies. They will not fire projectiles but will instead smash use melee attacks on the player instead. There will be 5 types of zombies.

  • Normals.
  • Fast (run instead of walk and gives 100% more cash than normals).
  • Strong (have more shield than normals and give 200% more cash than them).
  • Boss (walk slower than normals, but have 20000% more health and give 5000% more cash than them. They also spawn clones — who are like normals, but have 50% of their health).
  • Boss minions (normals but have less health).

Shapes

The player should have a way to earn cash without having to shoot zombies. In this game, the player will have 3 different shapes to destroy.

  • Squares (has low protection, and a low amount of points will be earned by destroying it).
  • Triangles (100% more protection that a square, and gives twice the cash).
  • Pentagons (has high protection, and gives a bundle of cash).

Displays

The scripts below will give the game a display, although you can skip these two steps and just show the variables with showvariable and hidevariable. Make sure you go to the costumes section of a new sprite and type all of the one-digit numbers (1, 2, 3, 4, 5, 6, 7, 8, 9, 0) in 11 costumes and name them their number. Then, include a blank costume named "" (clear the name spot) — this will help in the coding part. Lastly, make sure that you position them at the center. To properly center the costumes, use the marked cross section in the middle.

Before any code is created, create the variables below for this sprite only: variable and digit

Here's the code:

whenclickedhidesetyto150Makesureyou'recloningattherightheight...setvariableto1Thisvariablewillbeusedtodefinewhatvariablewillbedisplayed.setdigitto1Thisvariableisusedtodeterminethedigitofthevariable.clone|x:-205Usemultipleblockstomakethenumbersappearfaster.clone|x:xposition+17clone|x:xposition+17clone|x:xposition+17clone|x:xposition+17setyto130setvariableto2setdigitto1clone|x:-205Mostlikely,the"lives"variablewon'tgomorethanthreedigits,sotheblockisjustusedthreetimes.clone|x:xposition+17clone|x:xposition+17setyto-160setvariableto3clone|x:-165Mostlikely,the"waves"variablewon'tgomorethanthreedigits,sotheblockisjustusedthreetimes.clone|x:xposition+17clone|x:xposition+17defineclone|x:xshowsetxtoxcreatecloneofmyselfCreateasingle-digitdisplayer.changedigitby1Changewhatdigitthevariablewilldisplay.hidewhenIstartasaclonegotofrontlayerStopstheplayerfrom"walking"onthevariable.foreverifvariable=1thenswitchcostumetoletterdigitofendifvariable=2thenswitchcostumetoletterdigitofroundplayerlifeYouhavetorounditsoitdoesn'tgoanddisplayadecimalvalue.endifvariable=3thenswitchcostumetoletterdigitofwaveendend

Examples

Here is an example of a game built with this tutorial: