๐ฎ Avanserte Koder og Prosjekter
Her finner du kule koder og eksempler som gรฅr utover det grunnleggende!
Klassisk snake-spill i Minecraft
Bevegelige plattformer og utfordringer
Komplette spill og systemer
๐ Ring Race Timer
En utfordring der du mรฅ fly gjennom to ringer sรฅ raskt som mulig! Koden mรฅler tiden din og gir deg poeng for hver ring.
RING1 = world(53, -57, -62)
RING2 = world(30, -57, -70)
def on_run_in_background():
# Reset course so detection isn't instant
blocks.place(AIR, RING1)
blocks.place(AIR, RING2)
ring1done = False
ring2done = False
poeng = 0
started = False
finished = False
start_ticks = 0
last_check_tick = 0
check_interval_ticks = 2 # only check every 2 game ticks (~0.1s)
while True:
current_tick = gameplay.time_query(GAME_TIME)
# Only run logic if enough ticks have passed
if current_tick - last_check_tick >= check_interval_ticks:
last_check_tick = current_tick
# First ring detection
if not ring1done and blocks.test_for_block(GLASS, RING1):
ring1done = True
poeng += 1
player.say("RING 1 done")
if not started:
started = True
start_ticks = current_tick
continue
# Second ring detection
if not ring2done and blocks.test_for_block(GLASS, RING2):
ring2done = True
poeng += 1
player.say("RING 2 done")
if not started:
started = True
start_ticks = current_tick
continue
# Finish check
if started and not finished and ring1done and ring2done:
end_ticks = gameplay.time_query(GAME_TIME)
elapsed_ticks = end_ticks - start_ticks
total_seconds = elapsed_ticks // 20
minutes = total_seconds // 60
seconds = total_seconds % 60
time_str = str(minutes) + ":" + ("0" if seconds < 10 else "") + str(seconds)
player.say("Du har fullfรธrt alle ringer")
player.say("Du har " + str(poeng) + " poeng")
player.say("Tid: " + time_str)
finished = True
break
loops.run_in_background(on_run_in_background)
๐ Snake-spill Pakke
Her er en komplett samling av forskjellige Snake-spill varianter for Minecraft!
๐ฎ Multi-Snake Parkour Course
Et avansert parkour-system med 6 forskjellige bevegelige "slanger" som skaper utfordringer!
# ๐ SIMPLE 3-SNAKE PARKOUR - EASY SETUP
# Perfect for 12-year-olds and beginners!
# ================================================================
# ๐ STEP 1: CHANGE THESE COORDINATES TO YOUR WORLD!
# ================================================================
# Starting point (where Snake 1 will be)
START_X = 53
START_Y = -58
START_Z = -76
# Ending point (where Snake 3 will be)
END_X = 92
END_Y = -58
END_Z = -76
# Trigger location (where to place EMERALD_BLOCK to start)
TRIGGER_X = 52
TRIGGER_Y = -57
TRIGGER_Z = -75
# ================================================================
# ๐ฎ STEP 2: CHANGE SNAKE SETTINGS (EASY TO CUSTOMIZE!)
# ================================================================
# Snake 1 settings (EASY - Horizontal movement)
SNAKE1_LENGTH = 6 # How many blocks long
SNAKE1_RANGE = 8 # How far it moves (left-right)
SNAKE1_SPEED = 800 # How fast (bigger = slower)
# Snake 2 settings (MEDIUM - Vertical movement)
SNAKE2_LENGTH = 5 # How many blocks long
SNAKE2_RANGE = 6 # How far it moves (up-down)
SNAKE2_SPEED = 600 # How fast (bigger = slower)
# Snake 3 settings (HARD - Diagonal movement)
SNAKE3_LENGTH = 4 # How many blocks long
SNAKE3_RANGE = 10 # How far it moves (diagonal)
SNAKE3_SPEED = 400 # How fast (bigger = slower)
# ================================================================
# ๐ SNAKE 1: GREEN HORIZONTAL SNAKE (EASIEST)
# ================================================================
def snake_1():
snake_blocks = []
step = 0
while True:
# Move left and right
if step < SNAKE1_RANGE:
x_pos = START_X + step
else:
x_pos = START_X + (SNAKE1_RANGE * 2 - 1 - step)
# Reset when reaching end
if step >= SNAKE1_RANGE * 2 - 1:
step = 0
else:
step += 1
# Create snake head
head_pos = world(x_pos, START_Y, START_Z)
snake_blocks.append(head_pos)
blocks.place(EMERALD_BLOCK, head_pos) # Green blocks
# Remove tail to keep snake length
if len(snake_blocks) > SNAKE1_LENGTH:
tail_pos = snake_blocks.pop(0)
blocks.place(AIR, tail_pos)
loops.pause(SNAKE1_SPEED)
# ================================================================
# ๐ SNAKE 2: GOLD SPIRAL STAIR SNAKE (MEDIUM)
# ================================================================
def snake_2():
snake_blocks = []
step = 0
# Snake 2 position (10 blocks away from Snake 1)
snake2_x = START_X + 10
snake2_z = START_Z + 5
# Spiral stair pattern (8 positions around a circle, going up)
spiral_pattern = [
(0, 0), # Center-ish start
(2, 0), # Right
(2, 2), # Right-Back
(0, 2), # Back
(-2, 2), # Left-Back
(-2, 0), # Left
(-2, -2), # Left-Front
(0, -2) # Front
]
while True:
# Get current spiral position
pattern_step = step % len(spiral_pattern)
x_offset, z_offset = spiral_pattern[pattern_step]
# Go up one block every 2 steps in the spiral
y_offset = (step // 2) % 8 # Goes 0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7 then repeats
# Reset when completing full spiral cycle
if step >= len(spiral_pattern) * 8: # 8 height levels * 8 positions = 64 steps
step = 0
else:
step += 1
# Create snake head at spiral position
head_pos = world(snake2_x + x_offset, START_Y + y_offset, snake2_z + z_offset)
snake_blocks.append(head_pos)
blocks.place(GOLD_BLOCK, head_pos) # Gold blocks
# Remove tail to keep snake length
if len(snake_blocks) > SNAKE2_LENGTH:
tail_pos = snake_blocks.pop(0)
blocks.place(AIR, tail_pos)
loops.pause(SNAKE2_SPEED)
# ================================================================
# ๐ SNAKE 3: DIAMOND ZIGZAG SNAKE WITH GAPS (HARDEST)
# ================================================================
def snake_3():
snake_blocks = []
step = 0
# Snake 3 position (10 blocks away from Snake 2)
snake3_start_x = START_X + 20
snake3_start_z = START_Z + 10
# Zigzag pattern with permanent gaps that players must memorize
# 1 = place block, 0 = gap (no block)
zigzag_gaps = [1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1] # 16-step pattern
# Zigzag movement pattern (left-right-left-right)
zigzag_offsets = [0, 1, 2, 1, 0, -1, -2, -1, 0, 1, 2, 1, 0, -1, -2, -1] # 16-step pattern
while True:
# Get current position in patterns
pattern_step = step % len(zigzag_gaps)
# Calculate zigzag position
z_offset = zigzag_offsets[pattern_step]
x_pos = snake3_start_x + (step // 4) # Move forward every 4 steps
z_pos = snake3_start_z + z_offset
# Only place block if gap pattern says so (1 = block, 0 = gap)
if zigzag_gaps[pattern_step] == 1:
head_pos = world(x_pos, END_Y, z_pos)
snake_blocks.append(head_pos)
blocks.place(DIAMOND_BLOCK, head_pos) # Diamond blocks
else:
# Create a "ghost" position for timing but don't place block
player.say(f"Gap at step {pattern_step + 1}!") # Help players learn the pattern
# Remove tail to keep snake length
if len(snake_blocks) > SNAKE3_LENGTH:
tail_pos = snake_blocks.pop(0)
blocks.place(AIR, tail_pos)
# Reset pattern when reaching end
if step >= SNAKE3_RANGE * 4: # 4 steps per forward movement
step = 0
else:
step += 1
loops.pause(SNAKE3_SPEED)
# ================================================================
# ๐ฎ CONTROL SYSTEM - START THE PARKOUR!
# ================================================================
def start_parkour():
"""Start all 3 snakes when emerald block is placed"""
player.say("๐ STARTING 3-SNAKE PARKOUR! ๐")
player.say("Snake 1: GREEN blocks moving left-right (EASY)")
loops.pause(500)
player.say("Snake 2: GOLD blocks in spiral stair (MEDIUM)")
loops.pause(500)
player.say("Snake 3: DIAMOND zigzag with gaps - memorize the pattern! (HARD)")
loops.pause(500)
# Start all snakes in background
loops.run_in_background(snake_1)
loops.pause(300)
loops.run_in_background(snake_2)
loops.pause(300)
loops.run_in_background(snake_3)
player.say("All snakes active! Jump carefully! ๐ฎ")
player.say("Goal: Jump from green โ gold โ diamond!")
def clear_parkour():
"""Clear all snakes from the area"""
player.say("Clearing parkour area...")
# Clear large area to remove all snake blocks
blocks.fill(AIR,
world(START_X - 5, START_Y - 2, START_Z - 5),
world(END_X + 5, END_Y + 10, END_Z + 5))
player.say("Area cleared!")
# ================================================================
# ๐ฏ MAIN CONTROLLER - WATCHES FOR TRIGGER BLOCK
# ================================================================
def parkour_controller():
"""Main controller - watches for emerald block trigger"""
player.say("๐ฎ SNAKE PARKOUR READY!")
player.say(f"Place EMERALD_BLOCK at coordinates: {TRIGGER_X}, {TRIGGER_Y}, {TRIGGER_Z}")
player.say("Place REDSTONE_BLOCK at same location to clear area")
while True:
# Check for start trigger (emerald block)
if blocks.test_for_block(EMERALD_BLOCK, world(TRIGGER_X, TRIGGER_Y, TRIGGER_Z)):
blocks.place(AIR, world(TRIGGER_X, TRIGGER_Y, TRIGGER_Z)) # Remove trigger
start_parkour()
# Check for clear trigger (redstone block)
elif blocks.test_for_block(REDSTONE_BLOCK, world(TRIGGER_X, TRIGGER_Y, TRIGGER_Z)):
blocks.place(AIR, world(TRIGGER_X, TRIGGER_Y, TRIGGER_Z)) # Remove trigger
clear_parkour()
loops.pause(500) # Check twice per second
# ================================================================
# ๐ START THE SYSTEM!
# ================================================================
# Start the controller automatically
loops.run_in_background(parkour_controller)
# Welcome message
player.say("๐ 3-SNAKE PARKOUR LOADED! ๐")
player.say("๐ Step 1: Change coordinates at top of code")
player.say("๐ Step 2: Place EMERALD_BLOCK to start")
player.say("๐ Step 3: Jump and have fun!")
# ================================================================
# ๐ QUICK REFERENCE FOR KIDS:
# ================================================================
#
# HOW TO USE:
# 1. Change START_X, START_Y, START_Z to your location
# 2. Change END_X, END_Y, END_Z to where you want Snake 3
# 3. Change TRIGGER_X, TRIGGER_Y, TRIGGER_Z to where you'll place the emerald block
# 4. Place an EMERALD_BLOCK at the trigger location
# 5. Watch the snakes start moving!
# 6. Jump from green โ gold โ diamond blocks
#
# TO MAKE EASIER:
# - Make SNAKE_SPEED numbers bigger (slower snakes)
# - Make SNAKE_LENGTH numbers bigger (longer platforms)
# - Make SNAKE_RANGE numbers smaller (shorter movements)
#
# TO MAKE HARDER:
# - Make SNAKE_SPEED numbers smaller (faster snakes)
# - Make SNAKE_LENGTH numbers smaller (shorter platforms)
# - Make SNAKE_RANGE numbers bigger (longer movements)
#
# COLORS:
# - Snake 1: GREEN (emerald blocks) - moves left-right
# - Snake 2: GOLD (gold blocks) - spiral stair pattern
# - Snake 3: DIAMOND (diamond blocks) - zigzag with memorizable gaps
#
# SNAKE 3 DANGER PATTERN TO MEMORIZE:
# Safe-Safe-Safe-GAP-GAP-Safe-Safe-GAP-Safe-Safe-Safe-GAP-GAP-GAP-Safe-Safe
# EXTREME WIDE zigzag: 33 blocks total width! Goes from -15 to +18 blocks!
# Random positions: 0,5,-8,12,-3,15,-12,8,-5,18,-15,2,-10,14,-7,10
# (Completely unpredictable jumps - master the chaos!)
#
# ================================================================
๐ Klassisk Snake-spill
Et enklere, klassisk snake-spill som er perfekt for รฅ forstรฅ grunnleggende spillogikk!
# KLASSISK SNAKE SPILL
# En enkel versjon av det klassiske snake-spillet!
# Globale variabler
snake_body = []
snake_direction = "NORTH"
food_position = None
score = 0
game_active = False
def setup_snake_game():
"""Setup the snake game area"""
global snake_body, food_position, score
# Clear game area
blocks.fill(AIR, world(0, 64, 0), world(20, 64, 20))
# Create border
blocks.fill(STONE, world(-1, 64, -1), world(21, 64, 21))
blocks.fill(AIR, world(0, 64, 0), world(20, 64, 20))
# Initialize snake
snake_body = [world(10, 64, 10)]
blocks.place(EMERALD_BLOCK, snake_body[0])
# Place first food
spawn_food()
player.say(f"๐ Snake Game Started! Score: {score}")
def spawn_food():
"""Spawn food at random location"""
global food_position
import random
# Find empty spot
while True:
x = random.randint(1, 19)
z = random.randint(1, 19)
food_position = world(x, 64, z)
# Check if position is free
if food_position not in snake_body:
blocks.place(APPLE, food_position)
break
def move_snake():
"""Move the snake in current direction"""
global snake_body, score, game_active
if not game_active:
return
# Get current head position
head = snake_body[0]
# Calculate new head position
if snake_direction == "NORTH":
new_head = world(head.get_value(Axis.X), 64, head.get_value(Axis.Z) - 1)
elif snake_direction == "SOUTH":
new_head = world(head.get_value(Axis.X), 64, head.get_value(Axis.Z) + 1)
elif snake_direction == "EAST":
new_head = world(head.get_value(Axis.X) + 1, 64, head.get_value(Axis.Z))
elif snake_direction == "WEST":
new_head = world(head.get_value(Axis.X) - 1, 64, head.get_value(Axis.Z))
# Check collision with walls
x = new_head.get_value(Axis.X)
z = new_head.get_value(Axis.Z)
if x < 0 or x > 20 or z < 0 or z > 20:
game_over()
return
# Check collision with self
if new_head in snake_body:
game_over()
return
# Add new head
snake_body.insert(0, new_head)
blocks.place(EMERALD_BLOCK, new_head)
# Check if food eaten
if new_head == food_position:
score += 1
player.say(f"๐ Food eaten! Score: {score}")
spawn_food()
else:
# Remove tail
tail = snake_body.pop()
blocks.place(AIR, tail)
def game_over():
"""End the game"""
global game_active
game_active = False
player.say(f"๐ Game Over! Final Score: {score}")
player.say("Place EMERALD_BLOCK to play again!")
def snake_controller():
"""Control system for snake game"""
global snake_direction, game_active
while True:
# Start game
if blocks.test_for_block(EMERALD_BLOCK, world(25, 64, 10)):
blocks.place(AIR, world(25, 64, 10))
setup_snake_game()
game_active = True
# Direction controls
elif blocks.test_for_block(REDSTONE_BLOCK, world(25, 64, 8)): # North
blocks.place(AIR, world(25, 64, 8))
if snake_direction != "SOUTH":
snake_direction = "NORTH"
elif blocks.test_for_block(REDSTONE_BLOCK, world(25, 64, 12)): # South
blocks.place(AIR, world(25, 64, 12))
if snake_direction != "NORTH":
snake_direction = "SOUTH"
elif blocks.test_for_block(REDSTONE_BLOCK, world(23, 64, 10)): # West
blocks.place(AIR, world(23, 64, 10))
if snake_direction != "EAST":
snake_direction = "WEST"
elif blocks.test_for_block(REDSTONE_BLOCK, world(27, 64, 10)): # East
blocks.place(AIR, world(27, 64, 10))
if snake_direction != "WEST":
snake_direction = "EAST"
loops.pause(100)
def snake_game_loop():
"""Main game loop"""
while True:
if game_active:
move_snake()
loops.pause(800) # Game speed
else:
loops.pause(1000)
# Start the systems
loops.run_in_background(snake_controller)
loops.run_in_background(snake_game_loop)
player.say("๐ CLASSIC SNAKE GAME READY! ๐")
player.say("Place EMERALD_BLOCK at (25,64,10) to start!")
player.say("Use REDSTONE_BLOCK at compass positions to control!")
- Start spill: EMERALD_BLOCK pรฅ (25, 64, 10)
- Nord: REDSTONE_BLOCK pรฅ (25, 64, 8)
- Sรธr: REDSTONE_BLOCK pรฅ (25, 64, 12)
- Vest: REDSTONE_BLOCK pรฅ (23, 64, 10)
- รst: REDSTONE_BLOCK pรฅ (27, 64, 10)
๐ฏ Andre Mini-spill og Systemer
๐ Auto-Runner
En automatisk lรธpebane med hindringer som dukker opp
Kommer snart...๐จ Pixel Art Creator
System for รฅ lage pixel art automatisk fra kode
Kommer snart...๐ฐ Castle Defense
Forsvar slottet ditt mot bรธlger av monstre
Kommer snart...๐ต Music Maker
Lag musikk og melodier med note blocks
Kommer snart...๐ค Del din egen kode!
Har du laget noe kult? Del koden din her!
- Kopier koden din fra Minecraft MakeCode
- Lim den inn i en kommentar pรฅ GitHub-repositoryet
- Eller send den til kurslederen som kan legge den til!
- Beskriv hva koden gjรธr og hvordan den fungerer
- Legg til kommentarer som forklarer hva koden gjรธr
- Skriv tydelige instruksjoner for hvordan bruke koden
- Fortell hvilke koordinater som mรฅ endres
- Beskriv hva som er spesielt eller kult med prosjektet ditt
๐ Kode-mal for egne prosjekter
Bruk denne malen nรฅr du lager egne prosjekter!
# ================================
# PROSJEKT NAVN: [Skriv navnet pรฅ prosjektet ditt her]
# LAGET AV: [Ditt navn]
# DATO: [Dagens dato]
# BESKRIVELSE: [Forklar hva prosjektet gjรธr]
# ================================
# VIKTIGE KOORDINATER (endre disse til dine egne!):
# Start omrรฅde: world(0, 64, 0)
# Kontroll-blokk: world(100, 64, 100)
# Signal-blokk: world(101, 64, 100)
# ================================
# HOVEDFUNKSJONER
# ================================
def main_function():
"""Hovedfunksjon som gjรธr det viktigste i prosjektet"""
player.say("๐ฎ Prosjekt starter!")
# Din kode her...
player.say("โ
Prosjekt ferdig!")
def helper_function():
"""Hjelpefunksjon for spesielle oppgaver"""
# Din hjelpekode her...
pass
# ================================
# KONTROLL-SYSTEM
# ================================
def controller():
"""Kontroll-system som lytter etter input"""
while True:
# Start prosjekt
if blocks.test_for_block(EMERALD_BLOCK, world(100, 64, 100)):
blocks.place(AIR, world(100, 64, 100))
main_function()
# Reset prosjekt
elif blocks.test_for_block(REDSTONE_BLOCK, world(101, 64, 100)):
blocks.place(AIR, world(101, 64, 100))
reset_project()
loops.pause(100)
def reset_project():
"""Rydd opp og reset prosjektet"""
player.say("๐ Resetter prosjekt...")
# Rydd opp kode her...
player.say("โ
Prosjekt reset!")
# ================================
# START PROSJEKTET
# ================================
# Start kontroll-systemet
loops.run_in_background(controller)
# Oppstart-melding
player.say("๐ [PROSJEKT NAVN] READY!")
player.say("Place EMERALD_BLOCK at (100,64,100) to start!")
player.say("Place REDSTONE_BLOCK at (101,64,100) to reset!")
# ================================
# INSTRUKSJONER FOR BRUK:
# 1. Endre koordinatene รธverst til dine egne
# 2. Fyll inn dine funksjoner
# 3. Test at alt fungerer
# 4. Del koden med andre!
# ================================