Skip to content

Commit

Permalink
Update the things
Browse files Browse the repository at this point in the history
  • Loading branch information
pdevine committed Jul 17, 2019
1 parent 8169e44 commit 78fecbe
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 18 deletions.
2 changes: 1 addition & 1 deletion font.go
Expand Up @@ -292,7 +292,6 @@ XXX
`

func BuildString(s string) string {

c_lookup := map[rune]string{
'a': Font_a,
'b': Font_b,
Expand Down Expand Up @@ -342,6 +341,7 @@ func BuildString(s string) string {
for _, c := range s {
cs, ok := c_lookup[c]
if !ok {
// just add in some blank spaces if we don't have a char
cs = " \n \n \n \n \n "
}
t = append(t, strings.Split(cs, "\n"))
Expand Down
79 changes: 79 additions & 0 deletions test/mario-enemy.go
@@ -0,0 +1,79 @@
package main

import (
sprite "github.com/pdevine/go-asciisprite"
)

const goomba_walk1 = ` OOOO
OOOOOO
OOOOOOOO
OOOOOOOOOO
ONNOOOOOONNO
OOOwNOOOONwOOO
OOOwNNNNNNwOOO
OOOOwNwOOwNwOOOO
OOOOwwwOOwwwOOOO
OOOOOOOOOOOOOOOO
OOOOwwwwwwOOOO
wwwwwwww
wwwwwwwwNN
NNwwwwwNNNNN
NNNwwwNNNNNN
NNNwwNNNNN`

const goomba_walk2 = ` OOOO
OOOOOO
OOOOOOOO
OOOOOOOOOO
ONNOOOOOONNO
OOOwNOOOONwOOO
OOOwNNNNNNwOOO
OOOOwNwOOwNwOOOO
OOOOwwwOOwwwOOOO
OOOOOOOOOOOOOOOO
OOOOwwwwwwOOOO
wwwwwwww
NNwwwwwwww
NNNNNwwwwwNN
NNNNNNwwwNNN
NNNNNwwNNN`

const koopa_walk1 = `
w
www
wwwo
oGwwoo
oGwwoo
oGwwoo
owwwoo
ooowooo
oGooooo
oooooo GGGGG
ooo oo GoGGGoG
oo oo GGoGoGGG
oo oowGGGGoGwwG
o oowGGGoGoGwG
oowoGoGGGoGo
oowwGoGGGGGoG
owGoGoGGGoGo
owoGGGoGoGGG
wGGGGGoGGGG
wwGGGoGoGwww
oowwwoGGwww
ooooowwwwwooo
ooooo oooo`

type Enemy struct {
sprite.BaseSprite
TimeOut int
Timer int
}

35 changes: 35 additions & 0 deletions test/mario-level.go
Expand Up @@ -487,6 +487,41 @@ NNNNNNNNOOONOOOO
NNNNNNNNOOONOOOO
NNNNNNNNNNNNNNNN`

type Block struct {
sprite.BaseSprite
}

type QuestionBlock struct {
Block
Timer int
TimeOut int
}

func InitQuestionBlock(X, Y int) *QuestionBlock {
b := &QuestionBlock{Block: Block{BaseSprite: sprite.BaseSprite{
Visible: true,
X: X,
Y: Y},
},
}
return b
}

func (b *QuestionBlock) Update() {
b.Timer++
if b.Timer > b.TimeOut {
b.CurrentCostume++
if b.CurrentCostume >= len(b.Costumes) {
b.CurrentCostume = 0
}
b.Timer = 0
}
}

type BrickBlock struct {
Block
}

func ParseLevel(l string, bg tm.Attribute) []*Block {

allBlocks := []*Block{}
Expand Down
60 changes: 43 additions & 17 deletions test/mario.go
@@ -1,7 +1,9 @@
package main

import (
"fmt"
"math"
"strings"
"time"

sprite "github.com/pdevine/go-asciisprite"
Expand All @@ -14,6 +16,8 @@ var allBlocks []*Block
var Width int
var Height int

const BackgroundColor = 40

const big_mario = `
RRRRR
RRRRRRY
Expand Down Expand Up @@ -228,10 +232,6 @@ const (
const FacingLeft = -1
const FacingRight = 1

type Block struct {
sprite.BaseSprite
}

type Mario struct {
sprite.BaseSprite
AX float64
Expand Down Expand Up @@ -278,28 +278,54 @@ func (s *Mario) Update() {
func (s *Mario) Jump() {
s.State = Jumping
s.Costumes = []*sprite.Costume{}
s.AddCostume(sprite.ColorConvert(mario_jump, tm.Attribute(39)))
s.AddCostume(sprite.ColorConvert(mario_jump, tm.Attribute(BackgroundColor)))
}

func (s *Mario) Walk() {
s.State = Walking
s.Costumes = []*sprite.Costume{}
//s.AddCostume(sprite.ColorConvert(mario_turnaround))
bg := tm.Attribute(39)
s.AddCostume(sprite.ColorConvert(mario_walk1, bg))
s.AddCostume(sprite.ColorConvert(mario_walk2, bg))
s.AddCostume(sprite.ColorConvert(mario_walk3, bg))
s.AddCostume(sprite.ColorConvert(mario_walk2, bg))
func (s *Mario) Walk(Direction int) {
if s.State != Walking || s.Direction != Direction {
s.State = Walking
s.Direction = Direction
s.Costumes = []*sprite.Costume{}
//s.AddCostume(sprite.ColorConvert(mario_turnaround))
bg := tm.Attribute(BackgroundColor)
if Direction == FacingRight {
s.AddCostume(sprite.ColorConvert(mario_walk1, bg))
s.AddCostume(sprite.ColorConvert(mario_walk2, bg))
s.AddCostume(sprite.ColorConvert(mario_walk3, bg))
s.AddCostume(sprite.ColorConvert(mario_walk2, bg))
} else {
s.AddCostume(sprite.ColorConvert(reverseCostumeText(mario_walk1), bg))
s.AddCostume(sprite.ColorConvert(reverseCostumeText(mario_walk2), bg))
s.AddCostume(sprite.ColorConvert(reverseCostumeText(mario_walk3), bg))
s.AddCostume(sprite.ColorConvert(reverseCostumeText(mario_walk2), bg))
}
}
}

func (s *Mario) MoveRight() {
s.AX = 5
s.VX = 0
s.Walk(FacingRight)
}

func (s *Mario) MoveLeft() {
s.AX = -5
s.VX = 0
s.Walk(FacingLeft)
}

func reverseCostumeText(s string) string {
lines := strings.Split(s, "\n")
var fstr string

for _, l := range lines {
chars := []rune(fmt.Sprintf("%-16v", l))
for i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 {
chars[i], chars[j] = chars[j], chars[i]
}
fstr += string(chars) + "\n"
}
return fstr
}

func main() {
Expand All @@ -322,10 +348,10 @@ func main() {
}
}()

bg := tm.Attribute(40)
bg := tm.Attribute(BackgroundColor)

m := InitMario()
m.Walk()
m.Walk(FacingRight)

allBlocks = ParseLevel(level1, bg)
allSprites.Sprites = append(allSprites.Sprites, m)
Expand All @@ -350,7 +376,7 @@ mainloop:
if m.State == Walking {
m.Jump()
} else {
m.Walk()
m.Walk(m.Direction)
}
}
} else if ev.Type == tm.EventResize {
Expand Down

0 comments on commit 78fecbe

Please sign in to comment.