Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
fixed some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukinoko-kun committed Jan 7, 2024
1 parent 0857ffd commit 3f508d0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 42 deletions.
57 changes: 24 additions & 33 deletions cmd/editor/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ func SaveLevel() {
}

var (
mouseX int32
mouseY int32
posX int32
posY int32
posX int32
posY int32
)

var (
Expand All @@ -79,10 +77,9 @@ func DrawLevel() error {
rect := sdl.Rect{X: 0, Y: 0, W: unit, H: unit}

// control camera
mx, my, mouseState := sdl.GetMouseState()
if mouseState&sdl.ButtonMMask() != 0 {
posX -= int32(mx - mouseX)
posY -= int32(my - mouseY)
if core.MouseState&sdl.ButtonMMask() != 0 {
posX -= core.MouseDeltaX
posY -= core.MouseDeltaY

if posX < -unit {
posX = -unit
Expand All @@ -97,37 +94,17 @@ func DrawLevel() error {
if posY > l.Height*unit-unit {
posY = l.Height*unit - unit
}

mouseX = mx
mouseY = my
} else {
mouseX = mx
mouseY = my
}

if mouseState&sdl.ButtonLMask() != 0 {
x := (mouseX + posX) / unit
y := (mouseY + posY) / unit
l.SetWall(int(x), int(y), 1)
unsavedChanges = true
} else if mouseState&sdl.ButtonRMask() != 0 {
x := (mouseX + posX) / unit
y := (mouseY + posY) / unit
l.SetWall(int(x), int(y), 0)
unsavedChanges = true
}

// draw level
for x := int32(0); x < l.Width; x++ {
for y := int32(0); y < l.Height; y++ {
rect.X = x*unit - posX

if rect.X < -unit || rect.X > core.Width() {
continue
}
rect.X = x*unit - posX
if rect.X < -unit || rect.X > core.Width() {
continue
}

for y := int32(0); y < l.Height; y++ {
rect.Y = y*unit - posY

if rect.Y < -unit || rect.Y > core.Height() {
continue
}
Expand Down Expand Up @@ -155,3 +132,17 @@ func DrawLevel() error {

return nil
}

func EditLevel() {
if core.MouseState&sdl.ButtonLMask() != 0 {
x := (core.MouseX + posX) / unit
y := (core.MouseY + posY) / unit
l.SetWall(int(x), int(y), 1)
unsavedChanges = true
} else if core.MouseState&sdl.ButtonRMask() != 0 {
x := (core.MouseX + posX) / unit
y := (core.MouseY + posY) / unit
l.SetWall(int(x), int(y), 0)
unsavedChanges = true
}
}
9 changes: 9 additions & 0 deletions cmd/editor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ func main() {
if err := UpdateUi(); err != nil {
log.Fatal(err)
}

if ExitEl.Clicked() {
break
}

if SaveEl.Clicked() {
SaveLevel()
}

if !ExitEl.MouseOver() && !SaveEl.MouseOver() {
EditLevel()
}

// draw frame
core.Present()
}
Expand Down
4 changes: 0 additions & 4 deletions cmd/editor/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,5 @@ func UpdateUi() error {
return err
}

if SaveEl.Clicked() {
SaveLevel()
}

return nil
}
6 changes: 2 additions & 4 deletions engine/core/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,14 @@ var (
func eventLoop() {
var mouseX, mouseY int32
mouseX, mouseY, MouseState = sdl.GetMouseState()
MouseDeltaX = mouseX - MouseX
MouseDeltaY = mouseY - MouseY
if cursorLocked {
MouseDeltaX = mouseX - MouseX
MouseDeltaY = mouseY - MouseY
// reset mouse position to center of window
window.WarpMouseInWindow(centerX, centerY)
MouseX = centerX
MouseY = centerY
} else {
MouseDeltaX = 0
MouseDeltaY = 0
MouseX = mouseX
MouseY = mouseY
}
Expand Down
2 changes: 1 addition & 1 deletion engine/level/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func New() *Level {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
},
Floor: 0x102030,
Floor: 0x050200,
Ceiling: 0x301020,
}
}
Expand Down

0 comments on commit 3f508d0

Please sign in to comment.