Skip to content

Commit

Permalink
better presses for Android, other minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Noofbiz committed Jul 26, 2018
1 parent cd1b540 commit d717fa5
Show file tree
Hide file tree
Showing 41 changed files with 305 additions and 253 deletions.
Binary file modified android/androidglue/androidglue.aar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public void onSurfaceChanged(GL10 gl, int width, int height) {
}
}

private double dDensity = getResources().getDisplayMetrics().density;

public EngoGLSurfaceView(Context context) {
super(context);
initialize();
Expand Down Expand Up @@ -95,9 +97,7 @@ public boolean onTouchEvent(MotionEvent e) {
outputStream = getContext().openFileOutput("opts.json",Context.MODE_PRIVATE);
outputStream.write(fileContents);
outputStream.close();
} catch (Exception ex) {
Log.println(Log.WARN, "basdfa", "Asfdsdf");
}
} catch (Exception ex) {}
}
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions androidglue/androidglue.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func IsRunning() bool {
return running
}

type touch struct {
curX, curY, touchID, touchAction int
}

func Touch(x, y, id, action int) {
engo.TouchEvent(x, y, id, action)
}
Expand Down
61 changes: 30 additions & 31 deletions assets/bindata.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/opts.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"BGM":true,"SFX":true,"BGMLevel":0.999999,"SFXLevel":0.999999,"HighScore":1550,"Controls":"Keyboard"}
{"BGM":true,"SFX":true,"BGMLevel":0.5999990000000001,"SFXLevel":0.699999,"HighScore":1550,"Controls":"Keyboard"}
22 changes: 16 additions & 6 deletions game.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ import (

func Start(width, height int) {
var gscale float32
scaleX := width / 320
scaleY := height / 480
var cX float32
var cY float32
scaleX := float32(width) / 320
scaleY := float32(height) / 480
if scaleX > scaleY {
gscale = float32(scaleY)
gscale = scaleY
cX = (float32(width) - 320*gscale)
} else {
gscale = float32(scaleX)
gscale = scaleX
cY = (float32(height) - 480*gscale)
}
engo.RegisterScene(&mainmenu.Scene{})
engo.RegisterScene(&mainmenu.Scene{
XCenter: cX,
YCenter: cY,
})
engo.RegisterScene(&game.Scene{})
engo.RegisterScene(&credits.Scene{})
engo.RegisterScene(&opts.Scene{})
Expand All @@ -35,5 +42,8 @@ func Start(width, height int) {
X: gscale,
Y: gscale,
},
}, &mainmenu.Scene{})
}, &mainmenu.Scene{
XCenter: cX,
YCenter: cY,
})
}
1 change: 0 additions & 1 deletion scenes/gameend/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ type button struct {
ecs.BasicEntity
common.SpaceComponent
common.RenderComponent
common.MouseComponent
}
21 changes: 8 additions & 13 deletions scenes/gameend/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ func (s *Scene) Setup(u engo.Updater) {
var notrenderable *common.NotRenderable
w.AddSystemInterface(&common.RenderSystem{}, renderable, notrenderable)

// Add Mouse System
var mouseable *common.Mouseable
var notmouseable *common.NotMouseable
w.AddSystemInterface(&common.MouseSystem{}, mouseable, notmouseable)

// add game start system
restart := &gamerestart.System{}
w.AddSystem(restart)
Expand Down Expand Up @@ -129,13 +124,13 @@ func (s *Scene) Setup(u engo.Updater) {
sg.RenderComponent.Drawable = sgs
sg.RenderComponent.SetZIndex(2)
sg.SpaceComponent.Position = engo.Point{
X: 20 + options.XOffset,
Y: 100 + options.YOffset,
X: 50 + options.XOffset,
Y: 110 + options.YOffset,
}
sg.SpaceComponent.Width = sg.RenderComponent.Drawable.Width()
sg.SpaceComponent.Height = sg.RenderComponent.Drawable.Height()
w.AddEntity(&sg)
restart.Add(&sg.BasicEntity, &sg.MouseComponent)
restart.Add(&sg.BasicEntity, &sg.SpaceComponent)

// Start game text
sgt := sprite{BasicEntity: ecs.NewBasic()}
Expand All @@ -145,7 +140,7 @@ func (s *Scene) Setup(u engo.Updater) {
}
sgt.RenderComponent.SetZIndex(3)
sgt.SpaceComponent.Position = engo.Point{
X: 80 + options.XOffset,
X: 90 + options.XOffset,
Y: 130 + options.YOffset,
}
w.AddEntity(&sgt)
Expand All @@ -155,13 +150,13 @@ func (s *Scene) Setup(u engo.Updater) {
mm.RenderComponent.Drawable = sgs
mm.RenderComponent.SetZIndex(2)
mm.SpaceComponent.Position = engo.Point{
X: 20 + options.XOffset,
Y: 180 + options.YOffset,
X: 50 + options.XOffset,
Y: 190 + options.YOffset,
}
mm.SpaceComponent.Width = mm.RenderComponent.Drawable.Width()
mm.SpaceComponent.Height = mm.RenderComponent.Drawable.Height()
w.AddEntity(&mm)
m.Add(&mm.BasicEntity, &mm.MouseComponent)
m.Add(&mm.BasicEntity, &mm.SpaceComponent)

// main menu text
mmt := sprite{BasicEntity: ecs.NewBasic()}
Expand All @@ -171,7 +166,7 @@ func (s *Scene) Setup(u engo.Updater) {
}
mmt.RenderComponent.SetZIndex(3)
mmt.SpaceComponent.Position = engo.Point{
X: 80 + options.XOffset,
X: 90 + options.XOffset,
Y: 210 + options.YOffset,
}
w.AddEntity(&mmt)
Expand Down
1 change: 0 additions & 1 deletion scenes/mainmenu/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type button struct {
ecs.BasicEntity
common.SpaceComponent
common.RenderComponent
common.MouseComponent
common.AudioComponent
}

Expand Down
31 changes: 14 additions & 17 deletions scenes/mainmenu/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import (
"github.com/Noofbiz/hypnic/systems/optionsbtn"
)

type Scene struct{}
type Scene struct {
XCenter, YCenter float32
}

func (s *Scene) Type() string {
return "MainMenuScene"
Expand Down Expand Up @@ -52,8 +54,8 @@ func (s *Scene) Setup(u engo.Updater) {
common.SetBackground(color.Black)

// for canvas reasizing
options.XOffset = 3 * (320 - engo.WindowWidth()) / (8 * engo.GetGlobalScale().X)
options.YOffset = 3 * (480 - engo.WindowHeight()) / (8 * engo.GetGlobalScale().Y)
options.XOffset = (engo.ResizeXOffset + s.XCenter) / (2 * engo.GetGlobalScale().X)
options.YOffset = (engo.ResizeYOffset + s.YCenter) / (2 * engo.GetGlobalScale().Y)

// Add Render System
// To be added to the render system needs
Expand All @@ -64,11 +66,6 @@ func (s *Scene) Setup(u engo.Updater) {
var notrenderable *common.NotRenderable
w.AddSystemInterface(&common.RenderSystem{}, renderable, notrenderable)

// Add Mouse System
var mouseable *common.Mouseable
var notmouseable *common.NotMouseable
w.AddSystemInterface(&common.MouseSystem{}, mouseable, notmouseable)

// add audio system
var audioable *common.Audioable
var notaudioable *common.NotAudioable
Expand Down Expand Up @@ -176,14 +173,14 @@ func (s *Scene) Setup(u engo.Updater) {
sg.RenderComponent.Drawable = sgs
sg.RenderComponent.SetZIndex(2)
sg.SpaceComponent.Position = engo.Point{
X: 20 + options.XOffset,
Y: 100 + options.YOffset,
X: 50 + options.XOffset,
Y: 110 + options.YOffset,
}
sg.SpaceComponent.Width = sg.RenderComponent.Drawable.Width()
sg.SpaceComponent.Height = sg.RenderComponent.Drawable.Height()
sg.AudioComponent.Player = msfx
w.AddEntity(&sg)
start.Add(&sg.BasicEntity, &sg.MouseComponent, &sg.AudioComponent)
start.Add(&sg.BasicEntity, &sg.SpaceComponent, &sg.AudioComponent)

// Start game text
sgt := label{BasicEntity: ecs.NewBasic()}
Expand All @@ -203,14 +200,14 @@ func (s *Scene) Setup(u engo.Updater) {
op.RenderComponent.Drawable = sgs
op.RenderComponent.SetZIndex(2)
op.SpaceComponent.Position = engo.Point{
X: 20 + options.XOffset,
Y: 180 + options.YOffset,
X: 50 + options.XOffset,
Y: 190 + options.YOffset,
}
op.SpaceComponent.Width = op.RenderComponent.Drawable.Width()
op.SpaceComponent.Height = op.RenderComponent.Drawable.Height()
op.AudioComponent.Player = msfx
w.AddEntity(&op)
opts.Add(&op.BasicEntity, &op.MouseComponent, &op.AudioComponent)
opts.Add(&op.BasicEntity, &op.AudioComponent, &op.SpaceComponent)

// Options text
opt := label{BasicEntity: ecs.NewBasic()}
Expand All @@ -230,14 +227,14 @@ func (s *Scene) Setup(u engo.Updater) {
c.RenderComponent.Drawable = sgs
c.RenderComponent.SetZIndex(2)
c.SpaceComponent.Position = engo.Point{
X: 20 + options.XOffset,
Y: 380 + options.YOffset,
X: 50 + options.XOffset,
Y: 390 + options.YOffset,
}
c.SpaceComponent.Width = c.RenderComponent.Drawable.Width()
c.SpaceComponent.Height = c.RenderComponent.Drawable.Height()
c.AudioComponent.Player = msfx
w.AddEntity(&c)
crds.Add(&c.BasicEntity, &c.MouseComponent, &c.AudioComponent)
crds.Add(&c.BasicEntity, &c.SpaceComponent, &c.AudioComponent)

// Credits text
ct := label{BasicEntity: ecs.NewBasic()}
Expand Down
1 change: 0 additions & 1 deletion scenes/opts/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type button struct {
ecs.BasicEntity
common.SpaceComponent
common.RenderComponent
common.MouseComponent
common.AudioComponent
}

Expand Down
Loading

0 comments on commit d717fa5

Please sign in to comment.