CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 06:14:24 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=419b5496f08c348cf11d409b28a87ce07778a1fec5b8ed215769e43eb1349f34a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%222BwDFdG0IJacixveEUv5rAFBWnAQR5X5%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cc37918e7ee8e0-BLR
Snake - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rebol [title: "Snake"]
- snake-game-object: context [
- readme: {
- Snake
- original code by Nick Antonaccio at re-bol.com
- written in rebol rebol.com
- }
- snake: to-image layout/tight [box red 10x10 edge none]
- food: to-image layout/tight [box green 10x10 edge none] ;[1]
- the-score: 0 direction: 0x10 newsection: false random/seed now
- dq: [0x10] ;direction queue; future directions ;[2]
- rand-pair: func [s] [
- to-pair rejoin [(round/to random s 10) "x" (round/to random s 10)]
- ]
- ;b is the image that is drawn in the rebol draw dialect
- ;its structure is 'image <actual image> position 'image <actual image> position ...
- ;b/3 is apple position. b/6 is snake head position
- b: reduce [
- 'image food ((rand-pair 190) + 50x50)
- 'image snake 150x150
- 'image snake 150x160 ;[5]
- ]
- view/new win: layout [
- scrn: box white 300x300 effect [draw b] rate 20
- origin across h2 "Score:"
- score: h2 bold "000000"
- do [focus scrn]
- ]
- scrn/feel/engage: func [f a e] [
- if a = 'key [
- ;dq direction queue, d direction
- unless find [up down left right] e/key [exit]
- d: select [up 0x-10 down 0x10 left -10x0 right 10x0] e/key
- if not equal? last dq negate d [append dq d] ;[3] prevents turning directly backwards
- ]
- if a = 'time [
- direction: either 1 = length? dq [first dq] [take dq] ;[4]
- ;If snake hits self or wall
- if any [b/6/1 < 0 b/6/2 < 0 b/6/1 > 290 b/6/2 > 290] [
- alert "You hit the wall!" unview/only win
- ]
- if find (at b 7) b/6 [alert "You hit yourself!" unview/only win]
- ;If an apple is eaten
- if within? b/6 b/3 10x10 [
- append b reduce ['image snake (last b)]
- newsection: true
- b/3: (rand-pair 290)
- the-score: the-score + 1
- score/text: to-string the-score
- ]
- ;create new image b
- newb: copy/part head b 5 append newb (b/6 + direction)
- for item 7 (length? head b) 1 [
- either (type? (pick b item) = pair!) [
- append newb pick b (item - 3)
- ] [
- append newb pick b item
- ]
- ]
- if newsection = true [
- clear (back tail newb)
- append newb (last b)
- newsection: false
- ]
- ;show new image
- b: copy newb
- show scrn
- ]
- ]
- scrn/text: None ;[6]
- ;set global
- set 'snake-game scrn
- do-events
- doc: {
- Alterations
- added direction queue to replace single direction variable.
- This means all key events are actioned whereas
- beforehand if two key events were close together only the second one would be actioned.
- Also changed code so snake cannot backtrack on itself.
- Minor alterations - score changed when apple is eaten.
- Set scrn/text to none to remove white cursor artifact
- added comments
- changed images to green and red boxes
- Possible evolutions
- enable replay
- replace alert code. Just replace replace the draw code with something.
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment
-
✅⭐ Make $2500 in 15 minutes ✅ NEVER SEEN BEFO...
JavaScript | 3 sec ago | 0.24 KB
-
⭐ Instant BTC Profit Method ✅ NEVER SEEN BEFO...
JavaScript | 16 sec ago | 0.24 KB
-
⭐ Instant BTC Profit Method ✅ NEVER SEEN BEFO...
JavaScript | 23 sec ago | 0.24 KB
-
⭐✅ MAKE $2000 INSTANTLY ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 32 sec ago | 0.24 KB
-
⭐ Free Crypto Method ✅ NEVER SEEN BEFORE ⭐⭐⭐
JavaScript | 41 sec ago | 0.24 KB
-
✅⭐ Make huge profits on trading ✅ NEVER SEEN...
JavaScript | 51 sec ago | 0.24 KB
-
⭐✅ Marketplace Glitch ✅ Working ✅ NEVER SEEN...
JavaScript | 1 min ago | 0.24 KB
-
✅⭐ Make $2500 in 15 minutes ✅ NEVER SEEN BEFO...
JavaScript | 1 min ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand