forked from github/game-off-2012
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Worked on menu interaction and graphics
- Loading branch information
Showing
11 changed files
with
234 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
GitHubGameJam2012/src/com/mbl111/ggo12/gfx/menu/InventoryMenu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.mbl111.ggo12.gfx.menu; | ||
|
||
import com.mbl111.ggo12.Game; | ||
import com.mbl111.ggo12.gfx.Font; | ||
import com.mbl111.ggo12.gfx.Screen; | ||
import com.mbl111.ggo12.gfx.menu.component.Button; | ||
import com.mbl111.ggo12.gfx.menu.component.ClickListener; | ||
import com.mbl111.ggo12.input.Input; | ||
import com.mbl111.ggo12.inventory.Inventory; | ||
|
||
public class InventoryMenu extends Menu { | ||
|
||
private Inventory inventory; | ||
|
||
public InventoryMenu(Inventory inventory) { | ||
this.inventory = inventory; | ||
Button play = new Button(Game.GAME_WIDTH /2 - 36, Game.GAME_HEIGHT - 20, 72, 16, 0).setText("Close!"); | ||
play.setClickListener(new ClickListener(this) { | ||
public void onClick() { | ||
game.setMenu(null); | ||
} | ||
}); | ||
addComponent(play); | ||
} | ||
|
||
public void tick(Input input) { | ||
super.tick(input); | ||
} | ||
|
||
public boolean isFullScreen() { | ||
return true; | ||
} | ||
|
||
public void render(Screen screen) { | ||
super.render(screen); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,61 @@ | ||
package com.mbl111.ggo12.gfx.menu; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.mbl111.ggo12.Game; | ||
import com.mbl111.ggo12.gfx.Font; | ||
import com.mbl111.ggo12.gfx.Screen; | ||
import com.mbl111.ggo12.gfx.menu.component.MenuComponent; | ||
import com.mbl111.ggo12.input.Input; | ||
|
||
public class Menu { | ||
|
||
public Game game; | ||
public int aliveTime = 0; | ||
protected Game game; | ||
protected int tickCount; | ||
protected int selectedIndex; | ||
protected List<MenuComponent> components = new ArrayList<MenuComponent>(); | ||
private int actionCooldown = 0; | ||
private boolean initialised = false; | ||
public int lastClickedIndex = -1; | ||
|
||
public void tick(Input input) { | ||
if (initialised) { | ||
int x = input.x; | ||
int y = input.y; | ||
for (MenuComponent e : components) { | ||
boolean over = e.isOver(x, y); | ||
e.tick(tickCount, input); | ||
if (over && input.b0Released) { | ||
e.click(); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void init(Game game) { | ||
this.game = game; | ||
public void render(Screen screen) { | ||
if (initialised) { | ||
for (int i = 0; i < components.size(); i++) { | ||
components.get(i).render(screen); | ||
} | ||
} else { | ||
Font.draw("MENU NOT INITIALISED", 0, 0, 0xFFFFFF, screen); | ||
} | ||
} | ||
|
||
public void tick() { | ||
aliveTime++; | ||
public void init(Game game) { | ||
this.game = game; | ||
this.initialised = true; | ||
} | ||
|
||
public boolean isFullScreen() { | ||
return false; | ||
return true; | ||
} | ||
|
||
public void render(Screen screen) { | ||
|
||
public void addComponent(MenuComponent mc) { | ||
this.components.add(mc); | ||
mc.init(this); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
GitHubGameJam2012/src/com/mbl111/ggo12/gfx/menu/component/Button.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.mbl111.ggo12.gfx.menu.component; | ||
|
||
import com.mbl111.ggo12.gfx.Art; | ||
import com.mbl111.ggo12.gfx.Font; | ||
import com.mbl111.ggo12.gfx.Screen; | ||
import com.mbl111.ggo12.input.Input; | ||
|
||
public class Button extends MenuComponent { | ||
|
||
public Button(int x, int y, int width, int height, int selectedIndex) { | ||
super(x, y, width, height, selectedIndex); | ||
if (height < 12) throw new IllegalArgumentException("Height must be > 12 for buttons!!"); | ||
if (height % 4 != 0) throw new IllegalArgumentException("Height must be a multiple of 4 for buttons!!"); | ||
} | ||
|
||
public void tick(int TickCount, Input input) { | ||
super.tick(TickCount, input); | ||
} | ||
|
||
public void render(Screen screen) { | ||
int col = 0xFF333333; | ||
String msg = text; | ||
int yp = h / 4; | ||
int xp = w / 4; | ||
int xib = 0; | ||
int yib = 0; | ||
|
||
if (selected) { | ||
col = 0xFFFFFFFF; | ||
xib = 3; | ||
} | ||
// derp | ||
for (int yc = 0; yc < yp; yc++) { | ||
for (int xc = 0; xc < xp; xc++) { | ||
if (xc == 0 && yc == 0) screen.draw(Art.GUI[0 + xib][0 + yib], x + xc * 4, y + yc * 4); | ||
else if (xc == xp - 1 && yc == 0) screen.draw(Art.GUI[2 + xib][0 + yib], x + xc * 4, y + yc * 4); | ||
else if (xc == 0 && yc == yp - 1) screen.draw(Art.GUI[0 + xib][2 + yib], x + xc * 4, y + yc * 4); | ||
else if (xc == xp - 1 && yc == yp - 1) screen.draw(Art.GUI[2 + xib][2 + yib], x + xc * 4, y + yc * 4); | ||
else if (yc == 0) screen.draw(Art.GUI[1 + xib][0 + yib], x + xc * 4, y + yc * 4); | ||
else if (yc == yp - 1) screen.draw(Art.GUI[1 + xib][2 + yib], x + xc * 4, y + yc * 4); | ||
else if (xc == 0) screen.draw(Art.GUI[0 + xib][1 + yib], x + xc * 4, y + yc * 4); | ||
else if (xc == xp - 1) screen.draw(Art.GUI[2 + xib][1 + yib], x + xc * 4, y + yc * 4); | ||
else screen.draw(Art.GUI[1 + xib][1 + yib], x + xc * 4, y + yc * 4); | ||
} | ||
} | ||
Font.draw(msg, (x + w / 2) - ((msg.length()) / 2 * 8) + (msg.length() % 2 == 0 ? 4 : 0), y + 4, col, screen); | ||
} | ||
|
||
public Button setText(String text) { | ||
this.text = text; | ||
return this; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
GitHubGameJam2012/src/com/mbl111/ggo12/gfx/menu/component/ClickListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.mbl111.ggo12.gfx.menu.component; | ||
|
||
import com.mbl111.ggo12.gfx.menu.Menu; | ||
|
||
public abstract class ClickListener { | ||
|
||
public Menu menu; | ||
|
||
public ClickListener(Menu parent) { | ||
this.menu = parent; | ||
} | ||
|
||
public abstract void onClick(); | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
GitHubGameJam2012/src/com/mbl111/ggo12/gfx/menu/component/MenuComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.mbl111.ggo12.gfx.menu.component; | ||
|
||
import com.mbl111.ggo12.gfx.Screen; | ||
import com.mbl111.ggo12.gfx.menu.Menu; | ||
import com.mbl111.ggo12.input.Input; | ||
|
||
public class MenuComponent { | ||
|
||
public String text = ""; | ||
public boolean selected; | ||
protected int x, y, w, h, index; | ||
protected Menu menu; | ||
protected int tick = 0; | ||
protected ClickListener clickListener; | ||
|
||
public MenuComponent(int x, int y, int w, int h, int selectedIndex) { | ||
this.x = x; | ||
this.y = y; | ||
this.w = w; | ||
this.h = h; | ||
this.index = selectedIndex; | ||
} | ||
|
||
public void init(Menu menu) { | ||
this.menu = menu; | ||
} | ||
|
||
public void tick(int TickCount, Input input) { | ||
tick++; | ||
} | ||
|
||
public void render(Screen screen) { | ||
} | ||
|
||
public MenuComponent setText(String text) { | ||
this.text = text; | ||
return this; | ||
} | ||
|
||
public void setSize(int width, int height) { | ||
this.w = width; | ||
this.h = height; | ||
} | ||
|
||
public boolean isOver(int x2, int y2) { | ||
if (x2 > x && x2 <= x + w + 1 && y2 > y && y2 <= y + h + 1) { | ||
selected = true; | ||
} else { | ||
selected = false; | ||
} | ||
return selected; | ||
} | ||
|
||
public void click() { | ||
menu.lastClickedIndex = index; | ||
if (clickListener != null) { | ||
clickListener.onClick(); | ||
} | ||
} | ||
|
||
public MenuComponent setClickListener(ClickListener clickListener2) { | ||
this.clickListener = clickListener2; | ||
return this; | ||
} | ||
} |