Skip to content

Commit

Permalink
it works! I can now refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Robertson committed Jan 17, 2023
1 parent 25a6fa4 commit d4b9795
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions environment.go → environment/environment.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


package main
package environment

import (
"image"
Expand Down Expand Up @@ -35,7 +35,7 @@ func Rect(x1, y1, x2, y2 int, canvas *image.Paletted) {
VLine(x2, y1, y2, canvas)
}

func drawMaze(currentMaze *maze.Maze, canvas *image.Paletted) {
func DrawMaze(currentMaze *maze.Maze, canvas *image.Paletted) {
var foo bytes.Buffer

w := io.Writer(&foo)
Expand Down Expand Up @@ -76,7 +76,7 @@ func drawMaze(currentMaze *maze.Maze, canvas *image.Paletted) {


// does it intersec with environment?
func inteserction(img *image.Paletted, next_coords map[string]int, r image.Rectangle) bool {
func Inteserction(img *image.Paletted, next_coords map[string]int, r image.Rectangle) bool {

subRect := image.Rect(next_coords["x"], next_coords["y"], (r.Size().X + next_coords["x"]) , (r.Size().Y + next_coords["y"]))
gridSubImage := img.SubImage(subRect)
Expand All @@ -94,7 +94,7 @@ func inteserction(img *image.Paletted, next_coords map[string]int, r image.Recta
}

// is it still in the environment? when > width, height - tells to complete or render next section
func inEnvironment(img *image.Paletted, next_coords map[string]int, r image.Rectangle) bool {
func InEnvironment(img *image.Paletted, next_coords map[string]int, r image.Rectangle) bool {
log.Println(img.Bounds().Max.X);
log.Println(next_coords["x"]);
if (next_coords["x"] >= img.Bounds().Max.X){
Expand Down
2 changes: 1 addition & 1 deletion imageflip/flip.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package imageFlip
package imageflip

import (
"image"
Expand Down
2 changes: 1 addition & 1 deletion imageflip/flip_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package imageFlip
package imageflip

import (
"testing"
Expand Down
Binary file added main
Binary file not shown.
10 changes: 6 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"time"

"github.com/metalix2/pigames/imageflip"
"github.com/metalix2/pigames/environment"

"github.com/itchyny/maze"

"periph.io/x/conn/v3/i2c/i2creg"
Expand Down Expand Up @@ -208,11 +210,11 @@ func drawCanvas(w, h int, src image.Image, prev_coords map[string]int, next_coor
img := image.NewPaletted(image.Rect(0, 0, w, h), palette.Plan9)

currentMaze.Generate()
drawMaze(currentMaze, img)
environment.DrawMaze(currentMaze, img)

// bound detection
if 0 > prev_coords["x"] + r.Size().X {
if !inEnvironment(img, prev_coords, r) {
if !environment.InEnvironment(img, prev_coords, r) {
level += 1
prev_coords = map[string]int{"x": 2, "y": 2}
next_coords = map[string]int{"x": 2, "y": 2}
Expand All @@ -228,7 +230,7 @@ func drawCanvas(w, h int, src image.Image, prev_coords map[string]int, next_coor
prev_coords["y"] > r.Size().Y && screenY + 0 > prev_coords["y"] + r.Size().Y ||
prev_coords["y"] + r.Size().Y >= 64 + screenY + r.Size().Y {
log.Println(prev_coords["x"] + r.Size().X >= 128 + screenX + r.Size().X)
if inEnvironment(img, prev_coords, r) {
if environment.InEnvironment(img, prev_coords, r) {
var vector [2]int
vector[0] = (next_coords["x"] - prev_coords["x"])
vector[1] = (next_coords["y"] - prev_coords["y"])
Expand Down Expand Up @@ -281,7 +283,7 @@ func drawCanvas(w, h int, src image.Image, prev_coords map[string]int, next_coor
r = r.Add(image.Point{prev_coords["x"], prev_coords["y"]})

// check Avatar can't walk through walls
if inteserction(img, next_coords, r) {
if environment.Inteserction(img, next_coords, r) {
next_coords["x"] = prev_coords["x"]
next_coords["y"] = prev_coords["y"]
}
Expand Down
Binary file added pigames
Binary file not shown.

0 comments on commit d4b9795

Please sign in to comment.