DocumentInQuestion.png This page or section is in question as to whether it is useful or not. You can discuss whether you want it deleted or not on its talk page.
Reason: Same as Pen Projects

A 100% pen game is a game where the player and level are drawn in pen. This means having no sprites moving as the player. While pen games can range from having nothing in the costume to a large black rectangle being the costume, a 100% pen game’s costume should be blank or a very small dot.

Code

The coding on a pen platformer is usually complicated, it involves drawing everything even the player. Some pen platformers use Touching Color () blocks to detect walls, ceilings, and floors. Some pen platformers store solid blocks, hazard blocks, and high-jump blocks in lists to avoid lag with touching color blocks. You can also make pen games that are not platformers, these games usually have no gravity[1]

Platformer

First, you need to create five variables.

(PlayerX)//This Stores the player's left/right position
(PlayerY)//this does the same, but with up/down
(level)//this stores the level the player is on
(jump power)//this makes a realistic jumping motion
(can jump?)//this says if the player can jump or not

Second, you need to make the costume a single small dot in the middle of the picture.

Now to the coding.

Note Note: Pen games use a lot of code! This next section is very large!
define Draw line from (x)(y) to (x2)(y2) color (c) size (s) shade (s2)
pen up//this block will draw a line
go to x:(x)y:(y)
set pen color to (c)
set pen size to (s)
set pen shade to (s2)
pen down
go to x:(x2)y:(y2)
pen up

define Make circle at (x)(y) color (c) shade (s) radius (r)
pen up// this block will draw a circle
go to x:(x)y:(y)
set pen color to (c)
set pen size to (r)
set pen shade to (s)
pen down
pen up

when green flag clicked
set [level v] to [1]//resets the level
set [playerX v] to [-220]//resets the player's position
set [playerY v] to [-100]//resets the player's position
set [can jump? v] to [0]//tells the program if the player can jump
forever//Does what it says! runs it to ∞ and beyond!
clear//resets the screen
floor::custom
broadcast (level)//draws the level
Draw circle at (playerX)(playerY) color (120) shade (50) radius (15)::custom//draws the player
Keys::custom//left and right arrow keys are detected here
Detections::custom
end

when I receive [1 v]//Level 1!
floor::custom
Detections::custom

define floor
Draw line from (-240)(-180) to (240)(-180) color (115) size (50) shade (50)::custom// This draws the floor.  Include this in every level.

when I receive [2 v]//Level 2!
floor::custom//floor!
Draw line from (0)(-180) to (0)(-120) color (115) size (50) shade (50)::custom//draws a line in the middle of the screen
Detections::custom


when I receive [3 v]//Level 3, Featuring lava!
Draw line from (0)(-180) to (0)(-100) color (0) size (2) shade (50)::custom
//This color is defined as “bad color”
floor::custom//Now that this is under the lava, this means that the lava will be under the floor.
Detections::custom

define Keys
if <key [right arrow v] pressed> then
change [playerX v] by (3)//move right
end
if <key [left arrow v] pressed> then
change [playerX v] by (-3)//move left
end

when green flag clicked
forever
if <key [up arrow v] pressed> then//the up arrow key needs to be separate so then you can move and jump at the same time
if <(can jump?) = [1]> then
set [jump power v] to [12]//jump power is set to 12
repeat (jump power)//= jump power
change [playerY v] by (jump power)//moves the player
change [jump power v] by (-1)//makes the motion happen
end
end
end
end

define Detections
go to x:(playerX)y:((playerY) + (-12))//floor
if <touching color [Ground color goes here]?> then
set [can jump? v] to [1]//this block detects where the player is and what they are touching

else
set [can jump? v] to [0]
change [playerY v] by (-5)
end
go to x:((playerX) + (12))y:(playerY)//detecting a wall on the right
if <touching color [Wall color goes here]?> then
change [playerX v] by (-3)

end
go to x:((playerX) + (-12))y:(playerY)//detecting a wall on the left
if <touching color [Wall color goes here]?> then
change [playerX v] by (3)

end
go to x:(playerX)y:((playerY) + (-12))//detecting if player is standing on a bad color
if <touching color [Bad color goes here]?> then
set [playerX v] to [-220]
set [playerY v] to [-100]

end
go to x:((playerX) + (12))y:(playerY)//detecting if a bad color is on the right
if <touching color [Bad color goes here]?> then
set [playerX v] to [-220]
set [playerY v] to [-100]

end
go to x:((playerX) + (-12))y:(playerY)//detecting if a bad color is on the left
if <touching color [Bad color goes here]?> then
set [playerX v] to [-220]
set [playerY v] to [-100]

end
go to x:(playerX)y:((playerY) + (12))//up bad
if <touching color [Bad color goes here]?> then
set [playerX v] to [-220]
set [playerY v] to [-140]

end

when green flag clicked
forever
if <(playerX) > (235)> then
set [playerX v] to [-220]
set [playerY v] to [-140]
change [level v] by (1)
end


Other Pen Games

Other than a useal platformer these types of games can go from, avoiding large objects to jumping off walls avoiding stuff. All types of pen games usualy use a fair amount of coding. The code to make a game where the goal of the game is to avoid moving blocks is shown below[2]

First, you need to make two variables

