From f94a97e17be2b52d8db97df6ad4a2094f9419be8 Mon Sep 17 00:00:00 2001
From: ryanlambie <42672777+ryanlambie@users.noreply.github.com>
Date: Wed, 24 Apr 2019 15:59:13 +0100
Subject: [PATCH] Add files via upload
---
MakeSnake/css/snake.css | 5 +
MakeSnake/index.html | 14 ++
MakeSnake/js/snake.js | 156 +++++++++++++++++++++
pico-8-beyond-limits/beyond-limits.txt | 63 +++++++++
pico-8-getting-started/getstarted.txt | 34 +++++
source-code-bomberman/README-RYAN.txt | 5 +
source-code-bomberman/bombs.py | 112 +++++++++++++++
source-code-bomberman/images/bomb.png | Bin 0 -> 356 bytes
source-code-bomberman/images/brick.png | Bin 0 -> 189 bytes
source-code-bomberman/images/explosion.png | Bin 0 -> 188 bytes
source-code-bomberman/images/ground.png | Bin 0 -> 185 bytes
source-code-bomberman/images/player.png | Bin 0 -> 200 bytes
source-code-bomberman/images/wall.png | Bin 0 -> 188 bytes
13 files changed, 389 insertions(+)
create mode 100644 MakeSnake/css/snake.css
create mode 100644 MakeSnake/index.html
create mode 100644 MakeSnake/js/snake.js
create mode 100644 pico-8-beyond-limits/beyond-limits.txt
create mode 100644 pico-8-getting-started/getstarted.txt
create mode 100644 source-code-bomberman/README-RYAN.txt
create mode 100644 source-code-bomberman/bombs.py
create mode 100644 source-code-bomberman/images/bomb.png
create mode 100644 source-code-bomberman/images/brick.png
create mode 100644 source-code-bomberman/images/explosion.png
create mode 100644 source-code-bomberman/images/ground.png
create mode 100644 source-code-bomberman/images/player.png
create mode 100644 source-code-bomberman/images/wall.png
diff --git a/MakeSnake/css/snake.css b/MakeSnake/css/snake.css
new file mode 100644
index 0000000..f73acd7
--- /dev/null
+++ b/MakeSnake/css/snake.css
@@ -0,0 +1,5 @@
+canvas {
+ position: fixed;
+ top: 0;
+ left: 0;
+}
diff --git a/MakeSnake/index.html b/MakeSnake/index.html
new file mode 100644
index 0000000..cbaa0e9
--- /dev/null
+++ b/MakeSnake/index.html
@@ -0,0 +1,14 @@
+
+
+
+
+ Snake
+
+
+
+
+
+
+
+
+
diff --git a/MakeSnake/js/snake.js b/MakeSnake/js/snake.js
new file mode 100644
index 0000000..d0d903e
--- /dev/null
+++ b/MakeSnake/js/snake.js
@@ -0,0 +1,156 @@
+var canvas = document.getElementById('bg');
+var draw2D = canvas.getContext('2d');
+
+canvas.width = window.innerWidth;
+canvas.height = window.innerHeight;
+
+
+function drawBox(x, y, width, height, color){
+ draw2D.beginPath();
+ draw2D.rect(x, y, width, height);
+ draw2D.fillStyle = color;
+ draw2D.fill();
+ draw2D.closePath();
+}
+
+
+function roundToGrid(numb) {
+ return Math.round(numb/10) * 10;
+}
+
+function randomRange(min, max){
+ return Math.random() * (max - min) + min;
+}
+
+
+var snake = [];
+snake.push( {x:canvas.width/2, y:canvas.height/2} );
+snake.push( {x:-10, y:-10} );
+snake.push( {x:-10, y:-10} );
+
+var xDir = 0;
+var yDir = -1;
+
+var food = {};
+food.x = randomRange(0, canvas.width-10);
+food.y = randomRange(0, canvas.height-10);
+
+var moveTimer = 0;
+var moveTimerMax = 100;
+
+
+var lastFrameTime = Date.now();
+
+window.requestAnimationFrame(update);
+
+function update () {
+ var deltaTime = Date.now() - lastFrameTime;
+ lastFrameTime = Date.now();
+
+ moveTimer += deltaTime;
+ if (moveTimer > moveTimerMax) {
+ moveTimer = 0;
+
+ for(var i=snake.length-1; i > 0; i--){
+ snake[i].x = snake[i-1].x;
+ snake[i].y = snake[i-1].y;
+ }
+
+ snake[0].x += xDir*10;
+ snake[0].y += yDir*10;
+ }
+
+ render();
+ checkCollision();
+
+ window.requestAnimationFrame(update);
+}
+
+
+function render() {
+ drawBox(0,0, canvas.width, canvas.height, '#000000');
+
+ food.x = roundToGrid(food.x);
+ food.y = roundToGrid(food.y);
+ drawBox(food.x, food.y, 10, 10, '#ffffff');
+
+ for(var i=0; i < snake.length; i++) {
+ snake[i].x = roundToGrid(snake[i].x);
+ snake[i].y = roundToGrid(snake[i].y);
+ drawBox(snake[i].x, snake[i].y, 10, 10, '#ffffff');
+ }
+}
+
+
+function restart() {
+ snake = [];
+ snake.push( {x:canvas.width/2, y:canvas.height/2} );
+ snake.push( {x:-10, y:-10} );
+ snake.push( {x:-10, y:-10} );
+
+ xDir = 0;
+ yDir = -1;
+ moveTimer = 0;
+
+ food.x = randomRange(0, canvas.width-10);
+ food.y = randomRange(0, canvas.height-10);
+}
+
+
+function checkCollision() {
+ for(var i=1; i < snake.length; i++) {
+ if(snake[0].x == snake[i].x && snake[0].y == snake[i].y){
+ restart();
+ break;
+ }
+
+ if(food.x == snake[i].x && food.y == snake[i].y){
+ food.x = randomRange(0, canvas.width-10);
+ food.y = randomRange(0, canvas.height-10);
+ }
+ }
+
+ if (snake[0].x < 0 || snake[0].y < 0){
+ restart();
+ }
+
+ if (snake[0].x >= canvas.width || snake[0].y >= canvas.height){
+ restart();
+ }
+
+ if(snake[0].x == food.x && snake[0].y == food.y) {
+ snake.push( {x:-10, y:-10} );
+
+ food.x = randomRange(0, canvas.width-10);
+ food.y = randomRange(0, canvas.height-10);
+ }
+}
+
+
+window.addEventListener('keydown', function (evt) {
+
+ if(evt.key == 'ArrowUp' && yDir != 1) {
+ yDir = -1;
+ xDir = 0;
+ }
+ if(evt.key == 'ArrowDown' && yDir != -1){
+ yDir = 1;
+ xDir = 0;
+ }
+ if(evt.key == 'ArrowRight' && xDir != -1){
+ xDir = 1;
+ yDir= 0;
+ }
+ if(evt.key == 'ArrowLeft' && xDir != 1){
+ xDir = -1;
+ yDir= 0;
+ }
+}, false);
+
+
+window.addEventListener('resize', function() {
+ canvas.width = window.innerWidth;
+ canvas.height = window.innerHeight;
+
+ restart();
+}, false);
\ No newline at end of file
diff --git a/pico-8-beyond-limits/beyond-limits.txt b/pico-8-beyond-limits/beyond-limits.txt
new file mode 100644
index 0000000..5f9e479
--- /dev/null
+++ b/pico-8-beyond-limits/beyond-limits.txt
@@ -0,0 +1,63 @@
+--load bytes from code data
+function load_data()
+ for i = 0, 255 do
+ local byte = peek(0x5e00+i)
+ for j = 8, 1, -1 do
+ bits[i*8+j] = band(byte, 1)
+ byte = shr(byte, 1)
+ end
+ end
+end
+
+
+--saving
+function save_data()
+ for i = 0, 255 do
+ local byte = 0
+ for j = 1, 8 do
+ byte = shl(byte, 1)
+ byte = bor(byte, bits[i*8+j])
+ end
+ poke(0x5e00+i,byte)
+ end
+end
+
+--convert integers to bits
+function int_to_bits(int, addr, num_bits)
+ for i = 1, num_bits do
+ bits[addr+num_bits-i] = band(int, 1)
+ int = shr(int, 1)
+ end
+end
+
+--convert bits back to integers
+function bits_to_int(addr, num_bits)
+ local int = 0
+ for i = 0, num_bits-1 do
+ int = shl(int, 1)
+ int += bits[addr+i]
+ end
+ return int
+end
+
+
+--saving code to cartridges
+
+--cartridge_1:
+function _update60()
+ if(btnp(?)) load("cartridge_2")
+end
+
+function _draw()
+ ?"1 "
+end
+
+
+--cartridge_2:
+function _update60()
+ if(btnp(???)) load("cartridge_1")
+end
+
+function _draw()
+ ?"2 "
+end
\ No newline at end of file
diff --git a/pico-8-getting-started/getstarted.txt b/pico-8-getting-started/getstarted.txt
new file mode 100644
index 0000000..aedcd60
--- /dev/null
+++ b/pico-8-getting-started/getstarted.txt
@@ -0,0 +1,34 @@
+function _init()
+ --everything in here happens once as soon as your cart starts
+
+ --create a new table named player, containing x and y value
+ player = {x=64,y=64}
+end
+
+function _update()
+ --everything in here happens 30 times per second
+
+ --update the player's location if a dir button is pressed
+ if btn(0) then player.x-=1 end
+ if btn(1) then player.x+=1 end
+ if btn(2) then player.y-=1 end
+ if btn(3) then player.y+=1 end
+
+ --play SFX 0 if player hits the ‘z’ key or controller button
+ if btn(4) then sfx(0) end
+
+end
+
+function _draw()
+ --everything in here is drawn 30 times per second
+
+ --clear the screen
+ cls()
+
+ --draw a 16x16 tile section of the map from index 0,0 (top left)
+ --at point 0,0 on the screen (also top left)
+ map(0,0,0,0,16,16)
+
+ --draw sprite 1 at player x and y position
+ spr(1,player.x,player.y)
+end
diff --git a/source-code-bomberman/README-RYAN.txt b/source-code-bomberman/README-RYAN.txt
new file mode 100644
index 0000000..24582d9
--- /dev/null
+++ b/source-code-bomberman/README-RYAN.txt
@@ -0,0 +1,5 @@
+FUTURE RYAN: DO NOT USE THE CODE THAT'S IN THE WORD DOCUMENT EDITED FOR THE MAGAZINE. ITS SPACES HAVE BEEN HALVED TO SAVE SPACE, AND WON'T WORK IN PYTHON. USE THE CODE IN THIS FOLDER.
+
+LOVE
+
+PAST RYAN
\ No newline at end of file
diff --git a/source-code-bomberman/bombs.py b/source-code-bomberman/bombs.py
new file mode 100644
index 0000000..83ea4e8
--- /dev/null
+++ b/source-code-bomberman/bombs.py
@@ -0,0 +1,112 @@
+from math import cos, sin, radians
+
+# set game and screen sizes
+SIZE = 9
+WIDTH = SIZE*45 - 5
+HEIGHT = SIZE*45 - 5
+
+# bomb range
+RANGE = 3
+
+# constants for tile types
+GROUND = 0
+WALL = 1
+BRICK = 2
+BOMB = 3
+EXPLOSION = 4
+# images for tile types
+images = ['ground','wall','brick','bomb','explosion']
+
+# create player in top-left of the game
+player = Actor('player')
+player.mapx = 0
+player.mapy = 0
+
+# each position in the tilemap is a 'Tile'
+# with a type, an image and a timer
+class Tile():
+ def __init__(self, type):
+ self.set(type)
+ def set(self,type):
+ self.timer = 0
+ self.t=type
+ self.i=images[type]
+
+# populate the tilemap with some stuff
+tilemap = [[Tile(WALL) if x%2==1 and y%2==1 else Tile(GROUND) for y in range(10)] for x in range(10)]
+tilemap[3][2].set(BRICK)
+tilemap[4][7].set(BRICK)
+
+def on_key_down():
+
+ # store new temporary player position
+ newx = player.mapx
+ newy = player.mapy
+
+ # update new position using keyboard
+ if keyboard.left and player.mapx > 0:
+ newx -= 1
+ elif keyboard.right and player.mapx < SIZE-1:
+ newx += 1
+ elif keyboard.up and player.mapy > 0:
+ newy -= 1
+ elif keyboard.down and player.mapy < SIZE-1:
+ newy += 1
+
+ # move player to new position if allowed
+ if tilemap[newx][newy].t in [GROUND,EXPLOSION]:
+ player.mapx = newx
+ player.mapy = newy
+
+ # space key to place bomb
+ if keyboard.space:
+ tilemap[player.mapx][player.mapy].set(BOMB)
+ tilemap[player.mapx][player.mapy].timer = 150
+
+def update():
+
+ # iterate through each tile in tilemap
+ for x in range(SIZE):
+ for y in range(SIZE):
+
+ tile = tilemap[x][y]
+
+ # decrement timer
+ if tile.timer > 0:
+ tile.timer -= 1
+
+ # process tile types on timer finish
+ if tile.timer <= 0:
+
+ # explosions eventually become ground
+ if tile.t == EXPLOSION:
+ tile.set(GROUND)
+
+ # bombs eventually create explosions
+ if tile.t == BOMB:
+ # bombs radiate out in all 4 directions
+ for angle in range(0,360,90):
+ cosa = int(cos(radians(angle)))
+ sina = int(sin(radians(angle)))
+ # RANGE determines bomb reach
+ for ran in range(1,RANGE):
+ xoffset = ran*cosa
+ yoffset = ran*sina
+ # only create explosions within the tilemap, and only on ground and brick tiles
+ if x+xoffset in range(0,SIZE) and y+yoffset in range(0,SIZE) and tilemap[x+xoffset][y+yoffset].t in [GROUND,BRICK]:
+ tilemap[x+xoffset][y+yoffset].set(EXPLOSION)
+ tilemap[x+xoffset][y+yoffset].timer = 50
+ else:
+ break
+
+ # remove bomb
+ tile.set(EXPLOSION)
+ tile.timer = 50
+
+def draw():
+ # draw the tilemap
+ for x in range(SIZE):
+ for y in range(SIZE):
+ screen.blit( tilemap[x][y].i,(x*45,y*45) )
+ # draw the player
+ screen.blit( player.image, (player.mapx*45,player.mapy*45) )
\ No newline at end of file
diff --git a/source-code-bomberman/images/bomb.png b/source-code-bomberman/images/bomb.png
new file mode 100644
index 0000000000000000000000000000000000000000..05cd35009b4e3fe4e39eac88423f672caaf836a8
GIT binary patch
literal 356
zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1|)m_?Z^dEY)RhkE)4%caKYZ?lYt_f1s;*b
z3=G`DAk4@xYmNj^kiEpy*OmP-3zvYD-nJ(feSku;nIRD+&iT2ysd*(pE(3#eQEFmI
zYKlU6W=V#EyQgnJie4%^Q2d0ai(^Q{;kPpm@-i#(u)KXyv8=P^(w%9Wd1Ev~rqw9N
z`W<|9fN#@%g|@AGnN|nH30dR`*$5R>9$1@gE_JQIOu_0}aY9#jhUwwjM%_hMH@VKP
z5n%4>4%h5(yxOnLV7SBeB6EkQU6X3B)MU*KlbUwe&y!O~e=b)m&{t#_Z_GKPfm7nZ
zigNYE_o91monEsugx9F8s{Y>5FX8XEH+^Z%_BQFdh=n3`Ki;O^-gkfN8$
z4iq=`ba4!cIQ;gkAuodg2ZO;3HlBqX|L>nfLdA%=L8jb6Mw<&;$S;t}{RY
literal 0
HcmV?d00001
diff --git a/source-code-bomberman/images/explosion.png b/source-code-bomberman/images/explosion.png
new file mode 100644
index 0000000000000000000000000000000000000000..a5eb80e0018c1d9a6511dd1bfee6d788914cdf98
GIT binary patch
literal 188
zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1SFZ~=vx6P&H|6fVg?3oVGw3ym^DWND9B#o
z>Fdh=n3zopr0GRJFVE_OC
literal 0
HcmV?d00001
diff --git a/source-code-bomberman/images/ground.png b/source-code-bomberman/images/ground.png
new file mode 100644
index 0000000000000000000000000000000000000000..497c89c82be88a4fc545dd8ff06bd6a8f3776d9a
GIT binary patch
literal 185
zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1SFZ~=vx6P&H|6fVg?3oVGw3ym^DWND9B#o
z>Fdh=n3Eaj?aro_7LtX|34(1Jw|Ai0EP{XE
z)7O>#F*85AiG0B-$6lb2Y-UJAiF1B#Zfaf$kjuc}T$GwvlA5AWo>`Ki;O^-gkfN8$
z4ivZZba4!cIQ;g)MqUO59_E7wie}DynZUe4sd2~p*f}zap7qzyO*YKt+-dsdwmb_m
dn4+@xHj^t0lOB`QzGEOOJYD@<);T3K0RTi&G=Bg9
literal 0
HcmV?d00001
diff --git a/source-code-bomberman/images/wall.png b/source-code-bomberman/images/wall.png
new file mode 100644
index 0000000000000000000000000000000000000000..bbfa69089a0e972bea7cb6dace0747959605ebc8
GIT binary patch
literal 188
zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1SFZ~=vx6P&H|6fVg?3oVGw3ym^DWND9B#o
z>Fdh=n3