(Player X)//these store the player's position
(Player Y)//these store the player's position

Second, change/add 2 costumes. They should look the same. The costumes should be a single dot in the middle of the picture.


define Draw Square at (x) (y) color (c) size (s) shade (s2) Size of pen (s3) filled? (F)
pen up//This custom block is a Run Without Screen Refresh block
go to x: ((x) + (s)) y: ((y) + (s))//goes to the top left corner
set pen color to (c)//color
set pen shade to (s2)//shade
set pen size to (s3)//size
pen down
go to x: ((x) + (s)) y: ((y) - (s))//bottom right
go to x: ((x) - (s)) y: ((y) - (s))//bottom left
go to x: ((x) - (s)) y: ((y) + (s))//top left
go to x: ((x) + (s)) y: ((y) + (s))//top right
pen up
if <(F) = [1]> then //fill
  Draw Square at (x) (y) color (c) size ((s) - (6)) shade (s2) Size of pen (s3) filled? (0) :: custom
end
if <(costume #) = [3]> then
  go to x: (x) y: (y)//resets the clones so they don't fly off into the top left hand corner
end

define Draw line from (x) (y) to (x2) (y2) color (c) size (s) shade (s2) Draws lines
pen up
go to x: (x) y: (y)
set pen color to (c)
set pen shade to (s2)
set pen size to (s)
pen down
go to x: (x2) y: (y2)
pen up

when green flag clicked
switch costume to [costume1 v]//Telling  if you are a clone
set [player X v] to [0]//resetting the player's position
set [player Y v] to [0]//resetting the player's position
forever
  clear
  Draw Square at (player X) (player Y) color (0) size (10) shade (50) Size of pen (8) filled? (1) :: custom//drawing the player
  broadcast [Draw Clones v] and wait//drawing the flying squares
  Keys :: custom//Detecting up/down/left/right
  Detect :: custom//Are you touching the squares?
end

when green flag clicked
forever
  create clone of [Sprite1 v]//creating clones for the other squares
  wait (0.2) secs//waiting...
end

define Keys
if <key [up arrow v] pressed?> then//up
  change [player Y v] by (5)
end
if <key [down arrow v] pressed?> then //down
  change [player Y v] by (-5)
end
if <key [left arrow v] pressed?> then //left
  change [player X v] by (-5)
end
if <key [right arrow v] pressed?> then //right
  change [player X v] by (5)
end
if <(player X) > [226]> then //Stopping the player from going off screen
  set [player X v] to [226]
end
if <(player X) < [-226]> then //Stopping the player from going off screen
  set [player X v] to [-226]
end
if <(player Y) > [166]> then //Stopping the player from going off screen
  set [player Y v] to [166]
end
if <(player Y) < [-166]> then //Stopping the player from going off screen
  set [player Y v] to [-166]
end

when I receive [Game over v]//Game over!
clear//clearing the board
stop [all v]//stopping the game

define Detect
if <(costume #) = [4]> then//This line determines if the sprite is a clone. The block as a whole detects if you are touching the squares. ‘Run without screen refresh’ should be on
  go to x: ((player X) + (12)) y: ((player Y) + (12))
  if <touching color [your bad color] ?> then
    broadcast [Game over v]
  end
  go to x: ((player X) + (12)) y: ((player Y) - (12))
  if <touching color [your bad color] ?> then
    broadcast [Game over v]
  end
  go to x: ((player X) - (12)) y: ((player Y) - (12))
  if <touching color [your bad color] ?> then
    broadcast [Game over v]
  end
  go to x: ((player X) - (12)) y: ((player Y) + (12))
  if <touching color [your bad color] ?> then
    broadcast [Game over v]
  end
end

when I receive [Draw Clones v]
draw :: custom//drawing the other squares

when I start as a clone
switch costume to [costume3 v]
go to [random position v]
if <(pick random (1) to (2)) = [1]> then //this system moves the clone to a random edge
  if <(y position) > [0]> then
    set y to (180)
    point in direction (180 v)
  else
    set y to (180)
    point in direction (0 v)
  end
else
  if <(x position) > [0]> then
    set x to (240)
    point in direction (-90 v)
  else
    set x to (-240)
    point in direction (90 v)
  end
end
forever
  move (2) steps
  if <(direction) = [90]> then//this deletes the clone if it is at its destination
    if <(x position) = [240]> then
      delete this clone
    end
  end
  if <(direction) = [-90]> then //this deletes the clone if it is at its destination
    if <(x position) = [-240]> then
      delete this clone
    end
  end
  if <(direction) = [0]> then //this deletes the clone if it is at its destination
    if <(y position) = [180]> then
      delete this clone
    end
  end
  if <(direction) = [180]> then //this deletes the clone if it is at its destination
    if <(y position) = [-180]> then
      delete this clone
    end
  end
end

define draw
if <(costume #) = [3]> then//‘Run without screen refresh’ should be checked for this block
  Draw Square at (x position) (y position) color (115) size (10) shade (50) Size of pen (8) filled? (1) :: custom//draws the other squares
  stop [this script v]
end


Awesome! You have learned how to create your own pen game!

See also

References

  1. https://scratch.mit.edu/projects/137189127/
  2. https://scratch.mit.edu/projects/125478387/