file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
SwitchTeamDialogView.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/screens/dialog/SwitchTeamDialogView.java
/* * see license.txt */ package seventh.client.screens.dialog; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.Renderable; import seventh.math.Rectangle; import seventh.shared.TimeStep; import seventh.ui.view.ButtonView; import seventh.ui.view.LabelView; import seventh.ui.view.PanelView; /** * @author Tony * */ public class SwitchTeamDialogView implements Renderable { private SwitchTeamDialog dialog; private PanelView panelView; /** * */ public SwitchTeamDialogView(SwitchTeamDialog dialog) { this.dialog = dialog; this.panelView = new PanelView(); this.panelView.addElement(new LabelView(dialog.getTitle())); this.panelView.addElement(new ButtonView(dialog.getCancelBtn())); this.panelView.addElement(new ButtonView(dialog.getAllied())); this.panelView.addElement(new ButtonView(dialog.getAxis())); this.panelView.addElement(new ButtonView(dialog.getSpectator())); } public void clear() { this.panelView.clear(); } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { this.panelView.update(timeStep); } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { if(dialog.isVisible()) { Rectangle bounds = dialog.getBounds(); canvas.fillRect(bounds.x, bounds.y, bounds.width, bounds.height, 0xaf383e18); canvas.drawRect(bounds.x, bounds.y, bounds.width, bounds.height, 0xff000000); this.panelView.render(canvas, camera, alpha); } } }
1,907
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
InGameOptionsDialogView.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/screens/dialog/InGameOptionsDialogView.java
/* * see license.txt */ package seventh.client.screens.dialog; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.Renderable; import seventh.math.Rectangle; import seventh.shared.TimeStep; import seventh.ui.view.ButtonView; import seventh.ui.view.LabelView; import seventh.ui.view.PanelView; /** * @author Tony * */ public class InGameOptionsDialogView implements Renderable { private InGameOptionsDialog dialog; private PanelView panelView; private WeaponClassDialogView weaponClassDialogView; private SwitchTeamDialogView switchTeamDialogView; /** * */ public InGameOptionsDialogView(InGameOptionsDialog dialog) { this.dialog = dialog; this.panelView = new PanelView(); this.panelView.addElement(new LabelView(dialog.getTitle())); this.panelView.addElement(new ButtonView(dialog.getWeaponClasses())); this.panelView.addElement(new ButtonView(dialog.getSwitchTeam())); this.panelView.addElement(new ButtonView(dialog.getOptions())); this.panelView.addElement(new ButtonView(dialog.getLeaveGameBtn())); this.weaponClassDialogView= new WeaponClassDialogView(dialog.getWeaponDialog()); this.switchTeamDialogView = new SwitchTeamDialogView(dialog.getSwitchTeamDialog()); } public void clear() { this.panelView.clear(); } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { panelView.update(timeStep); weaponClassDialogView.update(timeStep); switchTeamDialogView.update(timeStep); } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { if(dialog.getWeaponDialog().isVisible()) { weaponClassDialogView.render(canvas, camera, alpha); } else if(dialog.getSwitchTeamDialog().isVisible()) { switchTeamDialogView.render(canvas, camera, alpha); } else if(dialog.isVisible()) { Rectangle bounds = dialog.getBounds(); canvas.fillRect(bounds.x, bounds.y, bounds.width, bounds.height, 0xaf383e18); canvas.drawRect(bounds.x, bounds.y, bounds.width, bounds.height, 0xff000000); this.panelView.render(canvas, camera, alpha); } } }
2,614
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
WeaponClassDialog.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/screens/dialog/WeaponClassDialog.java
/* * see license.txt */ package seventh.client.screens.dialog; import seventh.client.ClientTeam; import seventh.client.gfx.Theme; import seventh.client.network.ClientConnection; import seventh.game.entities.Entity.Type; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.network.messages.PlayerSwitchWeaponClassMessage; import seventh.shared.EventDispatcher; import seventh.ui.Button; import seventh.ui.Label; import seventh.ui.Label.TextAlignment; import seventh.ui.Widget; import seventh.ui.events.ButtonEvent; import seventh.ui.events.OnButtonClickedListener; /** * A dialog box to pick the weapon class. * * @author Tony * */ public class WeaponClassDialog extends Widget { private ClientTeam team; private Label title; private Theme theme; private Button[] weaponClasses; private Label[] weaponClassDescriptions; private Button cancel; private ClientConnection connection; private InGameOptionsDialog owner; /** */ public WeaponClassDialog(InGameOptionsDialog owner, ClientConnection network, Theme theme) { super(new EventDispatcher()); this.owner = owner; this.connection = network; this.team = ClientTeam.ALLIES; this.theme = theme; this.weaponClasses = new Button[7]; this.weaponClassDescriptions = new Label[7]; createUI(); } /* (non-Javadoc) * @see seventh.ui.Widget#setBounds(seventh.math.Rectangle) */ @Override public void setBounds(Rectangle bounds) { super.setBounds(bounds); createUI(); } /** * @return the team */ public ClientTeam getTeam() { return team; } /** * @return the weaponClasses */ public Button[] getWeaponClasses() { return weaponClasses; } /** * @return the weaponClassDescriptions */ public Label[] getWeaponClassDescriptions() { return weaponClassDescriptions; } private void createUI() { destroyChildren(); Rectangle bounds = getBounds(); this.title = new Label("Select a Weapon"); this.title.setTheme(theme); //this.title.setForegroundColor(0xffffffff); this.title.setBounds(new Rectangle(bounds)); this.title.getBounds().height = 15; this.title.getBounds().y += 20; this.title.setFont(theme.getSecondaryFontName()); this.title.setHorizontalTextAlignment(TextAlignment.CENTER); this.title.setTextSize(22); refreshButtons(); this.cancel = new Button(); this.cancel.setText("Cancel"); this.cancel.setBounds(new Rectangle(0,0,100,40)); this.cancel.getBounds().centerAround(bounds.x + 205, bounds.y + bounds.height - 10); this.cancel.setEnableGradiant(false); this.cancel.setTheme(theme); this.cancel.getTextLabel().setFont(theme.getSecondaryFontName()); this.cancel.getTextLabel().setForegroundColor(theme.getForegroundColor()); this.cancel.setTextSize(22); this.cancel.setHoverTextSize(26); this.cancel.addOnButtonClickedListener(new OnButtonClickedListener() { @Override public void onButtonClicked(ButtonEvent event) { owner.close(); } }); addWidget(cancel); addWidget(title); } private Vector2f refreshButtons() { Rectangle bounds = getBounds(); Vector2f pos = new Vector2f(); pos.x = bounds.x + 120; pos.y = bounds.y + 50; int yInc = 50; for(int i = 0; i < weaponClasses.length; i++) { if( this.weaponClasses[i] != null ) { removeWidget(weaponClasses[i]); this.weaponClasses[i].destroy(); this.weaponClasses[i] = null; removeWidget(this.weaponClassDescriptions[i]); this.weaponClassDescriptions[i].destroy(); this.weaponClassDescriptions[i] = null; } } switch(team) { case AXIS: this.weaponClasses[0] =setupButton(pos, Type.MP40); this.weaponClassDescriptions[0] = setupLabel(pos, Type.MP40); pos.y += yInc; this.weaponClasses[1] =setupButton(pos, Type.MP44); this.weaponClassDescriptions[1] = setupLabel(pos, Type.MP44); pos.y += yInc; this.weaponClasses[2] =setupButton(pos, Type.KAR98); this.weaponClassDescriptions[2] = setupLabel(pos, Type.KAR98); pos.y += yInc; break; case ALLIES: default: this.weaponClasses[0] =setupButton(pos, Type.THOMPSON); this.weaponClassDescriptions[0] = setupLabel(pos, Type.THOMPSON); pos.y += yInc; this.weaponClasses[1] =setupButton(pos, Type.M1_GARAND); this.weaponClassDescriptions[1] = setupLabel(pos, Type.M1_GARAND); pos.y += yInc; this.weaponClasses[2] =setupButton(pos, Type.SPRINGFIELD); this.weaponClassDescriptions[2] = setupLabel(pos, Type.SPRINGFIELD); pos.y += yInc; break; } this.weaponClasses[3] =setupButton(pos, Type.RISKER); this.weaponClassDescriptions[3] = setupLabel(pos, Type.RISKER); pos.y += yInc; this.weaponClasses[4] =setupButton(pos, Type.SHOTGUN); this.weaponClassDescriptions[4] = setupLabel(pos, Type.SHOTGUN); pos.y += yInc; this.weaponClasses[5] =setupButton(pos, Type.ROCKET_LAUNCHER); this.weaponClassDescriptions[5] = setupLabel(pos, Type.ROCKET_LAUNCHER); pos.y += yInc; this.weaponClasses[6] =setupButton(pos, Type.FLAME_THROWER); this.weaponClassDescriptions[6] = setupLabel(pos, Type.FLAME_THROWER); return pos; } private String getClassDescription(Type type) { String message = ""; switch(type) { case THOMPSON: message = "Thompson | 30/180 rnds\n" + "Pistol | 9/27 rnds \n" + "2 Frag Grenades"; break; case M1_GARAND: message = "M1 Garand | 8/40 rnds\n" + "Pistol | 9/27 rnds \n" + "2 Smoke Grenades"; break; case SPRINGFIELD: message = "Springfield | 5/35 rnds\n" + "Pistol | 9/27 rnds \n" + "1 Frag Grenades"; break; case MP40: message = "MP40 | 32/160 rnds\n" + "Pistol | 9/27 rnds \n" + "2 Frag Grenades"; break; case MP44: message = "MP44 | 30/120 rnds\n" + "Pistol | 9/27 rnds \n" + "2 Smoke Grenades"; break; case KAR98: message = "KAR-98 | 5/25 rnds\n" + "Pistol | 9/27 rnds \n" + "1 Frag Grenade"; break; case RISKER: message = "MG-z | 21/42 rnds\n" + "Pistol | 9/27 rnds"; break; case SHOTGUN: message = "Shotgun | 5/35 rnds\n" + "Pistol | 9/27 rnds"; break; case ROCKET_LAUNCHER: message = "M1 | 5 rnds\n" + "Pistol | 9/27 rnds\n" + "5 Frag Grenades"; break; case FLAME_THROWER: message = "Flame Thrower\n" + "Pistol | 9/27 rnds\n" + "2 Frag Grenades"; break; default:; } return message; } private Button setupButton(Vector2f pos, final Type type) { final Button btn = new Button(); btn.setBounds(new Rectangle((int)pos.x, (int)pos.y, 320, 40)); btn.setBorder(false); // btn.setText(getClassDescription(type)); // btn.setTextSize(12); // btn.setHoverTextSize(12); // btn.getTextLabel().setForegroundColor(this.theme.getForegroundColor()); // btn.getTextLabel().setHorizontalTextAlignment(TextAlignment.LEFT); // btn.getTextLabel().setVerticalTextAlignment(TextAlignment.BOTTOM); btn.addOnButtonClickedListener(new OnButtonClickedListener() { @Override public void onButtonClicked(ButtonEvent event) { if(connection.isConnected()) { PlayerSwitchWeaponClassMessage msg = new PlayerSwitchWeaponClassMessage(); msg.weaponType = type; connection.getClientProtocol().sendPlayerSwitchWeaponClassMessage(msg); } owner.close(); } }); addWidget(btn); return btn; } private Label setupLabel(Vector2f pos, final Type type) { Label lbl = new Label(this.getClassDescription(type)); lbl.setBounds(new Rectangle((int)pos.x + 80, (int)pos.y, 220, 60)); lbl.setTextSize(12); lbl.setForegroundColor(this.theme.getForegroundColor()); //0xff363e0f lbl.setShadow(false); lbl.setFont("Consola"); lbl.setHorizontalTextAlignment(TextAlignment.LEFT); lbl.setVerticalTextAlignment(TextAlignment.TOP); lbl.hide(); addWidget(lbl); return lbl; } /** * @return the cancel button */ public Button getCancelBtn() { return cancel; } /** * @return the title */ public Label getTitle() { return title; } /** * @param team the team to set */ public void setTeam(ClientTeam team) { this.team = team; refreshButtons(); if(this.isDisabled()) { owner.close(); } } @Override public void show() { super.show(); for(Label lbl : weaponClassDescriptions) { lbl.hide(); } } }
10,827
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
WeaponClassDialogView.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/screens/dialog/WeaponClassDialogView.java
/* * see license.txt */ package seventh.client.screens.dialog; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; import seventh.client.gfx.Art; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.Renderable; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.shared.TimeStep; import seventh.ui.Button; import seventh.ui.Label; import seventh.ui.Widget; import seventh.ui.view.ButtonView; import seventh.ui.view.ImageButtonView; import seventh.ui.view.LabelView; import seventh.ui.view.PanelView; /** * @author Tony * */ public class WeaponClassDialogView implements Renderable { static class SelectionAreaView implements Renderable { private Button btn; private Widget parent; public SelectionAreaView(Button btn, Widget parent) { this.btn = btn; this.parent = parent; } @Override public void update(TimeStep timeStep) { } @Override public void render(Canvas canvas, Camera camera, float alpha) { Rectangle bounds = this.btn.getScreenBounds(); int x = this.parent.getBounds().x; int width = this.parent.getBounds().width; int height = bounds.height + 9; if(this.btn.isHovering()) { //0xff8c955c very lite //0xff5a6136 //0xff202503 very dark canvas.fillRect(x, bounds.y, width, height, 0xaf202503); canvas.drawRect(x, bounds.y, width, height, 0xff5a6136); } else { canvas.fillRect(x, bounds.y, width, height, 0xaf363d0f); canvas.drawRect(x, bounds.y, width, height, 0xaf202503); } } } private WeaponClassDialog dialog; private PanelView panelView; private Button[] weaponBtns; private Label[] weaponDescriptions; private Vector2f origin; private int originalButtonWidth; /** * */ public WeaponClassDialogView(WeaponClassDialog dialog) { this.dialog = dialog; this.panelView = new PanelView(); this.panelView.addElement(new LabelView(dialog.getTitle())); this.panelView.addElement(new ButtonView(dialog.getCancelBtn())); this.origin = new Vector2f(); Button[] btns = dialog.getWeaponClasses(); this.weaponBtns = btns; if(btns.length != 7) { throw new IllegalArgumentException("Don't have all the weapons defined!"); } for(Button btn : this.weaponBtns) { this.panelView.addElement(new SelectionAreaView(btn, dialog)); } this.origin.set(this.weaponBtns[0].getBounds().x, this.weaponBtns[0].getBounds().y); this.originalButtonWidth = this.weaponBtns[0].getBounds().width; switch(dialog.getTeam()) { case ALLIES: this.panelView.addElement(new ImageButtonView(btns[0], scale(Art.thompsonIcon))); this.panelView.addElement(new ImageButtonView(btns[1], scale(Art.m1GarandIcon))); this.panelView.addElement(new ImageButtonView(btns[2], scale(Art.springfieldIcon))); break; case AXIS: this.panelView.addElement(new ImageButtonView(btns[0], scale(Art.mp40Icon))); this.panelView.addElement(new ImageButtonView(btns[1], scale(Art.mp44Icon))); this.panelView.addElement(new ImageButtonView(btns[2], scale(Art.kar98Icon))); break; default: break; } this.panelView.addElement(new ImageButtonView(btns[3], scale(Art.riskerIcon))); this.panelView.addElement(new ImageButtonView(btns[4], scale(Art.shotgunIcon))); this.panelView.addElement(new ImageButtonView(btns[5], scale(Art.rocketIcon))); this.panelView.addElement(new ImageButtonView(btns[6], scale(Art.flameThrowerIcon))); this.weaponDescriptions = dialog.getWeaponClassDescriptions(); for(Label lbl : this.weaponDescriptions) { this.panelView.addElement(new LabelView(lbl)); } } private TextureRegion scale(TextureRegion tex) { Sprite sprite = new Sprite(tex); sprite.setSize(110, 45); return sprite; } public void clear() { this.panelView.clear(); } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { this.panelView.update(timeStep); final int openSpeed = 15; final int closeSpeed = 9; final int maxMoveBy = 100; for(int i = 0; i < this.weaponBtns.length; i++) { Button btn = this.weaponBtns[i]; if(btn.isHovering()) { if( btn.getBounds().x > this.origin.x - maxMoveBy ) { btn.getBounds().x -= openSpeed; btn.getBounds().width = this.originalButtonWidth + ((int)this.origin.x - btn.getBounds().x); } else { btn.getBounds().x = (int)this.origin.x - maxMoveBy; btn.getBounds().width = this.originalButtonWidth + ((int)this.origin.x - btn.getBounds().x); this.weaponDescriptions[i].show(); } } else { if( btn.getBounds().x < this.origin.x ) { btn.getBounds().x += closeSpeed; btn.getBounds().width = this.originalButtonWidth + ((int)this.origin.x - btn.getBounds().x); this.weaponDescriptions[i].hide(); } else { btn.getBounds().x = (int)this.origin.x; btn.getBounds().width = this.originalButtonWidth + ((int)this.origin.x - btn.getBounds().x); } } } } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { if(dialog.isVisible()) { Rectangle bounds = dialog.getBounds(); canvas.fillRect(bounds.x, bounds.y, bounds.width, bounds.height, 0xaf383e18); canvas.drawRect(bounds.x, bounds.y, bounds.width, bounds.height, 0xff000000); this.panelView.render(canvas, camera, alpha); } } }
6,877
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
TileSelectDialogView.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/screens/dialog/TileSelectDialogView.java
/* * see license.txt */ package seventh.client.screens.dialog; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.Renderable; import seventh.shared.TimeStep; import seventh.ui.view.PanelView; /** * @author Tony * */ public class TileSelectDialogView implements Renderable { private TileSelectDialog dialog; private PanelView panelView; /** * */ public TileSelectDialogView(TileSelectDialog dialog) { this.dialog = dialog; this.panelView = new PanelView(dialog); } @Override public void update(TimeStep timeStep) { } @Override public void render(Canvas canvas, Camera camera, float alpha) { this.panelView.render(canvas, camera, alpha); this.dialog.getPanelView().render(canvas, camera, alpha); } }
857
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientBomb.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientBomb.java
/* * The Seventh * see license.txt */ package seventh.client.weapon; import seventh.client.ClientGame; import seventh.client.entities.ClientEntity; import seventh.client.gfx.Art; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * @author Tony * */ public class ClientBomb extends ClientEntity { /** * @param pos */ public ClientBomb(ClientGame game, Vector2f pos) { super(game, pos); } /* (non-Javadoc) * @see seventh.client.ClientEntity#isBackgroundObject() */ @Override public boolean isBackgroundObject() { return true; } /* (non-Javadoc) * @see seventh.client.ClientEntity#update(leola.live.TimeStep) */ @Override public void update(TimeStep timeStep) { super.update(timeStep); } /* (non-Javadoc) * @see leola.live.gfx.Renderable#render(leola.live.gfx.Canvas, leola.live.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { Vector2f cameraPos = camera.getRenderPosition(alpha); float x = (pos.x - cameraPos.x); float y = (pos.y - cameraPos.y); canvas.drawImage(Art.bombImage, x, y, null); } }
1,318
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientRisker.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientRisker.java
/* * see license.txt */ package seventh.client.weapon; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art; import seventh.shared.WeaponConstants; /** * @author Tony * */ public class ClientRisker extends ClientWeapon { /** * @param ownerId */ public ClientRisker(ClientPlayerEntity owner) { super(owner); this.weaponIcon = Art.riskerIcon; // this.weaponImage = Art.sniperRifleImage; this.weaponImage = Art.riskerImage; this.muzzleFlash = Art.newRiskerMuzzleFlash(); this.weaponWeight = WeaponConstants.RISKER_WEIGHT; this.weaponKickTime = 280; this.endFireKick = 10.7f; this.beginFireKick = 0f; } /* (non-Javadoc) * @see seventh.client.weapon.ClientWeapon#isBurstFire() */ @Override public boolean isBurstFire() { return true; } /* (non-Javadoc) * @see palisma.client.weapon.ClientWeapon#onFire() */ @Override protected boolean onFire() { return true; } }
1,091
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientFlameThrower.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientFlameThrower.java
/* * see license.txt */ package seventh.client.weapon; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art; import seventh.shared.WeaponConstants; /** * @author Tony * */ public class ClientFlameThrower extends ClientWeapon { /** * @param ownerId */ public ClientFlameThrower(ClientPlayerEntity owner) { super(owner); this.weaponIcon = Art.flameThrowerIcon; // this.weaponImage = Art.sniperRifleImage; this.weaponImage = Art.flameThrowerImage; this.muzzleFlash = null;//Art.newRiskerMuzzleFlash(); // TODO this.weaponWeight = WeaponConstants.FLAME_THROWER_WEIGHT; this.weaponKickTime = 0; this.endFireKick = 0.0f; this.beginFireKick = 0f; } @Override public boolean emitBulletCasing() { return false; } @Override public boolean isBurstFire() { return false; } @Override protected boolean onFire() { return true; } }
1,056
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientThompson.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientThompson.java
/* * see license.txt */ package seventh.client.weapon; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art; import seventh.shared.WeaponConstants; /** * @author Tony * */ public class ClientThompson extends ClientWeapon { /** * @param ownerId */ public ClientThompson(ClientPlayerEntity owner) { super(owner); this.weaponIcon = Art.thompsonIcon; this.weaponImage = Art.thompsonImage; this.muzzleFlash = Art.newThompsonMuzzleFlash(); this.weaponKickTime = 100; this.endFireKick = 0f; this.beginFireKick = 3.5f; this.weaponWeight = WeaponConstants.THOMPSON_WEIGHT; } /* (non-Javadoc) * @see seventh.client.weapon.ClientWeapon#isAutomatic() */ @Override public boolean isAutomatic() { return true; } /* (non-Javadoc) * @see seventh.client.weapon.ClientWeapon#hasLongBarrel() */ @Override public boolean hasLongBarrel() { return false; } }
1,110
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientRocketLauncher.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientRocketLauncher.java
/* * see license.txt */ package seventh.client.weapon; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art; import seventh.shared.WeaponConstants; /** * @author Tony * */ public class ClientRocketLauncher extends ClientWeapon { /** * @param ownerId */ public ClientRocketLauncher(ClientPlayerEntity owner) { super(owner); this.weaponIcon = Art.rocketIcon; this.weaponImage = Art.rpgImage; this.weaponWeight = WeaponConstants.RPG_WEIGHT; this.weaponKickTime = 0; this.endFireKick = 0f; this.beginFireKick = 0f; } @Override public boolean isHeavyWeapon() { return true; } @Override public boolean emitBulletCasing() { return false; } }
817
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientPistol.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientPistol.java
/* * The Seventh * see license.txt */ package seventh.client.weapon; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art; import seventh.shared.WeaponConstants; /** * @author Tony * */ public class ClientPistol extends ClientWeapon { /** * @param owner */ public ClientPistol(ClientPlayerEntity owner) { super(owner); this.weaponIcon = Art.pistolIcon; this.weaponImage = Art.pistolImage; this.muzzleFlash = Art.newThompsonMuzzleFlash(); this.weaponWeight = WeaponConstants.PISTOL_WEIGHT; this.weaponKickTime = 0; this.endFireKick = 0f; this.beginFireKick = 0f; } }
712
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientShotgun.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientShotgun.java
/* * see license.txt */ package seventh.client.weapon; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art; import seventh.shared.WeaponConstants; /** * @author Tony * */ public class ClientShotgun extends ClientWeapon { /** * @param ownerId */ public ClientShotgun(ClientPlayerEntity owner) { super(owner); this.weaponIcon = Art.shotgunIcon; this.weaponImage = Art.shotgunImage; this.muzzleFlash = Art.newShotgunMuzzleFlash(); this.weaponWeight = WeaponConstants.SHOTGUN_WEIGHT; this.weaponKickTime = 66; this.endFireKick = 18.7f; this.beginFireKick = 0f; } /* (non-Javadoc) * @see palisma.client.weapon.ClientWeapon#onFire() */ @Override protected boolean onFire() { return true; } /* (non-Javadoc) * @see seventh.client.weapon.ClientWeapon#isPumpAction() */ @Override public boolean isPumpAction() { return true; } }
1,054
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientMP40.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientMP40.java
/* * The Seventh * see license.txt */ package seventh.client.weapon; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art; import seventh.shared.WeaponConstants; /** * @author Tony * */ public class ClientMP40 extends ClientWeapon { /** * @param owner */ public ClientMP40(ClientPlayerEntity owner) { super(owner); this.weaponIcon = Art.mp40Icon; this.weaponImage = Art.mp40Image; this.muzzleFlash = Art.newMP40MuzzleFlash(); this.weaponWeight = WeaponConstants.MP40_WEIGHT; this.weaponKickTime = 100; this.endFireKick = 0f; this.beginFireKick = 3.2f; } /* (non-Javadoc) * @see seventh.client.weapon.ClientWeapon#isAutomatic() */ @Override public boolean isAutomatic() { return true; } /* (non-Javadoc) * @see seventh.client.weapon.ClientWeapon#hasLongBarrel() */ @Override public boolean hasLongBarrel() { return false; } }
1,100
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientM1Garand.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientM1Garand.java
/* * The Seventh * see license.txt */ package seventh.client.weapon; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art; import seventh.shared.WeaponConstants; /** * @author Tony * */ public class ClientM1Garand extends ClientWeapon { /** * @param owner */ public ClientM1Garand(ClientPlayerEntity owner) { super(owner); this.weaponIcon = Art.m1GarandIcon; this.weaponImage = Art.m1GarandImage; this.muzzleFlash = Art.newM1GarandMuzzleFlash(); this.weaponWeight = WeaponConstants.M1GARAND_WEIGHT; this.weaponKickTime = 50; this.endFireKick = 0f; this.beginFireKick = 8.5f; } }
766
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientSpringfield.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientSpringfield.java
/* * see license.txt */ package seventh.client.weapon; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art; import seventh.shared.WeaponConstants; /** * @author Tony * */ public class ClientSpringfield extends ClientWeapon { /** * @param ownerId */ public ClientSpringfield(ClientPlayerEntity owner) { super(owner); this.weaponIcon = Art.springfieldIcon; this.weaponImage = Art.springfieldImage; this.muzzleFlash = Art.newSpringfieldMuzzleFlash(); this.weaponWeight = WeaponConstants.SPRINGFIELD_WEIGHT; this.weaponKickTime = 100; this.endFireKick = 20.7f; this.beginFireKick = 0f; } /* (non-Javadoc) * @see palisma.client.weapon.ClientWeapon#onFire() */ @Override protected boolean onFire() { return true; } /* (non-Javadoc) * @see seventh.client.weapon.ClientWeapon#isBoltAction() */ @Override public boolean isBoltAction() { return true; } }
1,081
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientKar98.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientKar98.java
/* * The Seventh * see license.txt */ package seventh.client.weapon; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art; import seventh.shared.WeaponConstants; /** * @author Tony * */ public class ClientKar98 extends ClientWeapon { /** * @param owner */ public ClientKar98(ClientPlayerEntity owner) { super(owner); this.weaponIcon = Art.kar98Icon; this.weaponImage = Art.kar98Image; this.muzzleFlash = Art.newKar98MuzzleFlash(); this.weaponWeight = WeaponConstants.KAR98_WEIGHT; this.weaponKickTime = 100; this.endFireKick = 18.7f; this.beginFireKick = 0f; } /* (non-Javadoc) * @see seventh.client.weapon.ClientWeapon#isBoltAction() */ @Override public boolean isBoltAction() { return true; } }
917
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientWeapon.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientWeapon.java
/* * see license.txt */ package seventh.client.weapon; import com.badlogic.gdx.graphics.g2d.TextureRegion; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.AnimatedImage; import seventh.client.gfx.Camera; import seventh.game.net.NetWeapon; import seventh.game.weapons.Weapon.WeaponState; import seventh.shared.TimeStep; import seventh.shared.Timer; /** * @author Tony * */ public class ClientWeapon { private static final long boltActionTime = 500; private static final long pumpActionTime = 100; protected final int channelId; private NetWeapon prevState, nextState; protected float beginFireKick, endFireKick; protected int weaponKickTime; protected int weaponWeight; private boolean startReloading; private int firstFire; protected TextureRegion weaponIcon, weaponImage; protected AnimatedImage muzzleFlash; protected final ClientPlayerEntity owner; private Timer specialReloadActionReloadTimer; private Timer fireWaitTimer; /** * */ public ClientWeapon(ClientPlayerEntity owner) { this.owner = owner; this.channelId = this.owner.getPlayerId(); this.firstFire = 0; this.specialReloadActionReloadTimer = new Timer(false, boltActionTime); this.fireWaitTimer = new Timer(false, 100); this.weaponKickTime = 250; } /** * @return the weaponWeight */ public int getWeaponWeight() { return weaponWeight; } public int getAmmoInClip() { return (nextState!=null) ? nextState.ammoInClip : 0; } public int getTotalAmmo() { return (nextState!=null) ? nextState.totalAmmo : 0; } /** * @return the weaponIcon */ public TextureRegion getWeaponIcon() { return weaponIcon; } /** * @return the weaponImage */ public TextureRegion getWeaponImage() { return weaponImage; } /** * @return the muzzle flash animation */ public AnimatedImage getMuzzleFlash() { return muzzleFlash; } /** * @return the nextState */ protected NetWeapon getNextState() { return nextState; } /** * @return the prevState */ protected NetWeapon getPrevState() { return prevState; } public void updateState(NetWeapon state, long time) { this.prevState = nextState; this.nextState = state; } /** * @return the firstFire */ public boolean isFirstFire() { return firstFire==1; } public WeaponState getState() { if(this.nextState!=null) { WeaponState weaponState = nextState.weaponState; return weaponState; } return WeaponState.UNKNOWN; } public WeaponState getPreviousState() { if(this.prevState!=null) { WeaponState weaponState = prevState.weaponState; return weaponState; } return WeaponState.UNKNOWN; } protected boolean onFire() { return false; } public boolean isHeavyWeapon() { return false; } public boolean isAutomatic() { return false; } public boolean hasLongBarrel() { return true; } public boolean isBurstFire() { return false; } public boolean isBoltAction() { return false; } public boolean isPumpAction() { return false; } public boolean emitBulletCasing() { return true; } public boolean emitBarrelSmoke() { return true; } public boolean isSpecialReloadingAction() { return this.specialReloadActionReloadTimer.isUpdating(); } /** * @return true if the weapon is currently in the reloading state */ public boolean isReloading() { return getState() == WeaponState.RELOADING; } private void startSpecialReloadActionTimer() { if(isBoltAction()) this.specialReloadActionReloadTimer.setEndTime(boltActionTime); else if(isPumpAction()) this.specialReloadActionReloadTimer.setEndTime(pumpActionTime); this.specialReloadActionReloadTimer.reset(); this.specialReloadActionReloadTimer.start(); } public void update(TimeStep timeStep) { this.fireWaitTimer.update(timeStep); this.specialReloadActionReloadTimer.update(timeStep); if(this.nextState!=null) { WeaponState weaponState = nextState.weaponState; if(weaponState != WeaponState.FIRING) { firstFire = 0; } if(isPumpAction() /*|| isBoltAction()*/) { if(startReloading) { if(weaponState!=WeaponState.RELOADING) { startSpecialReloadActionTimer(); } } } switch(weaponState) { case FIRE_EMPTY: { break; } case FIRING: { firstFire++; if(!this.fireWaitTimer.isUpdating() && isFirstFire() && !isAutomatic()) { this.fireWaitTimer.setEndTime(isBoltAction() ? 50 : 300); this.fireWaitTimer.reset(); this.fireWaitTimer.start(); if(emitBulletCasing()) { this.owner.emitBulletCasing(); } } if(!this.specialReloadActionReloadTimer.isUpdating() && this.fireWaitTimer.isOnFirstTime()) { startSpecialReloadActionTimer(); } break; } case RELOADING: { if(!startReloading) { startReloading = true; } break; } case SWITCHING: { break; } default: { startReloading = false; } } } } /** * Kicks the camera if firing * @param camera */ public void cameraKick(Camera camera) { // this.weaponKickTime = 150; // this.endFireKick = 18.7f; // this.beginFireKick = 0f; //this.weaponKickTime = 100; //this.beginFireKick = 3.8f; if(getState() == WeaponState.FIRING && weaponKickTime>0) { if(firstFire==1) { camera.shakeFrom(weaponKickTime, this.owner.getFacing(), this.endFireKick); //camera.shake(weaponKickTime, endFireKick); } else if (beginFireKick > 0 ) { //camera.shake(weaponKickTime, beginFireKick); camera.shakeFrom(weaponKickTime, this.owner.getFacing(), this.beginFireKick); } } } }
7,470
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientGrenateBelt.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientGrenateBelt.java
/* * see license.txt */ package seventh.client.weapon; import seventh.client.entities.ClientPlayerEntity; /** * @author Tony * */ public class ClientGrenateBelt extends ClientWeapon { /** * @param ownerId */ public ClientGrenateBelt(ClientPlayerEntity owner) { super(owner); this.weaponIcon = null; this.weaponImage = null; } }
397
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientMP44.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientMP44.java
/* * The Seventh * see license.txt */ package seventh.client.weapon; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art; import seventh.shared.WeaponConstants; /** * @author Tony * */ public class ClientMP44 extends ClientWeapon { /** * @param owner */ public ClientMP44(ClientPlayerEntity owner) { super(owner); this.weaponIcon = Art.mp44Icon; this.weaponImage = Art.mp44Image; this.muzzleFlash = Art.newMP44MuzzleFlash(); this.weaponWeight = WeaponConstants.MP44_WEIGHT; this.weaponKickTime = 100; this.endFireKick = 0f; this.beginFireKick = 6.2f; } /* (non-Javadoc) * @see seventh.client.weapon.ClientWeapon#isAutomatic() */ @Override public boolean isAutomatic() { return true; } public boolean isBurstFire() { return false; } }
940
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientHammer.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/weapon/ClientHammer.java
/* * The Seventh * see license.txt */ package seventh.client.weapon; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art; import seventh.shared.WeaponConstants; /** * @author Tony * */ public class ClientHammer extends ClientWeapon { /** * @param owner */ public ClientHammer(ClientPlayerEntity owner) { super(owner); this.weaponIcon = Art.hammerIcon; this.weaponImage = Art.hammerImage; // this.muzzleFlash = Art.newThompsonMuzzleFlash(); this.weaponWeight = WeaponConstants.HAMMER_WEIGHT; this.weaponKickTime = 0; this.endFireKick = 0f; this.beginFireKick = 0f; } @Override public boolean emitBulletCasing() { return false; } @Override public boolean emitBarrelSmoke() { return false; } }
887
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ImageLight.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/ImageLight.java
/* * see license.txt */ package seventh.client.gfx; import seventh.math.Vector2f; import seventh.math.Vector3f; import seventh.shared.TimeStep; import seventh.shared.Updatable; import com.badlogic.gdx.graphics.g2d.TextureRegion; /** * A light source * * @author Tony * */ public class ImageLight implements Updatable, Light { private Vector2f pos, absolutePos; private float orientation; private float luminacity; private Vector3f color; private boolean lightOscillate; private TextureRegion texture; private int lightSize; private boolean on; private long flickerTime; private long timeToNextFlicker; private LightSystem lightSystem; public ImageLight(LightSystem lightSystem) { this(lightSystem, new Vector2f()); } /** * @param pos */ public ImageLight(LightSystem lightSystem, Vector2f pos) { this.lightSystem = lightSystem; this.pos = pos; this.absolutePos = new Vector2f(pos); this.orientation = 0; this.color = new Vector3f(0.3f, 0.3f, 0.7f); this.luminacity = 0.5f; this.lightOscillate = false; this.on = true; this.flickerTime = 70; setTexture(Art.lightMap); lightSize = 512; } /* (non-Javadoc) * @see seventh.client.gfx.Light#destroy() */ @Override public void destroy() { this.lightSystem.removeLight(this); } /* (non-Javadoc) * @see seventh.client.gfx.Light#isOn() */ @Override public boolean isOn() { return on; } /* (non-Javadoc) * @see seventh.client.gfx.Light#setOn(boolean) */ @Override public void setOn(boolean on) { this.on = on; } /* (non-Javadoc) * @see seventh.client.gfx.Light#getLightSize() */ @Override public int getLightSize() { return lightSize; } /* (non-Javadoc) * @see seventh.client.gfx.Light#setLightSize(int) */ @Override public void setLightSize(int lightSize) { int previousLightSize = this.lightSize; this.lightSize = lightSize; if(previousLightSize != lightSize) { setPos(this.absolutePos); } } /* (non-Javadoc) * @see seventh.client.gfx.Light#setLightOscillate(boolean) */ @Override public void setLightOscillate(boolean lightOscillate) { this.lightOscillate = lightOscillate; } /** * @param texture the texture to set */ public void setTexture(TextureRegion texture) { this.texture = texture; } /** * @return the texture */ public TextureRegion getTexture() { return texture; } /** * @param flickerTime the flickerTime to set */ public void setFlickerTime(long flickerTime) { this.flickerTime = flickerTime; } /** * @return the flickerTime */ public long getFlickerTime() { return flickerTime; } /* (non-Javadoc) * @see seventh.client.gfx.Light#getLuminacity() */ @Override public float getLuminacity() { return luminacity; } /* (non-Javadoc) * @see seventh.client.gfx.Light#setLuminacity(float) */ @Override public void setLuminacity(float luminacity) { this.luminacity = luminacity; } /* (non-Javadoc) * @see seventh.client.gfx.Light#getColor() */ @Override public Vector3f getColor() { return color; } /* (non-Javadoc) * @see seventh.client.gfx.Light#setColor(seventh.math.Vector3f) */ @Override public void setColor(Vector3f color) { this.color.set(color); } /* (non-Javadoc) * @see seventh.client.gfx.Light#setColor(float, float, float) */ @Override public void setColor(float r, float g, float b) { this.color.set(r, g, b); } /* (non-Javadoc) * @see seventh.client.gfx.Light#getOrientation() */ @Override public float getOrientation() { return orientation; } /* (non-Javadoc) * @see seventh.client.gfx.Light#setOrientation(float) */ @Override public void setOrientation(float orientation) { this.orientation = (float)Math.toDegrees(orientation) + 90; } /* (non-Javadoc) * @see seventh.client.gfx.Light#setPos(seventh.math.Vector2f) */ @Override public void setPos(Vector2f pos) { setPos(pos.x, pos.y); } /* (non-Javadoc) * @see seventh.client.gfx.Light#setPos(float, float) */ @Override public void setPos(float x, float y) { this.pos.set(x,y); this.absolutePos.set(pos); this.pos.x -= lightSize/2; this.pos.y -= lightSize/2; } /** * Sets the absolute position (the other setPos functions account * for the lightSize) * * @param pos */ public void setAbsolutePos(Vector2f pos) { this.pos.set(pos); this.absolutePos.set(pos); } /* (non-Javadoc) * @see seventh.client.gfx.Light#getPos() */ @Override public Vector2f getPos() { return pos; } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { if(this.lightOscillate) { this.timeToNextFlicker -= timeStep.getDeltaTime(); if(this.timeToNextFlicker < 0) { this.setOn(!isOn()); this.timeToNextFlicker = this.flickerTime; } } } }
5,827
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
GdxCanvas.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/GdxCanvas.java
/* * The Seventh * see license.txt */ package seventh.client.gfx; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Stack; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture.TextureFilter; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter; import com.badlogic.gdx.graphics.glutils.FrameBuffer; import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Matrix4; import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.Viewport; import seventh.client.SeventhGame; /** * @author Tony * */ public class GdxCanvas implements Canvas { private SpriteBatch batch; private Color color, tmpColor; private float compositeAlpha; private float fontSize; private float defaultFontSize; private String currentFontName; private String defaultFontName; private Map<String, FreeTypeFontGenerator> generators; private Map<String, BitmapFont> fonts; private BitmapFont font, defaultFont; private GlyphLayout bounds; private Matrix4 transform; private ShapeRenderer shapes; private OrthographicCamera camera; private Viewport viewport; private boolean isBegun; private Stack<ShaderProgram> shaderStack; private Stack<Float> zoomStack; private FrameBuffer fbo; /** * */ public GdxCanvas() { this.batch = new SpriteBatch(); this.color = new Color(); this.tmpColor = new Color(); this.shaderStack = new Stack<>(); this.zoomStack = new Stack<>(); this.camera = new OrthographicCamera(getWidth(), getHeight()); this.camera.setToOrtho(true, getWidth(), getHeight()); this.camera.position.x = this.camera.viewportWidth/2; this.camera.position.y = this.camera.viewportHeight/2; this.camera.update(); this.viewport = new FitViewport(getWidth(), getHeight(), camera); this.viewport.apply(); this.generators = new HashMap<String, FreeTypeFontGenerator>(); this.fonts = new HashMap<String, BitmapFont>(); this.bounds = new GlyphLayout(); this.transform = new Matrix4(); //this.batch.setTransformMatrix(transform); //Matrix4 projection = new Matrix4(); //projection.setToOrtho( 0, getWidth(), getHeight(), 0, -1, 1); //this.batch.setProjectionMatrix(projection); // this.wHeight = getHeight(); this.batch.setProjectionMatrix(this.camera.combined); this.shapes = new ShapeRenderer(); //this.shapes.setTransformMatrix(transform); // this.shapes.setProjectionMatrix(projection); //this.shapes.setProjectionMatrix(camera.combined); this.fbo = new FrameBuffer(Format.RGBA8888, getWidth(), getHeight(), false); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#getCamera() */ @Override public OrthographicCamera getCamera() { return this.camera; } /* * (non-Javadoc) * @see seventh.client.gfx.Canvas#setShader(com.badlogic.gdx.graphics.glutils.ShaderProgram) */ @Override public void setShader(ShaderProgram shader) { this.batch.setShader(shader); } /* * (non-Javadoc) * @see seventh.client.gfx.Canvas#pushShader(com.badlogic.gdx.graphics.glutils.ShaderProgram) */ @Override public void pushShader(ShaderProgram shader) { this.shaderStack.add(shader); this.batch.setShader(shader); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#popShader() */ @Override public void popShader() { if(!this.shaderStack.isEmpty()) { this.shaderStack.pop(); } if(this.shaderStack.isEmpty()) { this.batch.setShader(null); } else { this.batch.setShader(this.shaderStack.peek()); } } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#enableAntialiasing(boolean) */ @Override public void enableAntialiasing(boolean b) { } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#isAntialiasingEnabled() */ @Override public boolean isAntialiasingEnabled() { return false; } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#bindFrameBuffer(int) */ @Override public void bindFrameBuffer(int id) { fbo.getColorBufferTexture().bind(id); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#getFrameBuffer() */ @Override public Texture getFrameBuffer() { return fbo.getColorBufferTexture(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#fboBegin() */ @Override public void fboBegin() { fbo.begin(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#fboEnd() */ @Override public void fboEnd() { fbo.end(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#beginSprite() */ @Override public void begin() { this.batch.begin(); this.isBegun = true; } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#endSprite() */ @Override public void end() { this.batch.end(); this.isBegun = false; } /* * (non-Javadoc) * @see seventh.client.gfx.Canvas#flush() */ @Override public void flush() { this.batch.flush(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#setProjectionMatrix(com.badlogic.gdx.math.Matrix4) */ @Override public void setProjectionMatrix(Matrix4 mat) { this.batch.setProjectionMatrix(mat); this.shapes.setProjectionMatrix(mat); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#setTransform(com.badlogic.gdx.math.Matrix4) */ @Override public void setTransform(Matrix4 mat) { this.batch.setTransformMatrix(mat); this.shapes.setTransformMatrix(mat); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#setTransform() */ @Override public void setDefaultTransforms() { this.batch.setProjectionMatrix(this.camera.combined); this.batch.setTransformMatrix(this.transform); this.shapes.setProjectionMatrix(this.camera.combined); this.shapes.setTransformMatrix(this.transform); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#preRender() */ @Override public void preRender() { this.camera.update(); setDefaultTransforms(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#postRender() */ @Override public void postRender() { } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#setColor(int, java.lang.Integer) */ @Override public void setColor(int color, Integer alpha) { if(alpha != null) { //color = (color << 8) | alpha; color = (alpha << 24) | color; } _setColor(color); } private void _setColor(Integer color) { setColor(this.color, color); } private void setColor(Color c, Integer color) { if(color != null) { int alpha = color >>> 24; color = (color << 8) | alpha; c.set(color); } } private Color setTempColor(Integer color) { if(color != null) { int alpha = color >>> 24; color = (color << 8) | alpha; tmpColor.set(color); return tmpColor; } return this.color; } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#setClearColor(java.lang.Integer) */ @Override public void setClearColor(Integer color) { } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#getColor() */ @Override public int getColor() { int c = Color.rgba8888(color); return (c >>> 8) | (c<<24); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#loadFont(java.lang.String) */ @Override public void loadFont(String filename, String alias) throws IOException { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(filename)); this.generators.put(alias, generator); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#setFont(java.lang.String, int) */ @Override public void setFont(String alias, int size) { this.font = getFont(alias, size); this.fontSize = size; this.currentFontName = alias; } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#setDefaultFont(java.lang.String, int) */ @Override public void setDefaultFont(String alias, int size) { this.defaultFont = getFont(alias, size); this.defaultFontSize = size; this.defaultFontName = alias; } /** * Retrieve the desired font and size (may load the font * if not cached). * * @param alias * @param size * @return the font */ private BitmapFont getFont(String alias, int size) { BitmapFont font = null; String mask = alias + ":" + size; if(this.fonts.containsKey(mask)) { font = this.fonts.get(mask); } else if(this.generators.containsKey(alias)) { FreeTypeFontParameter params = new FreeTypeFontParameter(); params.size = size; params.characters = FreeTypeFontGenerator.DEFAULT_CHARS; params.flip = true; params.magFilter = TextureFilter.Linear; params.minFilter = TextureFilter.Linear; font = this.generators.get(alias).generateFont(params); this.fonts.put(mask, font); } return font; } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#setDefaultFont() */ @Override public void setDefaultFont() { this.font = defaultFont; this.fontSize = this.defaultFontSize; this.currentFontName = this.defaultFontName; } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#getGlythData(java.lang.String, int) */ @Override public GlythData getGlythData(String alias, int size) { BitmapFont font = getFont(alias, size); return new GlythData(font, bounds); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#getGlythData() */ @Override public GlythData getGlythData() { return new GlythData(font, bounds); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#getWidth(java.lang.String) */ @Override public int getWidth(String str) { return GlythData.getWidth(font, bounds, str); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#getHeight(java.lang.String) */ @Override public int getHeight(String str) { return GlythData.getHeight(font, bounds, str); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#boldFont() */ @Override public void boldFont() { } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#italicFont() */ @Override public void italicFont() { } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#plainFont() */ @Override public void plainFont() { } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#resizeFont(float) */ @Override public void resizeFont(float size) { if(font!=null) { /* get the scale increase */ // if(this.fontSize != 0 && this.fontSize != size) { // float delta = size - this.fontSize; // float scale = delta / this.fontSize; // this.fontSize = size; // font.scale(1.0f + scale); // } if(this.fontSize != 0 && this.fontSize != size) { setFont(currentFontName, (int)size); } } } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#setClip(int, int, int, int) */ @Override public void setClip(int x, int y, int width, int height) { } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#setCompositeAlpha(float) */ @Override public void setCompositeAlpha(float a) { this.compositeAlpha = a; } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#getCompositeAlpha() */ @Override public float getCompositeAlpha() { return this.compositeAlpha; } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#getWidth() */ @Override public int getWidth() { //return Gdx.graphics.getWidth(); return SeventhGame.DEFAULT_MINIMIZED_SCREEN_WIDTH; } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#getHeight() */ @Override public int getHeight() { //return Gdx.graphics.getHeight(); return SeventhGame.DEFAULT_MINIMIZED_SCREEN_HEIGHT; } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#toRadians(double) */ @Override public double toRadians(double degrees) { return Math.toRadians(degrees); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#toDegrees(double) */ @Override public double toDegrees(double radians) { return Math.toDegrees(radians); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawLine(int, int, int, int, java.lang.Integer) */ @Override public void drawLine(int x1, int y1, int x2, int y2, Integer color) { drawLine(x1, y1, x2, y2, color, 1); } @Override public void drawLine(int x1, int y1, int x2, int y2, Integer color, float thickness) { Color c=setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); Gdx.gl.glLineWidth(thickness); this.shapes.setColor(c); this.shapes.begin(ShapeType.Line); this.shapes.line(x1, y1, x2, y2); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawLine(float, float, float, float, java.lang.Integer) */ @Override public void drawLine(float x1, float y1, float x2, float y2, Integer color) { drawLine(x1, y1, x2, y2, color, 1); } @Override public void drawLine(float x1, float y1, float x2, float y2, Integer color, float thickness) { Color c=setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); Gdx.gl.glLineWidth(thickness); this.shapes.setColor(c); this.shapes.begin(ShapeType.Line); this.shapes.line(x1, y1, x2, y2); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } private Color startColor=new Color(), endColor=new Color(); /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawLine(int, int, int, int, java.lang.Integer, java.lang.Integer, float) */ @Override public void drawLine(int x1, int y1, int x2, int y2, Integer startColor, Integer endColor, float thickness) { Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); Gdx.gl.glLineWidth(thickness); int alpha = startColor >>> 24; startColor = (startColor << 8) | alpha; this.startColor.set(startColor); alpha = endColor >>> 24; endColor = (endColor << 8) | alpha; this.endColor.set(startColor); this.shapes.begin(ShapeType.Line); this.shapes.line(x1, y1, x2, y2, this.startColor, this.endColor); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } @Override public void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, Integer color) { drawTriangle((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, color); } @Override public void drawTriangle(float x1, float y1, float x2, float y2, float x3, float y3, Integer color) { Color c=setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); this.shapes.setColor(c); this.shapes.begin(ShapeType.Line); this.shapes.triangle(x1, y1, x2, y2, x3, y3, c, c, c); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawRect(int, int, int, int, java.lang.Integer) */ @Override public void drawRect(int x, int y, int width, int height, Integer color) { Color c=setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); this.shapes.setColor(c); this.shapes.begin(ShapeType.Line); this.shapes.rect(x, y, width, height); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawRect(float, float, float, float, java.lang.Integer) */ @Override public void drawRect(float x, float y, float width, float height, Integer color) { Color c=setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); this.shapes.setColor(c); this.shapes.begin(ShapeType.Line); this.shapes.rect(x, y, width, height); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } @Override public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, Integer color) { fillTriangle((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, color); } @Override public void fillTriangle(float x1, float y1, float x2, float y2, float x3, float y3, Integer color) { Color c=setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); this.shapes.setColor(c); this.shapes.begin(ShapeType.Filled); this.shapes.triangle(x1, y1, x2, y2, x3, y3, c, c, c); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#fillRect(int, int, int, int, java.lang.Integer) */ @Override public void fillRect(int x, int y, int width, int height, Integer color) { Color c=setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); this.shapes.begin(ShapeType.Filled); this.shapes.setColor(c); this.shapes.rect(x, y, width, height); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#fillRect(float, float, float, float, java.lang.Integer) */ @Override public void fillRect(float x, float y, float width, float height, Integer color) { Color c=setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); this.shapes.begin(ShapeType.Filled); this.shapes.setColor(c); this.shapes.rect(x, y, width, height); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawCircle(float, int, int, java.lang.Integer) */ @Override public void drawCircle(float radius, int x, int y, Integer color) { Color c=setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); this.shapes.setColor(c); this.shapes.begin(ShapeType.Line); this.shapes.circle(x+radius, y+radius, radius); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawCircle(float, float, float, java.lang.Integer) */ @Override public void drawCircle(float radius, float x, float y, Integer color) { Color c=setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); this.shapes.setColor(c); this.shapes.begin(ShapeType.Line); this.shapes.circle(x+radius, y+radius, radius); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#fillCircle(float, int, int, java.lang.Integer) */ @Override public void fillCircle(float radius, int x, int y, Integer color) { Color c=setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); this.shapes.setColor(c); this.shapes.begin(ShapeType.Filled); this.shapes.circle(x+radius, y+radius, radius); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#fillCircle(float, float, float, java.lang.Integer) */ @Override public void fillCircle(float radius, float x, float y, Integer color) { Color c=setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); this.shapes.setColor(c); this.shapes.begin(ShapeType.Filled); this.shapes.circle(x+radius, y+radius, radius); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } @Override public void fillArc(float x, float y, float radius, float start, float degrees, Integer color) { Color c=setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); this.shapes.setColor(c); this.shapes.begin(ShapeType.Filled); this.shapes.arc(x, y, radius, start, degrees); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawString(java.lang.String, int, int, java.lang.Integer) */ @Override public void drawString(String text, int x, int y, Integer color) { if(font!=null) { Color c=setTempColor(color); if(!isBegun) batch.begin(); font.setColor(c); font.draw(batch, text, x, y - font.getCapHeight()); if(!isBegun) batch.end(); } } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawString(java.lang.String, float, float, java.lang.Integer) */ @Override public void drawString(String text, float x, float y, Integer color) { if(font!=null) { Color c=setTempColor(color); if(!isBegun) batch.begin(); font.setColor(c); font.draw(batch, text, x, y - font.getCapHeight()); if(!isBegun) batch.end(); } } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawImage(com.badlogic.gdx.graphics.g2d.TextureRegion, int, int, java.lang.Integer) */ @Override public void drawImage(TextureRegion image, int x, int y, Integer color) { Color c= Color.WHITE; if (color != null) c = setTempColor(color); if(!isBegun) batch.begin(); batch.setColor(c); batch.draw(image, x, y); if(!isBegun) batch.end(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawImage(com.badlogic.gdx.graphics.g2d.TextureRegion, float, float, java.lang.Integer) */ @Override public void drawImage(TextureRegion image, float x, float y, Integer color) { Color c= Color.WHITE; if (color != null) c = setTempColor(color); if(!isBegun) batch.begin(); batch.setColor(c); batch.draw(image, x, y); if(!isBegun) batch.end(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawScaledImage(com.badlogic.gdx.graphics.g2d.TextureRegion, int, int, int, int, java.lang.Integer) */ @Override public void drawScaledImage(TextureRegion image, int x, int y, int width, int height, Integer color) { Color c=setTempColor(color); if(!isBegun) batch.begin(); batch.setColor(c); batch.draw(image, x, y, width, height); if(!isBegun) batch.end(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawScaledImage(com.badlogic.gdx.graphics.g2d.TextureRegion, float, float, int, int, java.lang.Integer) */ @Override public void drawScaledImage(TextureRegion image, float x, float y, int width, int height, Integer color) { Color c=setTempColor(color); if(!isBegun) batch.begin(); batch.setColor(c); batch.draw(image, x, y, width, height); if(!isBegun) batch.end(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawSubImage(com.badlogic.gdx.graphics.g2d.TextureRegion, int, int, int, int, int, int, java.lang.Integer) */ @Override public void drawSubImage(TextureRegion image, int x, int y, int imageX, int imageY, int width, int height, Integer color) { throw new IllegalStateException("Method not supported!"); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawSubImage(com.badlogic.gdx.graphics.g2d.TextureRegion, float, float, int, int, int, int, java.lang.Integer) */ @Override public void drawSubImage(TextureRegion image, float x, float y, int imageX, int imageY, int width, int height, Integer color) { throw new IllegalStateException("Method not supported!"); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawRawSprite(com.badlogic.gdx.graphics.g2d.Sprite) */ @Override public void drawRawSprite(Sprite sprite) { if(!isBegun) batch.begin(); sprite.draw(batch); if(!isBegun) batch.end(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawSprite(com.badlogic.gdx.graphics.g2d.Sprite) */ @Override public void drawSprite(Sprite sprite) { if(!isBegun) batch.begin(); sprite.setColor(1,1,1, this.compositeAlpha); sprite.draw(batch); if(!isBegun) batch.end(); } @Override public void drawSprite(Sprite sprite, int x, int y, Integer color) { if(!isBegun) batch.begin(); if(color!=null) { Color c = setTempColor(color); sprite.setColor(c); } else sprite.setColor(1,1,1, this.compositeAlpha); sprite.setPosition(x, y); sprite.draw(batch); if(!isBegun) batch.end(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#drawSprite(com.badlogic.gdx.graphics.g2d.Sprite, float, float, java.lang.Integer) */ @Override public void drawSprite(Sprite sprite, float x, float y, Integer color) { if(!isBegun) batch.begin(); if(color!=null) { Color c = setTempColor(color); sprite.setColor(c); } else sprite.setColor(1,1,1, this.compositeAlpha); sprite.setPosition(x, y); sprite.draw(batch); if(!isBegun) batch.end(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#rotate(double, java.lang.Integer, java.lang.Integer) */ @Override public void rotate(double degree, Integer x, Integer y) { //this.transform.rotate( x, y, 0, (float)degree); this.shapes.rotate( (float)x, (float)y, 0.0f, (float)degree); // camera.rotate( (float)Math.toRadians(degree), x, y, 0); // camera.rotate( (float)degree, x, y, 0); //batch.getTransformMatrix().rotate( x, y, 0, (float)Math.toRadians(degree)); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#rotate(double, float, float) */ @Override public void rotate(double degree, float x, float y) { this.shapes.rotate( x, y, 0.0f, (float)degree); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#translate(int, int) */ @Override public void translate(int x, int y) { this.transform.translate(x, y, 0); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#moveTo(double, double) */ @Override public void moveTo(double x, double y) { this.transform.translate( (float)x, (float)y, 0); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#scale(double, double) */ @Override public void scale(double sx, double sy) { this.transform.scale( (float)sx, (float)sy, 1.0f); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#shear(double, double) */ @Override public void shear(double sx, double sy) { } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#clearTransform() */ @Override public void clearTransform() { //this.transform.idt(); this.shapes.identity(); } private void setZoom(float zoom) { final float maxZoom = 2.0f; camera.zoom = MathUtils.clamp(zoom, 0.1f, 2.0f); float effectiveViewportWidth = camera.viewportWidth * camera.zoom; float effectiveViewportHeight = camera.viewportHeight * camera.zoom; camera.position.x = MathUtils.clamp(camera.position.x, effectiveViewportWidth / 2f, maxZoom - effectiveViewportWidth / 2f); camera.position.y = MathUtils.clamp(camera.position.y, effectiveViewportHeight / 2f, maxZoom - effectiveViewportHeight / 2f); this.camera.update(); this.batch.setProjectionMatrix(this.camera.combined); this.shapes.setProjectionMatrix(this.camera.combined); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#pushZoom(double) */ @Override public void pushZoom(double zoom) { this.zoomStack.push((float)zoom); setZoom(this.zoomStack.peek().floatValue()); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#popZoom() */ @Override public void popZoom() { this.zoomStack.pop(); setZoom(this.zoomStack.empty() ? 1f : this.zoomStack.peek().floatValue()); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#enableBlending() */ @Override public void enableBlending() { this.batch.enableBlending(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#disableBlending() */ @Override public void disableBlending() { this.batch.disableBlending(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#setBlendFunction(int, int) */ @Override public void setBlendFunction(int srcFunc, int dstFunc) { this.batch.setBlendFunction(srcFunc, dstFunc); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#getSrcBlendFunction() */ @Override public int getSrcBlendFunction() { return this.batch.getBlendSrcFunc(); } /* (non-Javadoc) * @see seventh.client.gfx.Canvas#getDstBlendFunction() */ @Override public int getDstBlendFunction() { return this.batch.getBlendDstFunc(); } }
33,215
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Renderable.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/Renderable.java
/* * leola-live * see license.txt */ package seventh.client.gfx; import seventh.shared.TimeStep; /** * A {@link Renderable} is anything that needs to be rendered to the screen. * * @author Tony * */ public interface Renderable { /** * Update this Renderable. Updates may include moving ahead with animation frames. * * @param timeStep */ public void update(TimeStep timeStep); /** * Render this object. * * @param renderer * @param camera * @param alpha */ public void render(Canvas canvas, Camera camera, float alpha); }
614
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
MiniMap.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/MiniMap.java
/* * see license.txt */ package seventh.client.gfx; import java.util.List; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; import seventh.client.ClientGame; import seventh.client.ClientPlayer; import seventh.client.ClientPlayers; import seventh.client.ClientTeam; import seventh.client.entities.ClientBombTarget; import seventh.client.weapon.ClientWeapon; import seventh.game.weapons.Weapon.WeaponState; import seventh.map.Layer; import seventh.map.Map; import seventh.map.Tile; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * Draws a mini map of the current map * * @author Tony * */ public class MiniMap implements Renderable { private ClientGame game; private TextureRegion miniMap; private long gameClock; private int mapColor; private Rectangle bounds; /** */ public MiniMap(ClientGame game) { this.game = game; Map map = game.getMap(); this.bounds = new Rectangle(); int size = 15; int ratioWidth = map.getMapWidth()/size; int ratioHeight = map.getMapHeight()/size; Pixmap pix = TextureUtil.createPixmap(ratioWidth, ratioHeight); int width = map.getTileWidth()/size; int height = map.getTileHeight()/size; Layer[] layers = map.getBackgroundLayers(); for(int y = 0; y < map.getTileWorldHeight(); y++) { for(int x = 0; x < map.getTileWorldWidth(); x++) { Tile topTile = null; boolean hasGroundTile = false; boolean hasCollidable = false; for(int i = 0; i < layers.length; i++) { Tile tile = layers[i].getRow(y)[x]; if(tile != null) { if(!layers[i].collidable()) { hasGroundTile = true; } else { hasCollidable = true; } topTile = tile; } } if(topTile != null && hasGroundTile) { int blendedColor = 0; if(hasCollidable) { int r = 150, g = 150, b = 150; blendedColor = Color.toIntBits(r, g, b, 100); } else { int r = 170, g = 200, b = 200; blendedColor = Color.toIntBits(r, g, b, 80); } pix.setColor(blendedColor); pix.fillRectangle(x*width, y*height, width, height); } } } this.miniMap = new TextureRegion(new Texture(pix)); this.miniMap.flip(false, true); this.mapColor = 0xff_ff_ff_ff; this.bounds.setSize(this.miniMap.getRegionWidth(), this.miniMap.getRegionHeight()); } /** * If the supplied coordinates touches the minimap. * * @param x * @param y * @return true if the coordinates are contained withing the mini map area */ public boolean intersectsMiniMap(float x, float y) { return this.bounds.contains( (int)x, (int)y); } /** * @param mapAlpha the mapAlpha to set */ public void setMapAlpha(int mapAlpha) { this.mapColor = Colors.setAlpha(mapColor, mapAlpha); } /** * @param mapColor the mapColor to set */ public void setMapColor(int mapColor) { this.mapColor = mapColor; } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { gameClock = timeStep.getGameClock(); } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { canvas.drawImage(miniMap, 0, 0, mapColor); Map map = game.getMap(); float xr = (float)miniMap.getRegionWidth() / (float)map.getMapWidth(); float yr = (float)miniMap.getRegionHeight() / (float)map.getMapHeight(); xr -= 0.005f; yr -= 0.005f; ClientPlayers players = game.getPlayers(); for(int i = 0; i < players.getMaxNumberOfPlayers(); i++) { ClientPlayer ent = players.getPlayer(i); if(ent != null && ent.isAlive() && (ent.getEntity().getLastUpdate() > gameClock-1000)) { ClientTeam team = ent.getTeam(); Vector2f p = ent.getEntity().getCenterPos(); int x = (int)(xr * p.x); int y = (int)(yr * p.y); ClientWeapon weapon = ent.getEntity().getWeapon(); if(weapon != null) { if(weapon.getState().equals(WeaponState.FIRING)) { canvas.fillCircle(3.0f, x-1, y-1, 0xfaffff00); } } canvas.fillCircle(2.0f, x, y, team.getColor()); } } /* Draw the bomb targets */ List<ClientBombTarget> targets = game.getBombTargets(); for(int i = 0; i < targets.size(); i++) { ClientBombTarget target = targets.get(i); Vector2f p = target.getCenterPos(); int x = (int)(xr * p.x); int y = (int)(yr * p.y); if(target.isAlive()) { if(target.isBombPlanted()) { canvas.fillCircle(4.0f, x-1, y-1, 0xfaFF3300); } canvas.fillCircle(3.0f, x, y, 0xfa009933); } // else { // canvas.fillCircle(3.0f, x, y, 0xfaFF3300); // } } Vector2f cameraPos = camera.getRenderPosition(alpha); int x = (int)Math.floor(xr * cameraPos.x + 2); int y = (int)Math.floor(yr * cameraPos.y); int width = (int)Math.floor(camera.getViewPort().width * xr); int height = (int)Math.floor(camera.getViewPort().height * yr); canvas.drawRect(x, y, width, height, 0x01fffffff); } }
6,738
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
VideoConfig.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/VideoConfig.java
/* * see license.txt */ package seventh.client.gfx; import seventh.shared.Config; /** * @author Tony * */ public class VideoConfig { private Config config; /** * */ public VideoConfig(Config config) { this.config = config; } /** * @return true if there are settings in this section */ public boolean isPresent() { return (config.getBool("video", "width") && config.getBool("video", "height")); } public int getWidth() { return this.config.getInt(800, "video", "width"); } public void setWidth(int width) { this.config.set(width, "video", "width"); } public int getHeight() { return this.config.getInt(800, "video", "height"); } public void setHeight(int height) { this.config.set(height, "video", "height"); } public boolean isFullscreen() { return this.config.getBool("video", "fullscreen"); } public void setFullscreen(boolean fullscreen) { this.config.set(fullscreen, "video", "fullscreen"); } public boolean isVsync() { return this.config.getBool("video", "vsync"); } public void setVsync(boolean vsync) { this.config.set(vsync, "video", "vsync"); } public boolean useGL30() { return this.config.getBool("video", "useGL30"); } public void setUseGL30(boolean useGL30) { this.config.set(useGL30, "video", "useGL30"); } }
1,556
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
PanzerTankSprite.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/PanzerTankSprite.java
/* * see license.txt */ package seventh.client.gfx; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; import seventh.client.entities.vehicles.ClientTank; /** * @author Tony * */ public class PanzerTankSprite extends TankSprite { /** * @param tank */ public PanzerTankSprite(ClientTank tank) { super(tank, Art.newPanzerTankTracks(), new Sprite(Art.panzerTankTurret), Art.newPanzerTankTracksDamaged(), new Sprite(Art.panzerTankTurretDamaged)); } /* (non-Javadoc) * @see seventh.client.gfx.TankSprite#renderTankBase(float, float, float, seventh.client.gfx.Canvas, seventh.client.gfx.Camera, float) */ @Override protected void renderTankBase(float rx, float ry, float trackAngle, Canvas canvas, Camera camera, float alpha) { // rx += 55f; // ry -= 40f; // rx += 10f; //15 ry -= 28f; // 25 TextureRegion tex = isDestroyed() ? tankTracksDamaged.getCurrentImage() : tankTracks.getCurrentImage(); tankTrack.setRegion(tex); tankTrack.setRotation(trackAngle); tankTrack.setOrigin(tex.getRegionWidth()/2f,tex.getRegionHeight()/2f-5f); tankTrack.setPosition(rx, ry); canvas.drawSprite(tankTrack); } /* (non-Javadoc) * @see seventh.client.gfx.TankSprite#renderTurret(float, float, float, seventh.client.gfx.Canvas, seventh.client.gfx.Camera, float) */ @Override protected void renderTurret(float rx, float ry, float turretAngle, Canvas canvas, Camera camera, float alpha) { // rx += 35f; // ry += 25f; rx += 15f; ry -= 25f; rx += 43f; ry += 25f; float originX = 89f; Sprite turretSprite = isDestroyed() ? tankTurretDamaged : tankTurret; float originY = 65f;//turretSprite.getRegionHeight()/2f; turretSprite.setRotation(turretAngle); turretSprite.setOrigin(originX, originY); turretSprite.setPosition(rx,ry); canvas.drawSprite(turretSprite); } }
2,235
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
RenderFont.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/RenderFont.java
/* * see license.txt */ package seventh.client.gfx; /** * @author Tony * */ public class RenderFont { /** * Text color directory */ public static final Integer[] COLORS = { 0xff000000, // BLCK 0 0xffff0000, // RED 1 0xff00ff00, // GREEN 2 0xffffff00, // YELLOW 3 0xff0000ff, // BLUE 4 0xff00ffff, // LIGHT BLUE 5 0xffff00ff, // PINK 6 0xffffffff, // WHITE 7 0xff006600, // DARK_GREEN 8 0xffd3d3d3, // GREY 9 }; /** * Get the text width (which will exclude any color encoding characters) * * @param canvas * @param str * @return the width of the text */ public static float getTextWidth(Canvas canvas, String str) { return getTextWidth(canvas, str, true, false); } /** * Get the text width (which will exclude any color encoding characters) * * @param canvas * @param str * @param colorEncoding true if color encoding should be accounted for * @param monospaced if the font is monospaced * @return the width of the text */ public static float getTextWidth(Canvas canvas, String str, boolean colorEncoding, boolean monospaced) { int len = str.length(); float width = 0f; final float CharWidth = canvas.getWidth("W"); for(int i = 0; i < len; i++) { char c = str.charAt(i); if(c == '^' && colorEncoding) { if(i+1 < len) { char c2 = str.charAt(i+1); if(Character.isDigit(c2)) { i++; continue; } } } String text = Character.toString(c); width += monospaced ? CharWidth : (canvas.getWidth(text) - 0.5f); } return width; } /** * Get the text without any color encodings * * @param str * @return the text without any color encodings */ public static String getDecodedText(String str) { StringBuilder sb = new StringBuilder(str.length()); int len = str.length(); for(int i = 0; i < len; i++) { char c = str.charAt(i); if(c == '^') { if(i+1 < len) { char c2 = str.charAt(i+1); if(Character.isDigit(c2)) { i++; continue; } } } sb.append(c); } return sb.toString(); } /** * Allow for embedding color encoding into strings just like Call Of Duty * * @param canvas * @param str * @param x * @param y * @param color * @param drawShadow */ public static void drawShadedString(Canvas canvas, String str, float x, float y, Integer color, boolean drawShadow, boolean drawColors, boolean monospaced) { int len = str.length(); float xPos = x; float yPos = y; Integer currentColor = color; final float CharWidth = canvas.getWidth("W"); if(drawShadow) { for(int i = 0; i < len; i++) { char c = str.charAt(i); if(c == '^' && drawColors) { if(i+1 < len) { char c2 = str.charAt(i+1); if(Character.isDigit(c2)) { i++; continue; } } } else if(c == '\n') { xPos = x; yPos += canvas.getHeight("n") - 0.5f; } String text = Character.toString(c); if(!text.equals(" ")) { canvas.drawString(text, xPos-1.5f, yPos+1, 0xff000000); } xPos += monospaced ? CharWidth : (canvas.getWidth(text) - 0.5f); } } xPos = x; yPos = y; for(int i = 0; i < len; i++) { char c = str.charAt(i); if(c == '^' && drawColors) { if(i+1 < len) { char c2 = str.charAt(i+1); if(Character.isDigit(c2)) { currentColor = COLORS[Character.getNumericValue(c2)]; i++; continue; } } } else if(c == '\n') { xPos = x; yPos += canvas.getHeight("n") - 0.5f; } String text = Character.toString(c); if(!text.equals(" ")) { canvas.drawString(text, xPos, yPos, currentColor); } xPos += monospaced ? CharWidth : (canvas.getWidth(text) - 0.5f); } } public static void drawShadedString(Canvas canvas, String str, int x, int y, Integer color, boolean drawShadow) { drawShadedString(canvas, str, x, y, color, drawShadow, true, false); } public static void drawShadedString(Canvas canvas, String str, float x, float y, Integer color, boolean drawShadow) { drawShadedString(canvas, str, x, y, color, drawShadow, true, false); } /** * Draws a shaded string * @param canvas * @param str * @param x * @param y * @param color */ public static void drawShadedString(Canvas canvas, String str, int x, int y, Integer color) { drawShadedString(canvas, str, x, y, color, true, true, false); } public static void drawShadedString(Canvas canvas, String str, float x, float y, Integer color) { drawShadedString(canvas, str, x, y, color, true, true, false); } }
6,227
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
TextureUtil.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/TextureUtil.java
/* * The Seventh * see license.txt */ package seventh.client.gfx; import java.util.ArrayList; import java.util.List; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; /** * @author Tony * */ public class TextureUtil { public static TextureRegion tex(Pixmap pixmap) { return new TextureRegion(new Texture(pixmap)); } public static TextureRegion tex(Texture tex) { return new TextureRegion(tex); } /** * Loads an image * * @param image * @return * @throws Exception */ public static TextureRegion loadImage(String image) { Texture texture = new Texture(Gdx.files.internal(image)); TextureRegion region = new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight()); region.flip(false, true); return region; } /** * Loads an image * * @param image * @return * @throws Exception */ public static TextureRegion loadImage(String image, int width, int height) { Texture texture = new Texture(Gdx.files.internal(image)); TextureRegion region = new TextureRegion(texture, 0, 0, width, height); region.flip(false, true); return region; } /** * Loads an image * * @param image * @return * @throws Exception */ public static Pixmap loadPixmap(String image) { return new Pixmap(Gdx.files.internal(image)); } /** * Loads an image * * @param image * @return * @throws Exception */ public static Pixmap loadPixmap(String image, int width, int height) { Pixmap pixmap = new Pixmap(Gdx.files.internal(image)); Pixmap result = pixmap; if(pixmap.getWidth() != width || pixmap.getHeight() != height) { result = resizePixmap(pixmap, width, height); pixmap.dispose(); } return result; } /** * Gets a subImage. * * @param image * @param x * @param y * @param width * @param height * @return */ public static TextureRegion subImage(TextureRegion image, int x, int y, int width, int height) { return new TextureRegion(image.getTexture(), x, y, width, height); } public static Pixmap subPixmap(Pixmap pix, int x, int y, int width, int height) { Pixmap sub = new Pixmap(width, height, pix.getFormat()); sub.drawPixmap(pix, x, y, width, height, 0, 0, width, height); return sub; } /** * Applying mask into image using specified masking color. Any Color in the * image that matches the masking color will be converted to transparent. * * @param img The source image * @param keyColor Masking color * @return Masked image */ public static Pixmap applyMask(Pixmap img, Color keyColor) { Pixmap alpha = new Pixmap(img.getWidth(), img.getHeight(), Format.RGBA8888); //alpha.drawPixmap(img, 0, 0); int width = alpha.getWidth(); int height = alpha.getHeight(); int colorMask = Color.rgba8888(keyColor); //alpha.setColor(0xff00009f); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int col = img.getPixel(x, y); if ( col != colorMask ) { alpha.drawPixel(x, y, img.getPixel(x, y)); } } } return alpha; } public static Pixmap toWhite(Pixmap img) { Pixmap alpha = new Pixmap(img.getWidth(), img.getHeight(), Format.RGBA8888); //alpha.drawPixmap(img, 0, 0); int width = alpha.getWidth(); int height = alpha.getHeight(); //alpha.setColor(0xff00009f); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int col = img.getPixel(x, y); Color color = new Color(col); if ( color.a > 0.2f ) { alpha.drawPixel(x, y, Color.WHITE.toIntBits()); } } } img.dispose(); return alpha; } /** * Resizes the image * * @param image * @param width * @param height * @return */ public static Pixmap resizePixmap(Pixmap image, int width, int height) { Pixmap pix = new Pixmap(width, height, image.getFormat()); pix.drawPixmap(image, 0, 0, width, height, // destination 0, 0, image.getWidth(), image.getHeight()); // source return pix; } public static Pixmap createPixmap(int width, int height) { return new Pixmap(width, height, Format.RGBA8888); } public static Texture createImage(int width, int height) { // BufferedImage newImage = new BufferedImage(width, height, Transparency.TRANSLUCENT); Texture texture = new Texture(width, height, Format.RGBA8888); return texture; } /** * Creates a tileset from an image * * @param image * @param tileWidth * @param tileHeight * @param margin * @param spacing * @return */ public static TextureRegion[] toTileSet(TextureRegion image, int tileWidth, int tileHeight, int margin, int spacing) { int nextX = margin; int nextY = margin; List<TextureRegion> images = new ArrayList<TextureRegion>(); while (nextY + tileHeight + margin <= image.getRegionHeight()) { TextureRegion tile = new TextureRegion(image, nextX, nextY, tileWidth, tileHeight); tile.flip(false, true); images.add(tile); nextX += tileWidth + spacing; if (nextX + tileWidth + margin > image.getRegionWidth()) { nextX = margin; nextY += tileHeight + spacing; } } return images.toArray(new TextureRegion[images.size()]); } /** * Splits the image, uses the image width/height * @param image * @param row * @param col * @return */ public static TextureRegion[] splitImage(TextureRegion image, int row, int col) { return splitImage(image, image.getRegionWidth(), image.getRegionHeight(), row, col); } /** * Splits the image * @param image * @param width * @param height * @param row * @param col * @return */ public static TextureRegion[] splitImage(TextureRegion image, int width, int height, int row, int col) { int total = col * row; // total returned images int frame = 0; // frame counter int w = width / col; int h = height / row; TextureRegion[] images = new TextureRegion[total]; for (int j = 0; j < row; j++) { for (int i = 0; i < col; i++) { TextureRegion region = new TextureRegion(image.getTexture(), i * w, j * h, w, h); //region.flip(false, true); images[frame++] = region; } } return images; } /** * Splits the image * @param image * @param width * @param height * @param row * @param col * @return */ public static Pixmap[] splitPixmap(Pixmap image, int width, int height, int row, int col) { int total = col * row; // total returned images int frame = 0; // frame counter int w = width / col; int h = height / row; Pixmap[] images = new Pixmap[total]; for (int j = 0; j < row; j++) { for (int i = 0; i < col; i++) { Pixmap region = new Pixmap(w, h, image.getFormat()); region.drawPixmap(image, 0, 0, i * w, j * h, w, h); images[frame++] = region; } } return images; } /** * Resizes the image * * @param image * @param width * @param height * @return */ public static Sprite resizeImage(TextureRegion image, int width, int height) { Sprite sprite = new Sprite(image); sprite.setSize(width, height); // TextureRegion region = new TextureRegion(image); // region.setRegionWidth(width); // region.setRegionHeight(height); return sprite; } public static void setFlips(Sprite sprite, boolean isFlippedHorizontal, boolean isFlippedVert, boolean isFlippedDiagnally) { if(sprite==null) return; if(isFlippedDiagnally) { if(isFlippedHorizontal && isFlippedVert) { sprite.flip(true, false); sprite.rotate(-270f); } else if(isFlippedHorizontal) { sprite.rotate(-270f); } else if(isFlippedVert) { sprite.rotate(-90f); } else { sprite.flip(false, true); sprite.rotate(-270f); } } else { sprite.flip(isFlippedHorizontal, isFlippedVert); } } }
9,664
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
PlayerSprite.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/PlayerSprite.java
/* * see license.txt */ package seventh.client.gfx; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; import seventh.client.ClientPlayer; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art.Model; import seventh.client.gfx.effects.Effects; import seventh.client.gfx.effects.ScreenFlashEffect; import seventh.client.gfx.effects.particle_system.Emitters; import seventh.client.weapon.ClientFlameThrower; import seventh.client.weapon.ClientRocketLauncher; import seventh.client.weapon.ClientWeapon; import seventh.game.entities.Entity.State; import seventh.game.weapons.Weapon; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.shared.TimeStep; import seventh.shared.Updatable; /** * Renders the Player * * @author Tony * */ public class PlayerSprite implements Renderable { private static class Motion implements Updatable { public double value; public double velocity; public double max; public int direction; { clear(); } @Override public void update(TimeStep timeStep) { value += direction*velocity; if(value>max) { value=max; direction *= -1; } else if(value<-max) { value=-max; direction *= -1; } } public void set(double maxValue, double velocity) { this.max = maxValue; this.velocity = velocity; } public void clear() { this.value = 0; this.direction = 1; } } private ClientPlayerEntity entity; private final AnimatedImage idleBody, crouchBody, walkBody, runBody, sprintBody, reloadBody, idlePumpActionReloadBody, crouchPumpActionReloadBody, walkPumpActionReloadBody, runPumpActionReloadBody, switchWeaponBody, meleeBody; private final AnimatedImage idleLegsAnimation, crouchingLegsAnimation, walkLegsAnimation, runLegsAnimation, sprintLegsAnimation ; private AnimatedImage activeBodyPosition; private AnimatedImage activeLegsAnimation; private Motion swayMotion, bobMotion; private float xOffset, yOffset, prevXOffset, prevYOffset; private boolean isReloading, isSwitching, isMelee, isFiring, isPumpAction; private Effects effects; private Sprite sprite; private long flashTime; private boolean showFlash, toggleFlash; private long timeSpentFiring; private boolean wasFiring; private ScreenFlashEffect fireWeaponEffect; private State currentState; private Vector2f facing; private float orientation; /** * Debug class * * @author Tony * */ static class Adjustments { public float xOffset, yOffset; public float x, y; public void poll() { if(Gdx.input.isKeyPressed(Keys.RIGHT)) { xOffset += 1; } if(Gdx.input.isKeyPressed(Keys.LEFT)) { xOffset -= 1; } if(Gdx.input.isKeyPressed(Keys.UP)) { yOffset += 1; } if(Gdx.input.isKeyPressed(Keys.DOWN)) { yOffset -= 1; } if(Gdx.input.isKeyPressed(Keys.PAGE_UP)) { y += 1; } if(Gdx.input.isKeyPressed(Keys.PAGE_DOWN)) { y -= 1; } if(Gdx.input.isKeyPressed(Keys.HOME)) { x += 1; } if(Gdx.input.isKeyPressed(Keys.END)) { x -= 1; } } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("[xOffset=").append(xOffset).append(", yOffset=").append(yOffset).append(", x=").append(x).append(", y=") .append(y).append("]"); return builder.toString(); } } // TEMP Remove this once we have the proper adjustments made Adjustments adjustments=new Adjustments(); /** * @param player * @param bodyModel * @param walkLegsModel * @param crouchLegsModel * @param sprintLegsModel */ public PlayerSprite(ClientPlayer player, Model bodyModel, Model walkLegsModel, TextureRegion crouchLegsModel, Model sprintLegsModel) { idleBody = newAnimation(100, bodyModel.getFrame(0)); crouchBody = newAnimation(100, bodyModel.getFrame(3)); walkBody = newAnimation(100, bodyModel.getFrame(2)); runBody = newAnimation(100, bodyModel.getFrame(0)); sprintBody = newAnimation(100, bodyModel.getFrame(1)); reloadBody = newAnimation(500, bodyModel.getFrame(5), bodyModel.getFrame(0)); switchWeaponBody = newAnimation(100, bodyModel.getFrame(5)); meleeBody = newAnimation(100, bodyModel.getFrame(1)); idlePumpActionReloadBody = newAnimation(200, bodyModel.getFrame(6)); crouchPumpActionReloadBody = newAnimation(200, bodyModel.getFrame(7)); walkPumpActionReloadBody = newAnimation(200, bodyModel.getFrame(8)); runPumpActionReloadBody = newAnimation(200, bodyModel.getFrame(6)); idleLegsAnimation = newAnimation(150, walkLegsModel.getFrame(0)); crouchingLegsAnimation = newAnimation(0, crouchLegsModel); walkLegsAnimation = newAnimation(150, walkLegsModel.getFrames()); runLegsAnimation = newAnimation(100, walkLegsModel.getFrames()); sprintLegsAnimation = newAnimation(130, sprintLegsModel.getFrames()); // 150 activeBodyPosition = idleBody; activeLegsAnimation = idleLegsAnimation; bobMotion = new Motion(); swayMotion = new Motion(); effects = new Effects(); sprite = new Sprite(); fireWeaponEffect = new ScreenFlashEffect(0xffff00, 0.045f, 25); facing = new Vector2f(); currentState = State.IDLE; reset(player); } private AnimatedImage newAnimation(int frameTime, TextureRegion ... frames) { int[] frameTimes = new int[frames.length]; for(int i = 0; i < frameTimes.length;i++) { frameTimes[i] = frameTime; } return Art.newAnimatedImage(frameTimes, frames); } private void resetLegMovements() { walkLegsAnimation.reset(); runLegsAnimation.reset(); sprintLegsAnimation.reset(); bobMotion.clear(); swayMotion.clear(); } /** * Resets this {@link PlayerSprite} for reuse by another * {@link ClientPlayerEntity}. Call this when the player is respawned. * * @param player */ public void reset(ClientPlayer player) { entity = player.getEntity(); activeBodyPosition = idleBody; activeLegsAnimation = idleLegsAnimation; resetLegMovements(); effects.clearEffects(); fireWeaponEffect.reset(); } private void updateSmokeEmitter(TimeStep timeStep, ClientWeapon weapon) { if(weapon.isAutomatic()) { if(weapon.getState().equals(Weapon.WeaponState.FIRING)) { timeSpentFiring += timeStep.getDeltaTime(); wasFiring = true; } else { if(wasFiring) { // automatic weapons only smoke after // some time firing if(timeSpentFiring > 500) { if(weapon.emitBarrelSmoke()) { effects.addEffect(Emitters.newGunSmokeEmitter(entity, 100)); } wasFiring = false; } timeSpentFiring = 0; } } } else { if(weapon.getState().equals(Weapon.WeaponState.FIRING)) { if(!wasFiring && weapon.emitBarrelSmoke()) { effects.addEffect(Emitters.newGunSmokeEmitter(entity, 100)); } wasFiring = true; } else { wasFiring = false; } } } /* (non-Javadoc) * @see leola.live.gfx.Renderable#update(leola.live.TimeStep) */ @Override public void update(TimeStep timeStep) { // TODO: delete adjustments.poll(); effects.update(timeStep); prevXOffset = xOffset; prevYOffset = yOffset; xOffset = yOffset = 0; this.isPumpAction = false; float weaponWeight = 1.0f; ClientWeapon weapon = entity.getWeapon(); if(weapon != null) { weaponWeight = 100.0f - weapon.getWeaponWeight(); weaponWeight *= 0.01f; if(weapon.isPumpAction()) { this.isPumpAction = weapon.isSpecialReloadingAction(); } } activeBodyPosition = idleBody; activeLegsAnimation = idleLegsAnimation; facing.set(entity.getFacing()); currentState = entity.getCurrentState(); orientation = entity.getOrientation(); switch(currentState) { case IDLE: activeBodyPosition = isPumpAction ? idlePumpActionReloadBody : idleBody; activeLegsAnimation = idleLegsAnimation; resetLegMovements(); break; case CROUCHING: activeBodyPosition = isPumpAction ? crouchPumpActionReloadBody : crouchBody; activeLegsAnimation = crouchingLegsAnimation; resetLegMovements(); break; case WALKING: { activeBodyPosition = isPumpAction ? walkPumpActionReloadBody : walkBody; activeLegsAnimation = walkLegsAnimation; bobMotion.set(5, 0.6); swayMotion.set(4, 1.55*weaponWeight); xOffset += (facing.y * swayMotion.direction) * 0.815f; yOffset += (facing.x * swayMotion.direction) * 0.815f; } break; case RUNNING: { activeBodyPosition = isPumpAction ? runPumpActionReloadBody : runBody; activeLegsAnimation = runLegsAnimation; bobMotion.set(12*weaponWeight,2.4*weaponWeight); //(8, 1.4); swayMotion.set(4, 2.5*weaponWeight); xOffset += (facing.y * swayMotion.direction) * 0.755f; yOffset += (facing.x * swayMotion.direction) * 0.755f; } break; case SPRINTING: activeBodyPosition = sprintBody; activeLegsAnimation = sprintLegsAnimation; bobMotion.set(0, 0); swayMotion.set(4, 3.25*weaponWeight); xOffset += (facing.y * swayMotion.direction) * 1.25f; yOffset += (facing.x * swayMotion.direction) * 1.25f; break; case DEAD: resetLegMovements(); break; default: resetLegMovements(); } bobMotion.update(timeStep); swayMotion.update(timeStep); if(weapon != null) { updateSmokeEmitter(timeStep, weapon); this.isReloading = weapon.getState() == seventh.game.weapons.Weapon.WeaponState.RELOADING; this.isSwitching = weapon.getState() == seventh.game.weapons.Weapon.WeaponState.SWITCHING; this.isMelee = weapon.getState() == seventh.game.weapons.Weapon.WeaponState.MELEE_ATTACK; this.isFiring = weapon.getState() == seventh.game.weapons.Weapon.WeaponState.FIRING; if(weapon.isBoltAction()) { if(!this.isReloading && weapon.isSpecialReloadingAction()) { this.isReloading = true; } } if( this.isReloading /*&& !this.isPumpAction*/) { this.activeBodyPosition = reloadBody; } else if (this.isMelee) { this.activeBodyPosition = meleeBody; } else if (this.isSwitching) { this.activeBodyPosition = switchWeaponBody; } if(weapon instanceof ClientRocketLauncher && !this.isMelee) { activeBodyPosition = crouchBody; } // if(weapon.isFirstFire()) { // Vector2f pos = entity.getCenterPos(); // Vector2f ejectPos = entity.getFacing().createClone(); // Vector2f.Vector2fMA(pos, ejectPos, 20, ejectPos); // effects.addEffect(new BrassEmitter(ejectPos, 10000, 10)); // } AnimatedImage muzzleAnim = weapon.getMuzzleFlash(); if(muzzleAnim!=null) { muzzleAnim.update(timeStep); } } if(this.isFiring) { this.flashTime -= timeStep.getDeltaTime(); if(this.flashTime <= 0) { boolean cycleFlash = weapon != null && weapon.isAutomatic(); if(cycleFlash) { this.showFlash = !this.showFlash; this.flashTime = 90; // this.fireWeaponEffect.reset(); // this.effects.addEffect(this.fireWeaponEffect); } else { if(toggleFlash) { this.showFlash = true; this.flashTime = 90; toggleFlash = false; } else { this.showFlash = false; } } } } else { this.showFlash = false; this.toggleFlash = true; this.flashTime = 90; } if( entity.isAlive() && (entity.getLastUpdate()+500) > timeStep.getGameClock()) { entity.getMussleFlash().setOn(showFlash); } else { entity.getMussleFlash().setOn(false); } activeLegsAnimation.update(timeStep); activeBodyPosition.update(timeStep); } /** * Renders the entities weapon * * @param canvas * @param weapon * @param rx * @param ry * @param rot */ private void renderWeapon(Canvas canvas, ClientWeapon weapon, float rx, float ry, float rot) { if(weapon != null && weapon.getWeaponImage()!=null && !this.isSwitching) { renderMuzzleFlash(canvas, weapon, rx, ry, rot); TextureRegion gun = weapon.getWeaponImage(); setTextureRegion(sprite, gun); sprite.setScale(1.0f); boolean isRocketLauncher = weapon instanceof ClientRocketLauncher; boolean isFlameThrower = weapon instanceof ClientFlameThrower; switch(this.entity.getCurrentState()) { case SPRINTING: { // original // sprite.setRotation(rot - 60.0f); // sprite.setPosition(rx-13f, ry-39f); // sprite.setOrigin(14f, 40f); sprite.setRegionY(-32); sprite.setRegionHeight(64); sprite.setRotation(rot - 240f); sprite.setPosition(rx - 16f, ry + 11f); sprite.setOrigin(17f, -10f); break; } case CROUCHING: { sprite.setPosition(rx-9.0f, ry-30.0f); sprite.setOrigin(10.0f, 31.0f); break; } default: { sprite.setPosition(rx-10.0f, ry-34.0f); sprite.setOrigin(12.0f, 35.0f); } } if(this.isReloading) { if(reloadBody.getAnimation().getCurrentFrame() == 0) { sprite.setRotation(rot - 12.0f); } } else if (this.isMelee) { // TODO: fix melee weapon sprite.setRegionY(-32); sprite.setRegionHeight(64); sprite.setRotation(rot - 240f); sprite.setPosition(rx - 16f, ry + 11f); sprite.setOrigin(17f, -10f); // sprite.setPosition(rx-adjustments.xOffset, ry-adjustments.yOffset); // sprite.setOrigin(adjustments.x, adjustments.y); } if(isRocketLauncher) { // TODO: Crouching sprite.setRotation(rot - 7); //sprite.setPosition(rx+3f, ry-31f); //sprite.setOrigin(-2f, 33f); sprite.setPosition(rx+0f, ry-28f); sprite.setOrigin(-0f, 28f); // sprite.setPosition(rx-adjustments.xOffset, ry-adjustments.yOffset); // sprite.setOrigin(adjustments.x, adjustments.y); } else if(isFlameThrower) { sprite.setPosition(rx-15.0f, ry-34.0f); sprite.setOrigin(17.0f, 35.0f); } canvas.drawSprite(sprite); debugRenderSprite(canvas, sprite, 0xffffff00); } } /** * Renders the muzzle flash * @param canvas * @param weapon * @param rx * @param ry * @param rot */ private void renderMuzzleFlash(Canvas canvas, ClientWeapon weapon, float rx, float ry, float rot) { AnimatedImage muzzleAnim = weapon.getMuzzleFlash(); if(muzzleAnim != null) { if(weapon.getState().equals(Weapon.WeaponState.FIRING)) { /* if the weapon is automatic, we want to show * the animation */ if(weapon.isAutomatic() && muzzleAnim.isDone()) { muzzleAnim.reset(); } /* if we still have some animation to go, and this isn't the * Rocket launcher, lets render the muzzle flash */ if(!muzzleAnim.isDone() ) { /* we don't want an animation for single fire weapons */ if(weapon.isAutomatic()||weapon.isBurstFire()) { setTextureRegion(sprite, muzzleAnim.getCurrentImage()); } else { setTextureRegion(sprite, muzzleAnim.getFrame(0)); muzzleAnim.moveToLastFrame(); } boolean isCrouching = currentState==State.CROUCHING; float offsetX = isCrouching ? 22f : 26f; //24 if(weapon.hasLongBarrel()) { offsetX = isCrouching ? 26f : 32f; //32.0f; } float offsetY = isCrouching ? -12f : -16f; sprite.setPosition(rx+offsetX, ry+offsetY); sprite.setOrigin(-offsetX, -offsetY); //18 sprite.setRotation(rot-80f); canvas.drawSprite(sprite); // debugRenderSprite(canvas, sprite, 0xffff00ff); sprite.setRotation(rot); } } else { muzzleAnim.reset(); } } } /** * Render the players body * * @param canvas * @param rx * @param ry * @param rot * @param color */ private void renderBody(Canvas canvas, float rx, float ry, float rot, int color) { // int offset = 32;//16; float x = rx - 32f;//offset; -32 float y = ry - 42f;//offset; -42 // TODO: do the math to do this outside // in imageScaler program sprite.setScale(0.8f, 0.8f); /* Renders the feet */ switch(currentState) { case CROUCHING: { sprite.setRotation(rot-10f); sprite.setPosition(rx, ry); setTextureRegion(sprite, activeLegsAnimation.getCurrentImage()); sprite.flip(true, false); sprite.translate(-32f, -32f); canvas.drawSprite(sprite); sprite.translate(32f, 32f); sprite.setRotation(rot); sprite.setPosition(x, y); sprite.translate(facing.x * -6.0f, facing.y * -6.0f); break; } case SPRINTING: { sprite.setScale(0.87f, 0.87f); sprite.setRotation(rot); sprite.setPosition(x, y); setTextureRegion(sprite, activeLegsAnimation.getCurrentImage()); float fx = (facing.y-9.0f); float fy = -(facing.x+5); sprite.translate(fx, fy); canvas.drawSprite(sprite); sprite.translate(-fx, -fy); sprite.setScale(0.8f, 0.8f); break; } default: { sprite.setRotation(rot); sprite.setPosition(x, y); setTextureRegion(sprite, activeLegsAnimation.getCurrentImage()); float fx = facing.x + -12.0f; float fy = facing.y - 5.0f; sprite.translate(fx, fy); canvas.drawSprite(sprite); sprite.translate(-fx, -fy); } } /* Renders the body */ { setTextureRegion(sprite, activeBodyPosition.getCurrentImage()); canvas.drawRawSprite(sprite); debugRenderSprite(canvas, sprite, 0xff00ffff); } } /** * Renders the player * * @param canvas * @param cameraPos * @param pos * @param color */ private void renderPlayer(Canvas canvas, Vector2f cameraPos, Vector2f pos, int color, float alpha) { Rectangle bounds = entity.getBounds(); //xOffset=yOffset=0; float nx = xOffset + ((prevXOffset - xOffset) * alpha); float ny = yOffset + ((prevYOffset - yOffset) * alpha); float rx = (pos.x - cameraPos.x) + (bounds.width/2.0f) + nx; float ry = (pos.y - cameraPos.y) + (bounds.height/2.0f) + ny; double angle = Math.toDegrees(orientation) + 90.0; float rot = (float)(angle + bobMotion.value); renderBody(canvas, rx, ry, rot, color); ClientWeapon weapon = this.entity.getWeapon(); renderWeapon(canvas, weapon, rx, ry, rot); } /* (non-Javadoc) * @see leola.live.gfx.Renderable#render(leola.live.gfx.Canvas, leola.live.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { Vector2f cameraPos = camera.getRenderPosition(alpha); // TODO: delete //canvas.drawString(adjustments.toString(), 350, 100, 0xffffffff); effects.render(canvas,camera, alpha); Vector2f renderPos = entity.getRenderPos(alpha); renderPlayer(canvas, cameraPos, renderPos, 0xffffffff, alpha); } private void setTextureRegion(Sprite sprite, TextureRegion region) { sprite.setTexture(region.getTexture()); sprite.setRegion(region); sprite.setSize(region.getRegionWidth(), region.getRegionHeight()); sprite.setOrigin(region.getRegionWidth()/2f, region.getRegionHeight()/2f); sprite.flip(false, true); } public static void debugRenderSprite(Canvas canvas, Sprite sprite, int color) { // canvas.drawSprite(sprite, sprite.getX(), sprite.getY(), 0x5f00aa00); // canvas.drawRect( (int)sprite.getX(), (int)sprite.getY(), sprite.getRegionWidth(), sprite.getRegionHeight(), 0x5fff0000); boolean drawDebug=false; if(drawDebug) { canvas.drawSprite(sprite, sprite.getX(), sprite.getY(), Colors.setAlpha(color, 0x5f)); canvas.drawRect( (int)sprite.getX(), (int)sprite.getY(), sprite.getRegionWidth(), sprite.getRegionHeight(), Colors.setAlpha(color, 0x5f)); canvas.fillRect( (int)(sprite.getX() + sprite.getOriginX()), (int)(sprite.getY() + sprite.getOriginY()), 5, 5, Colors.setAlpha(color, 0x5f));//0xff0000ff); } } }
26,918
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Animation.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/Animation.java
/* * leola-live * see license.txt */ package seventh.client.gfx; import seventh.shared.TimeStep; /** * @author Tony * */ public abstract class Animation { /** * Paused */ private boolean paused; /** * Loop */ private boolean loop; /** * If the animation is completed */ protected boolean isDone; /** * Constructs a new {@link Animation}. */ protected Animation() { this.pause(false); this.loop(true); } /** * @return true if the animation has completed */ public boolean isDone() { return isDone; } /** * Update the animation. * * @param timeStep */ public abstract void update(TimeStep timeStep); /** * Set the current frame. * * @param frameNumber */ public abstract void setCurrentFrame(int frameNumber); /** * @return the currentFrame */ public abstract int getCurrentFrame(); /** * @return the numberOfFrames */ public abstract int getNumberOfFrames(); /** * Reset the animation. */ public abstract void reset(); /** * @return the paused */ public boolean isPaused() { return paused; } /** * @param paused the paused to set */ public void pause(boolean paused) { this.paused = paused; } /** * @return the loop */ public boolean isLooping() { return loop; } /** * @param loop the loop to set */ public void loop(boolean loop) { this.loop = loop; } }
1,642
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ImageCursor.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/ImageCursor.java
/* * see license.txt */ package seventh.client.gfx; import com.badlogic.gdx.graphics.g2d.TextureRegion; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * Represents the mouse pointer for the game. This implementation relies on an {@link TextureRegion} for the cursor * image. * * @author Tony * */ public class ImageCursor extends Cursor { private TextureRegion cursorImg; private Vector2f imageOffset; /** */ public ImageCursor() { this(Art.cursorImg); } /** * @param image * the cursor image to use */ public ImageCursor(TextureRegion image) { super(new Rectangle(image.getRegionWidth(), image.getRegionHeight())); this.cursorImg = image; int imageWidth = cursorImg.getRegionWidth(); int imageHeight = cursorImg.getRegionHeight(); this.imageOffset = new Vector2f(imageWidth/2, imageHeight/2); } /** * Offset the image so that the image can correctly point * to the correct part of the image * * @param x * @param y * @return this instance for method chaining */ public ImageCursor setImageOffset(float x, float y) { this.imageOffset.set(x, y); return this; } @Override public void update(TimeStep timeStep) { } /** * Draws the cursor on the screen * @param canvas */ @Override protected void doRender(Canvas canvas) { Vector2f cursorPos = getCursorPos(); canvas.drawImage(cursorImg, (int)cursorPos.x - imageOffset.x, (int)cursorPos.y - imageOffset.y, null); } }
1,731
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
AnimationPools.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/AnimationPools.java
/* * see license.txt */ package seventh.client.gfx; import seventh.client.gfx.AnimationPool.AnimationFactory; import seventh.shared.SeventhConstants; /** * A pool of animations. This reduces the GC load * * @author Tony * */ public class AnimationPools { private AnimationPool alliedBackDeath; private AnimationPool alliedFrontDeath; private AnimationPool axisBackDeath; private AnimationPool axisFrontDeath; private AnimationPool explosion; private AnimationPool missle; /** * */ public AnimationPools() { this.alliedBackDeath = new AnimationPool("AlliedBackDeath", SeventhConstants.MAX_PLAYERS*2, new AnimationFactory() { @Override public AnimatedImage newAnimation() { return Art.newAlliedBackDeathAnim(); } }); this.alliedFrontDeath = new AnimationPool("AlliedFrontDeath", SeventhConstants.MAX_PLAYERS*2, new AnimationFactory() { @Override public AnimatedImage newAnimation() { return Art.newAlliedFrontDeathAnim(); } }); this.axisBackDeath = new AnimationPool("AxisBackDeath", SeventhConstants.MAX_PLAYERS*2, new AnimationFactory() { @Override public AnimatedImage newAnimation() { return Art.newAxisBackDeathAnim(); } }); this.axisFrontDeath = new AnimationPool("AxisFrontDeath", SeventhConstants.MAX_PLAYERS*2, new AnimationFactory() { @Override public AnimatedImage newAnimation() { return Art.newAxisFrontDeathAnim(); } }); this.explosion = new AnimationPool("Explosion", SeventhConstants.MAX_PLAYERS*32, new AnimationFactory() { @Override public AnimatedImage newAnimation() { return Art.newExplosionAnim(); } }); this.missle = new AnimationPool("Missle", SeventhConstants.MAX_PLAYERS*32, new AnimationFactory() { @Override public AnimatedImage newAnimation() { return Art.newMissileAnim(); } }); } /** * @return the alliedBackDeath */ public AnimationPool getAlliedBackDeath() { return alliedBackDeath; } /** * @return the alliedFrontDeath */ public AnimationPool getAlliedFrontDeath() { return alliedFrontDeath; } /** * @return the axisBackDeath */ public AnimationPool getAxisBackDeath() { return axisBackDeath; } /** * @return the axisFrontDeath */ public AnimationPool getAxisFrontDeath() { return axisFrontDeath; } /** * @return the explosion */ public AnimationPool getExplosion() { return explosion; } /** * @return the missle */ public AnimationPool getMissle() { return missle; } }
3,090
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Theme.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/Theme.java
/* * The Seventh * see license.txt */ package seventh.client.gfx; import seventh.ui.Widget; /** * Applies a consistent {@link Theme} for UI {@link Widget}s * * @author Tony * */ public class Theme { public static final String DEFAULT_FONT = "Courier New"; private int backgroundColor; private int foregroundColor; private int hoverColor; private String primaryFontName; private String primaryFontFile; private String secondaryFontName; private String secondaryFontFile; /** * @param backgroundColor * @param foregroundColor * @param primaryFontName * @param primaryFontFile * @param secondaryFontName * @param secondaryFontFile */ public Theme(int backgroundColor, int foregroundColor, int hoverColor, String primaryFontName, String primaryFontFile, String secondaryFontName, String secondaryFontFile) { super(); this.backgroundColor = backgroundColor; this.foregroundColor = foregroundColor; this.hoverColor = hoverColor; this.primaryFontName = primaryFontName; this.primaryFontFile = primaryFontFile; this.secondaryFontName = secondaryFontName; this.secondaryFontFile = secondaryFontFile; } /** * Uses the default theme */ public Theme() { this(//Color.toIntBits(0, 0, 183, 255) 0xff4b5320 , //0xffffffff 0xfff1f401 , 0xffffffff // , "Futurist Fixed-width" // , "./assets/gfx/fonts/future.ttf" // // , "Futurist Fixed-width" // , "./assets/gfx/fonts/future.ttf" // , "Bebas" // , "./assets/gfx/fonts/Bebas.ttf" // , "Bebas" // , "./assets/gfx/fonts/Bebas.ttf" , "Napalm Vertigo" , "./assets/gfx/fonts/Napalm Vertigo.ttf" , "Army" , "./assets/gfx/fonts/Army.ttf" ); } /** * @return the fontFile */ public String getPrimaryFontFile() { return primaryFontFile; } /** * @return the fontName */ public String getPrimaryFontName() { return primaryFontName; } /** * @return the secondaryFontFile */ public String getSecondaryFontFile() { return secondaryFontFile; } /** * @return the secondaryFontName */ public String getSecondaryFontName() { return secondaryFontName; } /** * @return the backgroundColor */ public int getBackgroundColor() { return backgroundColor; } /** * @return the foregroundColor */ public int getForegroundColor() { return foregroundColor; } /** * @return the hoverColor */ public int getHoverColor() { return hoverColor; } /** * @return a new {@link Theme} based on this one */ public Theme newTheme() { return new Theme(backgroundColor, foregroundColor, hoverColor, primaryFontName, primaryFontFile, secondaryFontName, secondaryFontFile); } /** * @param backgroundColor the backgroundColor to set */ public Theme setBackgroundColor(int backgroundColor) { this.backgroundColor = backgroundColor; return this; } /** * @param foregroundColor the foregroundColor to set */ public Theme setForegroundColor(int foregroundColor) { this.foregroundColor = foregroundColor; return this; } /** * @param hoverColor the hoverColor to set */ public Theme setHoverColor(int hoverColor) { this.hoverColor = hoverColor; return this; } /** * @param primaryFontFile the primaryFontFile to set */ public Theme setPrimaryFontFile(String primaryFontFile) { this.primaryFontFile = primaryFontFile; return this; } /** * @param primaryFontName the primaryFontName to set */ public Theme setPrimaryFontName(String primaryFontName) { this.primaryFontName = primaryFontName; return this; } /** * @param secondaryFontFile the secondaryFontFile to set */ public Theme setSecondaryFontFile(String secondaryFontFile) { this.secondaryFontFile = secondaryFontFile; return this; } /** * @param secondaryFontName the secondaryFontName to set */ public Theme setSecondaryFontName(String secondaryFontName) { this.secondaryFontName = secondaryFontName; return this; } }
4,816
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Camera2d.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/Camera2d.java
/* * leola-live * see license.txt */ package seventh.client.gfx; import static seventh.math.Vector2f.Vector2fAdd; import static seventh.math.Vector2f.Vector2fCopy; import static seventh.math.Vector2f.Vector2fGreaterOrEq; import static seventh.math.Vector2f.Vector2fLerp; import static seventh.math.Vector2f.Vector2fMult; import static seventh.math.Vector2f.Vector2fNormalize; import static seventh.math.Vector2f.Vector2fSubtract; import java.util.Random; import java.util.Stack; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * @author Tony * */ public class Camera2d implements Camera { private static final Vector2f SHAKE_SPEED = new Vector2f(4000, 4000); private Vector2f screenCoord; private Vector2f destination; private Vector2f position,prevPosition; private Rectangle viewport; private Rectangle originalViewport; private Rectangle worldViewport; private long timeToShake; private float shakeIntensity; private float zoom; private Vector2f vShakeVelocity; private Vector2f renderPosition; private Random rand; private Stack<Vector2f> pathToFollow; /* * Cache vectors to remove new overhead */ private Vector2f vSpeed; private Vector2f vVelocity; private Vector2f vDelta; private Vector2f vMovementSpeed; private Vector2f worldBounds; // camera shake private Vector2f shakeDirection; private float shakeAngle; /** * Constructs a new {@link Camera} * * @param data * @param physObj */ public Camera2d() { this.timeToShake = 0L; this.shakeIntensity = 1.0f; this.zoom = 1.0f; this.pathToFollow = new Stack<Vector2f>(); this.screenCoord = new Vector2f(0,0); this.destination = new Vector2f(0,0); this.vSpeed = new Vector2f(); this.vDelta = new Vector2f(); this.vVelocity = new Vector2f(); this.vMovementSpeed = new Vector2f(); this.position = new Vector2f(); this.prevPosition = new Vector2f(); this.worldViewport = new Rectangle(); this.worldBounds = new Vector2f(); this.originalViewport = new Rectangle(); this.viewport = new Rectangle(); this.vShakeVelocity = new Vector2f(); this.shakeDirection = new Vector2f(); this.renderPosition = new Vector2f(); this.rand = new Random(); load(); } /** * Load the EntDict data. * * @param data */ protected void load() { this.setViewPort( new Rectangle(0,0,DEFAULT_VIEWPORT_WIDTH, DEFAULT_VIEWPORT_HEIGHT)); this.worldBounds.set(this.viewport.width, this.viewport.height); } public Vector2f getMovementSpeed() { return this.vMovementSpeed; } public void setMovementSpeed(Vector2f speed) { this.vMovementSpeed.set(speed); } /* (non-Javadoc) * @see org.myriad.render.Camera#abortPath() */ @Override public void abortPath() { this.pathToFollow.clear(); } /* (non-Javadoc) * @see org.myriad.render.Camera#addToPath(org.lwjgl.util.vector.Vector2f) */ @Override public void addToPath(Vector2f v) { this.pathToFollow.add(v); } /* (non-Javadoc) * @see org.myriad.render.Camera#contains(org.lwjgl.util.Rectangle) */ @Override public boolean contains(Rectangle rect) { return getWorldViewPort().contains(rect); } /* (non-Javadoc) * @see org.myriad.render.Camera#contains(org.lwjgl.util.vector.Vector2f) */ @Override public boolean contains(Vector2f p) { return getWorldViewPort().contains(p); } /* (non-Javadoc) * @see org.myriad.render.Camera#intersects(org.lwjgl.util.Rectangle) */ @Override public boolean intersects(Rectangle rect) { return getWorldViewPort().intersects(rect); } /* (non-Javadoc) * @see org.myriad.render.Camera#getWorldViewPort() */ @Override public Rectangle getWorldViewPort() { this.worldViewport.setBounds(this.viewport); Vector2f position = this.getPosition(); this.worldViewport.setX((int)position.x); this.worldViewport.setY((int)position.y); return this.worldViewport; } /* (non-Javadoc) * @see org.myriad.render.Camera#getPosition() */ @Override public Vector2f getPosition() { return this.position; } /* (non-Javadoc) * @see seventh.client.gfx.Camera#getRenderPosition(float) */ @Override public Vector2f getRenderPosition(float alpha) { Vector2fLerp(prevPosition, position, alpha, renderPosition); // Fixes the pixel jitters of stationary objects Vector2f.Vector2fRound(renderPosition, renderPosition); return renderPosition; } /* (non-Javadoc) * @see org.myriad.render.Camera#getScreenCoord() */ @Override public Vector2f getScreenCoord() { return this.screenCoord; } /* (non-Javadoc) * @see org.myriad.render.Camera#getViewPort() */ @Override public Rectangle getViewPort() { return this.viewport; } /* (non-Javadoc) * @see org.myriad.render.Camera#getZoom() */ @Override public float getZoom() { return this.zoom; } /* (non-Javadoc) * @see org.myriad.render.Camera#isShaking() */ @Override public boolean isShaking() { return this.timeToShake > 0; } /* (non-Javadoc) * @see org.myriad.render.Camera#moveTo(org.lwjgl.util.vector.Vector2f) */ @Override public void moveTo(Vector2f dest) { this.destination.x = Math.abs( dest.x - this.screenCoord.x ); this.destination.y = Math.abs( dest.y - this.screenCoord.y ); } /* (non-Javadoc) * @see org.myriad.render.Camera#setPath(java.util.List) */ @Override public void setPath(Stack<Vector2f> pathToFollow) { this.pathToFollow = pathToFollow; } /* (non-Javadoc) * @see org.myriad.render.Camera#setPosition(org.lwjgl.util.vector.Vector2f) */ @Override public void setPosition(Vector2f pos) { this.position.set(pos); Vector2f.Vector2fSnap(position, position); } /* (non-Javadoc) * @see org.myriad.render.Camera#setScreenCoord(org.lwjgl.util.vector.Vector2f) */ @Override public void setScreenCoord(Vector2f pos) { this.screenCoord = pos; } /* (non-Javadoc) * @see org.myriad.render.Camera#setViewPort(org.lwjgl.util.Rectangle) */ @Override public void setViewPort(Rectangle rect) { this.viewport.set(rect); this.originalViewport.set(this.viewport); } /* (non-Javadoc) * @see org.myriad.render.Camera#shake(org.myriad.core.TimeUnit, float) */ @Override public void shake(long time, float magnitude) { this.shakeAngle = rand.nextInt(360); this.shakeIntensity = magnitude; this.timeToShake = time; this.shakeDirection.zeroOut(); } /* (non-Javadoc) * @see seventh.client.gfx.Camera#addShake(long, float) */ @Override public void addShake(long time, float magnitude) { this.shakeIntensity = (this.shakeIntensity + magnitude) / 2.0f; this.timeToShake = (this.timeToShake + time) / 2; this.shakeDirection.zeroOut(); } @Override public void shakeFrom(long time, Vector2f direction, float magnitude) { if(this.timeToShake <= 0) { this.shakeIntensity = magnitude; this.timeToShake = time; Vector2f.Vector2fMult(direction, this.shakeIntensity, this.shakeDirection); this.vShakeVelocity.zeroOut(); } } /* (non-Javadoc) * @see org.myriad.render.Camera#zoom(float) */ @Override public void zoom(float zoom) { // do not allow a negative zoom if ( zoom <= 0.0f ) { zoom = 1.0f; } this.zoom = zoom; Rectangle view = this.originalViewport; float width = view.getWidth(); float height = view.getHeight(); if ( zoom < 1 ) { width = width / zoom; height = height / zoom; } else { width = width * zoom; height = height * zoom; } // this.worldProjection.x = this.worldBounds.x * ; // this.worldProjection.y = height; this.viewport.set(view.getX(), view.getY(), (int)width, (int)height); } /* (non-Javadoc) * @see org.myriad.game.Entity#update(org.myriad.core.TimeStep) */ public void update(TimeStep timeStep) { Vector2f vPosition = this.position; Vector2fCopy(vPosition, prevPosition); Vector2f vNextPosition=null; float dt = (float)timeStep.asFraction(); /* * Determine if the camera is to follow * a path */ if ( ! this.pathToFollow.isEmpty() ) { vNextPosition = this.pathToFollow.peek(); /* If we reached our destination remove it from the path */ if ( Vector2fGreaterOrEq(vNextPosition, vPosition) ) { this.pathToFollow.pop(); } } else { /* Else move to our destination (if there is one) */ vNextPosition = this.destination; } boolean useEase = true; if(useEase) { this.vDelta.zeroOut(); Vector2fSubtract(vNextPosition, vPosition, this.vDelta); if(Vector2f.Vector2fLengthSq(vDelta) > 0.99f) { //Vector2fLerp(vPosition, vNextPosition, 0.242f, vPosition); //Vector2f.Vector2fInterpolate(vPosition, vNextPosition, 0.242f, vPosition); final float speed = 0.242f; final float ispeed = 1.0f - speed; Vector2fMult(vPosition, ispeed, vPosition); Vector2fMult(vNextPosition, speed, vVelocity); Vector2fAdd(vPosition, vVelocity, vPosition); Vector2f.Vector2fRound(vPosition, vPosition); } } else { this.vDelta.zeroOut(); Vector2fSubtract(vNextPosition, vPosition, this.vDelta); if(Vector2f.Vector2fLengthSq(vDelta) > 0.5f) { this.vVelocity.zeroOut(); Vector2fCopy(this.vDelta, this.vVelocity); Vector2fNormalize(this.vVelocity, this.vVelocity); float friction = 1.0f; if(isShaking()) { Vector2fCopy(SHAKE_SPEED, this.vSpeed ); } else { Vector2fCopy(this.vMovementSpeed, this.vSpeed ); } Vector2fMult(this.vSpeed, friction * dt, this.vSpeed); Vector2fMult(this.vVelocity, this.vSpeed, this.vVelocity); /* If the velocity for this frame is greater than our destination, * clamp it. */ if ( Vector2fGreaterOrEq(this.vVelocity, this.vDelta) ) { Vector2fCopy(this.vDelta, this.vVelocity); } // Store the updated position Vector2fAdd(vPosition, this.vVelocity, this.vVelocity); setPosition(this.vVelocity); } } // shake camera if needed checkShake(timeStep); } /** * Check to see if the Camera needs to be shaking. * * @param timeStep */ private void checkShake(TimeStep timeStep) { /* * If we are to shake do so */ if(isShaking()) { /* Decrement the amount of time to shake */ this.timeToShake -= timeStep.getDeltaTime(); // if this is a directional shake, jitter in that direction (used for weapon recoil). // otherwise make random shaking of the screen (used for explosives) if(this.shakeDirection.lengthSquared() > 0) { this.vShakeVelocity.set(this.shakeDirection); Vector2f.Vector2fRotate(this.shakeDirection, Math.toRadians(180), this.shakeDirection); } else { this.shakeAngle += (150 + rand.nextInt(60)); this.vShakeVelocity.set((float)Math.sin(this.shakeAngle) * this.shakeIntensity, (float)Math.cos(this.shakeAngle) * this.shakeIntensity); this.shakeIntensity *= 0.9f; } Vector2f position = getPosition(); Vector2fAdd(position, this.vShakeVelocity, position); setPosition(position); } } /* (non-Javadoc) * @see org.myriad.render.Camera#getRenderPosition() */ @Override public Vector2f getCenterPosition() { Vector2f position = this.getPosition(); float ratio = (float)this.viewport.getWidth() / (float)this.viewport.getHeight(); this.renderPosition.x = position.x+(ratio*this.zoom*25.0f); this.renderPosition.y = position.y+(ratio*this.zoom*25.0f); // new_view_center = zoom_center + zoom_ratio * (old_view_center - zoom_center) return this.renderPosition; } /* (non-Javadoc) * @see org.myriad.render.Camera#checkSceneBounds(int, int) */ @Override public void centerAround(Vector2f pos) { Rectangle viewport = getViewPort(); // screen dimensions float halfHeight = viewport.getHeight() / 2.0f; float halfWidth = viewport.getWidth() / 2.0f; // handle being on top edge of map if ( pos.y + halfHeight > this.worldBounds.y ) halfHeight = pos.y - this.worldBounds.y + halfHeight * 2.0f; // handle bottom edge if ( pos.y - halfHeight < 0 ) halfHeight = pos.y; // handle left edge if ( pos.x - halfWidth < 0 ) halfWidth = pos.x; // handle right edge if ( pos.x + halfWidth > this.worldBounds.x ) halfWidth = pos.x + this.worldBounds.x - halfWidth * 2.0f; // adjust the camera this.screenCoord.set(halfWidth, halfHeight); // move the camera moveTo(pos); } /* (non-Javadoc) * @see seventh.client.gfx.Camera#centerAroundNow(seventh.math.Vector2f) */ @Override public void centerAroundNow(Vector2f pos) { Rectangle viewport = getViewPort(); // screen dimensions float halfHeight = viewport.getHeight() / 2.0f; float halfWidth = viewport.getWidth() / 2.0f; // handle being on top edge of map if ( pos.y + halfHeight > this.worldBounds.y ) halfHeight = pos.y - this.worldBounds.y + halfHeight * 2.0f; // handle bottom edge if ( pos.y - halfHeight < 0 ) halfHeight = pos.y; // handle left edge if ( pos.x - halfWidth < 0 ) halfWidth = pos.x; // handle right edge if ( pos.x + halfWidth > this.worldBounds.x ) halfWidth += (pos.x + halfWidth) - this.worldBounds.x; this.position.x = pos.x - halfWidth; this.position.y = pos.y - halfHeight; } /* (non-Javadoc) * @see org.myriad.render.Camera#screenToWorld(org.myriad.shared.math.Vector2f, org.myriad.shared.math.Vector2f) */ @Override public void screenToWorld(Vector2f screenPos, Vector2f worldPos) { // Vector2f pos = this.getPosition(); // worldPos.x = (screenPos.x - this.viewport.width / 2.0f) * this.zoom + pos.x; // worldPos.y = (screenPos.y - this.viewport.height / 2.0f) * this.zoom + pos.y; Vector2f cameraPosition = this.getPosition(); Vector2fAdd(screenPos, cameraPosition, worldPos); worldPos.x -= this.viewport.x; worldPos.y -= this.viewport.y; worldPos.x = (worldPos.x * this.worldBounds.x) / this.originalViewport.width; worldPos.y = (worldPos.y * this.worldBounds.y) / this.originalViewport.height; } /* (non-Javadoc) * @see org.myriad.render.Camera#worldToScreen(org.myriad.shared.math.Vector2f, org.myriad.shared.math.Vector2f) */ @Override public void worldToScreen(Vector2f worldPos, Vector2f screenPos) { // Vector2f pos = this.getPosition(); // screenPos.x = ((worldPos.x - pos.x) / this.zoom) + this.viewport.width / 2.0f; // screenPos.y = ((worldPos.y - pos.y) / this.zoom) + this.viewport.height / 2.0f; Vector2f cameraPosition = this.getPosition(); Vector2fSubtract(worldPos, cameraPosition, screenPos); screenPos.x += this.viewport.x; screenPos.y += this.viewport.y; //screenPos.x = screenPos.x - this.worldBounds.x/2; //screenPos.y = screenPos.y - this.worldBounds.y/2; screenPos.x = (screenPos.x * (float)this.originalViewport.width) / (float)this.worldBounds.x; screenPos.y = (screenPos.y * (float)this.originalViewport.height) / (float)this.worldBounds.y; } /* (non-Javadoc) * @see org.myriad.render.Camera#getWorldBounds() */ @Override public Vector2f getWorldBounds() { return this.worldBounds; } /* (non-Javadoc) * @see org.myriad.render.Camera#setWorldBounds(org.myriad.shared.math.Vector2f) */ @Override public void setWorldBounds(Vector2f bounds) { this.worldBounds.set(bounds); } }
19,204
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ShermanTankSprite.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/ShermanTankSprite.java
/* * see license.txt */ package seventh.client.gfx; import com.badlogic.gdx.graphics.g2d.Sprite; import seventh.client.entities.vehicles.ClientTank; /** * Represents a Sherman tank * * @author Tony * */ public class ShermanTankSprite extends TankSprite { /** * @param tank */ public ShermanTankSprite(ClientTank tank) { super(tank, Art.newShermanTankTracks(), new Sprite(Art.shermanTankTurret), Art.newShermanTankTracksDamaged(), new Sprite(Art.shermanTankTurretDamaged)); } }
541
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
LightSystem.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/LightSystem.java
/* * see license.txt */ package seventh.client.gfx; import seventh.client.ClientGame.ClientEntityListener; import seventh.math.Vector2f; import seventh.math.Vector3f; import seventh.shared.TimeStep; /** * @author Tony * */ public interface LightSystem extends FrameBufferRenderable { static enum LightType { CONE, POSITIONAL, IMAGE, } /** * @return the {@link ClientEntityListener} */ public ClientEntityListener getClientEntityListener(); /** * Registers the light. Use if {@link ImageBasedLightSystem#addLight(ImageLight)} was not used * to construct the light. * * @param light */ public abstract void addLight(Light light); /** * Creates a new Light source * @return a {@link Light} */ public abstract Light newPointLight(); /** * Creates a new Light source * @param pos * @return a {@link Light} */ public abstract Light newPointLight(Vector2f pos); /** * Creates a new Light source * @return a {@link Light} */ public abstract Light newConeLight(); /** * Creates a new Light source * @param pos * @return a {@link Light} */ public abstract Light newConeLight(Vector2f pos); /** * Removes the light from the world * @param light */ public abstract void removeLight(Light light); /** * Remove all lights */ public abstract void removeAllLights(); /** * Destroys the light system, freeing resources */ public abstract void destroy(); /** * @return the enabled */ public abstract boolean isEnabled(); /** * @param enabled the enabled to set */ public abstract void setEnabled(boolean enabled); /** * @param ambientColor the ambientColor to set */ public abstract void setAmbientColor(Vector3f ambientColor); public abstract void setAmbientColor(float r, float g, float b); /** * @param ambientIntensity the ambientIntensity to set */ public abstract void setAmbientIntensity(float ambientIntensity); /** * @return the ambientIntensity */ public abstract float getAmbientIntensity(); /** * @return the ambientColor */ public abstract Vector3f getAmbientColor(); /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ public abstract void update(TimeStep timeStep); /* (non-Javadoc) * @see seventh.client.gfx.FrameBufferRenderable#frameBufferRender(seventh.client.gfx.Canvas, seventh.client.gfx.Camera) */ public abstract void frameBufferRender(Canvas canvas, Camera camera, float alpha); /* (non-Javadoc) * @see seventh.client.gfx.Renderable#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, long) */ public abstract void render(Canvas canvas, Camera camera, float alpha); }
2,973
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
CompoundCursor.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/CompoundCursor.java
/* * see license.txt */ package seventh.client.gfx; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * @author Tony * */ public class CompoundCursor extends Cursor { private Cursor a,b; private Cursor active; /** * @param bounds */ public CompoundCursor(Cursor a, Cursor b) { super(a.getBounds()); this.a = a; this.b = b; this.active = a; } /** * @return the active */ public Cursor getActive() { return active; } public CompoundCursor activateA() { this.active = a; return this; } public CompoundCursor activateB() { this.active = b; return this; } @Override public boolean isClampEnabled() { return this.active.isClampEnabled(); } @Override public void setClampEnabled(boolean isClampEnabled) { this.a.setClampEnabled(isClampEnabled); this.b.setClampEnabled(isClampEnabled); } @Override public boolean isInverted() { return this.active.isInverted(); } @Override public void setInverted(boolean isInverted) { this.a.setInverted(isInverted); this.b.setInverted(isInverted); } @Override public float getAccuracy() { return this.active.getAccuracy(); } @Override public Rectangle getBounds() { return this.active.getBounds(); } @Override public int getColor() { return this.active.getColor(); } @Override public Vector2f getCursorPos() { return this.active.getCursorPos(); } @Override public Vector2f getPreviousCursorPos() { return this.active.getPreviousCursorPos(); } @Override public float getMouseSensitivity() { return this.active.getMouseSensitivity(); } @Override public int getX() { return this.active.getX(); } @Override public int getY() { return this.active.getY(); } @Override public boolean isVisible() { return this.active.isVisible(); } @Override public void centerMouse() { this.a.centerMouse(); this.b.centerMouse(); } @Override public void moveByDelta(float dx, float dy) { this.a.moveByDelta(dx, dy); this.b.moveByDelta(dx, dy); } @Override public void moveTo(int x, int y) { this.a.moveTo(x, y); this.b.moveTo(x, y); } @Override public void snapTo(int x, int y) { this.a.snapTo(x, y); this.b.snapTo(x, y); } @Override public void snapTo(Vector2f screenPos) { this.a.snapTo(screenPos); this.b.snapTo(screenPos); } @Override public void setAccuracy(float accuracy) { this.active.setAccuracy(accuracy); } @Override public void setColor(int color) { this.active.setColor(color); } @Override public void setMouseSensitivity(float mouseSensitivity) { this.a.setMouseSensitivity(mouseSensitivity); this.b.setMouseSensitivity(mouseSensitivity); } @Override public void touchAccuracy() { this.active.touchAccuracy(); } @Override public void setVisible(boolean isVisible) { this.a.setVisible(isVisible); this.b.setVisible(isVisible); } @Override public void update(TimeStep timeStep) { this.active.update(timeStep); } @Override public void render(Canvas canvas) { this.active.render(canvas); } @Override protected void doRender(Canvas canvas) { } }
3,867
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
FrameBufferRenderable.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/FrameBufferRenderable.java
/* * see license.txt */ package seventh.client.gfx; /** * First renders to the framebuffer * * @author Tony * */ public interface FrameBufferRenderable extends Renderable { /** * Renders to the frame buffer * * @param canvas * @param camera */ public void frameBufferRender(Canvas canvas, Camera camera, float alpha); /** * @return true if expired */ public boolean isExpired(); }
453
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Camera.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/Camera.java
/* * leola-live * see license.txt */ package seventh.client.gfx; import java.util.Stack; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * Camera * * @author Tony * */ public abstract interface Camera { /** * Default Viewport width */ public static final int DEFAULT_VIEWPORT_WIDTH = 800; /** * Default Viewport height */ public static final int DEFAULT_VIEWPORT_HEIGHT = 600; /** * Default movement speed */ public static final Vector2f DEFAULT_MOVE_SPEED = new Vector2f(200, 200); /** * Updates the Camera * @param timeStep */ public void update(TimeStep timeStep); /** * @return the position relative to the {@link Camera#getPosition()} and {@link Camera#getZoom()} */ public abstract Vector2f getCenterPosition(); /** * @return the movement speed */ public Vector2f getMovementSpeed(); /** * Sets the movement speed * @param speed */ public void setMovementSpeed(Vector2f speed); /** * Centers the camera around the supplied position */ public abstract void centerAround(Vector2f position); /** * Centers the camera around the supplied position, moving the * camera there immediately. * @param position */ public abstract void centerAroundNow(Vector2f position); /** * Move the camera to a new location. * * @param destination */ public abstract void moveTo( Vector2f destination ); /** * Shake the camera * * @param time * @param magnitude */ public abstract void shake(long time, float magnitude); public abstract void addShake(long time, float magnitude); public abstract void shakeFrom(long time, Vector2f direction, float magnitude); /** * Determine if the camera is shaking * * @return */ public abstract boolean isShaking(); /** * Zoom in. * * @param zoom */ public abstract void zoom(float zoom); /** * Zoom factor. * * @return */ public abstract float getZoom(); /** * Path to move the camera to. * * @param pathToFollow */ public abstract void setPath( Stack<Vector2f> pathToFollow ); /** * Add to the path. * * @param v */ public abstract void addToPath(Vector2f v); /** * Abort the path. */ public abstract void abortPath(); /** * Determine if the {@link Rectangle} is in the viewport. * * @param rect * @return */ public abstract boolean contains(Rectangle rect); /** * Determine if the {@link Vector2f} is in the viewport. * * @param p * @return */ public abstract boolean contains(Vector2f p); /** * Test intersection. * * @param rect * @return */ public abstract boolean intersects(Rectangle rect); /** * Get the Screen coordinates of the camera. * * @return */ public abstract Vector2f getScreenCoord(); /** * Set the Screen coordinates of the camera. * * @param pos */ public abstract void setScreenCoord(Vector2f pos); /** * Get the world coordinates of the camera. * * @return */ public abstract Vector2f getPosition(); public abstract Vector2f getRenderPosition(float alpha); /** * Set the world coordinates of the camera. * * @param pos */ public abstract void setPosition(Vector2f pos); /** * Get the Viewport of this camera * @return */ public abstract Rectangle getViewPort(); /** * Set the Viewport of this camera * * @return */ public abstract void setViewPort(Rectangle rect); /** * Get the Viewport relative to the world. * * @return */ public abstract Rectangle getWorldViewPort(); /** * @return the world bounds */ public abstract Vector2f getWorldBounds(); /** * The worlds bounds * @param bounds */ public abstract void setWorldBounds(Vector2f bounds); /** * Converts the supplied screen coordinates to world coordinates. * * @param screenPos * @param worldPos */ public abstract void screenToWorld(Vector2f screenPos, Vector2f worldPos); /** * Converts the supplied world coordinates to screen coordinates. * * @param worldPos * @param screenPos */ public abstract void worldToScreen(Vector2f worldPos, Vector2f screenPos); }
5,042
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Light.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/Light.java
/* * see license.txt */ package seventh.client.gfx; import seventh.math.Vector2f; import seventh.math.Vector3f; import seventh.shared.TimeStep; import com.badlogic.gdx.graphics.g2d.TextureRegion; /** * @author Tony * */ public interface Light { public abstract TextureRegion getTexture(); public abstract void setTexture(TextureRegion tex); public abstract void destroy(); /** * @return the on */ public abstract boolean isOn(); /** * @param on the on to set */ public abstract void setOn(boolean on); /** * @return the lightSize */ public abstract int getLightSize(); /** * @param lightSize the lightSize to set */ public abstract void setLightSize(int lightSize); /** * @param lightOscillate the lightOscillate to set */ public abstract void setLightOscillate(boolean lightOscillate); /** * @return the luminacity */ public abstract float getLuminacity(); /** * @param luminacity the luminacity to set */ public abstract void setLuminacity(float luminacity); /** * @return the color */ public abstract Vector3f getColor(); /** * @param color the color to set */ public abstract void setColor(Vector3f color); /** * @param r * @param g * @param b */ public abstract void setColor(float r, float g, float b); /** * @return the orientation */ public abstract float getOrientation(); /** * @param orientation the orientation to set */ public abstract void setOrientation(float orientation); /** * @param pos the pos to set */ public abstract void setPos(Vector2f pos); /** * Sets the position * @param x * @param y */ public abstract void setPos(float x, float y); /** * @return the pos */ public abstract Vector2f getPos(); /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ public abstract void update(TimeStep timeStep); }
2,117
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Art.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/Art.java
/* * see license.txt */ package seventh.client.gfx; import java.lang.reflect.Field; import java.util.Random; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; import seventh.shared.Cons; /** * Art assets * * * @author Tony * */ public class Art { private static final Random random = new Random(); /** * Simple black image used to overlay */ public static final TextureRegion BLACK_IMAGE = new TextureRegion(); /*---------------------------------------------------------------- * Art for the Game *----------------------------------------------------------------*/ public static TextureRegion shotgunImage = null; public static TextureRegion rpgImage = null; public static Sprite fragGrenadeIcon = null; public static TextureRegion fragGrenadeImage = null; public static Sprite smokeGrenadeIcon = null; public static TextureRegion smokeGrenadeImage = null; public static TextureRegion springfieldImage = null; public static TextureRegion thompsonImage = null; public static TextureRegion m1GarandImage = null; public static TextureRegion kar98Image = null; public static TextureRegion mp44Image = null; public static TextureRegion mp40Image = null; public static TextureRegion pistolImage = null; public static TextureRegion riskerImage = null; public static TextureRegion flameThrowerImage = null; public static TextureRegion hammerImage = null; public static TextureRegion bombImage = null; public static TextureRegion radioImage = null; public static Model alliedBodyModel = null; public static Model alliedWalkModel = null; public static Model alliedSprintModel = null; public static TextureRegion alliedCrouchLegs = null; public static Model axisBodyModel = null; public static Model axisWalkModel = null; public static Model axisSprintModel = null; public static TextureRegion axisCrouchLegs = null; public static TextureRegion alliedIcon = null; public static TextureRegion axisIcon = null; public static TextureRegion shotgunIcon = null; public static TextureRegion rocketIcon = null; public static TextureRegion springfieldIcon = null; public static TextureRegion thompsonIcon = null; public static TextureRegion m1GarandIcon = null; public static TextureRegion kar98Icon = null; public static TextureRegion mp44Icon = null; public static TextureRegion mp40Icon = null; public static TextureRegion pistolIcon = null; public static TextureRegion riskerIcon = null; public static TextureRegion flameThrowerIcon = null; public static TextureRegion hammerIcon = null; public static TextureRegion tdmIcon = null; public static TextureRegion ctfIcon = null; public static TextureRegion objIcon = null; public static TextureRegion attackerIcon = null; public static TextureRegion defenderIcon = null; private static TextureRegion[] explosionImage = null; private static TextureRegion[] rocketImage = null; public static TextureRegion deathsImage = null; private static TextureRegion[] alliedBackDeathImage = null; private static TextureRegion[] alliedBackDeath2Image = null; private static TextureRegion[] alliedFrontDeathImage = null; private static TextureRegion[] alliedFrontDeath2Image = null; //private static TextureRegion[] alliedExplosionDeathImage = null; private static TextureRegion[] axisBackDeathImage = null; private static TextureRegion[] axisBackDeath2Image = null; private static TextureRegion[] axisFrontDeathImage = null; private static TextureRegion[] axisFrontDeath2Image = null; //private static TextureRegion[] axisExplosionDeathImage = null; public static TextureRegion[] bloodImages = null; public static TextureRegion[] gibImages = null; public static TextureRegion smokeImage = null; // public static TextureRegion tankImage = loadImage("./assets/gfx/tank.png"); public static Sprite smallAssaultRifleIcon = null; public static Sprite smallShotgunIcon = null; public static Sprite smallRocketIcon = null; public static Sprite smallSniperRifleIcon = null; public static Sprite smallM1GarandIcon = null; public static Sprite smallFragGrenadeIcon = null; public static Sprite smallSmokeGrenadeIcon = null; public static Sprite smallExplosionIcon = null; public static Sprite smallkar98Icon = null; public static Sprite smallmp44Icon = null; public static Sprite smallmp40Icon = null; public static Sprite smallPistolIcon = null; public static Sprite smallRiskerIcon = null; public static Sprite smallFlameThrowerIcon = null; public static TextureRegion cursorImg = null; public static TextureRegion reticleImg = null; public static TextureRegion[] thompsonMuzzleFlash = null; public static TextureRegion[] m1GarandMuzzleFlash = null; public static TextureRegion[] springfieldMuzzleFlash = null; public static TextureRegion[] kar98MuzzleFlash = null; public static TextureRegion[] mp44MuzzleFlash = null; public static TextureRegion[] mp40MuzzleFlash = null; public static TextureRegion[] shotgunMuzzleFlash = null; public static TextureRegion[] rocketMuzzleFlash = null; public static TextureRegion[] riskerMuzzleFlash = null; public static Sprite healthPack = null; public static Sprite healthIcon = null; public static Sprite staminaIcon = null; public static Sprite upArrow = null; public static Sprite downArrow = null; public static TextureRegion fireWeaponLight = null; public static TextureRegion lightMap = null; public static TextureRegion flashLight = null; public static TextureRegion bulletShell = null; public static TextureRegion tankTrackMarks = null; public static TextureRegion shermanTankImage = null; public static TextureRegion shermanTankBase = null; public static TextureRegion shermanTankTurret = null; public static TextureRegion shermanTankBaseDamaged = null; public static TextureRegion shermanTankTurretDamaged = null; public static TextureRegion panzerTankImage = null; public static TextureRegion panzerTankBase = null; public static TextureRegion panzerTankTurret = null; public static TextureRegion panzerTankBaseDamaged = null; public static TextureRegion panzerTankTurretDamaged = null; public static TextureRegion alliedFlagImg = null; public static TextureRegion axisFlagImg = null; public static TextureRegion doorImg = null; public static TextureRegion firstBloodIcon = null; public static TextureRegion killRollIcon = null; /** * Reloads the graphics */ public static void reload() { // destroy(); load(); } /** * Loads the graphics */ public static void load() { { Pixmap map = TextureUtil.createPixmap(128, 128); map.setColor(Color.BLACK); map.fillRectangle(0, 0, map.getWidth(), map.getHeight()); BLACK_IMAGE.setTexture(new Texture(map)); } shotgunImage = loadImage("./assets/gfx/weapons/m3.bmp", 0xff00ff); rpgImage = loadImage("./assets/gfx/weapons/rpg.bmp", 0xff00ff); // Pixmap grenadePixmap = loadPixmap("./assets/gfx/weapons/grenade.png"); // grenadeImage = TextureUtil.tex(TextureUtil.resizePixmap(grenadePixmap, 12, 12)); // grenadeIcon = TextureUtil.tex(grenadePixmap); fragGrenadeImage = loadImage("./assets/gfx/weapons/frag_grenade.png"); fragGrenadeIcon = TextureUtil.resizeImage(fragGrenadeImage, 12, 12); smokeGrenadeImage = loadImage("./assets/gfx/weapons/smoke_grenade.png"); smokeGrenadeIcon = TextureUtil.resizeImage(smokeGrenadeImage, 12, 12); springfieldImage = loadImage("./assets/gfx/weapons/springfield.bmp", 0xff00ff); thompsonImage = loadImage("./assets/gfx/weapons/thompson.bmp", 0xff00ff); m1GarandImage = loadImage("./assets/gfx/weapons/m1garand.bmp", 0xff00ff); kar98Image = loadImage("./assets/gfx/weapons/kar98.bmp", 0xff00ff); mp44Image = loadImage("./assets/gfx/weapons/mp44.bmp", 0xff00ff); mp40Image = loadImage("./assets/gfx/weapons/mp40.bmp", 0xff00ff); pistolImage = loadImage("./assets/gfx/weapons/pistol.bmp", 0xff00ff); riskerImage = loadImage("./assets/gfx/weapons/risker.bmp", 0xff00ff); flameThrowerImage = loadImage("./assets/gfx/weapons/flame_thrower.bmp", 0xff00ff); hammerImage = loadImage("./assets/gfx/weapons/pistol.bmp", 0xff00ff); // TODO bombImage = loadImage("./assets/gfx/weapons/bomb.bmp", 0xff00ff); bombImage.flip(false, true); radioImage = loadImage("./assets/gfx/entities/radio.png"); alliedBodyModel = new Model(loadImage("./assets/gfx/player/allied_positions.png"), 201, 256, 3, 3); alliedWalkModel = new Model(loadImage("./assets/gfx/player/allied_legs_walk.png"), 372, 196, 2, 4); alliedSprintModel = new Model(loadImage("./assets/gfx/player/allied_legs_sprint.png"), 256, 190, 2, 3); alliedCrouchLegs = loadImage("./assets/gfx/player/allied_crouch_legs.png"); axisBodyModel = new Model(loadImage("./assets/gfx/player/axis_positions.png"), 201, 256, 3, 3); axisWalkModel = new Model(loadImage("./assets/gfx/player/axis_legs_walk.png"), 372, 196, 2, 4); axisSprintModel = new Model(loadImage("./assets/gfx/player/axis_legs_sprint.png"), 256, 190, 2, 3); axisCrouchLegs = loadImage("./assets/gfx/player/axis_crouch_legs.png"); shotgunIcon = loadImage("./assets/gfx/weapons/shotgun_icon.png"); rocketIcon = loadImage("./assets/gfx/weapons/rpg_icon.png"); springfieldIcon = loadImage("./assets/gfx/weapons/springfield_icon.png"); thompsonIcon = loadImage("./assets/gfx/weapons/thompson_icon.png"); m1GarandIcon = loadImage("./assets/gfx/weapons/m1garand_icon.png"); kar98Icon = loadImage("./assets/gfx/weapons/kar98_icon.png"); mp44Icon = loadImage("./assets/gfx/weapons/mp44_icon.png"); mp40Icon = loadImage("./assets/gfx/weapons/mp40_icon.png"); pistolIcon = loadImage("./assets/gfx/weapons/pistol_icon.png"); riskerIcon = loadImage("./assets/gfx/weapons/risker_icon.png"); flameThrowerIcon = loadImage("./assets/gfx/weapons/flame_thrower_icon.png"); hammerIcon = loadImage("./assets/gfx/weapons/hammer_icon.png"); explosionImage = TextureUtil.splitImage(loadImage("./assets/gfx/particles/explosion.png"), 4, 4); rocketImage = TextureUtil.splitImage(loadImage("./assets/gfx/weapons/rocket.bmp", 0xff00ff), 1, 1); deathsImage = loadImage("./assets/gfx/player/death_symbol.png"); // alliedBackDeathImage = TextureUtil.splitImage( // TextureUtil.subImage(loadImage("./assets/gfx/player/allied_death_01.png"), 0, 0, 300, 210), 2, 4); // alliedBackDeath2Image = TextureUtil.splitImage( // TextureUtil.subImage(loadImage("./assets/gfx/player/allied_death_03.png"), 0, 0, 260, 290), 2, 3); // alliedFrontDeathImage = TextureUtil.splitImage( // TextureUtil.subImage(loadImage("./assets/gfx/player/allied_death_02.png"), 0, 0, 330, 190), 2, 6); // alliedExplosionDeathImage = TextureUtil.splitImage( // TextureUtil.subImage(loadImage("./assets/gfx/player/allied_death_04.png"), 0, 0, 330, 290), 2, 4); alliedBackDeathImage = TextureUtil.splitImage( TextureUtil.subImage(loadImage("./assets/gfx/player/allied_death_01.png"), 0, 0, 450, 200), 2, 6); alliedBackDeath2Image = TextureUtil.splitImage( TextureUtil.subImage(loadImage("./assets/gfx/player/allied_death_02.png"), 0, 0, 420, 175), 2, 6); alliedFrontDeathImage = TextureUtil.splitImage( TextureUtil.subImage(loadImage("./assets/gfx/player/allied_death_03.png"), 0, 0, 510, 218), 2, 6); alliedFrontDeath2Image = TextureUtil.splitImage( TextureUtil.subImage(loadImage("./assets/gfx/player/allied_death_04.png"), 0, 0, 510, 262), 2, 5); // axisBackDeathImage = TextureUtil.splitImage( // TextureUtil.subImage(loadImage("./assets/gfx/player/axis_death_01.png"), 0, 0, 300, 210), 2, 4); // axisBackDeath2Image = TextureUtil.splitImage( // TextureUtil.subImage(loadImage("./assets/gfx/player/axis_death_03.png"), 0, 0, 260, 290), 2, 3); // axisFrontDeathImage = TextureUtil.splitImage( // TextureUtil.subImage(loadImage("./assets/gfx/player/axis_death_02.png"), 0, 0, 330, 190), 2, 6); // axisExplosionDeathImage = TextureUtil.splitImage( // TextureUtil.subImage(loadImage("./assets/gfx/player/axis_death_04.png"), 0, 0, 330, 290), 2, 4); axisBackDeathImage = TextureUtil.splitImage( TextureUtil.subImage(loadImage("./assets/gfx/player/axis_death_01.png"), 0, 0, 450, 200), 2, 6); axisBackDeath2Image = TextureUtil.splitImage( TextureUtil.subImage(loadImage("./assets/gfx/player/axis_death_02.png"), 0, 0, 420, 175), 2, 6); axisFrontDeathImage = TextureUtil.splitImage( TextureUtil.subImage(loadImage("./assets/gfx/player/axis_death_03.png"), 0, 0, 510, 218), 2, 6); axisFrontDeath2Image = TextureUtil.splitImage( TextureUtil.subImage(loadImage("./assets/gfx/player/axis_death_04.png"), 0, 0, 510, 262), 2, 5); // bloodImages = TextureUtil.splitImage( // TextureUtil.subImage(loadImage("./assets/gfx/particles/blood.png"), 0, 0, 128, 32), 1, 4); bloodImages = TextureUtil.splitImage(loadImage("./assets/gfx/particles/blood.png"), 2, 3); gibImages = TextureUtil.splitImage(loadImage("./assets/gfx/particles/gibs.png"), 2, 2); smokeImage = loadImage("./assets/gfx/particles/smoke.png"); // tankImage = loadImage("./assets/gfx/tank.png"); final int smallIconWidth = 64, smallIconHeight = 32; smallAssaultRifleIcon = TextureUtil.resizeImage(thompsonIcon, smallIconWidth, smallIconHeight); smallShotgunIcon = TextureUtil.resizeImage(shotgunIcon, smallIconWidth, smallIconHeight); smallRocketIcon = TextureUtil.resizeImage(rocketIcon, smallIconWidth, smallIconHeight); smallSniperRifleIcon = TextureUtil.resizeImage(springfieldIcon, smallIconWidth, smallIconHeight); smallM1GarandIcon = TextureUtil.resizeImage(m1GarandIcon, smallIconWidth, smallIconHeight); smallFragGrenadeIcon = TextureUtil.resizeImage(fragGrenadeImage, smallIconWidth / 3, smallIconHeight / 3); smallSmokeGrenadeIcon = TextureUtil.resizeImage(fragGrenadeImage, smallIconWidth / 3, smallIconHeight / 3); smallExplosionIcon = TextureUtil.resizeImage(explosionImage[0], smallIconWidth / 2, smallIconHeight / 2); smallkar98Icon = TextureUtil.resizeImage(kar98Icon, smallIconWidth, smallIconHeight); smallmp44Icon = TextureUtil.resizeImage(mp44Icon, smallIconWidth, smallIconHeight); smallmp40Icon = TextureUtil.resizeImage(mp40Icon, smallIconWidth, smallIconHeight); smallPistolIcon = TextureUtil.resizeImage(pistolIcon, smallIconWidth, smallIconHeight); smallRiskerIcon = TextureUtil.resizeImage(riskerIcon, smallIconWidth, smallIconHeight); smallFlameThrowerIcon = TextureUtil.resizeImage(flameThrowerIcon, smallIconWidth, smallIconHeight); cursorImg = loadImage("./assets/gfx/ui/menu_cursor.png"); reticleImg = loadImage("./assets/gfx/ui/reticle.png"); thompsonMuzzleFlash = TextureUtil.splitImage(loadImage("./assets/gfx/weapons/thompson_muzzle_flash.png"), 2, 2); springfieldMuzzleFlash = TextureUtil.splitImage(loadImage("./assets/gfx/weapons/springfield_muzzle_flash.png"), 2, 2); m1GarandMuzzleFlash = TextureUtil.splitImage(loadImage("./assets/gfx/weapons/m1garand_muzzle_flash.png"), 2, 2); kar98MuzzleFlash = TextureUtil.splitImage(loadImage("./assets/gfx/weapons/kar98_muzzle_flash.png"), 2, 2); mp40MuzzleFlash = TextureUtil.splitImage(loadImage("./assets/gfx/weapons/mp40_muzzle_flash.png"), 2, 2); mp44MuzzleFlash = TextureUtil.splitImage(loadImage("./assets/gfx/weapons/mp44_muzzle_flash.png"), 2, 2); shotgunMuzzleFlash = TextureUtil.splitImage(loadImage("./assets/gfx/weapons/shotgun_muzzle_flash.png"), 2, 2); rocketMuzzleFlash = TextureUtil.splitImage(loadImage("./assets/gfx/weapons/rpg_muzzle_flash.png"), 2, 2); riskerMuzzleFlash = TextureUtil.splitImage(loadImage("./assets/gfx/weapons/risker_muzzle_flash.png"), 2, 2); healthPack = TextureUtil.resizeImage(loadImage("./assets/gfx/entities/healthpack.png"), 16, 16); healthIcon = healthPack; //TextureUtil.resizeImage(loadImage("./assets/gfx/ui/health.bmp"), 12, 12); staminaIcon = TextureUtil.resizeImage(loadImage("./assets/gfx/ui/stamina.png"), 16, 16); TextureRegion navArrow = loadImage("./assets/gfx/ui/ui_nav_arrows.png"); upArrow = new Sprite(navArrow); upArrow.flip(false, true); downArrow = new Sprite(navArrow); fireWeaponLight = loadImage("./assets/gfx/weapon_fire.png"); lightMap = loadImage("./assets/gfx/entities/light.png"); flashLight = loadImage("./assets/gfx/lightmap_flashlight.png"); bulletShell = loadImage("./assets/gfx/particles/bullet_shell.png"); tankTrackMarks = loadImage("./assets/gfx/vehicles/tank_track_mark.png"); shermanTankImage = loadImage("./assets/gfx/vehicles/tanks/sherman/sherman_tank.png"); shermanTankBase = TextureUtil.subImage(shermanTankImage, 15, 180, 272, 149); shermanTankTurret = TextureUtil.subImage(shermanTankImage, 304, 187, 197, 108); shermanTankBaseDamaged = TextureUtil.subImage(shermanTankImage, 15, 8, 272, 155); shermanTankTurretDamaged = TextureUtil.subImage(shermanTankImage, 304, 22, 187, 108); panzerTankImage = loadImage("./assets/gfx/vehicles/tanks/panzer/panzer_tank.png"); panzerTankBase = TextureUtil.subImage(panzerTankImage, 0, 310, 257, 195); panzerTankTurret = TextureUtil.subImage(panzerTankImage, 35, 20, 273, 125); panzerTankBaseDamaged = TextureUtil.subImage(panzerTankImage, 254, 310, 265, 195); panzerTankTurretDamaged = TextureUtil.subImage(panzerTankImage, 35, 168, 273, 125); alliedFlagImg = loadImage("./assets/gfx/entities/allied_flag.png"); axisFlagImg = loadImage("./assets/gfx/entities/axis_flag.png"); alliedIcon = loadImage("./assets/gfx/ui/allied_icon.png"); axisIcon = loadImage("./assets/gfx/ui/axis_icon.png"); tdmIcon = loadImage("./assets/gfx/ui/tdm_icon.png"); ctfIcon = loadImage("./assets/gfx/ui/ctf_icon.png"); objIcon = loadImage("./assets/gfx/ui/obj_icon.png"); attackerIcon = loadImage("./assets/gfx/ui/attacker_icon.png"); defenderIcon = loadImage("./assets/gfx/ui/defender_icon.png"); doorImg = loadImage("./assets/gfx/entities/door.png"); firstBloodIcon = loadImage("./assets/gfx/ui/first_blood_icon.png"); killRollIcon = loadImage("./assets/gfx/ui/kill_roll_icon.png"); } /** * Releases all the textures */ public static void destroy() { try { /* * Iterate through all of the static fields, * free the Sprite's, TextureRegion's, and Model's */ Field[] fields = Art.class.getFields(); for(Field field : fields) { field.setAccessible(true); Class<?> type = field.getType(); Object value = field.get(null); if(value != null) { if(type.equals(Sprite.class)) { free( (Sprite)value ); } else if(type.equals(TextureRegion.class)) { free( (TextureRegion)value ); } else if(type.equals(TextureRegion[].class)) { free( (TextureRegion[])value ); } else if(type.equals(Model.class)) { free( (Model)value ); } } } } catch(Exception e) { Cons.println("Problem freeing the textures: " + e); } } /** * Frees the texture * * @param region */ public static void free(TextureRegion region) { if(region != null) { region.getTexture().dispose(); } } /** * Frees the textures * * @param region */ public static void free(TextureRegion[] region) { if(region != null) { for(TextureRegion r : region) free(r); } } /** * Frees the memory associated with the model * * @param model */ public static void free(Model model) { if(model!=null) { model.destroy(); } } /** * Loads an image from the file system * * @param image * @return the texture */ public static TextureRegion loadImage(String image) { try { return TextureUtil.loadImage(image); } catch (Exception e) { Cons.println("*** A problem occured loading an image: " + e); } return new TextureRegion(TextureUtil.createImage(10, 10)); } /** * Loads a pixel map from the file system. * * @param image * @return the Pixmap */ public static Pixmap loadPixmap(String image) { try { return TextureUtil.loadPixmap(image); } catch (Exception e) { Cons.println("*** A problem occured loading an image: " + e); } return new Pixmap(10, 10, Format.RGBA8888); } /** * Loads the image from the file system, with a supplied color mask * @param image * @param mask the color to change to transparent * @return the texture */ public static TextureRegion loadImage(String image, int mask) { try { Pixmap map = TextureUtil.loadPixmap(image); TextureRegion region = TextureUtil.tex(TextureUtil.applyMask(map, new Color( (mask<<8) | 0xff))); map.dispose(); return region; } catch (Exception e) { Cons.println("*** A problem occured loading an image: " + e); } return new TextureRegion(TextureUtil.createImage(10, 10)); } /** * Model consists of multiple frames * * @author Tony * */ public static class Model { private TextureRegion[] frames; public Model(TextureRegion image, int width, int height, int row, int col) { this.frames = TextureUtil.splitImage(image, width, height, row, col); } /** * @return the frames */ public TextureRegion[] getFrames() { return frames; } /** * @param i * @return the frame at the supplied index */ public TextureRegion getFrame(int i) { return frames[i]; } /** * Destroys all images */ public void destroy() { if(frames!=null) { for(int i = 0; i < frames.length;i++) { frames[i].getTexture().dispose(); } } } } public static AnimatedImage newMissileAnim() { Animation animation = newAnimation(new int[]{ 200 }); return new AnimatedImage(rocketImage, animation); } public static AnimatedImage newExplosionAnim() { int v = 50; Animation animation = newAnimation(new int[]{ /*90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 10 */ v, v, v, v, v, v, v, v, v, v, v, v, 10, 10, 10, 0 }); animation.loop(false); return new AnimatedImage(explosionImage, animation); } public static AnimatedImage newAlliedBackDeathAnim() { int frameTime = 75; Animation animation = newAnimation(new int[] { frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime*9, }); AnimatedImage anim = new AnimatedImage(alliedBackDeathImage, animation); anim.loop(false); return anim; } public static AnimatedImage newAlliedBackDeath2Anim() { int frameTime = 75; Animation animation = newAnimation(new int[] { frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime*9, }); AnimatedImage anim = new AnimatedImage(alliedBackDeath2Image, animation); anim.loop(false); return anim; } public static AnimatedImage newAlliedExplosionDeathAnim() { // TODO return newAlliedFrontDeath2Anim(); } public static AnimatedImage newAlliedFrontDeathAnim() { int frameTime = 75; Animation animation = newAnimation(new int[] { frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime*9, }); AnimatedImage anim = new AnimatedImage(alliedFrontDeathImage, animation); anim.loop(false); return anim; } public static AnimatedImage newAlliedFrontDeath2Anim() { int frameTime = 50; Animation animation = newAnimation(new int[] { frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime*9, }); AnimatedImage anim = new AnimatedImage(alliedFrontDeath2Image, animation); anim.loop(false); return anim; } public static AnimatedImage newAxisBackDeathAnim() { int frameTime = 75; Animation animation = newAnimation(new int[] { frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime*9, }); AnimatedImage anim = new AnimatedImage(axisBackDeathImage, animation); anim.loop(false); return anim; } public static AnimatedImage newAxisBackDeath2Anim() { int frameTime = 75; Animation animation = newAnimation(new int[] { frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime*9, }); AnimatedImage anim = new AnimatedImage(axisBackDeath2Image, animation); anim.loop(false); return anim; } public static AnimatedImage newAxisFrontDeathAnim() { int frameTime = 75; Animation animation = newAnimation(new int[] { frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime*9, }); AnimatedImage anim = new AnimatedImage(axisFrontDeathImage, animation); anim.loop(false); return anim; } public static AnimatedImage newAxisFrontDeath2Anim() { int frameTime = 50; Animation animation = newAnimation(new int[] { frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime, frameTime*9, }); AnimatedImage anim = new AnimatedImage(axisFrontDeath2Image, animation); anim.loop(false); return anim; } public static AnimatedImage newAxisExplosionDeathAnim() { // TODO return newAxisFrontDeath2Anim(); } /** * Creates a new {@link Animation} * @param obj * @return */ public static Animation newAnimation(int[] frameTimes) { AnimationFrame[] frames = new AnimationFrame[frameTimes.length]; int frameNumber = 0; for(; frameNumber < frameTimes.length; frameNumber++) { frames[frameNumber] = new AnimationFrame(frameTimes[frameNumber], frameNumber); } Animation animation = new FramedAnimation(frames); return animation; } public static AnimatedImage newAnimatedImage(int[] frameTimes, TextureRegion[] frames) { Animation animation = newAnimation(frameTimes); return new AnimatedImage(frames, animation); } public static AnimatedImage newAnimatedSplitImage(int[] frameTimes, TextureRegion image, int row, int col) { Animation animation = newAnimation(frameTimes); TextureRegion[] images = TextureUtil.splitImage(image, row, col); return new AnimatedImage(images, animation); } public static AnimatedImage newAnimatedSplitImage(int[] frameTimes, Pixmap image, int row, int col, Integer mask) { if(mask!=null) { Pixmap oldimage = image; image = TextureUtil.applyMask(image, new Color(mask)); oldimage.dispose(); } Animation animation = newAnimation(frameTimes); TextureRegion[] images = TextureUtil.splitImage(TextureUtil.tex(image), row, col); return new AnimatedImage(images, animation); } public static TextureRegion randomBloodspat() { return bloodImages[ random.nextInt(4) ]; } public static TextureRegion randomGib() { return gibImages[ random.nextInt(4) ]; } public static AnimatedImage newThompsonMuzzleFlash() { return newAnimatedImage(new int[] { 20, 20, 10, 20 }, thompsonMuzzleFlash).loop(false); } public static AnimatedImage newM1GarandMuzzleFlash() { return newAnimatedImage(new int[] { 20, 20, 10, 20 }, m1GarandMuzzleFlash).loop(false); } public static AnimatedImage newSpringfieldMuzzleFlash() { return newAnimatedImage(new int[] { 20, 20, 10, 20 }, springfieldMuzzleFlash).loop(false); } public static AnimatedImage newKar98MuzzleFlash() { return newAnimatedImage(new int[] { 20, 20, 10, 20 }, kar98MuzzleFlash).loop(false); } public static AnimatedImage newMP40MuzzleFlash() { return newAnimatedImage(new int[] { 20, 20, 10, 20 }, mp40MuzzleFlash).loop(false); } public static AnimatedImage newMP44MuzzleFlash() { return newAnimatedImage(new int[] { 50, 150, 120, 50 }, mp44MuzzleFlash).loop(false); } public static AnimatedImage newShotgunMuzzleFlash() { return newAnimatedImage(new int[] { 20, 20, 10, 20 }, shotgunMuzzleFlash).loop(false); } public static AnimatedImage newRocketMuzzleFlash() { return newAnimatedImage(new int[] { 20, 20, 10, 20 }, rocketMuzzleFlash).loop(false); } public static AnimatedImage newRiskerMuzzleFlash() { return newAnimatedImage(new int[] { 20, 20, 10, 20 }, riskerMuzzleFlash).loop(false); } public static AnimatedImage newShermanTankTracks() { return newAnimatedImage(new int[] {100}, new TextureRegion[] {shermanTankBase}); } public static AnimatedImage newShermanTankTracksDamaged() { return newAnimatedImage(new int[] {100}, new TextureRegion[] {shermanTankBaseDamaged}); } public static AnimatedImage newPanzerTankTracks() { return newAnimatedImage(new int[] {100}, new TextureRegion[] {panzerTankBase}); } public static AnimatedImage newPanzerTankTracksDamaged() { return newAnimatedImage(new int[] {100}, new TextureRegion[] {panzerTankBaseDamaged}); } }
33,424
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ImageUtil.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/ImageUtil.java
/* * leola-live * see license.txt */ package seventh.client.gfx; import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.Transparency; import java.awt.image.BufferedImage; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import javax.imageio.ImageIO; /** * Simple image utility functions * * @author Tony * */ public class ImageUtil { // public static final void main(String [] args) throws Exception { // BufferedImage img = loadImage("./assets/gfx/lightmap_flashlight.png"); // System.out.println(img); // // BufferedImage alpha = new BufferedImage(img.getWidth(), img.getHeight(), Transparency.BITMASK); // // Graphics2D g = alpha.createGraphics(); // g.setComposite(AlphaComposite.Src); // g.drawImage(img, 0, 0, null); // g.dispose(); // // for (int y = 0; y < alpha.getHeight(); y++) { // for (int x = 0; x < alpha.getWidth(); x++) { // int col = alpha.getRGB(x, y); // if ( (col<<8) == 0x0) { // alpha.setRGB(x, y, col & 0x00ffffff); // } // else if ( ((col<<8)>>8) < 0x090909) // { // // make transparent // alpha.setRGB(x, y, col & 0x00ffffff); // } // } // } // alpha.flush(); // // ImageIO.write(alpha, "png", new File("./test.png")); // // } /** * Loads an image * * @param image * @return * @throws Exception */ public static BufferedImage loadImage(String image) throws Exception { return ImageIO.read(new File(image)); } /** * Gets a subImage. * * @param image * @param x * @param y * @param width * @param height * @return */ public static BufferedImage subImage(BufferedImage image, int x, int y, int width, int height) { return image.getSubimage(x, y, width, height); } /** * Applying mask into image using specified masking color. Any Color in the * image that matches the masking color will be converted to transparent. * * @param img The source image * @param keyColor Masking color * @return Masked image */ public static BufferedImage applyMask(BufferedImage img, Color keyColor) { BufferedImage alpha = new BufferedImage(img.getWidth(), img.getHeight(), Transparency.BITMASK); Graphics2D g = alpha.createGraphics(); g.setComposite(AlphaComposite.Src); g.drawImage(img, 0, 0, null); g.dispose(); for (int y = 0; y < alpha.getHeight(); y++) { for (int x = 0; x < alpha.getWidth(); x++) { int col = alpha.getRGB(x, y); if (col == keyColor.getRGB()) { // make transparent alpha.setRGB(x, y, col & 0x00ffffff); } } } alpha.flush(); return alpha; } /** * Resizes the image * * @param image * @param width * @param height * @return */ public static BufferedImage resizeImage(BufferedImage image, int width, int height) { BufferedImage newImage = new BufferedImage(width, height, image.getColorModel().getTransparency()); Graphics2D g = newImage.createGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.drawImage(image, 0, 0, width, height, // destination 0, 0, image.getWidth(), image.getHeight(), // source null); g.dispose(); return newImage; } public static BufferedImage createImage(int width, int height) { BufferedImage newImage = new BufferedImage(width, height, Transparency.TRANSLUCENT); return newImage; } /** * Creates a tileset from an image * * @param image * @param tileWidth * @param tileHeight * @param margin * @param spacing * @return */ public static BufferedImage[] toTileSet(BufferedImage image, int tileWidth, int tileHeight, int margin, int spacing) { int nextX = margin; int nextY = margin; List<BufferedImage> images = new ArrayList<BufferedImage>(); while (nextY + tileHeight + margin <= image.getHeight()) { BufferedImage tile = image.getSubimage(nextX, nextY, tileWidth, tileHeight); images.add(tile); nextX += tileWidth + spacing; if (nextX + tileWidth + margin > image.getWidth()) { nextX = margin; nextY += tileHeight + spacing; } } return images.toArray(new BufferedImage[images.size()]); } /** * Splits the image, uses the image width/height * @param image * @param row * @param col * @return */ public static BufferedImage[] splitImage(BufferedImage image, int row, int col) { return splitImage(image, image.getWidth(), image.getHeight(), row, col); } /** * Splits the image * @param image * @param width * @param height * @param row * @param col * @return */ public static BufferedImage[] splitImage(BufferedImage image, int width, int height, int row, int col) { int total = col * row; // total returned images int frame = 0; // frame counter int w = width / col; int h = height / row; BufferedImage[] images = new BufferedImage[total]; for (int j = 0; j < row; j++) { for (int i = 0; i < col; i++) { BufferedImage tmp = image.getSubimage(i * w, j * h, w, h); images[frame++] = tmp; } } return images; } /** * A structure which removes the duplicate sub-images and contains an mapping to * how to render the full image. * * @author Tony * */ public static class OptimizedImage { public BufferedImage[] images; public int[] order; public final int width; public final int height; public final int row; public final int col; public OptimizedImage(BufferedImage[] images , int[] order , int width , int height , int row , int col) { this.images = images; this.order = order; this.width = width; this.height = height; this.row = row; this.col = col; } public int getWidth() { return width; } public int getHeight() { return height; } } public static OptimizedImage optimizeImage(BufferedImage image, int row, int col) { BufferedImage[] images = splitImage(image, row, col); int[] order = new int[images.length]; for(int i = 0; i < order.length; i++) order[i] = i; images = removeDuplicates(images, order); int width = image.getWidth(); int height = image.getHeight(); return new OptimizedImage(images, order, width, height, row, col); } public static BufferedImage[] removeDuplicates(BufferedImage[] image, int[] order) { Arrays.fill(order, -1); // Assumes all sub-images are equal size int w = image[0].getWidth(); int h = image[0].getHeight(); for(int i = 0; i < image.length; i++) { if(order[i] > -1) { image[i] = null; /* remove the image */ continue; } BufferedImage left = image[i]; scanForDuplicates(left, image, i, order, w, h); order[i] = i; } return image; } private static void scanForDuplicates(BufferedImage leftImage, BufferedImage[] images, int i, int[] order, int width, int height) { for(int j = i+1; j < images.length; j++) { BufferedImage right = images[j]; if( right != null ) { if(isDataEqual(leftImage, right, width, height)) { order[j] = i; } } } } /** * Tests to see if the data is equal * * @param left * @param right * @param width * @param height * @return */ private static boolean isDataEqual(BufferedImage left, BufferedImage right, int width, int height) { for(int x = 0; x < width; x++) { for(int y = 0; y < height; y++) { if(left.getRGB(x, y) != right.getRGB(x, y)) { return false; } } } return true; } }
9,088
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ReticleCursor.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/ReticleCursor.java
/* * see license.txt */ package seventh.client.gfx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * Represents the mouse pointer for the game. This implementation relies on an {@link TextureRegion} for the cursor * image. * * @author Tony * */ public class ReticleCursor extends Cursor { private float desiredAccuracy; //private boolean isTouched; private Sprite reticle; /** */ public ReticleCursor() { this(96, 96); } /** * @param image * the cursor image to use */ public ReticleCursor(int width, int height) { super(new Rectangle(width, height)); setColor(0xafffff00); this.setAccuracy(1); this.reticle = new Sprite(Art.reticleImg); this.reticle.rotate(90); this.reticle.setScale(0.8f); } @Override public void touchAccuracy() { //this.isTouched = true; } /* (non-Javadoc) * @see seventh.client.gfx.Cursor#setAccuracy(float) */ @Override public void setAccuracy(float accuracy) { this.desiredAccuracy = accuracy; } @Override public void update(TimeStep timeStep) { /*if(this.isTouched) { if(getAccuracy() < 0.501f) { this.isTouched = false; this.desiredAccuracy = 1f; } else { this.desiredAccuracy = 0.5f; } }*/ float delta = this.getAccuracy() - this.desiredAccuracy; if(Math.abs(delta) > 0.001f) { float speed = (delta < 0) ? 0.33f : 0.5f; float newAccuracy = this.getAccuracy() - (delta * speed); super.setAccuracy(newAccuracy); } else { super.setAccuracy(this.desiredAccuracy); } } /** * Draws the cursor on the screen * @param canvas */ @Override protected void doRender(Canvas canvas) { Vector2f cursorPos = getCursorPos(); Rectangle bounds = getBounds(); final float accuracy = getAccuracy(); final float xRange = bounds.width / 2f; final float yRange = bounds.height / 2f; final float centerSize = 5; final float markHeight = 16;//15; final float markWidth = 32;//2; final int color = getColor(); // center { //float x = cursorPos.x; //float y = cursorPos.y; //canvas.fillRect(x-1, y, centerSize, centerSize, 0xff000000); //canvas.fillRect(x, y, centerSize, centerSize, color); //canvas.fillRect(x, y, centerSize, centerSize, color); } reticle.setRotation(90); Color col = reticle.getColor(); Color.argb8888ToColor(col, color); reticle.setColor(col); // top { float x = cursorPos.x - markWidth/2f; float y = (cursorPos.y - markHeight - centerSize) - (yRange - (yRange * accuracy)); //canvas.fillRect(x, y, markWidth, markHeight, color); reticle.setPosition(x+2, y+2); canvas.drawRawSprite(reticle); } // bottom { float x = cursorPos.x - markWidth/2f; float y = (cursorPos.y + centerSize + centerSize) + (yRange - (yRange * accuracy)); //canvas.fillRect(x, y, markWidth, markHeight, color); reticle.setPosition(x+2, y-4); canvas.drawRawSprite(reticle); } reticle.setRotation(0); // left { float x = (cursorPos.x - markHeight - centerSize) - (xRange - (xRange * accuracy)); float y = cursorPos.y - markWidth/2f; //canvas.fillRect(x, y, markHeight, markWidth, color); reticle.setPosition(x-5, y+10); canvas.drawRawSprite(reticle); } // right { float x = (cursorPos.x + centerSize + centerSize) + (xRange - (xRange * accuracy)); float y = cursorPos.y - markWidth/2f; //canvas.fillRect(x, y, markHeight, markWidth, color); reticle.setPosition(x-12, y+10); canvas.drawRawSprite(reticle); } } }
4,697
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Colors.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/Colors.java
/* * see license.txt */ package seventh.client.gfx; import com.badlogic.gdx.graphics.Color; import seventh.math.Vector3f; /** * @author Tony * */ public class Colors { public static int subtract(int left, int right) { int r = ( (left>>16) & 0x000000ff) - ( (right>>16) & 0x000000ff); int g = ( (left>>8) & 0x000000ff) - ( (right>>8) & 0x000000ff); int b = ( (left>>0) & 0x000000ff) - ( (right>>0) & 0x000000ff); int result = 0xff000000 | (r<<16) | (g<<8) | (b<<0); return result; } /** * Sets the Alpha component of the color * @param color * @param alpha * @return the color merged with the supplied alpha */ public static int setAlpha(int color, int alpha) { return (alpha << 24) | ((color<<8)>>>8); } public static int setAlpha(int color, float alpha) { return setAlpha(color, (int) (255f * alpha)); } /** * Converts the {@link Vector3f} into a int color * @param v * @param alpha * @return the int color rgba */ public static int toColor(Vector3f v, float alpha) { return Color.rgba8888(v.x, v.y, v.z, alpha); } public static int toColor(float r, float g, float b, float alpha) { int c = Color.rgba8888(r,g,b, alpha); return (c >>> 8) | (c<<24); } /** * Converts the {@link Vector3f} into a int color * @param v * @return the int color rgba */ public static int toColor(Vector3f v) { return Color.rgba8888(v.x, v.y, v.z, 1.0f)<<16; } public static Vector3f toVector3f(int color) { Color c = new Color(color); return new Vector3f(c.r, c.g, c.b); } }
1,839
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Canvas.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/Canvas.java
/* * leola-live * see license.txt */ package seventh.client.gfx; import java.io.IOException; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.math.Matrix4; /** * @author Tony * */ public interface Canvas { public void enableAntialiasing(boolean b); public boolean isAntialiasingEnabled(); public void preRender(); public void postRender(); public void fboBegin(); public void fboEnd(); public void bindFrameBuffer(int id); public Texture getFrameBuffer(); public OrthographicCamera getCamera(); public void begin(); public void end(); public void flush(); public void setShader(ShaderProgram shader); public void pushShader(ShaderProgram shader); public void popShader(); // public void beginShape(); // public void endShape(); public void setColor(int color, Integer alpha); public void setClearColor(Integer color); public int getColor(); /** * Loads the font and registers it * @param filename * @throws IOException */ public void loadFont(String filename, String alias) throws IOException; public void setFont(String fontName, int size); public void setDefaultFont(); public void setDefaultFont(String fontName, int size); public GlythData getGlythData(String font, int size); public GlythData getGlythData(); /** * @param str * @return the width in pixels that the supplied str takes up */ public int getWidth(String str); /** * @param str * @return the height in pixels that the supplied str takes up */ public int getHeight(String str); public void boldFont(); public void italicFont(); public void plainFont(); public void resizeFont(float size); public void setClip(int x, int y, int width, int height); public void setCompositeAlpha(float a); public float getCompositeAlpha(); /** * @return the width */ public int getWidth(); /** * @return the height */ public int getHeight(); public double toRadians(double degrees); public double toDegrees(double radians); public void drawLine(int x1, int y1, int x2, int y2, Integer color); public void drawLine(float x1, float y1, float x2, float y2, Integer color); public void drawLine(int x1, int y1, int x2, int y2, Integer color, float thickness); public void drawLine(float x1, float y1, float x2, float y2, Integer color, float thickness); public void drawLine(int x1, int y1, int x2, int y2, Integer startColor, Integer endColor, float thickness); public void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, Integer color); public void drawTriangle(float x1, float y1, float x2, float y2, float x3, float y3, Integer color); public void drawRect(int x, int y, int width, int height, Integer color); public void drawRect(float x, float y, float width, float height, Integer color); public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, Integer color); public void fillTriangle(float x1, float y1, float x2, float y2, float x3, float y3, Integer color); public void fillRect(int x, int y, int width, int height, Integer color); public void fillRect(float x, float y, float width, float height, Integer color); public void drawCircle(float radius, int x, int y, Integer color); public void drawCircle(float radius, float x, float y, Integer color); public void fillCircle(float radius, int x, int y, Integer color); public void fillCircle(float radius, float x, float y, Integer color); public void fillArc(float x, float y, float radius, float start, float degrees, Integer color); public void drawString(String text, int x, int y, Integer color); public void drawString(String text, float x, float y, Integer color); public void drawImage(TextureRegion image, int x, int y, Integer color); public void drawImage(TextureRegion image, float x, float y, Integer color); public void drawScaledImage(TextureRegion image, int x, int y, int width, int height, Integer color); public void drawScaledImage(TextureRegion image, float x, float y, int width, int height, Integer color); public void drawSubImage(TextureRegion image, int x, int y, int imageX, int imageY, int width, int height, Integer color); public void drawSubImage(TextureRegion image, float x, float y, int imageX, int imageY, int width, int height, Integer color); public void drawRawSprite(Sprite sprite); public void drawSprite(Sprite sprite); public void drawSprite(Sprite sprite, int x, int y, Integer color); public void drawSprite(Sprite sprite, float x, float y, Integer color); public void rotate(double degree, Integer x, Integer y); public void rotate(double degree, float x, float y); public void translate(int x, int y); public void moveTo(double x, double y); public void scale(double sx, double sy); public void shear(double sx, double sy); public void clearTransform(); public void pushZoom(double zoom); public void popZoom(); public void setDefaultTransforms(); public void setTransform(Matrix4 mat); public void setProjectionMatrix(Matrix4 mat); public void enableBlending(); public void disableBlending(); public void setBlendFunction(int srcFunc, int dstFunc); public int getSrcBlendFunction(); public int getDstBlendFunction(); }
5,847
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Cursor.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/Cursor.java
/* * see license.txt */ package seventh.client.gfx; import com.badlogic.gdx.Gdx; import seventh.client.SeventhGame; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.shared.Updatable; /** * Represents the mouse pointer during menu screens, but more importantly acts as the players cursor/reticle in game. * * @author Tony * */ public abstract class Cursor implements Updatable { private Vector2f cursorPos, previousCursorPos; private Rectangle bounds; private boolean isVisible; private float mouseSensitivity; private float accuracy; private int color; private int prevX, prevY; private boolean isInverted; private boolean isClampEnabled; /** * @param bounds * the cursor size */ public Cursor(Rectangle bounds) { this.bounds = bounds; this.cursorPos = new Vector2f(); this.previousCursorPos = new Vector2f(); this.isVisible = true; this.mouseSensitivity = 1.0f; this.accuracy = 1.0f; this.isInverted = false; this.isClampEnabled = true; } /** * @return the isClampEnabled */ public boolean isClampEnabled() { return isClampEnabled; } /** * @param isClampEnabled the isClampEnabled to set */ public void setClampEnabled(boolean isClampEnabled) { this.isClampEnabled = isClampEnabled; } /** * @param isInverted the isInverted to set */ public void setInverted(boolean isInverted) { this.isInverted = isInverted; } /** * @return the isInverted */ public boolean isInverted() { return isInverted; } /** * @param color the color to set */ public void setColor(int color) { this.color = color; } /** * @param bounds the bounds to set */ public void setBounds(Rectangle bounds) { this.bounds = bounds; } /** * Sets the dimensions of the cursor * * @param width * @param height */ public void setBounds(int width, int height) { this.bounds.setSize(width, height); } /** * @param mouseSensitivity the mouseSensitivity to set */ public void setMouseSensitivity(float mouseSensitivity) { this.mouseSensitivity = mouseSensitivity; } /** * optional method to flex the accuracy */ public void touchAccuracy() { } /** * @param accuracy the accuracy to set */ public void setAccuracy(float accuracy) { this.accuracy = accuracy; if(this.accuracy < 0) this.accuracy = 0f; if(this.accuracy > 1f) this.accuracy = 1f; } /** * Centers the mouse */ public void centerMouse() { int width = SeventhGame.DEFAULT_MINIMIZED_SCREEN_WIDTH; int height = SeventhGame.DEFAULT_MINIMIZED_SCREEN_HEIGHT; int x = width/2; int y = height/2; moveNativeMouse(x, y); moveTo(x,y); } /** * Moves the native mouse * @param x * @param y */ private void moveNativeMouse(int x, int y) { Gdx.input.setCursorPosition(x,y); } /** * Clamp the cursor position so that it doesn't * move outside of the screen */ private void clamp() { int width = SeventhGame.DEFAULT_MINIMIZED_SCREEN_WIDTH; int height = SeventhGame.DEFAULT_MINIMIZED_SCREEN_HEIGHT; if(!this.isClampEnabled) { if(this.cursorPos.x < 0 || this.cursorPos.y < 0 || this.cursorPos.x > width || this.cursorPos.y > height) { Gdx.input.setCursorCatched(false); this.prevX = (int) this.previousCursorPos.x; this.prevY = (int) this.previousCursorPos.y; int windowWidth = Gdx.graphics.getWidth(); int windowHeight = Gdx.graphics.getHeight(); int nativeMouseX = (int) ((this.cursorPos.x/(float)width) * (float)windowWidth); int nativeMouseY = (int) ((this.cursorPos.y/(float)height) * (float)windowHeight); nativeMouseX = Math.min(windowWidth, nativeMouseX); nativeMouseY = Math.min(windowHeight, nativeMouseY); nativeMouseX = Math.max(0, nativeMouseX); nativeMouseY = Math.max(0, nativeMouseY); moveNativeMouse(nativeMouseX, nativeMouseY); } else { Gdx.input.setCursorCatched(true); } } if(this.cursorPos.x < 0) { this.cursorPos.x = 0f; } if(this.cursorPos.y < 0) { this.cursorPos.y = 0f; } if(this.cursorPos.x > width) { this.cursorPos.x = width; } if(this.cursorPos.y > height) { this.cursorPos.y = height; } } /** * @return the mouseSensitivity */ public float getMouseSensitivity() { return mouseSensitivity; } /** * @return the accuracy */ public float getAccuracy() { return accuracy; } /** * @return the color */ public int getColor() { return color; } /** * @return the bounds */ public Rectangle getBounds() { bounds.centerAround(getCursorPos()); return bounds; } /** * @return the isVisible */ public boolean isVisible() { return isVisible; } /** * @param isVisible the isVisible to set */ public void setVisible(boolean isVisible) { this.isVisible = isVisible; } /** * Instantly moves the cursor to the specified location. * * @param x * @param y */ public void snapTo(int x, int y) { this.cursorPos.set(x, y); this.previousCursorPos.set(this.cursorPos); } /** * Instantly moves the cursor to the specified location. * * @param screenPos */ public void snapTo(Vector2f screenPos) { snapTo((int)screenPos.x, (int)screenPos.y); } /** * Moves the cursor towards the specified location * * @param x * @param y */ public void moveTo(int x, int y) { // convert window coordinates to game screen coordinates x = (int) (((float)x / (float)Gdx.graphics.getWidth()) * (float)SeventhGame.DEFAULT_MINIMIZED_SCREEN_WIDTH); y = (int) (((float)y / (float)Gdx.graphics.getHeight()) * (float)SeventhGame.DEFAULT_MINIMIZED_SCREEN_HEIGHT); if(isVisible()) { float deltaX = this.mouseSensitivity * (this.prevX - x); float deltaY = this.mouseSensitivity * (this.prevY - y); this.previousCursorPos.set(this.cursorPos); if(this.isInverted) { this.cursorPos.x += deltaX; this.cursorPos.y += deltaY; } else { this.cursorPos.x -= deltaX; this.cursorPos.y -= deltaY; } this.prevX = x; this.prevY = y; clamp(); } } /** * Moves the cursor based on the delta movement * @param dx either 1, -1 or 0 * @param dy either 1, -1 or 0 */ public void moveByDelta(float dx, float dy) { float deltaX = this.mouseSensitivity * (dx*20); float deltaY = this.mouseSensitivity * (dy*20); this.prevX = (int)cursorPos.x; this.prevY = (int)cursorPos.y; this.previousCursorPos.set(this.cursorPos); if(this.isInverted) { this.cursorPos.x -= deltaX; this.cursorPos.y -= deltaY; } else { this.cursorPos.x += deltaX; this.cursorPos.y += deltaY; } clamp(); } /** * @return the x position */ public int getX() { return (int)this.cursorPos.x; } /** * @return the y position */ public int getY() { return (int)this.cursorPos.y; } /** * @return the cursorPos */ public Vector2f getCursorPos() { return cursorPos; } /** * @return the previousCursorPos */ public Vector2f getPreviousCursorPos() { return previousCursorPos; } /** * Draws the cursor on the screen * * @param canvas */ public void render(Canvas canvas) { if(isVisible()) { doRender(canvas); } } protected abstract void doRender(Canvas canvas); }
9,093
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Shader.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/Shader.java
/* * see license.txt */ package seventh.client.gfx; import seventh.shared.Cons; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.glutils.ShaderProgram; /** * @author Tony * */ public class Shader { private ShaderProgram shader; private String vert, frag; /** * @param vert * @param frag */ public Shader(String vert, String frag) { this.vert = vert; this.frag = frag; reload(); } /** * Reloads the shader from disk */ public void reload() { shader = new ShaderProgram(Gdx.files.internal(vert), Gdx.files.internal(frag)); if (!shader.isCompiled()) { Cons.println("Unable to compile shaders: " + vert + " : " + frag); } // Good idea to log any warnings if they exist if (shader.getLog().length() != 0) { Cons.println(shader.getLog()); } } public Shader begin() { ShaderProgram shader = getShader(); shader.begin(); return this; } public Shader end() { ShaderProgram shader = getShader(); shader.end(); return this; } public Shader setParam(String name, float v) { ShaderProgram shader = getShader(); shader.setUniformf(name, v); return this; } public Shader setParam(String name, float v1, float v2) { ShaderProgram shader = getShader(); shader.setUniformf(name, v1, v2); return this; } /** * Destroys this shader */ public void destroy() { try { getShader().dispose(); } catch(Exception ignore) {} } /** * @return the shader */ public ShaderProgram getShader() { return shader; } }
1,893
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
TankSprite.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/TankSprite.java
/* * see license.txt */ package seventh.client.gfx; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; import seventh.client.ClientPlayer; import seventh.client.entities.ClientPlayerEntity; import seventh.client.entities.vehicles.ClientTank; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.shared.TimeStep; import seventh.shared.WeaponConstants; /** * @author Tony * */ public class TankSprite implements Renderable { protected AnimatedImage tankTracksDamaged; protected Sprite tankTurretDamaged; protected AnimatedImage tankTracks; protected Sprite tankTurret; protected Sprite tankTrack; private float bobScale; private float bobTime; private float bobDir; protected ClientTank tank; protected AnimatedImage railgunFlash; protected Sprite muzzleFlash; private boolean isDestroyed; /** * @param tank * @param tankTracks * @param tankTurret * @param damagedTankTracks * @param damagedTankTurret */ protected TankSprite(ClientTank tank, AnimatedImage tankTracks, Sprite tankTurret, AnimatedImage damagedTankTracks, Sprite damagedTankTurret) { this.tank = tank; this.tankTracks = tankTracks; this.tankTurret = tankTurret; this.tankTracksDamaged = damagedTankTracks; this.tankTurretDamaged = damagedTankTurret; this.tankTrack = new Sprite(this.tankTracks.getCurrentImage()); this.bobDir = 1.0f; this.bobScale = 1.0f; this.railgunFlash = Art.newThompsonMuzzleFlash(); this.railgunFlash.loop(true); this.muzzleFlash = new Sprite(); this.isDestroyed = false; } /** * @param isDestroyed the isDestroyed to set */ public void setDestroyed(boolean isDestroyed) { this.isDestroyed = isDestroyed; } /** * @return the isDestroyed */ public boolean isDestroyed() { return isDestroyed; } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { switch(tank.getCurrentState()) { case RUNNING: case SPRINTING: case WALKING: tankTracks.update(timeStep); bobTime += timeStep.getDeltaTime();//timeStep.asFraction(); if(bobTime > 1200) { bobDir *= -1f; bobTime = 0; // if(bobDir < 0) { // bobScale = 0.98f; // } // else { // bobScale = 1.0f; // } } else { bobScale += 0.001f * bobDir; if(bobScale < 0.98f) { bobScale = 0.98f; } else if(bobScale > 1.0f) { bobScale = 1f; } } break; default: { bobScale = 1.0f; } } if(tank.isSecondaryWeaponFiring()) { this.railgunFlash.update(timeStep); } else { this.railgunFlash.reset(); } // bobScale = ((float)-Math.cos(bobTime)/50.0f) + 0.9f; // Vector2f pos = mech.getRenderPos(); // mechTorso.setPosition(pos.x, pos.y); } protected void renderTankBase(float rx, float ry, float trackAngle, Canvas canvas, Camera camera, float alpha) { rx += 0f; ry -= 15f; TextureRegion tex = isDestroyed ? tankTracksDamaged.getCurrentImage() : tankTracks.getCurrentImage(); tankTrack.setRegion(tex); tankTrack.setRotation(trackAngle); tankTrack.setOrigin(tex.getRegionWidth()/2f,tex.getRegionHeight()/2f); tankTrack.setPosition(rx, ry); canvas.drawSprite(tankTrack); } /** * Allow the implementing tank to adjust some of the rendering properties * * @param rx * @param ry * @param turretAngle * @param canvas * @param camera * @param alpha */ protected void renderTurret(float rx, float ry, float turretAngle, Canvas canvas, Camera camera, float alpha) { rx += 0f; ry -= 15f; rx += 70f; ry += 15f; float originX = 62f; Sprite turretSprite = isDestroyed ? tankTurretDamaged : tankTurret; float originY = turretSprite.getRegionHeight()/2f; turretSprite.setRotation(turretAngle); turretSprite.setOrigin(originX, originY); turretSprite.setPosition(rx,ry); canvas.drawSprite(turretSprite); } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { Rectangle bounds = tank.getBounds(); Vector2f pos = tank.getRenderPos(alpha); Vector2f cameraPos = camera.getRenderPosition(alpha); float rx = Math.round((pos.x - cameraPos.x) - (bounds.width/2.0f) + WeaponConstants.TANK_WIDTH/2f); float ry = Math.round((pos.y - cameraPos.y) - (bounds.height/2.0f) + WeaponConstants.TANK_HEIGHT/2f); rx = Math.round((pos.x+15f) - cameraPos.x); ry = Math.round((pos.y+90f) - cameraPos.y); float trackAngle = (float) (Math.toDegrees(tank.getOrientation())); renderTankBase(rx, ry, trackAngle, canvas, camera, alpha); float turretAngle = (float)Math.toDegrees(tank.getTurretOrientation()); renderTurret(rx, ry, turretAngle, canvas, camera, alpha); if(tank.isSecondaryWeaponFiring()) { TextureRegion tx = railgunFlash.getCurrentImage(); //int i = tank.getRandom().nextInt(3); //for(int i = 0; i < 3; i++) { muzzleFlash.setRegion(tx); //float xOffset = 70; //float yOffset = -100; muzzleFlash.setSize(tx.getRegionWidth()+16, tx.getRegionHeight()+16); muzzleFlash.setPosition(rx, ry); muzzleFlash.translate(0, 0); // muzzleFlash.setOrigin(12); muzzleFlash.setRotation(turretAngle+80f); // canvas.drawSprite(muzzleFlash); } } if(tank.hasOperator()) { canvas.setFont("Consola", 14); canvas.boldFont(); ClientPlayerEntity ent = tank.getOperator(); ClientPlayer player = ent.getPlayer(); float strln = RenderFont.getTextWidth(canvas, player.getName()); RenderFont.drawShadedString(canvas, player.getName(), (int)(rx+WeaponConstants.TANK_AABB_WIDTH/2)-strln*2, (int)ry+WeaponConstants.TANK_AABB_HEIGHT-100, player.getTeam().getColor() ); } } }
7,273
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
AnimationPool.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/AnimationPool.java
/* * see license.txt */ package seventh.client.gfx; /** * A pool of animations. This reduces the GC load * * @author Tony * */ public class AnimationPool { public static interface AnimationFactory { AnimatedImage newAnimation(); } private AnimatedImage[] pool; private AnimationFactory factory; private String name; /** * @param name * @param size * @param factory */ public AnimationPool(String name, int size, AnimationFactory factory) { this.name = name; this.factory = factory; this.pool = newPool(size, factory); } private AnimatedImage[] newPool(int size, AnimationFactory factory) { AnimatedImage[] frames = new AnimatedImage[size]; for(int i = 0; i < size; i++) { frames[i] = factory.newAnimation(); } return frames; } public AnimatedImage create() { // TODO: Fix bug that doesn't animate the // animations correctly is collected from the pool, // by commenting this out, it forces the pool to allocate // each call, effectively eliminating the pool /*for(int i = 0; i < pool.length; i++) { if(pool[i] != null) { AnimatedImage image = pool[i]; image.reset(); pool[i] = null; return image; } }*/ //Cons.println("*** WARNING: The animation pool '" + name + "' has been exhausted!"); return factory.newAnimation(); } public void free(AnimatedImage image) { for(int i = 0; i < pool.length; i++) { if(pool[i] == null) { pool[i] = image; } } } }
1,809
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Terminal.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/Terminal.java
/* * see license.txt */ package seventh.client.gfx; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Keys; import seventh.client.ClientSeventhConfig; import seventh.client.SeventhGame; import seventh.client.inputs.Inputs; import seventh.client.sfx.Sounds; import seventh.math.Rectangle; import seventh.shared.Console; import seventh.shared.Logger; import seventh.shared.TimeStep; import seventh.shared.Timer; import seventh.shared.Updatable; /** * @author Tony * */ public class Terminal implements Updatable, Logger { private static final int MAX_HEIGHT = SeventhGame.DEFAULT_MINIMIZED_SCREEN_HEIGHT/2; private static final int MAX_TEXT_HISTORY = 2000; private boolean isActive, isCollapsing, isOpening; private Rectangle background; private int backgroundColor; private int foregroundColor; private Timer blinkTimer; private boolean showCursor; private List<String> textBuffer; private List<String> cmdHistory; private StringBuilder inputBuffer; private int cursorIndex; private int scrollY, scrollPosition; private int cmdHistoryIndex; private DeactivateCallback callback; private Console console; private boolean queuedClear; private boolean isCtrlDown; private GlythData glythData; /** * * @author Tony * */ public static interface DeactivateCallback { void onDeactived(Terminal terminal); } private Inputs inputs = new Inputs() { @Override public boolean scrolled(int amount) { if(!isActive) { return false; } if(amount > 0) { scrollPosition -= 15; } else if (amount < 0) { scrollPosition += 15; } return true; } public boolean keyDown(int key) { if(!isActive) { return false; } switch(key) { case Keys.UP: { if(!cmdHistory.isEmpty()) { setInputText(cmdHistory.get(cmdHistoryIndex)); cmdHistoryIndex--; if(cmdHistoryIndex < 0) { cmdHistoryIndex = cmdHistory.size()-1; } } break; } case Keys.DOWN: { if(!cmdHistory.isEmpty()) { setInputText(cmdHistory.get(cmdHistoryIndex)); cmdHistoryIndex++; if(cmdHistoryIndex >= cmdHistory.size()) { cmdHistoryIndex = 0; } } break; } case Keys.LEFT: { cursorIndex--; if(cursorIndex < 0) { cursorIndex = 0; } break; } case Keys.RIGHT: { cursorIndex++; if(cursorIndex >= inputBuffer.length()) { cursorIndex = inputBuffer.length(); } break; } // case Keys.BACKSPACE: { // if(cursorIndex>0) { // inputBuffer.deleteCharAt(--cursorIndex); // if(cursorIndex < 0) { // cursorIndex = 0; // } // } // // break; // } // case Keys.FORWARD_DEL: { // if(cursorIndex<inputBuffer.length()) { // inputBuffer.deleteCharAt(cursorIndex); // } // // break; // } case Keys.HOME: { cursorIndex = 0; break; } case Keys.END: { cursorIndex = inputBuffer.length(); break; } case Keys.PAGE_UP: { scrollY = 1; break; } case Keys.PAGE_DOWN: { scrollY = -1; break; } case Keys.TAB: { String inputText = inputBuffer.toString(); List<String> cmdNames = console.find(inputText); if(!cmdNames.isEmpty()) { if(cmdNames.size() == 1) { setInputText(cmdNames.get(0) + " "); } else { console.println(""); for(String cmd : cmdNames) { console.println(cmd); } console.println(""); setInputText(findMaxMatchingChars(inputText, cmdNames)); } } break; } case Keys.CONTROL_LEFT: case Keys.CONTROL_RIGHT: isCtrlDown = true; break; case Keys.V: if(isCtrlDown) { String contents = Gdx.app.getClipboard().getContents(); if(contents != null) { inputBuffer.insert(cursorIndex, contents); cursorIndex += contents.length(); } } break; default: { } } return true; } @Override public boolean keyUp(int key) { if(!isActive) { return false; } switch(key) { case Keys.PAGE_UP: { scrollY = 0; break; } case Keys.PAGE_DOWN: { scrollY = 0; break; } case Keys.CONTROL_LEFT: case Keys.CONTROL_RIGHT: isCtrlDown = false; break; default: { } } return true; } public boolean keyTyped(char key) { if(!isActive) { return false; } switch(key) { case /*Keys.BACKSPACE*/8: { if(cursorIndex>0) { inputBuffer.deleteCharAt(--cursorIndex); if(cursorIndex < 0) { cursorIndex = 0; } } break; } case /*Keys.FORWARD_DEL*/127: { if(cursorIndex<inputBuffer.length()) { inputBuffer.deleteCharAt(cursorIndex); } break; } case '\r': case '\n': { String command = inputBuffer.toString(); if(command != null && !"".equals(command)) { cmdHistory.add(command); cmdHistoryIndex = cmdHistory.size()-1; } setInputText(""); console.execute(command); break; } default: { char c =key; if(c>31&&c<127 && c != 96) { inputBuffer.insert(cursorIndex, key); cursorIndex++; } } } return true; } }; /** * @param console * @param config */ public Terminal(Console console, ClientSeventhConfig config) { this.console = console; this.console.addLogger(this); this.isActive = false; this.blinkTimer = new Timer(true, 500); this.showCursor = true; this.background = new Rectangle(); this.backgroundColor = config.getConsoleBackgroundColor(); this.foregroundColor = config.getConsoleForegroundColor(); this.textBuffer = new LinkedList<String>(); this.inputBuffer = new StringBuilder(); this.cmdHistory = new ArrayList<String>(); } /** * Attempts to find the common characters for the matched command names * * Always assumes that cmdNames contains at least 1 entry (should be at least 2). * * @param buffer * @param cmdNames * @return the command */ private String findMaxMatchingChars(String buffer, List<String> cmdNames) { String firstCmd = cmdNames.get(0); final int bufferLength = buffer.length(); int numberOfMatchedChars = 0; boolean hasMatches = true; while(hasMatches) { final int positionToCheck = numberOfMatchedChars + bufferLength; if(firstCmd.length() > positionToCheck) { char c = cmdNames.get(0).charAt(positionToCheck); for(int i = 1; i < cmdNames.size(); i++) { String secondCmd = cmdNames.get(i); if(secondCmd.length() <= positionToCheck || secondCmd.charAt(positionToCheck) != c) { hasMatches = false; break; } } if(hasMatches) { numberOfMatchedChars++; } } else { hasMatches = false; } } String result = firstCmd.substring(0, buffer.length() + numberOfMatchedChars); return result; } /** * @param text */ public void setInputText(String text) { inputBuffer.delete(0, inputBuffer.length()); inputBuffer.append(text); this.cursorIndex = inputBuffer.length(); } /** * @return the input text */ public String getInputText() { return inputBuffer.toString(); } /** * @param text */ public void appendInputText(String text) { setInputText(inputBuffer.toString() + text); } /* (non-Javadoc) * @see seventh.shared.Logger#print(java.lang.Object) */ @Override public void print(Object msg) { if(msg!=null) { String message = msg.toString(); String[] split = message.split("\n"); for(String n : split) { this.textBuffer.add(n.replace("\t", " ")); } } } /* (non-Javadoc) * @see seventh.shared.Logger#printf(java.lang.Object, java.lang.Object[]) */ @Override public void printf(Object msg, Object... args) { String str = String.format(msg.toString(), args); println(str); } /* (non-Javadoc) * @see seventh.shared.Logger#println(java.lang.Object) */ @Override public void println(Object msg) { if(msg!=null) { String message = msg.toString(); String[] split = message.split("\n"); if(split.length> 0) { for(String n : split) { this.textBuffer.add(n.replace("\t", " ")); } } else { this.textBuffer.add(""); } } } /** * Clears the terminal window */ public void clear() { this.queuedClear = true; } /** * if we queued up a clear buffer, lets * go ahead and do so. */ private void queuedClear() { if(queuedClear) { this.textBuffer.clear(); this.scrollPosition = 0; this.scrollY = 0; this.queuedClear = false; } } /** * @return the terminal input */ public Inputs getInputs() { return inputs; } public void open() { if(!this.isActive) { toggle(); } } /** * Toggles the console * @return true if opening, false if closing */ public boolean toggle() { Sounds.playGlobalSound(Sounds.uiSelect); if(!this.isActive) { this.isActive = true; this.isOpening = true; return true; } this.isCollapsing = true; return false; } /** * @param callback */ public void setOnDeactive(DeactivateCallback callback) { this.callback = callback; } /** * @return the isActive */ public boolean isActive() { return isActive; } /** * Chomps the size if too big */ private void checkOutputSize() { if(this.textBuffer.size() > MAX_TEXT_HISTORY) { int range = this.textBuffer.size() - MAX_TEXT_HISTORY; while(range > 0) { this.textBuffer.remove(0); range--; } } } /* (non-Javadoc) * @see leola.live.Updatable#update(leola.live.TimeStep) */ @Override public void update(TimeStep timeStep) { queuedClear(); checkOutputSize(); if(this.isOpening) { if(background.height < MAX_HEIGHT) { background.height += 100; } else { this.isOpening = false; } } if(this.isCollapsing) { if(background.height > 0) { background.height -= 50; } else { this.isActive = false; this.isCollapsing = false; if(this.callback != null) { this.callback.onDeactived(this); } } } this.blinkTimer.update(timeStep); if(this.blinkTimer.isTime()) { this.showCursor = !this.showCursor; } if(scrollY>0) { scrollPosition += 5; } else if(scrollY<0) { scrollPosition -= 5; } } /** * Renders the text * @param canvas */ public void render(Canvas canvas, float alpha) { background.width = canvas.getWidth() + 50; canvas.fillRect(background.x, background.y, background.width, background.height, backgroundColor); canvas.begin(); canvas.setFont("Courier New", 14); canvas.boldFont(); // capture the font glyth data so // we can correctly make selections if( this.glythData == null ) { this.glythData = canvas.getGlythData(); } int textHeight = canvas.getHeight("W"); int outputHeight = background.height - textHeight - 5; int y = outputHeight - 10 + scrollPosition; int x = 10; boolean itemsSkipped = false; int size = this.textBuffer.size(); for(int i = size-1; i >= 0; i--) { if(y>outputHeight-10) { y -= textHeight; itemsSkipped = true; continue; } if(y<0) break; String rowText = this.textBuffer.get(i); RenderFont.drawShadedString(canvas, rowText, x, y, foregroundColor); y -= textHeight; } if(itemsSkipped) { String notificationText = "^ ^ ^ ^ ^ ^ ^ ^"; float width = RenderFont.getTextWidth(canvas, notificationText); RenderFont.drawShadedString(canvas, notificationText, background.width/2 - width/2, outputHeight - 5, foregroundColor); } canvas.end(); canvas.fillRect(background.x, outputHeight, background.width, textHeight+5, 0xff070ff); int fadeColor = 0xffacacca; canvas.drawLine(background.x, outputHeight-1, background.width, outputHeight-1, 0); canvas.drawLine(background.x, outputHeight, background.width, outputHeight, fadeColor); canvas.drawLine(background.x, background.height-1, background.width, background.height-1, fadeColor); canvas.drawLine(background.x, background.height, background.width, background.height, 0); int inputTextColor = 0xffffffff; canvas.begin(); int inputBufferY = background.height - textHeight/2; RenderFont.drawShadedString(canvas, "> ", x, inputBufferY, 0xffffffff, true, false, true); RenderFont.drawShadedString(canvas, this.inputBuffer.toString(), x + RenderFont.getTextWidth(canvas, "> ", false, true), inputBufferY, inputTextColor, true, false, true); if(showCursor) { float textWidth = RenderFont.getTextWidth(canvas, "> " + this.inputBuffer.substring(0, this.cursorIndex), false, true); RenderFont.drawShadedString(canvas, "_", x + textWidth, inputBufferY, inputTextColor, true, false, true); } canvas.end(); } }
18,677
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
AnimatedImage.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/AnimatedImage.java
/* * leola-live * see license.txt */ package seventh.client.gfx; import seventh.shared.TimeStep; import com.badlogic.gdx.graphics.g2d.TextureRegion; /** * @author Tony * */ public class AnimatedImage { /** * images */ private TextureRegion [] images; /** * The animation */ private Animation animation; /** * Constructs a new {@link AnimatedImage}. * * @param image * @param animation */ public AnimatedImage(TextureRegion [] images, Animation animation) { if ( images == null ) { throw new NullPointerException("Images can not be null!"); } this.images = images; this.animation = animation; } /** * @param loop * @return this instance for method chaining */ public AnimatedImage loop(boolean loop) { this.animation.loop(loop); return this; } public boolean isDone() { return this.animation.isDone(); } /** * Update the animation. * * @param timeStep */ public void update(TimeStep timeStep) { this.animation.update(timeStep); } /** * Return the current frame. * * @return */ public TextureRegion getCurrentImage() { return this.images[ this.animation.getCurrentFrame() ]; } /** * Get the Images that make up this animation. * @return */ public TextureRegion[] getImages() { return this.images; } /** * @param i * @return the frame */ public TextureRegion getFrame(int i) { return this.images[i]; } /** * Get the animation. * * @return */ public Animation getAnimation() { return this.animation; } /** * @return this instance for method chaining */ public AnimatedImage reset() { this.animation.reset(); return this; } /** * Set to the last frame * @return this instance for method chaining */ public AnimatedImage moveToLastFrame() { this.animation.setCurrentFrame(this.animation.getNumberOfFrames()-1); return this; } }
2,218
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
FramedAnimation.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/FramedAnimation.java
/* * leola-live * see license.txt */ package seventh.client.gfx; import java.util.Arrays; import java.util.Comparator; import seventh.shared.TimeStep; /** * @author Tony * */ public class FramedAnimation extends Animation { /** * Animation frames */ private AnimationFrame [] animationFrames; /** * Current frame */ private AnimationFrame currentAnimationFrame; /** * Current frame index */ private int currentFrame; /** * Time elapsed */ private long elapsedTime; /** * Number of frames */ private int numberOfFrames; /** * Constructs a new {@link FramedAnimation}. * * @param frames */ public FramedAnimation(final AnimationFrame[] frames) { super(); this.animationFrames = frames; this.numberOfFrames = frames.length; Arrays.sort(frames, new Comparator<AnimationFrame>() { public int compare(AnimationFrame o1, AnimationFrame o2) { return o1.getFrameNumber() - o2.getFrameNumber(); } }); setCurrentFrame(0); this.elapsedTime = 0L; } /** * Update the animation. * * @param timeStep */ public void update(TimeStep timeStep) { /* Do not increment the animation if we are paused */ if ( this.isPaused() ) { return; } /* Increment the elapsed time */ this.elapsedTime += timeStep.getDeltaTime(); /* If the frame time has expired, increment to the next frame */ if ( this.elapsedTime > this.currentAnimationFrame.getFrameTime() ) { /* Reset the elapsed timer */ this.elapsedTime -= this.currentAnimationFrame.getFrameTime(); int desiredFrame = this.currentFrame + 1; if ( !this.isLooping() && desiredFrame >= this.numberOfFrames ) { desiredFrame = this.numberOfFrames - 1; } /* Advance the frame */ setCurrentFrame(desiredFrame); } } /* (non-Javadoc) * @see leola.live.animation.Animation#isDone() */ @Override public boolean isDone() { return !isLooping() && this.currentFrame >= (this.numberOfFrames-1); } /** * The current frame number. * * @return */ public int getCurrentFrame() { return this.currentFrame; } /** * Set the current frame. * * @param frameNumber */ public void setCurrentFrame(int frameNumber) { this.currentFrame = frameNumber % this.numberOfFrames; this.currentAnimationFrame = this.animationFrames[ this.currentFrame ]; if(! this.isLooping()) { this.isDone = this.currentFrame >= (this.numberOfFrames-1); } } /* (non-Javadoc) * @see org.myriad.render.animation.Animation#getNumberOfFrames() */ @Override public int getNumberOfFrames() { return this.numberOfFrames; } /* (non-Javadoc) * @see org.myriad.render.animation.Animation#reset() */ @Override public void reset() { setCurrentFrame(0); this.elapsedTime = 0L; this.isDone = false; } }
3,308
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
AnimationFrame.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/AnimationFrame.java
/* * leola-live * see license.txt */ package seventh.client.gfx; /** * @author Tony * */ public class AnimationFrame { /** * Time to spend on this frame */ private long frameTime; /** * Frame Number */ private int frameNumber; /** * Constructs a new {@link AnimationFrame}. * * @param frameTime * @param frameNumber */ public AnimationFrame(long frameTime, int frameNumber) { this.frameTime = frameTime; this.frameNumber = frameNumber; } /** * @return the frameTime */ public long getFrameTime() { return frameTime; } /** * @return the frameNumber */ public int getFrameNumber() { return frameNumber; } }
775
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ImageBasedLightSystem.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/ImageBasedLightSystem.java
/* * see license.txt */ package seventh.client.gfx; import java.util.ArrayList; import java.util.List; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.glutils.ShaderProgram; import seventh.client.ClientGame.ClientEntityListener; import seventh.client.entities.ClientEntity; import seventh.client.gfx.effects.LightEffectShader; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.math.Vector3f; import seventh.shared.TimeStep; /** * @author Tony * */ public class ImageBasedLightSystem implements LightSystem { private Vector3f ambientColor; private float ambientIntensity; private boolean enabled; private List<ImageLight> lights; private Shader shader; private Sprite framebufferTexture; private Rectangle cameraViewport; /** * */ public ImageBasedLightSystem() { this.enabled = true; this.lights = new ArrayList<>(); // this.shader = LightEffectShader.getInstance(); this.shader = new LightEffectShader(); this.ambientColor = new Vector3f(0.3f, 0.3f, 0.7f); this.ambientIntensity = 0.7f; this.framebufferTexture = new Sprite(Art.BLACK_IMAGE); this.cameraViewport = new Rectangle(); } /* (non-Javadoc) * @see seventh.client.gfx.FrameBufferRenderable#isExpired() */ @Override public boolean isExpired() { return false; } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#getClientEntityListener() */ @Override public ClientEntityListener getClientEntityListener() { return new ClientEntityListener() { @Override public void onEntityDestroyed(ClientEntity ent) { } @Override public void onEntityCreated(ClientEntity ent) { } }; } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#addLight(seventh.client.gfx.Light) */ @Override public void addLight(Light light) { this.lights.add( (ImageLight)light); } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#newConeLight() */ @Override public Light newConeLight() { return newConeLight(new Vector2f()); } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#newConeLight(seventh.math.Vector2f) */ @Override public Light newConeLight(Vector2f pos) { ImageLight light = new ImageLight(this, pos); light.setTexture(Art.flashLight); addLight(light); return light; } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#newPointLight() */ @Override public Light newPointLight() { return newPointLight(new Vector2f()); } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#newPointLight(seventh.math.Vector2f) */ @Override public Light newPointLight(Vector2f pos) { ImageLight light = new ImageLight(this, pos); light.setTexture(Art.lightMap); addLight(light); return light; } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#removeLight(seventh.client.gfx.Light) */ @Override public void removeLight(Light light) { this.lights.remove(light); } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#removeAllLights() */ @Override public void removeAllLights() { this.lights.clear(); } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#destroy() */ @Override public void destroy() { removeAllLights(); this.shader.destroy(); } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#isEnabled() */ @Override public boolean isEnabled() { return enabled; } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#setEnabled(boolean) */ @Override public void setEnabled(boolean enabled) { this.enabled = enabled; } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#setAmbientColor(seventh.math.Vector3f) */ @Override public void setAmbientColor(Vector3f ambientColor) { this.ambientColor.set(ambientColor); } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#setAmbientColor(float, float, float) */ @Override public void setAmbientColor(float r, float g, float b) { this.ambientColor.set(r, g, b); } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#setAmbientIntensity(float) */ @Override public void setAmbientIntensity(float ambientIntensity) { this.ambientIntensity = ambientIntensity; } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#getAmbientIntensity() */ @Override public float getAmbientIntensity() { return ambientIntensity; } /* (non-Javadoc) * @see seventh.client.gfx.LightSystem#getAmbientColor() */ @Override public Vector3f getAmbientColor() { return ambientColor; } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { ShaderProgram shader = this.shader.getShader(); shader.begin(); { // this.ambientColor.set(0.3f, 0.3f, 0.4f); // this.ambientColor.set(0.9f, 0.9f, 0.9f); // this.ambientIntensity = 0.4f; shader.setUniformi("u_lightmap", 1); shader.setUniformf("ambientColor", ambientColor.x, ambientColor.y, ambientColor.z, ambientIntensity); shader.setUniformf("resolution", Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); //SeventhGame.DEFAULT_MINIMIZED_SCREEN_WIDTH, SeventhGame.DEFAULT_MINIMIZED_SCREEN_HEIGHT); } shader.end(); for(int i = 0; i < this.lights.size(); i++) { Light light = this.lights.get(i); light.update(timeStep); } } /* (non-Javadoc) * @see seventh.client.gfx.FrameBufferRenderable#frameBufferRender(seventh.client.gfx.Canvas, seventh.client.gfx.Camera) */ @Override public void frameBufferRender(Canvas canvas, Camera camera, float alpha) { Vector2f cameraPos = camera.getRenderPosition(alpha); Rectangle viewport = camera.getWorldViewPort(); final int extended = 530; cameraViewport.set( (int)cameraPos.x - extended, (int)cameraPos.y - extended , viewport.width + extended, viewport.height + extended); /* canvas.setShader(this.shader.getShader()); canvas.bindFrameBuffer(1); framebufferTexture.getTexture().bind(0); */ for(int i = 0; i < this.lights.size(); i++) { ImageLight light = this.lights.get(i); if(light.isOn()) { Vector2f pos = light.getPos(); if(cameraViewport.contains(pos)) { int rx = (int) (pos.x - cameraPos.x); int ry = (int) (pos.y - cameraPos.y); framebufferTexture.setRegion(light.getTexture()); framebufferTexture.setRotation(light.getOrientation()); int lightSize = light.getLightSize(); framebufferTexture.setBounds(rx, ry, lightSize, lightSize); framebufferTexture.setOrigin(lightSize/2, lightSize/2); Vector3f color = light.getColor(); framebufferTexture.setColor(color.x, color.y, color.z, light.getLuminacity()); canvas.drawRawSprite(framebufferTexture); } } } } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { canvas.begin(); canvas.setShader(this.shader.getShader()); canvas.bindFrameBuffer(1); Texture tex = framebufferTexture.getTexture(); if(tex!=null) { tex.bind(0); } canvas.end(); } }
8,733
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
GlythData.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/GlythData.java
/* * see license.txt */ package seventh.client.gfx; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.GlyphLayout; /** * @author Tony * */ public class GlythData { public static int getWidth(BitmapFont font, GlyphLayout bounds, String str) { bounds.setText(font, str); int textWidth = (int)bounds.width+1; // bug in libgdx, doesn't like strings ending with a space, // it ignores it if(str.endsWith(" ")) { textWidth += font.getSpaceWidth(); } return textWidth; } public static int getHeight(BitmapFont font, GlyphLayout bounds, String str) { bounds.setText(font, str); return (int)bounds.height + 8; } private BitmapFont font; private GlyphLayout bounds; /** * @param font * @param bounds */ public GlythData(BitmapFont font, GlyphLayout bounds) { super(); this.font = font; this.bounds = bounds; } /** * Get the text width of the string * * @param str * @return the width in pixels */ public int getWidth(String str) { return getWidth(font, bounds, str); } /** * The text height of the string * * @param str * @return the height in pixels */ public int getHeight(String str) { return getHeight(font, bounds, str); } }
1,513
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
KillLog.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/hud/KillLog.java
/* * see license.txt */ package seventh.client.gfx.hud; import java.util.ArrayList; import java.util.List; import seventh.client.ClientPlayer; import seventh.client.gfx.Art; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.RenderFont; import seventh.client.gfx.Renderable; import seventh.game.entities.Entity.Type; import seventh.shared.TimeStep; import seventh.shared.Timer; /** * Logs deaths * * @author Tony * */ public class KillLog implements Renderable { static class Entry { ClientPlayer killed, killer; Type mod; /** * @param killed * @param killer * @param mod */ public Entry(ClientPlayer killed, ClientPlayer killer, Type mod) { super(); this.killed = killed; this.killer = killer; this.mod = mod; } } private List<Entry> logs; private Timer timeToShow; private final int startY; /** * */ public KillLog(int x, int y, int bleedOffTime) { // this.startX = x; this.startY = y; this.timeToShow = new Timer(true, bleedOffTime); this.logs = new ArrayList<KillLog.Entry>(); } /** * Log a death * @param killed * @param killer * @param meansOfDeath */ public void logDeath(ClientPlayer killed, ClientPlayer killer, Type meansOfDeath) { if(logs.isEmpty()) { timeToShow.reset(); } else if (logs.size() > 6) { logs.remove(0); } this.logs.add(new Entry(killed, killer, meansOfDeath)); // if(killer != null) { // Cons.println(killer.getName() + " killed " + killed.getName()); // } // else { // Cons.println(killed.getName() + " died. "); // } } /* (non-Javadoc) * @see leola.live.gfx.Renderable#update(leola.live.TimeStep) */ @Override public void update(TimeStep timeStep) { timeToShow.update(timeStep); if(timeToShow.isTime()) { if(!logs.isEmpty()) { logs.remove(0); } } } /* (non-Javadoc) * @see leola.live.gfx.Renderable#render(leola.live.gfx.Canvas, leola.live.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { // canvas.resizeFont(14); canvas.setFont("Consola", 12); canvas.boldFont(); int height = canvas.getHeight("W") + 5; int startX = canvas.getWidth() - 10; int y = startY; int size = logs.size(); for(int i = 0; i < size; i++) { Entry m = logs.get(i); int killedColor = m.killed.getTeam().getColor(); int killerColor = killedColor; String message = m.killed.getName() + "^7 died"; if(m.killer != null) { killerColor = m.killer.getTeam().getColor(); if(m.killed.getId() == m.killer.getId()) { message = m.killed.getName() + "^7 took their own life"; float length = RenderFont.getTextWidth(canvas, message); RenderFont.drawShadedString(canvas, message, startX-length, y, killerColor); } else { int yOffset = (int)Art.smallAssaultRifleIcon.getHeight() / 2; float killedLength = RenderFont.getTextWidth(canvas, m.killed.getName()) + 10; float killerLength = RenderFont.getTextWidth(canvas, m.killer.getName()) + 10; int iconLength = (int)Art.smallAssaultRifleIcon.getWidth() + 10; switch(m.mod) { case EXPLOSION: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawImage(Art.smallFragGrenadeIcon, startX-killedLength-iconLength+10, y-16, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } case NAPALM_GRENADE: case GRENADE: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawImage(Art.smallFragGrenadeIcon, startX-killedLength-iconLength, y-10, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } case THOMPSON: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawSprite(Art.smallAssaultRifleIcon, startX-killedLength-iconLength, y-yOffset, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } case ROCKET: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawSprite(Art.smallRocketIcon, startX-killedLength-iconLength, y-yOffset-5, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } case SHOTGUN: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawSprite(Art.smallShotgunIcon, startX-killedLength-iconLength, y-yOffset, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } case ROCKET_LAUNCHER: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawSprite(Art.smallRocketIcon, startX-killedLength-iconLength, y-yOffset, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } case SPRINGFIELD: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawSprite(Art.smallSniperRifleIcon, startX-killedLength-iconLength, y-yOffset, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } case M1_GARAND: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawSprite(Art.smallM1GarandIcon, startX-killedLength-iconLength, y-yOffset, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } case KAR98: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawSprite(Art.smallkar98Icon, startX-killedLength-iconLength, y-yOffset, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } case MP44: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawSprite(Art.smallmp44Icon, startX-killedLength-iconLength, y-yOffset, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } case MP40: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawSprite(Art.smallmp40Icon, startX-killedLength-iconLength, y-yOffset, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } case PISTOL: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawSprite(Art.smallPistolIcon, startX-killedLength-iconLength, y-yOffset, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } case RISKER: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawSprite(Art.smallRiskerIcon, startX-killedLength-iconLength, y-yOffset, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } case FIRE: case FLAME_THROWER: { RenderFont.drawShadedString(canvas, m.killer.getName(), startX-killedLength-killerLength-iconLength, y, killerColor); canvas.drawSprite(Art.smallFlameThrowerIcon, startX-killedLength-iconLength, y-yOffset, null); RenderFont.drawShadedString(canvas, m.killed.getName(), startX-killedLength, y, killedColor); break; } default: { message = m.killer.getName() + " killed " + m.killed.getName(); float messageLength = RenderFont.getTextWidth(canvas, message) + 10; RenderFont.drawShadedString(canvas, message, startX-messageLength, y, killerColor); } } } } else { float messageLength = RenderFont.getTextWidth(canvas, message) + 10; RenderFont.drawShadedString(canvas, message, startX-messageLength, y, killedColor); } y+=height; } } }
11,687
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
AIGroupCommand.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/hud/AIGroupCommand.java
/* * see license.txt */ package seventh.client.gfx.hud; import seventh.client.ClientGame; import seventh.client.ClientPlayer; /** * @author Tony * */ public abstract class AIGroupCommand { private int shortcutKey; private String description; private AIShortcut cmd; /** * @param shortcutKey */ public AIGroupCommand(int shortcutKey, String description, AIShortcut cmd) { this.shortcutKey = shortcutKey; this.description = description; this.cmd = cmd; } /** * @return the description */ public String getDescription() { return description; } /** * @return the shortcutKey */ public int getShortcutKey() { return shortcutKey; } public void execute(ClientGame game) { // NetFireTeam fireTeam = game.getLocalPlayersFireTeam(); // TODO :: // if(fireTeam!=null) { // for(int i = 0; i < fireTeam.memberPlayerIds.length; i++) { // ClientPlayer aiPlayer = game.getPlayers().getPlayer(fireTeam.memberPlayerIds[i]); // if(aiPlayer!=null) { // cmd.execute(game.getApp().getConsole(), game, aiPlayer); // } // } // } } }
1,289
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
SlowDisplayMessageLog.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/hud/SlowDisplayMessageLog.java
/* * see license.txt */ package seventh.client.gfx.hud; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.RenderFont; import seventh.client.sfx.Sounds; import seventh.shared.TimeStep; import seventh.shared.Timer; /** * Slowly prints out a message to the log * * @author Tony * */ public class SlowDisplayMessageLog extends MessageLog { private static class Entry { Timer nextCharTimer; String currentMessage; String builtMessage; boolean isFinished; int currentIndex; Entry next; public Entry(String message) { this.nextCharTimer = new Timer(true, 500); this.nextCharTimer.reset(); this.nextCharTimer.start(); this.isFinished = false; this.currentMessage = message; this.builtMessage = ""; this.currentIndex = 0; } void add(Entry entry) { if(this.next == null) { this.next = entry; } else { next.add(entry); } } public void update(TimeStep timeStep) { if(!this.isFinished && this.currentMessage != null) { this.nextCharTimer.update(timeStep); if(this.nextCharTimer.isTime()) { if(this.currentIndex < this.currentMessage.length()) { if(this.currentMessage.charAt(currentIndex)==' ') { this.nextCharTimer.setEndTime(230); } else this.nextCharTimer.setEndTime(50); this.builtMessage += this.currentMessage.charAt(currentIndex++); Sounds.playGlobalSound(Sounds.uiKeyType); } else { this.isFinished = true; } } } else { if(this.next != null) { this.next.update(timeStep); } } } void onRenderMesage(Canvas canvas, Camera camera, String message, int x, int y) { if(this.currentMessage == message) { RenderFont.drawShadedString(canvas, this.builtMessage, x, y, 0xffffff00); } if(this.next != null) { this.next.onRenderMesage(canvas, camera, message, x, y); } } } private Entry entries; /** * @param x * @param y * @param bleedOffTime * @param maxLogEntries */ public SlowDisplayMessageLog(int x, int y, int bleedOffTime, int maxLogEntries) { super(x, y, bleedOffTime, maxLogEntries); this.entries = null; } /* (non-Javadoc) * @see seventh.client.MessageLog#log(java.lang.String) */ @Override public void log(String message) { super.log(message); if(this.entries != null) { this.entries.add( new Entry(message)); } else { this.entries = new Entry(message); } } /* (non-Javadoc) * @see seventh.client.MessageLog#expireEntry() */ @Override protected void expireEntry() { super.expireEntry(); if(this.entries != null) { this.entries = null; Sounds.playGlobalSound(Sounds.uiSelect); } } /* (non-Javadoc) * @see seventh.client.MessageLog#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { super.update(timeStep); if(this.entries != null) { this.entries.update(timeStep); } } /* (non-Javadoc) * @see seventh.client.MessageLog#onRenderMesage(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, java.lang.String, int, int) */ @Override protected void onRenderMesage(Canvas canvas, Camera camera, String message, int x, int y) { if(entries != null) { entries.onRenderMesage(canvas, camera, message, x, y); } } }
4,222
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Hud.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/hud/Hud.java
/* * The Seventh * see license.txt */ package seventh.client.gfx.hud; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.TimeZone; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; import harenet.api.Client; import seventh.client.ClientGame; import seventh.client.ClientPlayer; import seventh.client.ClientPlayers; import seventh.client.ClientSeventhConfig; import seventh.client.ClientTeam; import seventh.client.SeventhGame; import seventh.client.entities.ClientBombTarget; import seventh.client.entities.ClientPlayerEntity; import seventh.client.gfx.Art; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.Cursor; import seventh.client.gfx.MiniMap; import seventh.client.gfx.RenderFont; import seventh.client.gfx.Renderable; import seventh.client.inputs.KeyMap; import seventh.client.sfx.Sounds; import seventh.client.weapon.ClientHammer; import seventh.client.weapon.ClientWeapon; import seventh.game.entities.Entity.Type; import seventh.game.entities.PlayerEntity.Keys; import seventh.map.DefaultMapObjectFactory; import seventh.map.DefaultMapObjectFactory.TileDefinition; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.shared.TimeStep; import seventh.shared.Timer; import seventh.ui.ProgressBar; import seventh.ui.view.ProgressBarView; /** * The players Heads Up Display * * @author Tony * */ public class Hud implements Renderable { private static final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss"); static { TIME_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT")); } private ClientGame game; private SeventhGame app; private Cursor cursor; private ClientSeventhConfig config; private KillLog killLog; private MessageLog messageLog, centerLog, objectiveLog; private Scoreboard scoreboard; private EffectsLog awardsLog; private MiniMap miniMap; private ClientPlayer localPlayer; private Date gameClockDate; private ProgressBar bombProgressBar; private ProgressBarView bombProgressBarView; private long bombTime, completionTime; private boolean isAtBomb, useButtonReleased; private boolean isHoveringOverBomb; private Timer weaponHoverTimer; private boolean isHoveringOverWeapon; /** * */ public Hud(ClientGame game) { this.game = game; this.app = game.getApp(); this.config = app.getConfig(); this.localPlayer = game.getLocalPlayer(); this.cursor = app.getUiManager().getCursor(); int screenWidth = app.getScreenWidth(); this.killLog = new KillLog(screenWidth-260, 30, 5000); this.messageLog = new MessageLog(10, 60, 15000, 6); this.objectiveLog = new SlowDisplayMessageLog(10, 120, 8000, 3); this.objectiveLog.setFont(app.getTheme().getSecondaryFontName()); this.objectiveLog.setFontSize(24); this.awardsLog = new EffectsLog(-190, 100, 15); this.centerLog = new MessageLog(screenWidth/2, 50, 3000, 2) { @Override protected void onRenderMesage(Canvas canvas, Camera camera, String message, int x, int y) { // int width = canvas.getWidth(message); // canvas.drawString(message, x - (width/2), y, 0xffffffff); float width = RenderFont.getTextWidth(canvas, message); RenderFont.drawShadedString(canvas, message, x - (width/2), y, 0xffffffff); } }; this.centerLog.setFontSize(24); this.scoreboard = game.getScoreboard(); this.gameClockDate = new Date(); this.bombProgressBar = new ProgressBar(); this.bombProgressBar.setTheme(app.getTheme()); this.bombProgressBar.setBounds(new Rectangle(300, 15)); this.bombProgressBar.getBounds().centerAround(screenWidth/2, app.getScreenHeight() - 80); this.bombProgressBarView = new ProgressBarView(bombProgressBar); this.weaponHoverTimer = new Timer(false, 500); this.weaponHoverTimer.stop(); this.isHoveringOverWeapon = false; this.miniMap = new MiniMap(game); } /** * @return the killLog */ public KillLog getKillLog() { return killLog; } /** * @return the messageLog */ public MessageLog getMessageLog() { return messageLog; } /** * @return the objectiveLog */ public MessageLog getObjectiveLog() { return objectiveLog; } /** * @return the awardsLog */ public EffectsLog getAwardsLog() { return awardsLog; } /** * @return the centerLog */ public MessageLog getCenterLog() { return centerLog; } /** * Posts a death message * @param killed * @param killer * @param meansOfDeath */ public void postDeathMessage(ClientPlayer killed, ClientPlayer killer, Type meansOfDeath) { killLog.logDeath(killed, killer, meansOfDeath); if(killer!=null) { if ( killer.getId() == this.game.getLocalPlayer().getId()) { if(killer.getId() == killed.getId()) { this.centerLog.log("You killed yourself"); } else { this.centerLog.log("You killed " + killed.getName()); } } } } /** * Posts a message to the notifications * @param message */ public void postMessage(String message) { if(message!=null) { messageLog.log(message); Sounds.playGlobalSound(Sounds.logAlert); } } /** * Checks the players actions and determines if it impacts the {@link Hud} * * @param keys */ public void applyPlayerInput(float mx, float my, int keys) { /* Check to see if the user is planting or disarming * a bomb */ setAtBomb(false); boolean hasLocalPlayer = this.localPlayer != null && this.localPlayer.isAlive(); if(Keys.USE.isDown(keys)) { if(hasLocalPlayer) { Rectangle bounds = this.localPlayer.getEntity().getBounds(); List<ClientBombTarget> bombTargets = this.game.getBombTargets(); for(int i = 0; i < bombTargets.size(); i++) { ClientBombTarget target = bombTargets.get(i); if(target.isAlive()) { if(bounds.intersects(target.getBounds())) { /* if we are disarming it takes longer * than planting */ if(target.isBombPlanted()) { setBombCompletionTime(5_000); } else { setBombCompletionTime(3_000); } setAtBomb(true); break; } } } } } if(hasLocalPlayer) { ClientPlayerEntity ent = this.localPlayer.getEntity(); ClientWeapon weapon = ent.getWeapon(); if(weapon!=null && weapon.isReloading()) { cursor.setAccuracy(0); cursor.setColor(0x6fffffff); } else { if(game.isHoveringOverEnemy(mx, my)) { cursor.setColor(0xafff0000); } else { cursor.setColor(0xafffff00); } } } else { cursor.setColor(0xafffff00); } } /** * @param isAtBomb the isAtBomb to set */ public void setAtBomb(boolean isAtBomb) { this.isAtBomb = isAtBomb; } /** * @return the isAtBomb */ public boolean isAtBomb() { return isAtBomb; } /** * @param completionTime the completionTime to set */ public void setBombCompletionTime(long completionTime) { this.completionTime = completionTime; } private void updateProgressBar(TimeStep timeStep) { if(this.isAtBomb) { /* this forces the user to release the USE key * which therefore doesn't spaz out the progress bar * with continuous repeated progress */ if(useButtonReleased) { bombTime += timeStep.getDeltaTime(); float percentageCompleted = (float) ((float)bombTime / this.completionTime); bombProgressBar.setProgress( (int)(percentageCompleted * 100)); bombProgressBar.show(); if(bombProgressBar.getProgress() >= 99) { bombTime = 0; bombProgressBar.hide(); useButtonReleased = false; } } } else { bombProgressBar.hide(); bombProgressBar.setProgress(0); bombTime = 0; useButtonReleased = true; } bombProgressBarView.update(timeStep); } /* * (non-Javadoc) * @see leola.live.gfx.Renderable#update(leola.live.TimeStep) */ @Override public void update(TimeStep timeStep) { killLog.update(timeStep); messageLog.update(timeStep); centerLog.update(timeStep); objectiveLog.update(timeStep); awardsLog.update(timeStep); miniMap.update(timeStep); // if the player is under the mini-map, hide it int miniMapAlpha = scoreboard.isVisible() ? 0x3f : 0x8f; ClientPlayer player = game.getLocalPlayer(); if(player.isAlive()) { Vector2f cameraPos = game.getCamera().getPosition(); Vector2f playerPos = player.getEntity().getCenterPos(); float x = playerPos.x - cameraPos.x; float y = playerPos.y - cameraPos.y; if(miniMap.intersectsMiniMap(x, y)) { miniMapAlpha = 0x0a; } } miniMap.setMapAlpha(miniMapAlpha); updateProgressBar(timeStep); isHoveringOverBomb = game.isHoveringOverBomb(); isHoveringOverWeapon = game.isNearDroppedItem(this.localPlayer.getEntity()); if(isHoveringOverWeapon) { weaponHoverTimer.start(); weaponHoverTimer.update(timeStep); } else { weaponHoverTimer.stop(); } } /* (non-Javadoc) * @see leola.live.gfx.Renderable#render(leola.live.gfx.Canvas, leola.live.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { if(this.config.showFps()) { canvas.setFont("Consola", 12); canvas.drawString("FPS: " + app.getFps(), canvas.getWidth() - 60, 10, 0xff10f0ef); } miniMap.render(canvas, camera, alpha); killLog.render(canvas, camera, 0); messageLog.render(canvas, camera, 0); centerLog.render(canvas, camera, 0); objectiveLog.render(canvas, camera, 0); awardsLog.render(canvas, camera, 0); boolean isPlayerAlive = localPlayer.isAlive(); if(isPlayerAlive) { ClientPlayerEntity ent = localPlayer.getEntity(); ClientWeapon weapon = ent.getWeapon(); if(!ent.isOperatingVehicle()) { drawWeaponIcons(canvas, camera, weapon); drawGrenadeIcons(canvas, ent.getNumberOfGrenades()); drawActiveTile(canvas, localPlayer, weapon); } drawHealth(canvas, ent.getHealth()); } else { drawHealth(canvas, 0); } drawScore(canvas); drawPlayersRemaining(canvas); drawClock(canvas); drawSpectating(canvas); if(game.getGameType()==seventh.game.game_types.GameType.Type.OBJ && isPlayerAlive) { ClientPlayerEntity ent = localPlayer.getEntity(); if(!ent.isOperatingVehicle()) { ClientTeam attackingTeam = game.getAttackingTeam(); boolean isAttacker = false; if(attackingTeam!=null) { isAttacker = this.localPlayer.getTeam().equals(attackingTeam); } if(isHoveringOverBomb) { if(isAttacker) { drawPlantBombNotification(canvas); } else { drawDefuseBombNotification(canvas); } } //drawObjectiveStance(canvas, isAttacker); drawBombProgressBar(canvas, camera); } } drawPickupWeaponNotication(canvas); drawEnterVehicleNotication(canvas); if(this.config.showDebugInfo()) { drawMemoryUsage(canvas); drawNetworkUsage(canvas); } if(this.scoreboard.isVisible()) { this.scoreboard.drawScoreboard(canvas); } } private void drawWeaponIcons(Canvas canvas, Camera camera, ClientWeapon weapon) { if(weapon!=null) { canvas.setFont("Consola", 14); canvas.boldFont(); if(!(weapon instanceof ClientHammer)) { RenderFont.drawShadedString(canvas, weapon.getAmmoInClip() + " | " + weapon.getTotalAmmo() , canvas.getWidth() - 200 , canvas.getHeight() - 50, 0xffffff00); } TextureRegion icon = weapon.getWeaponIcon(); if(icon!=null) { canvas.drawImage(icon, canvas.getWidth() - icon.getRegionWidth() - 10, canvas.getHeight() - icon.getRegionHeight() - 30, null); } } } private void drawGrenadeIcons(Canvas canvas, int numberOfGrenades) { Sprite sprite = this.localPlayer.getEntity().isSmokeGrenades() ? Art.smokeGrenadeIcon : Art.fragGrenadeIcon; int imageWidth = sprite.getRegionWidth(); canvas.drawImage(sprite, 10, canvas.getHeight() - sprite.getRegionHeight() - 20, 0xffffff00); canvas.setFont("Consola", 14); canvas.boldFont(); RenderFont.drawShadedString(canvas, "x " + numberOfGrenades, imageWidth+20, canvas.getHeight() - 30, 0xffffff00); } private void drawScore(Canvas canvas) { canvas.setFont("Consola", 18); float textLen = RenderFont.getTextWidth(canvas, "WWWWW"); float x = canvas.getWidth() / 2 - textLen; float y = canvas.getHeight() - 10; int width = 50; int height = 20; canvas.fillRect(x, y-15, width, height, 0x8fffffff & ClientTeam.ALLIES.getColor()); canvas.drawRect(x, y-15, width, height, 0xff000000); String txt = scoreboard.getAlliedScore() + ""; RenderFont.drawShadedString(canvas, txt, x + (width - RenderFont.getTextWidth(canvas, txt)) - 1, y, 0xffffffff); x += textLen + 2; canvas.fillRect(x-2, y-15, 2, height, 0xff000000); canvas.fillRect(x, y-15, width, height, 0x8fffffff & ClientTeam.AXIS.getColor()); canvas.drawRect(x, y-15, width, height, 0xff000000); txt = scoreboard.getAxisScore() + ""; RenderFont.drawShadedString(canvas, txt, x + 4, y, 0xffffffff); } private void drawPlayersRemaining(Canvas canvas) { seventh.game.game_types.GameType.Type type = game.getGameType(); if(type!=null && (type.equals(seventh.game.game_types.GameType.Type.OBJ) || type.equals(seventh.game.game_types.GameType.Type.SVR))) { int numberOfAxisAlive = 0; int numberOfAlliedAlive = 0; ClientPlayers players = game.getPlayers(); for(int i = 0; i < players.getMaxNumberOfPlayers(); i++) { ClientPlayer player = players.getPlayer(i); if(player!=null) { if(player.isAlive()) { if(player.getTeam()==ClientTeam.ALLIES) { numberOfAlliedAlive++; } else { numberOfAxisAlive++; } } } } int x = 200; int y = canvas.getHeight() - 40; canvas.fillCircle(14, x + 2, y + 2, 0xff000000); canvas.fillCircle(13, x + 3, y + 3, 0xffffffff); canvas.drawImage(Art.alliedIcon, x, y, null); RenderFont.drawShadedString(canvas, Integer.toString(numberOfAlliedAlive), x + 40, y + 20, ClientTeam.ALLIES.getColor()); x += 70; canvas.fillCircle(13, x + 3, y + 3, 0xffffffff); canvas.drawImage(Art.axisIcon, x, y, null); RenderFont.drawShadedString(canvas, Integer.toString(numberOfAxisAlive), x + 40, y + 20, ClientTeam.AXIS.getColor()); } } private void drawClock(Canvas canvas) { this.gameClockDate.setTime(game.getGameClock()); String time = TIME_FORMAT.format(gameClockDate); int timeX = canvas.getWidth()/2-40; int timeY = 25; canvas.setFont("Consola", 24); RenderFont.drawShadedString(canvas, time, timeX, timeY, 0xffffff00); } private void drawSpectating(Canvas canvas) { if(localPlayer.isSpectating()) { String message = "Spectating"; ClientPlayer spectated = game.getPlayers().getPlayer(localPlayer.getSpectatingPlayerId()); if(spectated!=null) { message += ": " + spectated.getName(); } float width = RenderFont.getTextWidth(canvas, message); RenderFont.drawShadedString(canvas, message, canvas.getWidth()/2 - (width/2), canvas.getHeight() - canvas.getHeight("W") - 25, 0xffffffff); } } private void drawActiveTile(Canvas canvas, ClientPlayer player, ClientWeapon weapon) { if(weapon instanceof ClientHammer) { DefaultMapObjectFactory factory = (DefaultMapObjectFactory) game.getMap().getMapObjectFactory(); TileDefinition def = factory.getTileDefinitions().get(player.getActiveTileId()); if(def != null) { TextureRegion tileTex = game.getMap().geTilesetAtlas().getTile(def.tileId); if(tileTex != null) { canvas.drawScaledImage(tileTex, 695, 430, 16, 16, 0xffffffff); } } } } private void drawHealth(Canvas canvas, int health) { int x = canvas.getWidth() - 125; int y = canvas.getHeight() - 25; canvas.fillRect( x, y, 100, 15, 0x7fFF0000 ); if (health > 0) { canvas.fillRect( x, y, (100 * health/100), 15, 0xff9aFF1a ); } //canvas.drawLine(x, y, x, y + 10, 0xff0000ff, 0x0000000a, 440); //canvas.drawRect(x, y, 100, 15, 0xbf000000); //canvas.drawRect(x, y+2, 100, 13, 0x9f000000); // add a shadow effect canvas.drawLine( x, y+1, x+100, y+1, 0x8f000000 ); canvas.drawLine( x, y+2, x+100, y+2, 0x5f000000 ); canvas.drawLine( x, y+3, x+100, y+3, 0x2f000000 ); canvas.drawLine( x, y+4, x+100, y+4, 0x0f000000 ); canvas.drawLine( x, y+5, x+100, y+5, 0x0b000000 ); y = y+15; canvas.drawLine( x, y-5, x+100, y-5, 0x0b000000 ); canvas.drawLine( x, y-4, x+100, y-4, 0x0f000000 ); canvas.drawLine( x, y-3, x+100, y-3, 0x2f000000 ); canvas.drawLine( x, y-2, x+100, y-2, 0x5f000000 ); canvas.drawLine( x, y-1, x+100, y-1, 0x8f000000 ); /* // canvas.drawLine( x, y+0, x+100, y+0, 0xff000000, 2 ); canvas.drawLine( x, y+1, x+100, y+1, 0x8f000000, 4 ); canvas.drawLine( x, y+2, x+100, y+2, 0x5f000000, 4 ); canvas.drawLine( x, y+3, x+100, y+3, 0x2f000000, 4 ); canvas.drawLine( x, y+4, x+100, y+4, 0x0f000000, 4 ); canvas.drawLine( x, y+5, x+100, y+5, 0x0b000000, 4 ); canvas.drawLine( x, y+6, x+100, y+6, 0x0a000000, 4 ); //canvas.drawLine( x, y+7, x+100, y+7, 0x5f000000, 2 ); canvas.drawLine( x, y+8, x+100, y+8, 0xf000000, 2 ); canvas.drawLine( x, y+9, x+100, y+9, 0x0b000000, 2 ); canvas.drawLine( x, y+10, x+100, y+10, 0x0b000000, 2 ); canvas.drawLine( x, y+11, x+100, y+11, 0x0a000000, 2 ); canvas.drawLine( x, y+12, x+100, y+12, 0x0a000000, 2 );// y = y+15; canvas.drawLine( x, y-6, x+100, y-6, 0x0a000000, 4 ); canvas.drawLine( x, y-5, x+100, y-5, 0x0b000000, 4 ); canvas.drawLine( x, y-4, x+100, y-4, 0x0f000000, 4 ); canvas.drawLine( x, y-3, x+100, y-3, 0x2f000000, 4 ); canvas.drawLine( x, y-2, x+100, y-2, 0x5f000000, 4 ); canvas.drawLine( x, y-1, x+100, y-1, 0x8f000000, 4 ); // canvas.drawLine( x, y-0, x+100, y-0, 0xff000000, 2 ); canvas.drawRect( x, y-15, 100, 15, 0xff000000 ); */ canvas.drawRect( x, y-15, 100, 15, 0xff000000 ); // Art.healthIcon.setSize(12, 12); canvas.drawSprite(Art.healthIcon, x - 20, y - 16, null); } private void drawBombProgressBar(Canvas canvas, Camera camera) { this.bombProgressBarView.render(canvas, camera, 0); } private void drawMemoryUsage(Canvas canvas) { Runtime runtime = Runtime.getRuntime(); long maxMemory = runtime.totalMemory() / (1024*1024); long usedMemory = maxMemory - runtime.freeMemory() / (1024*1024); int x = 12; int y = canvas.getHeight() - 125; canvas.fillRect( x, y, 100, 15, 0x9f696969 ); if (usedMemory > 0 && maxMemory > 0) { double percentage = ((double)usedMemory / (double)maxMemory); canvas.fillRect( x, y, (int)(100 * percentage), 15, 0xaf2f2f2f ); } // add a shadow effect canvas.drawLine( x, y+1, x+100, y+1, 0x8f000000 ); canvas.drawLine( x, y+2, x+100, y+2, 0x5f000000 ); canvas.drawLine( x, y+3, x+100, y+3, 0x2f000000 ); canvas.drawLine( x, y+4, x+100, y+4, 0x0f000000 ); canvas.drawLine( x, y+5, x+100, y+5, 0x0b000000 ); y = y+15; canvas.drawLine( x, y-5, x+100, y-5, 0x0b000000 ); canvas.drawLine( x, y-4, x+100, y-4, 0x0f000000 ); canvas.drawLine( x, y-3, x+100, y-3, 0x2f000000 ); canvas.drawLine( x, y-2, x+100, y-2, 0x5f000000 ); canvas.drawLine( x, y-1, x+100, y-1, 0x8f000000 ); canvas.drawRect( x, y-15, 100, 15, 0xff000000 ); canvas.setFont("Consola", 14); canvas.drawString(usedMemory + " / " + maxMemory + " MiB", x, y - 20, 0x6f00CC00); } /** * Network usage * * @param canvas */ private void drawNetworkUsage(Canvas canvas) { int x = 12; int y = canvas.getHeight() - 150; int color = 0x6f00CC00; canvas.setFont("Consola", 14); Client client = app.getClientConnection().getClient(); canvas.drawString("Avg. R: " + client.getAvgBitsPerSecRecv() + " B/S", x, y - 20, color); canvas.drawString("Avg. S: " + client.getAvgBitsPerSecSent() + " B/S", x, y - 35, color); canvas.drawString("Drop : " + client.getNumberOfDroppedPackets(), x, y - 50, color); canvas.drawString("Tot. R: " + client.getNumberOfBytesReceived()/1024 + " KiB", x, y - 70, color); canvas.drawString("Tot. S: " + client.getNumberOfBytesSent()/1024 + " KiB", x, y - 85, color); String compressedBytes = client.getNumberOfBytesCompressed()>1024? client.getNumberOfBytesCompressed()/1024 + " KiB" : client.getNumberOfBytesCompressed() + " B"; canvas.drawString("Comp B: " + compressedBytes, x, y - 100, color); } private void drawDefuseBombNotification(Canvas canvas) { drawBombNotification(canvas, false); } private void drawPlantBombNotification(Canvas canvas) { drawBombNotification(canvas, true); } private void drawBombNotification(Canvas canvas, boolean isAttacking) { KeyMap keyMap = app.getKeyMap(); String action = isAttacking ? "plant" : "defuse"; String text = "Hold the '" + keyMap.keyString(keyMap.getUseKey()) +"' key to " + action + " the bomb."; drawMessage(canvas, text); } private void drawEnterVehicleNotication(Canvas canvas) { if(game.isNearVehicle(this.localPlayer.getEntity())) { KeyMap keyMap = app.getKeyMap(); String text = "Press the '" + keyMap.keyString(keyMap.getUseKey()) +"' key to enter the vehicle"; drawMessage(canvas, text); } } private void drawPickupWeaponNotication(Canvas canvas) { if(isHoveringOverWeapon && weaponHoverTimer.isExpired()) { KeyMap keyMap = app.getKeyMap(); String text = "Press the '" + keyMap.keyString(keyMap.getDropWeaponKey()) +"' key to pick up or swap weapons"; drawMessage(canvas, text); } } private void drawMessage(Canvas canvas, String text) { canvas.setFont("Consola", 18); float width = RenderFont.getTextWidth(canvas, text); RenderFont.drawShadedString(canvas, text, canvas.getWidth()/2 - width/2, 140, 0xffffff00); } // private void drawObjectiveStance(Canvas canvas, boolean isAttacking) { // int defaultColor = 0xffffffff; // ClientTeam localTeam = game.getLocalPlayer().getTeam(); // int teamColor = (localTeam!=null) ? localTeam.getColor() : defaultColor; // // //isAttacking = false; // TextureRegion tex = isAttacking ? Art.attackerIcon : Art.defenderIcon; // canvas.drawScaledImage(tex, 380 - (tex.getRegionWidth()/2), canvas.getHeight() - tex.getRegionHeight() + 15, 45, 45, teamColor); // // } }
27,322
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
EffectsLog.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/hud/EffectsLog.java
/* * The Seventh * see license.txt */ package seventh.client.gfx.hud; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.Renderable; import seventh.client.gfx.effects.Effect; import seventh.client.gfx.effects.Effects; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * @author Tony * */ public class EffectsLog implements Renderable { private Effects logs; private final int maxLogEntries; private final int startX, startY; /** * @param x * @param y * @param bleedOffTime * @param maxLogEntries */ public EffectsLog(int x, int y, int maxLogEntries) { this.startX = x; this.startY = y; this.maxLogEntries = maxLogEntries; this.logs = new Effects(); } public Vector2f nextOffset() { Vector2f pos = new Vector2f(startX, startY); pos.y += ((logs.size()+1) * 50); return pos; } /** * @param message * @param color */ public void addEffect(Effect effect) { if (logs.size() > maxLogEntries) { expireEntry(); } this.logs.addEffect(effect); } public void clearLogs() { logs.clearEffects(); } protected void expireEntry() { } @Override public void update(TimeStep timeStep) { this.logs.update(timeStep); } @Override public void render(Canvas canvas, Camera camera, float alpha) { this.logs.render(canvas, camera, alpha); } }
1,666
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
AIShortcut.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/hud/AIShortcut.java
/* * see license.txt */ package seventh.client.gfx.hud; import seventh.client.ClientGame; import seventh.client.ClientPlayer; import seventh.client.ClientPlayers; import seventh.client.ClientTeam; import seventh.client.entities.ClientPlayerEntity; import seventh.math.Vector2f; import seventh.shared.Console; /** * Sends an AI command * * @author Tony * */ public abstract class AIShortcut { private int shortcutKey; private String description; /** * @param shortcutKey */ public AIShortcut(int shortcutKey, String description) { this.shortcutKey = shortcutKey; this.description = description; } /** * @return the description */ public String getDescription() { return description; } /** * @return the shortcutKey */ public int getShortcutKey() { return shortcutKey; } /** * Sends the command * * @param console * @param game * @param aiPlayer */ public abstract void execute(Console console, ClientGame game, ClientPlayer aiPlayer); /** * @param game * @return the id of the bot to send the command to */ protected int getBotId(ClientGame game) { int botId = -1; if(game.isLocalPlayerCommander()) { ClientPlayerEntity bot = game.getSelectedEntity(); if(bot != null && bot.isAlive()) { botId = bot.getId(); } } else { ClientPlayer localPlayer = game.getLocalPlayer(); if(localPlayer.isAlive()) { botId = findClosestBot(game, localPlayer); } } return botId; } /** * Finds the closest friendly bot * @param game * @return the id of the closest bot, or -1 if no bots are available. */ protected int findClosestBot(ClientGame game, ClientPlayer otherPlayer) { ClientPlayers players = game.getPlayers(); if(!otherPlayer.isAlive()) { return -1; } ClientTeam team = otherPlayer.getTeam(); int closestBot = -1; float closestDistance = -1f; for(int i = 0; i < players.getMaxNumberOfPlayers(); i++) { ClientPlayer player = players.getPlayer(i); if(player != null && otherPlayer != player && player.isAlive() && player.isBot()) { if(player.getTeam().equals(team)) { Vector2f pos = otherPlayer.getEntity().getPos(); Vector2f botPos = player.getEntity().getPos(); float dist = Vector2f.Vector2fDistanceSq(pos, botPos); if(closestBot == -1 || dist < closestDistance) { closestBot = i; closestDistance = dist; } } } } return closestBot; } /** * Get the mouse position in world coordinates * * @param game * @return the mouse position in world coordinates */ protected Vector2f getMouseWorldPosition(ClientGame game) { Vector2f mouse = game.getApp().getUiManager().getCursor().getCursorPos(); Vector2f worldPosition = game.screenToWorldCoordinates( (int) mouse.x, (int) mouse.y); Vector2f.Vector2fSnap(worldPosition, worldPosition); return worldPosition; } }
3,558
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
MessageLog.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/hud/MessageLog.java
/* * The Seventh * see license.txt */ package seventh.client.gfx.hud; import java.util.ArrayList; import java.util.List; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.RenderFont; import seventh.client.gfx.Renderable; import seventh.shared.TimeStep; import seventh.shared.Timer; /** * @author Tony * */ public class MessageLog implements Renderable { private List<String> logs; private Timer timeToShow; private final int maxLogEntries; private final int startX, startY; private int fontSize; private String font; /** * @param x * @param y * @param bleedOffTime * @param maxLogEntries */ public MessageLog(int x, int y, int bleedOffTime, int maxLogEntries) { this.startX = x; this.startY = y; this.maxLogEntries = maxLogEntries; this.fontSize = 12; this.font = "Consola"; this.timeToShow = new Timer(true, bleedOffTime); this.logs = new ArrayList<String>(); } /** * Enables or disables the bleeding off of messages (removing them after * X amount of seconds) * * @param bleedOffEnabled */ public void enableBleedOff(boolean bleedOffEnabled) { if(!bleedOffEnabled) { this.timeToShow.stop(); } else { this.timeToShow.start(); } } /** * @param fontSize the fontSize to set */ public void setFontSize(int fontSize) { this.fontSize = fontSize; } /** * @param font the font to set */ public void setFont(String font) { this.font = font; } /** * @param message * @param color */ public void log(String message) { if(logs.isEmpty()) { timeToShow.reset(); } else if (logs.size() > maxLogEntries) { expireEntry(); } this.logs.add(message); } public void clearLogs() { logs.clear(); } protected void expireEntry() { logs.remove(0); } /* (non-Javadoc) * @see leola.live.gfx.Renderable#update(leola.live.TimeStep) */ @Override public void update(TimeStep timeStep) { timeToShow.update(timeStep); if(timeToShow.isTime()) { if(!logs.isEmpty()) { expireEntry(); } } } /** * Renders the message * * @param canvas * @param camera * @param message * @param x * @param y */ protected void onRenderMesage(Canvas canvas, Camera camera, String message, int x, int y) { RenderFont.drawShadedString(canvas, message, x, y, 0xFFffffff); } /* (non-Javadoc) * @see leola.live.gfx.Renderable#render(leola.live.gfx.Canvas, leola.live.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { //canvas.resizeFont(this.fontSize); canvas.setFont(font, fontSize); canvas.boldFont(); int height = canvas.getHeight("W") + 5; int y = startY; int size = logs.size(); for(int i = 0; i < size; i++) { String message = logs.get(i); // int width = canvas.getWidth(message); // if(startX + width > canvas.getWidth()) { // TODO wrap the text // } onRenderMesage(canvas, camera, message, startX, y); y+=height; } } }
3,673
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
AIShortcuts.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/hud/AIShortcuts.java
/* * see license.txt */ package seventh.client.gfx.hud; import java.util.ArrayList; import java.util.List; import com.badlogic.gdx.Input.Keys; import seventh.client.ClientGame; import seventh.client.ClientPlayer; import seventh.client.ClientPlayers; import seventh.client.inputs.Inputs; import seventh.client.inputs.KeyMap; import seventh.math.Vector2f; import seventh.shared.Console; /** * @author Tony * */ public class AIShortcuts { private static final int FOLLOW_ME=0, //SUPRESS_FIRE=1, //MOVE_TO=2, //TAKE_COVER=3, DEFEND_LEADER=4 ; private int[] shortcuts; private boolean[] isDown; private boolean[] isGroupDown; private List<AIShortcut> commands; private List<AIGroupCommand> groupCommands; private KeyMap keyMap; /** * */ public AIShortcuts(KeyMap keyMap) { this.keyMap = keyMap; // TODO: Allow shortcuts to be configurable this.commands = new ArrayList<AIShortcut>(); commands.add(new FollowMeAIShortcut(Keys.NUM_1)); commands.add(new SurpressFireAIShortcut(Keys.NUM_2)); commands.add(new MoveToAIShortcut(Keys.NUM_3)); commands.add(new TakeCoverAIShortcut(Keys.NUM_4)); commands.add(new DefendLeaderAIShortcut(Keys.NUM_5)); commands.add(new PlantBombAIShortcut(Keys.NUM_6)); commands.add(new DefuseBombAIShortcut(Keys.NUM_7)); commands.add(new DefendPlantedBombAIShortcut(Keys.NUM_8)); this.shortcuts = new int[commands.size()]; this.isDown = new boolean[this.shortcuts.length]; for(int i = 0; i < this.shortcuts.length; i++) { this.shortcuts[i] = commands.get(i).getShortcutKey(); } this.groupCommands = new ArrayList<>(); this.groupCommands.add(new RegroupAIGroupCommand(Keys.F1)); this.groupCommands.add(new DefendAIGroupCommand(Keys.F2)); this.isGroupDown = new boolean[this.groupCommands.size()]; } /** * @return the commands */ public List<AIShortcut> getCommands() { return commands; } /** * Check and see if any of the {@link AIShortcut} should be executed * * @param inputs * @param game */ public boolean checkShortcuts(Inputs inputs, ClientGame game, int memberIndex) { ClientPlayer aiPlayer = null; // TODO: // game.getPlayerByFireTeamId(memberIndex); boolean result = false; for(int i = 0; i < this.shortcuts.length; i++) { boolean isKeyDown = inputs.isKeyDown(this.shortcuts[i]); if(isKeyDown) { this.isDown[i] = true; } if(this.isDown[i] && !isKeyDown) { this.commands.get(i).execute(game.getApp().getConsole(), game, aiPlayer); result = true; } if(!isKeyDown) { this.isDown[i] = false; } } return result; } public boolean checkGroupCommands(Inputs inputs, ClientGame game) { boolean result = false; for(int i = 0; i < this.groupCommands.size(); i++) { AIGroupCommand cmd = this.groupCommands.get(i); boolean isKeyDown = inputs.isKeyDown(cmd.getShortcutKey()); if(isKeyDown) { this.isGroupDown[i] = true; } if(this.isGroupDown[i] && !isKeyDown) { cmd.execute(game); result = true; } if(!isKeyDown) { this.isGroupDown[i] = false; } } return result; } public static class FollowMeAIShortcut extends AIShortcut { /** * @param shortcutKey */ public FollowMeAIShortcut(int shortcutKey) { super(shortcutKey, "Call for a partner"); } /* (non-Javadoc) * @see seventh.client.AIShortcut#execute(seventh.client.ClientGame) */ @Override public void execute(Console console, ClientGame game, ClientPlayer aiPlayer) { int botId = aiPlayer!=null ? aiPlayer.getId() : getBotId(game); if(botId > -1) { ClientPlayers players = game.getPlayers(); ClientPlayer bot = players.getPlayer(botId); int playerId = game.isLocalPlayerCommander() ? findClosestBot(game, bot) : game.getLocalPlayer().getId(); console.execute("ai " + botId + " followMe " + playerId); console.execute("team_say " + bot.getName() + " follow me!" ); //console.execute("speech " + 2); } } } public static class SurpressFireAIShortcut extends AIShortcut { /** * @param shortcutKey * @param description */ public SurpressFireAIShortcut(int shortcutKey) { super(shortcutKey, "Call for surpressing fire"); } /* (non-Javadoc) * @see seventh.client.AIShortcut#execute(seventh.shared.Console, seventh.client.ClientGame) */ @Override public void execute(Console console, ClientGame game, ClientPlayer aiPlayer) { int botId = aiPlayer!=null ? aiPlayer.getId() : getBotId(game); if(botId > -1) { ClientPlayers players = game.getPlayers(); Vector2f worldPosition = getMouseWorldPosition(game); console.execute("ai " + botId+ " surpressFire " + (int)worldPosition.x + " " + (int)worldPosition.y); console.execute("team_say " + players.getPlayer(botId).getName() + " surpress fire!" ); } } } public static class MoveToAIShortcut extends AIShortcut { /** * @param shortcutKey * @param description */ public MoveToAIShortcut(int shortcutKey) { super(shortcutKey, "Move to here"); } /* (non-Javadoc) * @see seventh.client.AIShortcut#execute(seventh.shared.Console, seventh.client.ClientGame) */ @Override public void execute(Console console, ClientGame game, ClientPlayer aiPlayer) { int botId = aiPlayer!=null ? aiPlayer.getId() : getBotId(game); if(botId > -1) { ClientPlayers players = game.getPlayers(); Vector2f worldPosition = getMouseWorldPosition(game); console.execute("ai " + botId + " moveTo " + (int)worldPosition.x + " " + (int)worldPosition.y); console.execute("team_say " + players.getPlayer(botId).getName() + " take cover here!" ); // console.execute("speech " + 5); } } } public static class DefuseBombAIShortcut extends AIShortcut { /** * @param shortcutKey */ public DefuseBombAIShortcut(int shortcutKey) { super(shortcutKey, "Defuse bomb"); } /* (non-Javadoc) * @see seventh.client.AIShortcut#execute(seventh.shared.Console, seventh.client.ClientGame) */ @Override public void execute(Console console, ClientGame game, ClientPlayer aiPlayer) { int botId = //getBotId(game); aiPlayer!=null ? aiPlayer.getId() : -1; if(botId > -1) { ClientPlayers players = game.getPlayers(); console.execute("ai " + botId + " defuseBomb"); console.execute("team_say " + players.getPlayer(botId).getName() + " defuse the bomb!" ); } } } public static class PlantBombAIShortcut extends AIShortcut { /** * @param shortcutKey */ public PlantBombAIShortcut(int shortcutKey) { super(shortcutKey, "Plant bomb"); } /* (non-Javadoc) * @see seventh.client.AIShortcut#execute(seventh.shared.Console, seventh.client.ClientGame) */ @Override public void execute(Console console, ClientGame game, ClientPlayer aiPlayer) { int botId = aiPlayer!=null ? aiPlayer.getId() : getBotId(game); if(botId > -1) { ClientPlayers players = game.getPlayers(); console.execute("ai " + botId + " plantBomb"); console.execute("team_say " + players.getPlayer(botId).getName() + " plant the bomb!" ); } } } public static class DefendPlantedBombAIShortcut extends AIShortcut { /** * @param shortcutKey */ public DefendPlantedBombAIShortcut(int shortcutKey) { super(shortcutKey, "Defend Bomb"); } /* (non-Javadoc) * @see seventh.client.AIShortcut#execute(seventh.shared.Console, seventh.client.ClientGame) */ @Override public void execute(Console console, ClientGame game, ClientPlayer aiPlayer) { int botId = aiPlayer!=null ? aiPlayer.getId() : getBotId(game); if(botId > -1) { ClientPlayers players = game.getPlayers(); console.execute("ai " + botId + " defendBomb"); console.execute("team_say " + players.getPlayer(botId).getName() + " defend the bomb!" ); } } } public static class TakeCoverAIShortcut extends AIShortcut { /** * @param shortcutKey * @param description */ public TakeCoverAIShortcut(int shortcutKey) { super(shortcutKey, "Take Cover"); } /* (non-Javadoc) * @see seventh.client.AIShortcut#execute(seventh.shared.Console, seventh.client.ClientGame) */ @Override public void execute(Console console, ClientGame game, ClientPlayer aiPlayer) { int botId = aiPlayer!=null ? aiPlayer.getId() : getBotId(game); if(botId > -1) { ClientPlayers players = game.getPlayers(); Vector2f worldPosition = getMouseWorldPosition(game); console.execute("ai " + botId + " takeCover " + (int)worldPosition.x + " " + (int)worldPosition.y); console.execute("team_say " + players.getPlayer(botId).getName() + " take cover!" ); //console.execute("speech " + 5); } } } public static class DefendLeaderAIShortcut extends AIShortcut { /** * @param shortcutKey * @param description */ public DefendLeaderAIShortcut(int shortcutKey) { super(shortcutKey, "Defend Me"); } /* (non-Javadoc) * @see seventh.client.AIShortcut#execute(seventh.shared.Console, seventh.client.ClientGame) */ @Override public void execute(Console console, ClientGame game, ClientPlayer aiPlayer) { int botId = aiPlayer!=null ? aiPlayer.getId() : getBotId(game); if(botId > -1) { ClientPlayers players = game.getPlayers(); ClientPlayer bot = players.getPlayer(botId); int playerId = game.isLocalPlayerCommander() ? findClosestBot(game, bot) : game.getLocalPlayer().getId(); console.execute("ai " + botId + " defendLeader " + playerId); console.execute("team_say " + players.getPlayer(botId).getName() + " help!" ); //console.execute("speech " + 5); } } } private class RegroupAIGroupCommand extends AIGroupCommand { public RegroupAIGroupCommand(int shortcutKey) { super(shortcutKey, "Regroup", commands.get(FOLLOW_ME)); } } private class DefendAIGroupCommand extends AIGroupCommand { public DefendAIGroupCommand(int shortcutKey) { super(shortcutKey, "Defend", commands.get(DEFEND_LEADER)); } } }
12,262
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Scoreboard.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/hud/Scoreboard.java
/* * see license.txt */ package seventh.client.gfx.hud; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import com.badlogic.gdx.graphics.g2d.TextureRegion; import seventh.client.ClientGame; import seventh.client.ClientPlayer; import seventh.client.ClientTeam; import seventh.client.gfx.Art; import seventh.client.gfx.Canvas; import seventh.client.gfx.RenderFont; /** * @author Tony * */ public class Scoreboard { private static final Comparator<ClientPlayer> comparator = new Comparator<ClientPlayer>() { @Override public int compare(ClientPlayer a, ClientPlayer b) { return b.getKills() - a.getKills(); } }; private ClientGame game; private boolean showScoreBoard; private boolean gameEnded; private Map<ClientTeam, Integer> teamScores; private Map<ClientTeam, List<ClientPlayer>> teams; private ClientTeam winningTeam; private int yOffset; private static final int Y_START = 50; /** * */ public Scoreboard(ClientGame game) { this.game = game; this.showScoreBoard = false; this.teamScores = new HashMap<ClientTeam, Integer>(); this.teams = new HashMap<ClientTeam, List<ClientPlayer>>(); this.teams.put(ClientTeam.NONE, new ArrayList<ClientPlayer>()); this.teams.put(ClientTeam.ALLIES, new ArrayList<ClientPlayer>()); this.teams.put(ClientTeam.AXIS, new ArrayList<ClientPlayer>()); resetScroll(); setScore(ClientTeam.ALLIES, 0); setScore(ClientTeam.AXIS, 0); setScore(ClientTeam.NONE, 0); } public void resetScroll() { this.yOffset = Y_START; } public void scrollDown() { this.yOffset += 20; if(this.yOffset > Y_START) { this.yOffset = Y_START; } } public void scrollUp() { this.yOffset -= 20; } /** * @param gameEnded the gameEnded to set */ public void setGameEnded(boolean gameEnded) { this.gameEnded = gameEnded; } /** * @param winner the winner to set */ public void setWinner(ClientTeam winner) { this.winningTeam = winner; } /** * @param showScoreBoard the showScoreBoard to set */ public void showScoreBoard(boolean showScoreBoard) { this.showScoreBoard = showScoreBoard; if(!this.showScoreBoard) { resetScroll(); } } public boolean isVisible() { return this.showScoreBoard; } public void setScore(ClientTeam team, int score) { this.teamScores.put(team, score); } /** * @return the axis score */ public int getAxisScore() { return this.teamScores.get(ClientTeam.AXIS); } /** * @return the allies score */ public int getAlliedScore() { return this.teamScores.get(ClientTeam.ALLIES); } private void setSmallFont(Canvas canvas) { canvas.setFont("Consola", 14); canvas.boldFont(); } private void setBigFont(Canvas canvas) { canvas.setFont("Consola", 18); canvas.boldFont(); } private int drawTeam(Canvas canvas, List<ClientPlayer> team, int x, int y) { setSmallFont(canvas); for(int i = 0; i < team.size(); i++) { ClientPlayer player = team.get(i); y += 20; if(y < Y_START + 20) { continue; } if(player == game.getLocalPlayer()) { canvas.fillRect(x-5, y-15, 680, 20, 0x5fffffff); } RenderFont.drawShadedString(canvas, player.getName(), x, y, 0xffffffff); String output = String.format("%-30s %-13d %-13d %-10d %-8d %-13d", "" , player.getKills(), player.getAssists(), player.getDeaths(), player.getHitPercentage(), player.getPing()); RenderFont.drawShadedString(canvas, output, x, y, 0xffffffff, true, true, true); if(!player.isAlive()) { canvas.drawScaledImage(Art.deathsImage, x-30, y-12, 20, 20, 0xffffffff); } } setBigFont(canvas); return y; } /** * Renders the scoreboard * * @param canvas */ public void drawScoreboard(Canvas canvas) { if(!isVisible()) { return; } int yIncBig = 35; int y = 50; int x = 90; setBigFont(canvas); int defaultColor = 0xffffffff; //ClientTeam localTeam = game.getLocalPlayer().getTeam(); //int teamColor = (localTeam==ClientTeam.AXIS) ? ClientTeam.AXIS.getColor() : ClientTeam.ALLIES.getColor(); boolean isObjective = false; // TextureRegion gameTypeIcon = Art.tdmIcon; // switch(game.getGameType()) { // case CTF: // gameTypeIcon = Art.ctfIcon; // break; // case OBJ: // gameTypeIcon = Art.objIcon; // isObjective = true; // break; // case TDM: // default: // gameTypeIcon = Art.tdmIcon; // break; // } // // canvas.drawImage(gameTypeIcon, (canvas.getWidth()/2) - (gameTypeIcon.getRegionWidth()/2), gameTypeIcon.getRegionHeight()/2, teamColor); // RenderFont.drawShadedString(canvas, "Name Kills Assists Deaths Hit% Ping", x, y, defaultColor); List<ClientPlayer> vals = game.getPlayers().asList(); teams.get(ClientTeam.NONE).clear(); teams.get(ClientTeam.ALLIES).clear(); teams.get(ClientTeam.AXIS).clear(); Collections.sort(vals, comparator); for(int i = 0; i < vals.size(); i++) { ClientPlayer player = vals.get(i); ClientTeam team = player.getTeam(); if(team != null) { teams.get(team).add(player); } else { teams.get(ClientTeam.NONE).add(player); } } y = this.yOffset; int numberOfBlue = teams.get(ClientTeam.ALLIES).size(); int numberOfRed = teams.get(ClientTeam.AXIS).size(); int numberOfIndividuals = teams.get(ClientTeam.NONE).size(); if(numberOfIndividuals>0) { if(numberOfBlue>0||numberOfRed>0) { y+=yIncBig; if(y > Y_START + 20) { RenderFont.drawShadedString(canvas, "Spectators", x, y, defaultColor); } y = drawTeam(canvas, teams.get(ClientTeam.NONE), x, y); } } int redScore = this.teamScores.get(ClientTeam.AXIS); int blueScore = this.teamScores.get(ClientTeam.ALLIES); if(blueScore > redScore) { if (numberOfBlue>0) { y+=yIncBig; if(y > Y_START + 20) { canvas.fillCircle(14, x - 38, y - 18, 0xff000000); canvas.fillCircle(13, x - 37, y - 17, 0xffffffff); canvas.drawImage(Art.alliedIcon, x - 40, y - 20, null); if(isObjective) { TextureRegion tex = game.getAttackingTeam()==ClientTeam.ALLIES ? Art.attackerIcon : Art.defenderIcon; canvas.drawScaledImage(tex, x - 80, y - 30, 45, 45, ClientTeam.ALLIES.getColor()); } RenderFont.drawShadedString(canvas, "Allies " + blueScore, x, y, ClientTeam.ALLIES.getColor()); } y = drawTeam(canvas, teams.get(ClientTeam.ALLIES), x, y); } if (numberOfRed>0) { y+=yIncBig; if(y > Y_START + 20) { canvas.fillCircle(13, x - 37, y - 17, 0xffffffff); canvas.drawImage(Art.axisIcon, x - 40, y - 20, null); if(isObjective) { TextureRegion tex = game.getAttackingTeam()==ClientTeam.AXIS ? Art.attackerIcon : Art.defenderIcon; canvas.drawScaledImage(tex, x - 80, y - 30, 45, 45, ClientTeam.AXIS.getColor()); } RenderFont.drawShadedString(canvas, "Axis " + redScore, x, y, ClientTeam.AXIS.getColor()); } y = drawTeam(canvas, teams.get(ClientTeam.AXIS), x, y); } } else { if (numberOfRed>0) { y+=yIncBig; if(y > Y_START + 20) { canvas.fillCircle(13, x - 37, y - 17, 0xffffffff); canvas.drawImage(Art.axisIcon, x - 40, y - 20, null); if(isObjective) { TextureRegion tex = game.getAttackingTeam()==ClientTeam.AXIS? Art.attackerIcon : Art.defenderIcon; canvas.drawScaledImage(tex, x - 80, y - 30, 45, 45, ClientTeam.AXIS.getColor()); } RenderFont.drawShadedString(canvas, "Axis " + redScore, x, y, ClientTeam.AXIS.getColor()); } y = drawTeam(canvas, teams.get(ClientTeam.AXIS), x, y); } if (numberOfBlue>0) { y+=yIncBig; if(y > Y_START + 20) { canvas.fillCircle(14, x - 38, y - 18, 0xff000000); canvas.fillCircle(13, x - 37, y - 17, 0xffffffff); canvas.drawImage(Art.alliedIcon, x - 40, y - 20, null); if(isObjective) { TextureRegion tex = game.getAttackingTeam()==ClientTeam.ALLIES ? Art.attackerIcon : Art.defenderIcon; canvas.drawScaledImage(tex, x - 80, y - 30, 45, 45, ClientTeam.ALLIES.getColor()); } //canvas.drawScaledImage(Art.axisIcon, x-32, y-16, 24, 24, null); RenderFont.drawShadedString(canvas, "Allies " + blueScore, x, y, ClientTeam.ALLIES.getColor()); } y = drawTeam(canvas, teams.get(ClientTeam.ALLIES), x, y); } } if(gameEnded) { String winner = "Allies win!"; int color = 0xffffffff; if(winningTeam!=null&&winningTeam!=ClientTeam.NONE) { winner = winningTeam.getName() + " win!"; color = winningTeam.getColor(); } else { if(blueScore>redScore) { winner = "Allies win!"; color = ClientTeam.ALLIES.getColor(); } else if(blueScore<redScore) { winner = "Axis win!"; color = ClientTeam.AXIS.getColor(); } else { winner = "It's a tie!"; } } y+=yIncBig; float strWidth = RenderFont.getTextWidth(canvas, winner); RenderFont.drawShadedString(canvas, winner, canvas.getWidth() / 2 - strWidth/2, y, color); } } }
11,706
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
AIShortcutsMenu.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/hud/AIShortcutsMenu.java
/* * see license.txt */ package seventh.client.gfx.hud; import seventh.client.ClientGame; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.RenderFont; import seventh.client.gfx.Renderable; import seventh.client.inputs.KeyMap; import seventh.shared.TimeStep; /** * @author Tony * */ public class AIShortcutsMenu implements Renderable { private final ClientGame game; private AIShortcuts shortcuts; private boolean show; private String[] texts; private int activeMemberIndex; /** * @param game * @param keyMap * @param shortcuts */ public AIShortcutsMenu(ClientGame game, KeyMap keyMap, AIShortcuts shortcuts) { this.game = game; this.shortcuts = shortcuts; this.texts = new String[this.shortcuts.getCommands().size() + 1]; this.texts[0] = "Dispatch command:"; int i = 1; for(AIShortcut s : this.shortcuts.getCommands()) { this.texts[i++] = " PRESS '" + keyMap.humanReadableKey(s.getShortcutKey()) + "' : " + s.getDescription(); } } public boolean isShowing() { return this.show || this.game.isLocalPlayerCommander(); } public void show() { this.show = true; } public void hide() { this.show = false; } public void toggle() { this.show = !this.show; } /** * Opens the AI menu for the supplied AI unit * * @param teamMemberIndex */ public void openFor(int teamMemberIndex) { this.activeMemberIndex = teamMemberIndex; show(); } /** * @return the activeMemberIndex */ public int getActiveMemberIndex() { return activeMemberIndex; } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { if(isShowing()) { int x = 20; int y = 200; int color = 0xffffff00; canvas.setFont("Consola", 14); canvas.boldFont(); for(int i = 0; i < this.texts.length; i++) { RenderFont.drawShadedString(canvas, this.texts[i], x, y, color); y+=30; } } } }
2,584
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Effects.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/Effects.java
/* * see license.txt */ package seventh.client.gfx.effects; import java.util.ArrayList; import java.util.List; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.Renderable; import seventh.shared.TimeStep; /** * A simple effects container. Draws {@link AnimatedImage}s at a specific location * * @author Tony * */ public class Effects implements Renderable { private List<Effect> effects; private List<Effect> finishedEffects; /** * */ public Effects() { this.effects = new ArrayList<Effect>(); this.finishedEffects = new ArrayList<Effect>(); } public void addEffect(Effect effect) { this.effects.add(effect); } public boolean isEmpty() { return this.effects.isEmpty(); } public int size() { return this.effects.size(); } public void clearEffects() { for(int i = 0; i < this.effects.size(); i++) { this.effects.get(i).destroy(); } this.effects.clear(); this.finishedEffects.clear(); } /* (non-Javadoc) * @see leola.live.gfx.Renderable#render(leola.live.gfx.Canvas, leola.live.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { int size = this.effects.size(); for(int i = 0; i < size; i++) { Effect e = this.effects.get(i); e.render(canvas, camera, alpha); } } /* (non-Javadoc) * @see leola.live.gfx.Renderable#update(leola.live.TimeStep) */ @Override public void update(TimeStep timeStep) { this.finishedEffects.clear(); int size = this.effects.size(); for(int i = 0; i < size; i++) { Effect e = this.effects.get(i); e.update(timeStep); if(e.isDone()) { e.destroy(); this.finishedEffects.add(this.effects.get(i)); } } this.effects.removeAll(this.finishedEffects); } }
2,112
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
DebugAnimationEffect.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/DebugAnimationEffect.java
/* * The Seventh * see license.txt */ package seventh.client.gfx.effects; import seventh.client.gfx.AnimatedImage; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.math.Vector2f; import seventh.shared.TimeStep; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; /** * @author Tony * */ public class DebugAnimationEffect implements Effect { private AnimatedImage anim; private Vector2f pos; private boolean persist; private FadeValue fade; private float rotation; private Sprite sprite; private int offsetX, offsetY; /** * @param anim * @param pos * @param persist */ public DebugAnimationEffect(AnimatedImage anim, Vector2f pos, float rotation) { this(anim, pos, rotation, false); } /** * @param anim * @param pos * @param persist */ public DebugAnimationEffect(AnimatedImage anim, Vector2f pos, float rotation, boolean persist) { this(anim, pos, rotation, persist, 4000); } /** * @param anim * @param pos * @param persist */ public DebugAnimationEffect(AnimatedImage anim, Vector2f pos, float rotation, boolean persist, int fadeTime) { super(); this.anim = anim; this.pos = pos; this.persist = persist; this.rotation = rotation; this.fade = new FadeValue(255, 0, fadeTime); this.sprite = new Sprite(anim.getCurrentImage()); this.sprite.flip(false, true); } public void setOffset(int x, int y) { this.offsetX = x; this.offsetY = y; } /* (non-Javadoc) * @see leola.live.gfx.Renderable#render(leola.live.gfx.Canvas, leola.live.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float a) { int rx = (int)(pos.x); int ry = (int)(pos.y); float alpha = 1.0f; if(!this.persist) { alpha = (float)this.fade.getCurrentValue() / 255.0f; } float priorAlpha = canvas.getCompositeAlpha(); canvas.setCompositeAlpha(alpha); TextureRegion region = anim.getCurrentImage(); sprite.setRegion(region); if(offsetX != 0 || offsetY != 0) { //sprite.setSize(16, 16); sprite.setPosition(rx-offsetX, ry-offsetY); //sprite.setPosition(rx+22, ry-43); sprite.setOrigin(offsetX, offsetY); } else { int w = region.getRegionWidth() / 2; int h = region.getRegionHeight() / 2; sprite.setPosition(rx-w, ry-h); } sprite.setRotation(this.rotation-90); // sprite.setColor(1, 1, 1, alpha); canvas.drawSprite(sprite); canvas.drawRect( (int)sprite.getX(), (int)sprite.getY(), sprite.getRegionWidth(), sprite.getRegionHeight(), 0xff00aa00); canvas.setCompositeAlpha(priorAlpha); } /* (non-Javadoc) * @see leola.live.gfx.Renderable#update(leola.live.TimeStep) */ @Override public void update(TimeStep timeStep) { anim.update(timeStep); // if(anim.isDone() && this.persist) { // anim.reset(); // } if(!this.persist) { this.fade.update(timeStep); } } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#isDone() */ @Override public boolean isDone() { return !persist && anim.isDone() && this.fade.isDone(); } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#destroy() */ @Override public void destroy() { } }
3,792
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ShaderTest.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/ShaderTest.java
/* * see license.txt */ package seventh.client.gfx.effects; import org.lwjgl.opengl.GL11; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Mesh; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.FrameBuffer; import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.math.Matrix3; import com.badlogic.gdx.math.Matrix4; import seventh.client.gfx.Art; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.Renderable; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * @author Tony * */ @SuppressWarnings("all") public class ShaderTest implements Renderable { private ShaderProgram shader; private Mesh mesh; private Texture texture; private Matrix3 matrix; private SpriteBatch batch; private OrthographicCamera camera; private Matrix4 transform; private FrameBuffer buffer; Vector2f position=new Vector2f(0.1f,0.23f); float time; private FrameBuffer fboPing, fboPong; private ShaderProgram vertBlur, horBlur, light; private ShaderProgram loadShader(String fragFile) { ShaderProgram shader = new ShaderProgram(Gdx.files.internal("./assets/gfx/shaders/base.vert") , Gdx.files.internal("./assets/gfx/shaders/" + fragFile)); if(!shader.isCompiled()) { System.out.println("Not compiled!"); } //Good idea to log any warnings if they exist if (shader.getLog().length()!=0) { System.out.println(shader.getLog()); } return shader; } /** * */ public ShaderTest() { ShaderProgram.pedantic = false; vertBlur = loadShader("blurv.frag"); horBlur = loadShader("blurh.frag"); light = loadShader("light.frag"); shader = loadShader("inprint.frag"); this.camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); this.camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // camera.setToOrtho(false); transform = new Matrix4(); camera.update(); batch = new SpriteBatch();//1024, shader); batch.setShader(null); batch.setProjectionMatrix(camera.combined); batch.setTransformMatrix(transform); this.buffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); this.fboPing = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); this.fboPong = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); } public void destroy() { this.shader.dispose(); this.vertBlur.dispose(); this.horBlur.dispose(); } /** * @return the shader */ public ShaderProgram getShader() { return shader; } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { shader.begin(); { time += timeStep.asFraction(); if(time > 1.0f) { time = 0f; } //shader.setUniformi("u_texture", 0); // shader.setUniformf("center", position.x, position.y); // shader.setUniformf("time", time); // shader.setUniformf("shockParams", 10.0f, 0.8f, 0.1f); //shader.setUniformi("u_texture", 0); shader.setUniformi("mark", 1); shader.setUniformf("resolution", Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); } shader.end(); light.begin(); light.setUniformf("ambientColor", 0.8f, 0.8f, 0.51f, 0.4f); light.setUniformf("resolution", Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); light.end(); horBlur.begin(); horBlur.setUniformf("blurRadius", 0.0315125f); horBlur.end(); vertBlur.begin(); vertBlur.setUniformf("blurRadius", 0.0181264f); vertBlur.end(); } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { batch.setShader(null); this.camera.update(); Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setProjectionMatrix(this.camera.combined); batch.setTransformMatrix(transform); //batch.enableBlending(); // batch.setBlendFunction(Gdx.gl10.GL_NEAREST, Gdx.gl10.GL_LINEAR); //batch.setBlendFunction(Gdx.gl10.GL_SRC_ALPHA, Gdx.gl10.GL_ONE_MINUS_SRC_ALPHA); /* batch.begin(); fboPing.begin(); batch.draw(Art.lightMap, -30, -20); fboPing.end(); batch.end(); batch.begin(); batch.setShader(light); fboPing.getColorBufferTexture().bind(1); Art.lightMap.getTexture().bind(0); batch.end(); */ batch.enableBlending(); //batch.begin(); { fboPing.begin(); batch.begin(); Gdx.gl.glClearColor(0, 0.5f, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setShader(null); batch.draw(Art.alliedBodyModel.getFrame(0), 120, 200); batch.setShader(horBlur); // batch.draw(Art.bulletImage, 200, 200); batch.end(); fboPing.end(); //batch.end(); batch.flush(); // batch.disableBlending(); batch.enableBlending(); //batch.flush(); //batch.enableBlending(); //batch.setBlendFunction(Gdx.gl10.GL_NEAREST, Gdx.gl10.GL_LINEAR); //batch.setBlendFunction(Gdx.gl10.GL_SRC_ALPHA, Gdx.gl10.GL_ONE_MINUS_SRC_ALPHA); fboPong.begin(); batch.begin(); //Gdx.gl.glClearColor(0,0.5f,0, 0); //Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); batch.enableBlending(); //Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); //Gdx.gl.glColorMask(true, true, true, true); // fboPing.getColorBufferTexture().bind(1); batch.setShader(null); //batch.setColor(1, 1, 1, 1f); batch.draw(fboPing.getColorBufferTexture(), 0, 0); // batch.draw(Art.bulletImage, 300, 200); batch.setShader(vertBlur); //batch.enableBlending(); batch.disableBlending(); //batch.draw(Art.bulletImage, 200, 200); // int y = fboPing.getHeight()-(200+Art.bulletImage.getRegionHeight()); // batch.draw(fboPing.getColorBufferTexture(), 200, 300, 200, y, Art.bulletImage.getRegionWidth(), Art.bulletImage.getRegionHeight()); //batch.draw(fboPing.getColorBufferTexture(), 0, 0); batch.setShader(null); batch.end(); fboPong.end(); batch.flush(); } //batch.setShader(null); //batch.draw(fboPong.getColorBufferTexture(), 0, 0); //batch.end(); batch.setShader(null); batch.begin(); batch.draw(fboPong.getColorBufferTexture(), 0, 0); batch.end(); } /* * Sprite tracks = new Sprite(Art.tankTrackMarks); tracks.setColor(0.82f, 0.83f, 0.82f, 0.5f); //buffer.getColorBufferTexture().bind(1); //batch.setColor(1f, 1f, 1f, 1f); batch.draw(Art.tankTurret, 140,290); Art.tankTurret.getTexture().bind(0); Art.tankTrackMarks.getTexture().bind(1); batch.setShader(shader); batch.draw(Art.tankTrackMarks, 190, 310); batch.draw(Art.tankTrackMarks, 190, 310+Art.tankTrackMarks.getRegionHeight()); //batch.draw(Art.bulletImage, 140, 290); //batch.setColor(0.2f, 0.3f, 0.2f, 0.5f); //batch.draw(tracks, 150, 300); //batch.draw(buffer.getColorBufferTexture(), 0, 0); batch.flush(); //Art.tankTurret.getTexture().bind(1); Art.tankTrackMarks.getTexture().bind(0); */ }
9,083
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ExplosionEffectShader.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/ExplosionEffectShader.java
/* * see license.txt */ package seventh.client.gfx.effects; import seventh.client.gfx.Shader; /** * @author Tony * */ public class ExplosionEffectShader extends Shader { private static final Shader INSTANCE = new ExplosionEffectShader(); /** */ private ExplosionEffectShader() { super("./assets/gfx/shaders/base.vert", "./assets/gfx/shaders/explosion.frag"); } /** * @return */ public static Shader getInstance() { return INSTANCE; } }
520
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
AwardEffect.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/AwardEffect.java
/* * see license.txt */ package seventh.client.gfx.effects; import com.badlogic.gdx.graphics.g2d.TextureRegion; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.RenderFont; import seventh.math.Vector2f; import seventh.shared.TimeStep; import seventh.shared.Timer; /** * An award was achieved * * @author Tony * */ public class AwardEffect implements Effect { private String text; private TextureRegion icon; private Timer showTimer; private Vector2f startPos, endPos; private Vector2f pos, destPos; private Integer color; private float slideSpeed; /** * @param icon * @param text * @param time * @param startPos * @param endPos */ public AwardEffect(TextureRegion icon, String text, long time, Vector2f startPos, Vector2f endPos) { this(icon, text, time, startPos, endPos, 0xffffffff); } /** * @param icon * @param text * @param time * @param startPos * @param endPos * @param color */ public AwardEffect(TextureRegion icon, String text, long time, Vector2f startPos, Vector2f endPos, Integer color) { this.icon = icon; this.text = text; this.startPos = startPos; this.endPos = endPos; this.color = color; this.showTimer = new Timer(false, time).stop(); this.pos = new Vector2f(startPos); this.destPos = new Vector2f(endPos); this.slideSpeed = 0.5f; } @Override public void update(TimeStep timeStep) { if(!showTimer.isUpdating() && Vector2f.Vector2fApproxEquals(pos, endPos)) { pos.set(endPos); showTimer.start(); slideSpeed = 0.15f; } showTimer.update(timeStep); if(showTimer.isOnFirstTime()) { this.destPos.set(startPos); } Vector2f.Vector2fInterpolate(pos, destPos, this.slideSpeed, pos); } @Override public void render(Canvas canvas, Camera camera, float alpha) { canvas.resizeFont(16f); RenderFont.drawShadedString(canvas, text, pos.x + icon.getRegionWidth() + 10, pos.y, 0xffffffff); canvas.drawImage(icon, pos.x, pos.y - (icon.getRegionHeight()/2 + canvas.getHeight("W")/2), this.color); } @Override public boolean isDone() { return Vector2f.Vector2fApproxEquals(pos, startPos) && showTimer.isExpired(); } @Override public void destroy() { } }
2,806
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
LightEffectShader.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/LightEffectShader.java
/* * see license.txt */ package seventh.client.gfx.effects; import seventh.client.gfx.Shader; /** * @author Tony * */ public class LightEffectShader extends Shader { private static final Shader INSTANCE = new LightEffectShader(); /** */ public LightEffectShader() { super("./assets/gfx/shaders/base.vert", "./assets/gfx/shaders/light.frag"); } /** * @return */ public static Shader getInstance() { return INSTANCE; } }
524
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Explosion.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/Explosion.java
/* * see license.txt */ package seventh.client.gfx.effects; import seventh.client.ClientGame; import seventh.client.gfx.AnimatedImage; import seventh.client.gfx.AnimationPool; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.math.Vector2f; import seventh.shared.TimeStep; import com.badlogic.gdx.graphics.g2d.Sprite; /** * @author Tony * */ public class Explosion implements Effect { private AnimatedImage image; private Vector2f pos; private Sprite sprite; private AnimationPool pool; /** * */ public Explosion(ClientGame game, Vector2f pos) { this.pos = pos; this.pool = game.getPools().getExplosion(); this.image = pool.create(); this.sprite = new Sprite(this.image.getCurrentImage()); this.sprite.setRotation(game.getRandom().nextInt(360)); } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { this.image.update(timeStep); } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { Vector2f cameraPos = camera.getRenderPosition(alpha); sprite.setRegion(this.image.getCurrentImage()); sprite.setPosition(this.pos.x-cameraPos.x, this.pos.y-cameraPos.y); canvas.drawSprite(sprite); } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#isDone() */ @Override public boolean isDone() { return this.image.isDone(); } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#destroy() */ @Override public void destroy() { this.pool.free(image); } }
1,895
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
RenderableEffect.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/RenderableEffect.java
/* * The Seventh * see license.txt */ package seventh.client.gfx.effects; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.Renderable; import seventh.shared.TimeStep; /** * @author Tony * */ public class RenderableEffect implements Effect { private Renderable renderable; /** * @param tex * @param pos * @param rotation */ public RenderableEffect(seventh.client.gfx.Renderable renderable) { super(); this.renderable = renderable; } /* (non-Javadoc) * @see leola.live.gfx.Renderable#render(leola.live.gfx.Canvas, leola.live.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float a) { renderable.render(canvas, camera, a); } /* (non-Javadoc) * @see leola.live.gfx.Renderable#update(leola.live.TimeStep) */ @Override public void update(TimeStep timeStep) { renderable.update(timeStep); } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#isDone() */ @Override public boolean isDone() { return false; } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#destroy() */ @Override public void destroy() { } }
1,302
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
DebugSpriteEffect.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/DebugSpriteEffect.java
/* * The Seventh * see license.txt */ package seventh.client.gfx.effects; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.math.Vector2f; import seventh.shared.TimeStep; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; /** * @author Tony * */ public class DebugSpriteEffect implements Effect { private Vector2f pos; private float rotation; private int color; private Sprite sprite; private int offsetX, offsetY; /** * @param tex * @param pos * @param rotation */ public DebugSpriteEffect(TextureRegion tex, Vector2f pos, float rotation, int color) { super(); this.pos = pos; this.rotation = rotation; this.color = color; this.sprite = new Sprite(tex); this.sprite.flip(false, true); } public void setOffset(int x, int y) { this.offsetX = x; this.offsetY = y; } /* (non-Javadoc) * @see leola.live.gfx.Renderable#render(leola.live.gfx.Canvas, leola.live.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float a) { int rx = (int)(pos.x); int ry = (int)(pos.y); if(offsetX != 0 || offsetY != 0) { //sprite.setSize(16, 16); sprite.setPosition(rx-offsetX, ry-offsetY); //sprite.setPosition(rx+22, ry-43); sprite.setOrigin(offsetX, offsetY); } else { int w = sprite.getRegionWidth() / 2; int h = sprite.getRegionHeight() / 2; sprite.setPosition(rx-w, ry-h); } sprite.setRotation(this.rotation-90); float priorAlpha = canvas.getCompositeAlpha(); canvas.drawSprite(sprite, (int)sprite.getX(), (int)sprite.getY(), color); canvas.drawRect( (int)sprite.getX(), (int)sprite.getY(), sprite.getRegionWidth(), sprite.getRegionHeight(), 0xff00aa00); canvas.setCompositeAlpha(priorAlpha); } /* (non-Javadoc) * @see leola.live.gfx.Renderable#update(leola.live.TimeStep) */ @Override public void update(TimeStep timeStep) { } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#isDone() */ @Override public boolean isDone() { return false; } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#destroy() */ @Override public void destroy() { } }
2,567
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
TankTrackMarks.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/TankTrackMarks.java
/* * see license.txt */ package seventh.client.gfx.effects; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.glutils.ShaderProgram; import seventh.client.SeventhGame; import seventh.client.gfx.Art; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.Renderable; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * @author Tony * */ public class TankTrackMarks implements Renderable { static class TankTrack { float x, y; float orientation; float alpha; public void set(float x, float y, float orientation) { this.x = x; this.y = y; this.orientation = orientation; this.alpha = 0.15f; } public void decay(TimeStep timeStep) { if(this.alpha > 0) { this.alpha -= 0.000445f; if(this.alpha < 0) { this.alpha = 0f; } } } } private Sprite trackMarkSprite; private TankTrack[] tracks; private int index; private ShaderProgram shader; /** * */ public TankTrackMarks(int size) { if(size<=0) { throw new IllegalArgumentException("Size can not be zero!"); } this.tracks = new TankTrack[size]; for(int i = 0; i < tracks.length;i++) { this.tracks[i] = new TankTrack(); } this.trackMarkSprite = new Sprite(Art.tankTrackMarks); this.shader = MarkEffectShader.getInstance().getShader(); shader.begin(); { //shader.setUniformi("u_texture", 0); shader.setUniformi("mark", 1); shader.setUniformf("resolution", SeventhGame.DEFAULT_MINIMIZED_SCREEN_WIDTH, SeventhGame.DEFAULT_MINIMIZED_SCREEN_HEIGHT); } shader.end(); } public void add(Vector2f p, float orientation) { add(p.x, p.y, orientation); } public void add(float x, float y, float orientation) { this.tracks[this.index].set(x, y, orientation); this.index = (this.index+1) % this.tracks.length; } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { for(int i = 0; i < tracks.length;i++) { TankTrack track = tracks[i]; track.decay(timeStep); } } @Override public void render(Canvas canvas, Camera camera, float alpha) { Vector2f cameraPos = camera.getRenderPosition(alpha); for(int i = 0; i < tracks.length;i++) { TankTrack track = tracks[i]; float rx = track.x-cameraPos.x; float ry = track.y-cameraPos.y; trackMarkSprite.setRotation( (float)Math.toDegrees(track.orientation)-90f); trackMarkSprite.setOrigin(16, 8); trackMarkSprite.setPosition(rx-16, ry-16); trackMarkSprite.setColor(73f/255f, 49f/255f, 28f/255f, track.alpha); //canvas.setShader(shader); //canvas.getFrameBuffer().bind(0); //trackMarkSprite.getTexture().bind(1); //int srcFunc = canvas.getSrcBlendFunction(); //int dstFunc = canvas.getDstBlendFunction(); //canvas.enableBlending(); //canvas.setBlendFunction(GL20.GL_ZERO, GL20.GL_BLEND_SRC_RGB ); canvas.drawRawSprite(trackMarkSprite); //canvas.setBlendFunction(srcFunc, dstFunc); //canvas.disableBlending(); //canvas.flush(); //trackMarkSprite.getTexture().bind(0); //canvas.setShader(null); } } public void clear() { for(int i = 0; i < tracks.length;i++) { this.tracks[i].set(0, 0, 0); } } }
4,082
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
HurtEffect.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/HurtEffect.java
/* * see license.txt */ package seventh.client.gfx.effects; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.Colors; import seventh.shared.TimeStep; import seventh.shared.Timer; /** * Flashes red on the screen indicating the player has received damage * * @author Tony * */ public class HurtEffect implements Effect { private float alpha; private Timer hurtTimer; /** * */ public HurtEffect() { this.hurtTimer = new Timer(false, 150); } public void reset() { reset(760); } public void reset(long time) { this.hurtTimer.reset(); this.hurtTimer.setEndTime(time); this.alpha = 0.35f; } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { this.hurtTimer.update(timeStep); this.alpha *= 0.9f; } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, float) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { if(this.hurtTimer.isUpdating()) { canvas.fillRect(0, 0, canvas.getWidth(), canvas.getHeight(), Colors.toColor(1.0f, 0, 0, this.alpha)); } } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#isDone() */ @Override public boolean isDone() { boolean isDone = this.hurtTimer.isExpired(); if(isDone) { this.hurtTimer.stop(); } return isDone; } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#destroy() */ @Override public void destroy() { } }
1,800
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Effect.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/Effect.java
/* * The Seventh * see license.txt */ package seventh.client.gfx.effects; import seventh.client.gfx.Renderable; /** * A visual effect * * @author Tony * */ public interface Effect extends Renderable { /** * @return true if this effect is done */ public boolean isDone(); public void destroy(); }
331
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
FireEffectShader.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/FireEffectShader.java
/* * see license.txt */ package seventh.client.gfx.effects; import seventh.client.gfx.Shader; /** * @author Tony * */ public class FireEffectShader extends Shader { private static final Shader INSTANCE = new FireEffectShader(); /** */ private FireEffectShader() { super("./assets/gfx/shaders/base.vert", "./assets/gfx/shaders/fire.frag"); } /** * @return */ public static Shader getInstance() { return INSTANCE; } }
500
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ExplosionEffect.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/ExplosionEffect.java
/* * see license.txt */ package seventh.client.gfx.effects; import seventh.math.Vector2f; import seventh.shared.TimeStep; import seventh.shared.Updatable; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.glutils.ShaderProgram; /** * Makes explosion (ripple effects) using post-processing shader. This class is responsible for keeping track of the * data sent to the shader. We limit the amount of explosions in a scene, we then pass this information in a float array * to the shader. * * @author Tony * */ public class ExplosionEffect implements Updatable { private final float spreadRate; private final long timeToLive; private class ExplosionEffectData { long ttlCountDown; Vector2f position; float time; public ExplosionEffectData() { this.position = new Vector2f(); } /** * Activate this effect * @param pos */ public void activate(Vector2f pos) { this.position.set(pos); this.time = 0f; this.ttlCountDown = timeToLive; } public void deactive() { this.ttlCountDown = 0; this.position.zeroOut(); } /** * @return If this is active */ public boolean isActive() { return this.ttlCountDown > 0; } public void update(TimeStep timeStep) { this.time += (Gdx.graphics.getDeltaTime() * spreadRate); this.ttlCountDown -= timeStep.getDeltaTime(); } public void set(float[] data, int index) { data[index ] = this.position.x; data[index+1] = this.position.y; data[index+2] = this.time; } } private ExplosionEffectData[] instances; private float[] shaderData; /** * @param maxInstances * @param ttl * @param spreadRate */ public ExplosionEffect(int maxInstances, long ttl, float spreadRate) { this.timeToLive = ttl; this.spreadRate = spreadRate; this.instances = new ExplosionEffectData[maxInstances]; for(int i = 0; i < maxInstances; i++) { this.instances[i] = new ExplosionEffectData(); } this.shaderData = new float[3 * maxInstances]; } /** * Activate this effect * @param pos */ public void activate(int index, Vector2f pos) { if(index > -1 && index < this.instances.length) { if(!this.instances[index].isActive()) { this.instances[index].activate(pos); } } } /** * Deactivates all of the explosions */ public void deactiveAll() { for(int i = 0; i < this.instances.length; i++) { this.instances[i].deactive(); } } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { /* Always clear out the data, this will get * overridden by the next loop if the explosion * is active */ for(int i = 0; i < this.instances.length; i++) { this.shaderData[i ] = -0.1f; this.shaderData[i+1] = -0.1f; this.shaderData[i+2] = 0; } int activeCount = 0; for(int i = 0; i < this.instances.length; i++) { this.instances[i].update(timeStep); if(this.instances[i].isActive()) { this.instances[i].set(shaderData, activeCount++); } } ShaderProgram shader = ExplosionEffectShader.getInstance().getShader(); shader.begin(); shader.setUniform3fv("shockData", this.shaderData, 0, this.shaderData.length); shader.setUniformf("shockParams", 10.0f, 0.08f, 0.1f); shader.end(); } }
4,025
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ScreenFlashEffect.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/ScreenFlashEffect.java
/* * see license.txt */ package seventh.client.gfx.effects; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.Colors; import seventh.shared.TimeStep; import seventh.shared.Timer; /** * Flashes a color on the screen * * @author Tony * */ public class ScreenFlashEffect implements Effect { private final int color; private final float startingAlpha; private float alpha; private Timer flashTimer; /** * */ public ScreenFlashEffect(int color, float startingAlpha, long flashTime) { this.color = color; this.startingAlpha = startingAlpha; this.flashTimer = new Timer(false, flashTime); } public void reset() { reset(this.flashTimer.getEndTime()); } public void reset(long time) { this.flashTimer.reset(); this.flashTimer.setEndTime(time); this.alpha = this.startingAlpha; } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { this.flashTimer.update(timeStep); this.alpha *= 0.9f; } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, float) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { if(this.flashTimer.isUpdating()) { canvas.fillRect(0, 0, canvas.getWidth(), canvas.getHeight(), Colors.setAlpha(this.color, this.alpha)); } } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#isDone() */ @Override public boolean isDone() { boolean isDone = this.flashTimer.isExpired(); if(isDone) { this.flashTimer.stop(); } return isDone; } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#destroy() */ @Override public void destroy() { } }
2,106
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ClientGameEffects.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/ClientGameEffects.java
/* * see license.txt */ package seventh.client.gfx.effects; import java.util.ArrayList; import java.util.List; import java.util.Random; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.glutils.ShaderProgram; import seventh.client.ClientGame; import seventh.client.ClientTeam; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.Colors; import seventh.client.gfx.FrameBufferRenderable; import seventh.client.gfx.ImageBasedLightSystem; import seventh.client.gfx.LightSystem; import seventh.client.gfx.effects.particle_system.Emitter; import seventh.client.gfx.effects.particle_system.Emitters; import seventh.game.net.NetCtfGameTypeInfo; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.shared.SeventhConstants; import seventh.shared.TimeStep; /** * @author Tony * */ public class ClientGameEffects { private final Effects backgroundEffects, foregroundEffects; private final LightSystem lightSystem; private final ExplosionEffect explosions; private final HurtEffect hurtEffect; private final List<FrameBufferRenderable> frameBufferRenderables; private final Sprite frameBufferSprite; private final TankTrackMarks[] trackMarks; private final Emitter[] playerBloodEmitters; private final BulletCasingEffect[] bulletCasings; private NetCtfGameTypeInfo ctfInfo; /** */ public ClientGameEffects(Random random) { this.frameBufferRenderables = new ArrayList<>(); this.hurtEffect = new HurtEffect(); this.backgroundEffects = new Effects(); this.foregroundEffects = new Effects(); this.playerBloodEmitters = new Emitter[SeventhConstants.MAX_PLAYERS*3]; for(int i = 0; i < this.playerBloodEmitters.length; i++) { this.playerBloodEmitters[i] = Emitters.newBloodEmitter(new Vector2f(), 5, 20_000, 30) .kill(); } this.lightSystem = new ImageBasedLightSystem(); this.frameBufferRenderables.add(lightSystem); this.explosions = new ExplosionEffect(15, 800, 0.6f); this.frameBufferSprite = new Sprite(); this.trackMarks = new TankTrackMarks[SeventhConstants.MAX_ENTITIES]; this.bulletCasings = new BulletCasingEffect[256]; for(int i = 0; i < this.bulletCasings.length; i++) { this.bulletCasings[i] = new BulletCasingEffect(random); } } public void addCtfInformation(NetCtfGameTypeInfo info) { this.ctfInfo = info; } public void clearCtfInformation() { this.ctfInfo = null; } public void spawnBulletCasing(Vector2f pos, float orientation) { for(int i = 0; i < this.bulletCasings.length; i++) { if(this.bulletCasings[i].isFree()) { this.bulletCasings[i].respawn(pos, orientation); this.backgroundEffects.addEffect(this.bulletCasings[i]); break; } } } public void spawnBloodSplatter(Vector2f pos) { for(int i = 0; i < this.playerBloodEmitters.length; i++) { Emitter emitter = this.playerBloodEmitters[i]; if(!emitter.isAlive()) { this.backgroundEffects.addEffect(emitter.reset().setPos(pos)); break; } } } /** * @return the explosions */ public ExplosionEffect getExplosions() { return explosions; } /** * @return the lightSystem */ public LightSystem getLightSystem() { return lightSystem; } /** * @return the hurtEffect */ public HurtEffect getHurtEffect() { return hurtEffect; } /** * Removes all lights */ public void removeAllLights() { lightSystem.removeAllLights(); } /** * Clear all the effects */ public void clearEffects() { explosions.deactiveAll(); backgroundEffects.clearEffects(); foregroundEffects.clearEffects(); for(int i =0; i < trackMarks.length; i++) { if(trackMarks[i] != null) { trackMarks[i].clear(); trackMarks[i] = null; } } for(int i = 0; i < this.playerBloodEmitters.length; i++) { this.playerBloodEmitters[i].kill(); } clearCtfInformation(); } /** * Destroys these effects, releasing any resources */ public void destroy() { clearEffects(); removeAllLights(); lightSystem.destroy(); frameBufferRenderables.clear(); for(int i = 0; i < this.playerBloodEmitters.length; i++) { this.playerBloodEmitters[i].destroy(); this.playerBloodEmitters[i] = null; } } /** * Adds an explosion * * @param index * @param pos */ public void addExplosion(ClientGame game, int index, Vector2f pos) { //explosions.activate(index, pos); this.foregroundEffects.addEffect(new Explosion(game, pos)); } /** * Adds a background effect * * @param effect */ public void addBackgroundEffect(Effect effect) { this.backgroundEffects.addEffect(effect); } public void addLightSource(Vector2f pos) { this.lightSystem.newConeLight(pos); } /** * Adds a foreground effect * * @param effect */ public void addForegroundEffect(Effect effect) { this.foregroundEffects.addEffect(effect); } public void allocateTrackMark(int id) { this.trackMarks[id] = new TankTrackMarks(256); } public void addTankTrackMark(int id, Vector2f pos, float orientation) { if(this.trackMarks[id]==null) { this.trackMarks[id] = new TankTrackMarks(256*2); } this.trackMarks[id].add(pos, orientation); } /** * Updates the special effects, etc. * * @param timeStep */ public void update(TimeStep timeStep) { lightSystem.update(timeStep); backgroundEffects.update(timeStep); foregroundEffects.update(timeStep); explosions.update(timeStep); hurtEffect.update(timeStep); int size = frameBufferRenderables.size(); for(int i = 0; i < size; i++) { FrameBufferRenderable r = this.frameBufferRenderables.get(i); r.update(timeStep); } for(int i =0; i < trackMarks.length; i++) { if(trackMarks[i] != null) { trackMarks[i].update(timeStep); } } } /** * Renders to the frame buffer * @param canvas */ public void preRenderFrameBuffer(Canvas canvas, Camera camera, float alpha) { int size = this.frameBufferRenderables.size(); if(size>0) { canvas.setDefaultTransforms(); canvas.setShader(null); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); canvas.begin(); for(int i = 0; i < size; i++) { FrameBufferRenderable r = this.frameBufferRenderables.get(i); r.frameBufferRender(canvas, camera, alpha); } canvas.end(); } } public void postRenderFrameBuffer(Canvas canvas, Camera camera, float alpha) { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); canvas.setDefaultTransforms(); canvas.setShader(null); for(int i = 0; i < this.frameBufferRenderables.size(); ) { FrameBufferRenderable r = this.frameBufferRenderables.get(i); if(r.isExpired()) { this.frameBufferRenderables.remove(i); } else { r.render(canvas, camera, alpha); i++; } } } public void renderFrameBuffer(Canvas canvas, Camera camera, float alpha) { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); canvas.setDefaultTransforms(); frameBufferSprite.setRegion(canvas.getFrameBuffer()); canvas.begin(); { canvas.getFrameBuffer().bind(); { ShaderProgram shader = ExplosionEffectShader.getInstance().getShader(); canvas.setShader(shader); canvas.drawImage(frameBufferSprite, 0, 0, 0x0); } } canvas.end(); } public void renderBackground(Canvas canvas, Camera camera, float alpha) { backgroundEffects.render(canvas, camera, alpha); for(int i =0; i < trackMarks.length; i++) { if(trackMarks[i] != null) { trackMarks[i].render(canvas, camera, alpha); } } if(this.ctfInfo != null) { renderCtfBase(canvas, camera, alpha, this.ctfInfo.axisHomeBase, Colors.setAlpha(ClientTeam.AXIS.getColor(), 50)); renderCtfBase(canvas, camera, alpha, this.ctfInfo.alliedHomeBase, Colors.setAlpha(ClientTeam.ALLIES.getColor(), 50)); } } private void renderCtfBase(Canvas canvas, Camera camera, float alpha, Rectangle base, Integer color) { Vector2f cam = camera.getRenderPosition(alpha); canvas.fillRect(base.x - cam.x, base.y - cam.y, base.width, base.height, color); canvas.drawRect(base.x - cam.x, base.y - cam.y, base.width, base.height, 0x1a000000); } public void renderForeground(Canvas canvas, Camera camera, float alpha) { foregroundEffects.render(canvas, camera, alpha); } public void renderLightSystem(Canvas canvas, Camera camera, float alpha) { lightSystem.render(canvas, camera, alpha); } public void renderHurtEffect(Canvas canvas, Camera camera, float alpha) { this.hurtEffect.render(canvas, camera, alpha); } }
10,367
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
FadeValue.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/FadeValue.java
/* * The Seventh * see license.txt */ package seventh.client.gfx.effects; import seventh.shared.TimeStep; /** * @author Tony * */ public class FadeValue { private int currentValue, startValue, endValue, delta; /** * */ public FadeValue(int start, int end, int time) { this.currentValue = start; this.startValue = start; this.endValue = end; int numberOfTicks = time / 33; if(numberOfTicks==0) numberOfTicks=1; if(time > 0) { if(end > start) { delta = ((end - start) / numberOfTicks) + 1; } else { delta = - (((start - end) / numberOfTicks) + 1); } } } public void reset() { this.currentValue = this.startValue; } public void update(TimeStep timeStep) { this.currentValue += delta;//(delta * timeStep.asFraction()); if(delta> 0) { if(this.currentValue>this.endValue) { this.currentValue = this.endValue; } } else { if(this.currentValue<this.endValue) { this.currentValue = this.endValue; } } } public boolean isDone() { return this.currentValue == this.endValue; } /** * @return the endValue */ public int getEndValue() { return endValue; } /** * @return the currentValue */ public int getCurrentValue() { return currentValue; } }
1,583
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
MarkEffectShader.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/MarkEffectShader.java
/* * see license.txt */ package seventh.client.gfx.effects; import seventh.client.gfx.Shader; /** * @author Tony * */ public class MarkEffectShader extends Shader { private static final Shader INSTANCE = new MarkEffectShader(); /** */ private MarkEffectShader() { super("./assets/gfx/shaders/base.vert", "./assets/gfx/shaders/inprint.frag"); } /** * @return */ public static Shader getInstance() { return INSTANCE; } }
503
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
BulletCasingEffect.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/BulletCasingEffect.java
/* * see license.txt */ package seventh.client.gfx.effects; import java.util.Random; import com.badlogic.gdx.graphics.g2d.Sprite; import seventh.client.gfx.Art; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.math.Vector2f; import seventh.shared.TimeStep; import seventh.shared.Timer; /** * @author Tony * */ public class BulletCasingEffect implements Effect { private Timer timeToLive; private Vector2f pos; private Vector2f vel; private Sprite sprite; private Timer rotationTimer; private Timer ejectTimer; private Random random; private float rotation; private float speed; private float alpha; /** * */ public BulletCasingEffect(Random random) { this.random = random; this.timeToLive = new Timer(false, 25_000); this.timeToLive.stop(); this.rotationTimer = new Timer(false, 800); this.ejectTimer = new Timer(false, 1400); this.pos = new Vector2f(); this.vel = new Vector2f(); this.sprite = new Sprite(Art.bulletShell); this.alpha = 0.68f; } public void respawn(Vector2f pos, float orientation) { this.pos.set(pos); this.timeToLive.reset(); this.timeToLive.start(); this.rotationTimer.reset(); this.rotationTimer.setEndTime(200 + random.nextInt(200)); this.ejectTimer.reset(); this.ejectTimer.setEndTime(300 + random.nextInt(200)); float angle = (float)Math.toDegrees(orientation); this.sprite.setRotation(angle); float dir = random.nextBoolean() ? -1 : 1; angle += dir * (random.nextInt(9) * 5) + random.nextInt(5); this.vel.set(0,1); Vector2f.Vector2fRotate(vel, Math.toRadians(angle), vel); this.rotation = 25f; this.speed = 8f + random.nextInt(3); this.alpha = 0.68f; } public boolean isFree() { return !this.timeToLive.isUpdating(); } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#update(seventh.shared.TimeStep) */ @Override public void update(TimeStep timeStep) { this.timeToLive.update(timeStep); this.rotationTimer.update(timeStep); this.ejectTimer.update(timeStep); if(!this.rotationTimer.isExpired()) { this.rotation *= .9f; } else { this.rotation = 0f; } if(!this.ejectTimer.isExpired()) { Vector2f.Vector2fMA(pos, vel, speed, pos); this.speed *= .7f; } else { this.alpha *= 0.996f; } } /* (non-Javadoc) * @see seventh.client.gfx.Renderable#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, float) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { Vector2f cameraPos = camera.getRenderPosition(alpha); this.sprite.setPosition(this.pos.x-cameraPos.x, this.pos.y-cameraPos.y); this.sprite.rotate(rotation); this.sprite.setAlpha(this.alpha); canvas.drawRawSprite(sprite); } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#isDone() */ @Override public boolean isDone() { boolean isDone = this.timeToLive.isExpired(); if(isDone) { this.timeToLive.stop(); } return isDone; } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#destroy() */ @Override public void destroy() { // TODO Auto-generated method stub } }
3,749
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
ShadeTiles.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/ShadeTiles.java
/* * The Seventh * see license.txt */ package seventh.client.gfx.effects; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.g2d.TextureRegion; import seventh.client.gfx.TextureUtil; /** * @author Tony * */ public class ShadeTiles { private final int startAlpha; private final int tileWidth, tileHeight; private int decayRate = 5; /** * @param startAlpha * @param tileWidth * @param tileHeight */ public ShadeTiles(int startAlpha, int tileWidth, int tileHeight) { super(); // this.startAlpha = startAlpha-20; this.startAlpha = startAlpha; this.tileWidth = tileWidth; this.tileHeight = tileHeight; } /** * @return the shaded tiles */ public TextureRegion[] createShadeTiles() { Pixmap bigImage = TextureUtil.createPixmap(tileWidth * 4, tileHeight * 4); Pixmap[] tiles = TextureUtil.splitPixmap(bigImage, bigImage.getWidth(), bigImage.getHeight(), 4, 4); //decayRate = 7; decayRate = 7; // 1's drawNorth(tiles[0]); drawEast(tiles[1]); drawSouth(tiles[2]); drawWest(tiles[3]); // 2's Pixmap image = tiles[4]; drawNorth(image); drawEast(image); image = tiles[5]; drawNorth(image); drawWest(image); image = tiles[6]; drawSouth(image); drawEast(image); image = tiles[7]; drawSouth(image); drawWest(image); // 3's image = tiles[8]; drawNorth(image); drawWest(image); drawEast(image); image = tiles[9]; drawSouth(image); drawWest(image); drawEast(image); image = tiles[10]; drawNorth(image); drawSouth(image); drawWest(image); image = tiles[11]; drawNorth(image); drawSouth(image); drawEast(image); // 2's separated image = tiles[12]; drawNorth(image); drawSouth(image); image = tiles[13]; drawWest(image); drawEast(image); // 4's image = tiles[14]; drawNorth(image); drawSouth(image); drawWest(image); drawEast(image); TextureRegion[] regions = new TextureRegion[tiles.length]; for(int i = 0; i < regions.length; i++) { regions[i] = TextureUtil.tex(tiles[i]); tiles[i].dispose(); } return regions; } private void drawSouth(Pixmap image) { int currentAlpha = startAlpha; for (int i = 0; i < tileHeight; i++) { int color = (currentAlpha << 24); drawLine(image, 0, i, tileWidth-1, i, color); currentAlpha -= decayRate; if (currentAlpha < 0) { break; } } } private void drawEast(Pixmap image) { int currentAlpha = startAlpha; for (int i = 0; i < tileWidth; i++) { int color = (currentAlpha << 24); drawLine(image, tileWidth - i - 1, 0, tileWidth - i - 1, tileHeight - 1, color); currentAlpha -= decayRate; if (currentAlpha < 0) { break; } } } private void drawNorth(Pixmap image) { int currentAlpha = startAlpha; for (int i = 0; i < tileHeight; i++) { int color = (currentAlpha << 24); drawLine(image, 0, tileHeight - 1 - i, tileWidth-1, tileHeight - 1 - i, color); currentAlpha -= decayRate; if (currentAlpha < 0) { break; } } } private void drawWest(Pixmap image) { int currentAlpha = startAlpha; for (int i = 0; i < tileWidth; i++) { int color = (currentAlpha << 24); drawLine(image, i, 0, i, tileHeight - 1, color); currentAlpha -= decayRate; if (currentAlpha < 0) { break; } } } private void drawLine(Pixmap image, int x0, int y0, int x1, int y1, int color) { if(color == 0) { return; } color = (color << 8) | (color >>> 24); //color = 0xff00ffff; // Uses the Bresenham Line Algorithm int dx = Math.abs(x1 - x0); int dy = Math.abs(y1 - y0); int sx = 0; int sy = 0; if (x0 < x1) sx = 1; else sx = -1; if (y0 < y1) sy = 1; else sy = -1; int err = dx - dy; do { int pixel = image.getPixel(x0, y0); if(pixel==0) { image.drawPixel(x0, y0, color); } else { //int alpha = ((color>>24)+(pixel>>24));///2; //image.drawPixel(x0, y0, alpha<<24); int alpha = Math.min((pixel+color)/2, this.startAlpha); //int alpha = this.startAlpha/2; image.drawPixel(x0, y0, alpha); } if (x0 == x1 && y0 == y1) { break; } int e2 = err * 2; if (e2 > -dy) { err = err - dy; x0 = x0 + sx; } if (x0 == x1 && y0 == y1) { pixel = image.getPixel(x0, y0); if(pixel==0) { image.drawPixel(x0, y0, color); } else { //int alpha = ((color>>24)+(pixel>>24));///2; //image.drawPixel(x0, y0, alpha<<24); int alpha = Math.min( (pixel+color)/2, this.startAlpha); //int alpha = this.startAlpha/2; image.drawPixel(x0, y0, alpha); } break; } if (e2 < dx) { err = err + dx; y0 = y0 + sy; } } while (true); } }
6,150
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
AnimationEffect.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/AnimationEffect.java
/* * The Seventh * see license.txt */ package seventh.client.gfx.effects; import seventh.client.gfx.AnimatedImage; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.math.Vector2f; import seventh.shared.TimeStep; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; /** * @author Tony * */ public class AnimationEffect implements Effect { private AnimatedImage anim; private Vector2f pos; private boolean persist; private FadeValue fade; private float rotation; private Sprite sprite; private int offsetX, offsetY; /** * @param anim * @param pos * @param persist */ public AnimationEffect(AnimatedImage anim, Vector2f pos, float rotation) { this(anim, pos, rotation, false); } /** * @param anim * @param pos * @param persist */ public AnimationEffect(AnimatedImage anim, Vector2f pos, float rotation, boolean persist) { this(anim, pos, rotation, persist, 12000); } /** * @param anim * @param pos * @param persist */ public AnimationEffect(AnimatedImage anim, Vector2f pos, float rotation, boolean persist, int fadeTime) { super(); this.anim = anim; this.pos = pos; this.persist = persist; this.rotation = (float)(Math.toDegrees(rotation)); this.fade = new FadeValue(255, 0, fadeTime); this.sprite = new Sprite(anim.getCurrentImage()); this.sprite.flip(false, true); } public void setOffset(int x, int y) { this.offsetX = x; this.offsetY = y; } /** * Reset the animation effect */ public void reset(Vector2f pos, float rotation) { this.pos.set(pos); this.rotation = (float)(Math.toDegrees(rotation)); this.anim.reset(); this.fade.reset(); } /* (non-Javadoc) * @see leola.live.gfx.Renderable#render(leola.live.gfx.Canvas, leola.live.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { Vector2f cameraPos = camera.getRenderPosition(alpha); float rx = (pos.x - cameraPos.x); float ry = (pos.y - cameraPos.y); float currentAlpha = 1.0f; if(!this.persist) { currentAlpha = (float)this.fade.getCurrentValue() / 255.0f; } float priorAlpha = canvas.getCompositeAlpha(); canvas.setCompositeAlpha(currentAlpha); TextureRegion region = anim.getCurrentImage(); sprite.setRegion(region); if(offsetX != 0 || offsetY != 0) { sprite.setPosition(rx-offsetX, ry-offsetY); sprite.setOrigin(offsetX, offsetY); } else { float w = region.getRegionWidth() / 2f; float h = region.getRegionHeight() / 2f; float x = Math.round(rx-w); float y = Math.round(ry-h); sprite.setPosition(x,y); } sprite.setRotation(this.rotation-90); // sprite.setColor(1, 1, 1, alpha); canvas.drawSprite(sprite); canvas.setCompositeAlpha(priorAlpha); } /* (non-Javadoc) * @see leola.live.gfx.Renderable#update(leola.live.TimeStep) */ @Override public void update(TimeStep timeStep) { anim.update(timeStep); if(!this.persist) { this.fade.update(timeStep); } } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#isDone() */ @Override public boolean isDone() { return !persist && anim.isDone() && this.fade.isDone(); } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#destroy() */ @Override public void destroy() { } }
4,050
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
BlurEffectShader.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/BlurEffectShader.java
/* * see license.txt */ package seventh.client.gfx.effects; import seventh.client.gfx.Shader; /** * @author Tony * */ public class BlurEffectShader extends Shader { private static final Shader INSTANCE = new BlurEffectShader(); /** */ private BlurEffectShader() { super("./assets/gfx/shaders/base.vert", "./assets/gfx/shaders/blur.frag"); } /** * @return */ public static Shader getInstance() { return INSTANCE; } }
516
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
RippleEffectShader.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/RippleEffectShader.java
/* * see license.txt */ package seventh.client.gfx.effects; import seventh.client.gfx.Shader; /** * @author Tony * */ public class RippleEffectShader extends Shader { private static final Shader INSTANCE = new RippleEffectShader(); /** */ private RippleEffectShader() { super("./assets/gfx/shaders/base.vert", "./assets/gfx/shaders/ripple.frag"); } /** * @return */ public static Shader getInstance() { return INSTANCE; } }
524
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
SpriteParticleRenderer.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/SpriteParticleRenderer.java
/* * see license.txt */ package seventh.client.gfx.effects.particle_system; import com.badlogic.gdx.graphics.g2d.Sprite; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.effects.particle_system.Emitter.ParticleRenderer; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * Renders the Sprite associated with the particle * * @author Tony * */ public class SpriteParticleRenderer implements ParticleRenderer { @Override public void update(TimeStep timeStep, ParticleData particles) { } @Override public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles) { Vector2f cameraPos = camera.getRenderPosition(alpha); for(int i = 0; i < particles.numberOfAliveParticles; i++) { Sprite sprite = particles.sprite[i]; Vector2f pos = particles.pos[i]; sprite.setPosition(pos.x - cameraPos.x, pos.y - cameraPos.y); sprite.setScale(particles.scale[i]); sprite.setColor(particles.color[i]); sprite.setRotation(particles.rotation[i]); canvas.drawRawSprite(sprite); } } }
1,247
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
RandomScaleGrowthSingleParticleGenerator.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/RandomScaleGrowthSingleParticleGenerator.java
/* * see license.txt */ package seventh.client.gfx.effects.particle_system; import seventh.client.gfx.effects.particle_system.BatchedParticleGenerator.SingleParticleGenerator; import seventh.shared.TimeStep; /** * Spawns a particle randomly around a radius * * @author Tony * */ public class RandomScaleGrowthSingleParticleGenerator implements SingleParticleGenerator { private final float endingScale; /** * */ public RandomScaleGrowthSingleParticleGenerator(float endingScale) { this.endingScale = endingScale; } @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { long remainingTime = particles.emitter.timeToLive.getRemainingTime(); long endTime = particles.emitter.timeToLive.getEndTime(); float alpha = 1.0f - ((float)remainingTime / (float)endTime); float startingScale = particles.scale[index]; float scale = startingScale + ((this.endingScale-startingScale) * alpha); particles.scale[index] = scale; } }
1,116
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
RandomPositionInRadiusSingleParticleGenerator.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/RandomPositionInRadiusSingleParticleGenerator.java
/* * see license.txt */ package seventh.client.gfx.effects.particle_system; import java.util.Random; import seventh.client.gfx.effects.particle_system.BatchedParticleGenerator.SingleParticleGenerator; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * Spawns a particle randomly around a radius * * @author Tony * */ public class RandomPositionInRadiusSingleParticleGenerator implements SingleParticleGenerator { private final int maxDistance; /** * */ public RandomPositionInRadiusSingleParticleGenerator(int maxDistance) { this.maxDistance = maxDistance; } @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { if(this.maxDistance>0) { Random r = particles.emitter.getRandom(); Vector2f pos = particles.pos[index]; pos.set(1,0); Vector2f.Vector2fRotate(pos, Math.toRadians(r.nextInt(360)), pos); Vector2f.Vector2fMA(particles.emitter.getPos(), pos, r.nextInt(this.maxDistance), pos); } } }
1,134
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
RandomVelocitySingleParticleGenerator.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/RandomVelocitySingleParticleGenerator.java
/* * see license.txt */ package seventh.client.gfx.effects.particle_system; import java.util.Random; import seventh.client.gfx.effects.particle_system.BatchedParticleGenerator.SingleParticleGenerator; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * Spawns a particle randomly around a radius * * @author Tony * */ public class RandomVelocitySingleParticleGenerator implements SingleParticleGenerator { private final Vector2f startingVel; private final int maxDistance; /** * */ public RandomVelocitySingleParticleGenerator(Vector2f startingVel, int maxDistance) { this.startingVel = startingVel; this.maxDistance = maxDistance; } @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { Random r = particles.emitter.getRandom(); Vector2f vel = particles.vel[index]; vel.set(this.startingVel); int rotateBy = r.nextInt(maxDistance); Vector2f.Vector2fRotate(vel, Math.toRadians((r.nextInt(2) > 0) ? rotateBy : -rotateBy), vel); } }
1,136
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
RandomPositionInRadiusGrowthSingleParticleGenerator.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/RandomPositionInRadiusGrowthSingleParticleGenerator.java
/* * see license.txt */ package seventh.client.gfx.effects.particle_system; import java.util.Random; import seventh.client.gfx.effects.particle_system.BatchedParticleGenerator.SingleParticleGenerator; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * Spawns a particle randomly around a radius * * @author Tony * */ public class RandomPositionInRadiusGrowthSingleParticleGenerator implements SingleParticleGenerator { private final int startingMaxDistance, endingMaxDistance; /** * */ public RandomPositionInRadiusGrowthSingleParticleGenerator(int startingMaxDistance, int endingMaxDistance) { this.startingMaxDistance = startingMaxDistance; this.endingMaxDistance = endingMaxDistance; } @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { Random r = particles.emitter.getRandom(); long remainingTime = particles.emitter.timeToLive.getRemainingTime(); long endTime = particles.emitter.timeToLive.getEndTime(); float alpha = 1.0f - ((float)remainingTime / (float)endTime); int maxDistance = this.startingMaxDistance + (int)((this.endingMaxDistance-this.startingMaxDistance) * alpha); Vector2f pos = particles.pos[index]; pos.set(1,0); Vector2f.Vector2fRotate(pos, Math.toRadians(r.nextInt(360)), pos); Vector2f.Vector2fMA(particles.emitter.getPos(), pos, r.nextInt(maxDistance), pos); } }
1,547
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Emitters.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/Emitters.java
/* * see license.txt */ package seventh.client.gfx.effects.particle_system; import java.util.Random; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; import seventh.client.entities.ClientEntity; import seventh.client.gfx.Art; import seventh.client.gfx.TextureUtil; import seventh.client.gfx.effects.particle_system.BatchedParticleGenerator.SingleParticleGenerator; import seventh.client.gfx.effects.particle_system.Emitter.EmitterLifeCycleListener; import seventh.client.gfx.effects.particle_system.Emitter.ParticleUpdater; import seventh.map.Tile; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * @author Tony * */ public class Emitters { private static EmitterPool fireEmitterPool = new EmitterPool(new EmitterPool.EmitterFactory() { @Override public Emitter newEmitter() { return _newFireEmitter(new Vector2f()); } }); public static Emitter newFireEmitter(Vector2f pos) { return fireEmitterPool.allocate(pos); //return _newFireEmitter(pos); } private static Emitter _newFireEmitter(Vector2f pos) { int emitterTimeToLive = 2_400; int maxParticles = 140; int maxSpread = 40; Emitter emitter = new Emitter(pos.createClone(), emitterTimeToLive, maxParticles) .setName("FireEmitter") .setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(0, 5) .addSingleParticleGenerator(new RandomColorSingleParticleGenerator(new Color(0xEB5aaFff), new Color(0xEB502Fff),new Color(0x434B43ff))) .addSingleParticleGenerator(new SingleParticleGenerator() { @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { particles.color[index].a = 0.92f; } }) .addSingleParticleGenerator(new RandomPositionInRadiusGrowthSingleParticleGenerator(1, maxSpread)) // .addSingleParticleGenerator(new RandomRotationSingleParticleGenerator()) .addSingleParticleGenerator(new RandomScaleSingleParticleGenerator(0.355f, 0.362f)) .addSingleParticleGenerator(new RandomScaleGrowthSingleParticleGenerator(2.4f)) .addSingleParticleGenerator(new RandomSpeedSingleParticleGenerator(80, 140)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(100, 200)) .addSingleParticleGenerator(new RandomSpriteSingleParticleGenerator(Art.smokeImage)) ; emitter.addParticleGenerator(gen); emitter.addParticleUpdater(new KillUpdater()); // emitter.addParticleUpdater(new KillIfAttachedIsDeadUpdater()); emitter.addParticleUpdater(new RandomMovementParticleUpdater(880)); emitter.addParticleUpdater(new AlphaDecayUpdater(0f, 0.9498f)); //emitter.addParticleUpdater(new ScaleUpdater(2.3f, 0.08f)); emitter.addParticleRenderer(new BlendingSpriteParticleRenderer()); emitter.setLifeCycleListener(new EmitterLifeCycleListener() { @Override public void onKilled(Emitter emitter) { fireEmitterPool.free(emitter); } }); return emitter; } public static Emitter newBloodEmitter(Vector2f pos, int maxParticles, int emitterTimeToLive, int maxSpread) { Emitter emitter = new Emitter(pos.createClone(), emitterTimeToLive, maxParticles) .setName("BloodEmitter") .setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(0, maxParticles) .addSingleParticleGenerator(new RandomPositionInRadiusSingleParticleGenerator(maxSpread)) .addSingleParticleGenerator(new RandomRotationSingleParticleGenerator()) .addSingleParticleGenerator(new RandomScaleSingleParticleGenerator(0.55f, 1.2f)) .addSingleParticleGenerator(new RandomSpeedSingleParticleGenerator(5, 5)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(emitterTimeToLive, emitterTimeToLive)) .addSingleParticleGenerator(new RandomSpriteSingleParticleGenerator(Art.bloodImages)) ; emitter.addParticleGenerator(gen); emitter.addParticleUpdater(new KillUpdater()); emitter.addParticleUpdater(new MovementParticleUpdater(0, 2)); emitter.addParticleUpdater(new AlphaDecayUpdater(0f, 0.994898f)); emitter.addParticleRenderer(new SpriteParticleRenderer()); return emitter; } public static Emitter newBulletImpactFleshEmitter(Vector2f pos, Vector2f targetVel) { // 5, 5200, 4000, 0, 60); // int maxParticles, int emitterTimeToLive, int particleTimeToLive, int timeToNextSpawn, int maxSpread) { Vector2f vel = targetVel.isZero() ? new Vector2f(-1.0f, -1.0f) : new Vector2f(-targetVel.x*1.0f, -targetVel.y*1.0f); Emitter emitter = new Emitter(pos.createClone(), 100, 30) .setName("BulletImpactFleshEmitter") .setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(0, 9); gen.addSingleParticleGenerator(new SingleParticleGenerator() { @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { particles.speed[index] = 105f; //particles.scale[index] = 0.32f; } }) //.addSingleParticleGenerator(new SetPositionSingleParticleGenerator()) .addSingleParticleGenerator(new RandomPositionInRadiusSingleParticleGenerator(5)) .addSingleParticleGenerator(new RandomColorSingleParticleGenerator(new Color(0x660000fa), new Color(0x5f0301fa), new Color(0xb63030fa), new Color(0x330000fa))) .addSingleParticleGenerator(new RandomVelocitySingleParticleGenerator(vel, 20)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(200, 350)) // .addSingleParticleGenerator(new RandomSpriteSingleParticleGenerator(Art.bloodImages)) ; emitter.addParticleGenerator(gen); emitter.addParticleUpdater(new KillUpdater()); emitter.addParticleUpdater(new RandomMovementParticleUpdater(125)); emitter.addParticleUpdater(new AlphaDecayUpdater(0f, 0.782718f)); emitter.addParticleRenderer(new CircleParticleRenderer(1.5f)); //emitter.addParticleRenderer(new BlendingSpriteParticleRenderer()); //emitter.addParticleRenderer(new SpriteParticleRenderer()); return emitter; } public static Emitter newGibEmitter(Vector2f pos, int maxParticles) { int emitterTimeToLive = 10_000; int maxSpread = 35; Emitter emitter = new Emitter(pos.createClone(), emitterTimeToLive, maxParticles) .setName("GibEmitter") .setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(0, maxParticles) .addSingleParticleGenerator(new RandomPositionInRadiusSingleParticleGenerator(maxSpread)) .addSingleParticleGenerator(new RandomRotationSingleParticleGenerator()) .addSingleParticleGenerator(new RandomScaleSingleParticleGenerator(0.15f, 1.2f)) .addSingleParticleGenerator(new RandomSpeedSingleParticleGenerator(0, 0)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(emitterTimeToLive, emitterTimeToLive)) .addSingleParticleGenerator(new RandomSpriteSingleParticleGenerator(Art.gibImages)) ; emitter.addParticleGenerator(gen); emitter.addParticleUpdater(new KillUpdater()); emitter.addParticleUpdater(new MovementParticleUpdater(0, 2)); emitter.addParticleUpdater(new AlphaDecayUpdater(0f, 0.9898f)); emitter.addParticleRenderer(new SpriteParticleRenderer()); return emitter; } public static Emitter newRocketTrailEmitter(Vector2f pos, int emitterTimeToLive) { //int emitterTimeToLive = 10_000; int maxParticles = 1000; int maxSpread = 15; Emitter emitter = new Emitter(pos.createClone(), emitterTimeToLive, maxParticles) .setName("RocketTrailEmitter") .setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(0, 7) .addSingleParticleGenerator(new RandomColorSingleParticleGenerator(new Color(0x474B48ff),new Color(0x434B43ff))) .addSingleParticleGenerator(new SingleParticleGenerator() { @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { particles.color[index].a = 0.92f; } }) .addSingleParticleGenerator(new RandomPositionInRadiusSingleParticleGenerator(maxSpread)) .addSingleParticleGenerator(new RandomRotationSingleParticleGenerator()) .addSingleParticleGenerator(new RandomScaleSingleParticleGenerator(0.25f, 1.2f)) .addSingleParticleGenerator(new RandomSpeedSingleParticleGenerator(0, 0)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(5500, 6000)) .addSingleParticleGenerator(new RandomSpriteSingleParticleGenerator(Art.smokeImage)) ; emitter.addParticleGenerator(gen); emitter.addParticleUpdater(new KillUpdater()); emitter.addParticleUpdater(new KillIfAttachedIsDeadUpdater()); emitter.addParticleUpdater(new RandomMovementParticleUpdater(80)); emitter.addParticleUpdater(new AlphaDecayUpdater(0f, 0.9498f)); emitter.addParticleRenderer(new SpriteParticleRenderer()); return emitter; } public static Emitter newSmokeEmitter(Vector2f pos, int emitterTimeToLive) { return newSmokeEmitter(pos, emitterTimeToLive, false); } public static Emitter newSmokeEmitter(Vector2f pos, int emitterTimeToLive, boolean killIfAttachedIsDead) { return newSmokeEmitter(pos, emitterTimeToLive, 35, 0.55f, 1.2f); } public static Emitter newSmokeEmitter(Vector2f pos, int emitterTimeToLive, int colorStart, int colorEnd) { return newSmokeEmitter(pos, emitterTimeToLive, colorStart, colorEnd, 35, 0.55f, 1.2f, false); } public static Emitter newSmokeEmitter(Vector2f pos, int emitterTimeToLive, int maxSpread, float minSize, float maxSize) { return newSmokeEmitter(pos, emitterTimeToLive, 0x838B8Bff, 0x838B83ff, maxSpread, minSize, maxSize, false); } public static Emitter newSmokeEmitter(Vector2f pos, int emitterTimeToLive, int colorStart, int colorEnd, int maxSpread, float minSize, float maxSize, boolean killIfAttachedIsDead) { int maxParticles = 1500; Emitter emitter = new Emitter(pos.createClone(), emitterTimeToLive, maxParticles) .setName("SmokeEmitter") .setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(100, 4) .addSingleParticleGenerator(new RandomColorSingleParticleGenerator(new Color(colorStart), new Color(colorEnd))) .addSingleParticleGenerator(new SingleParticleGenerator() { @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { particles.color[index].a = 0.32f; } }) .addSingleParticleGenerator(new RandomPositionInRadiusSingleParticleGenerator(maxSpread)) .addSingleParticleGenerator(new RandomRotationSingleParticleGenerator()) .addSingleParticleGenerator(new RandomScaleSingleParticleGenerator(minSize, maxSize)) .addSingleParticleGenerator(new RandomSpeedSingleParticleGenerator(1, 1)) .addSingleParticleGenerator(new RandomVelocitySingleParticleGenerator(new Vector2f(1,0), 180)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(3800, 4000)) .addSingleParticleGenerator(new RandomSpriteSingleParticleGenerator(Art.smokeImage)) ; emitter.addParticleGenerator(gen); if (killIfAttachedIsDead) emitter.addParticleUpdater(new KillIfAttachedIsDeadUpdater()); emitter.addParticleUpdater(new KillUpdater()); emitter.addParticleUpdater(new RandomMovementParticleUpdater(20)); //emitter.addParticleUpdater(new MovementParticleUpdater(0, 40f)); emitter.addParticleUpdater(new AlphaDecayUpdater(0f, 0.9898f)); emitter.addParticleRenderer(new SpriteParticleRenderer()); return emitter; } public static Emitter newGunSmokeEmitter(final ClientEntity entity, int emitterTimeToLive) { int maxParticles = 1500; final int maxSpread = 5; final Vector2f tmp = new Vector2f(entity.getPos()); final Vector2f vel = entity.getFacing(); Emitter emitter = new Emitter(tmp, emitterTimeToLive, maxParticles) .setName("GunSmokeEmitter") .setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(0, 4) .addSingleParticleGenerator(new RandomColorSingleParticleGenerator(new Color(0xDCDCDCff),new Color(0xD3D3D3ff))) .addSingleParticleGenerator(new SingleParticleGenerator() { @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { particles.color[index].a = 0.32f; if(maxSpread > 0) { Random r = particles.emitter.getRandom(); Vector2f pos = particles.pos[index]; pos.set(1,0); Vector2f.Vector2fRotate(pos, Math.toRadians(r.nextInt(360)), pos); Vector2f.Vector2fMA(entity.getPos(), entity.getFacing(), 25.0f, tmp); Vector2f.Vector2fMA(tmp, pos, r.nextInt(maxSpread), pos); } } }) .addSingleParticleGenerator(new RandomRotationSingleParticleGenerator()) .addSingleParticleGenerator(new RandomScaleSingleParticleGenerator(0.25f, 0.30f)) .addSingleParticleGenerator(new RandomSpeedSingleParticleGenerator(1, 1)) .addSingleParticleGenerator(new RandomVelocitySingleParticleGenerator(vel, 130)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(3800, 4000)) .addSingleParticleGenerator(new RandomSpriteSingleParticleGenerator(Art.smokeImage)) ; emitter.addParticleGenerator(gen); emitter.addParticleUpdater(new KillUpdater()); emitter.addParticleUpdater(new KillIfAttachedIsDeadUpdater()); emitter.addParticleUpdater(new RandomMovementParticleUpdater(20)); //emitter.addParticleUpdater(new MovementParticleUpdater(0, 40f)); emitter.addParticleUpdater(new AlphaDecayUpdater(0f, 0.9898f)); emitter.addParticleRenderer(new SpriteParticleRenderer()); return emitter; } public static Emitter newBulletTracerEmitter(Vector2f pos, int emitterTimeToLive) { int maxParticles = 68; final Emitter emitter = new Emitter(pos.createClone(), emitterTimeToLive, maxParticles) .setName("BulletTracerEmitter") .setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(0, maxParticles) .addSingleParticleGenerator(new RandomColorSingleParticleGenerator(new Color(0xffbA00ff),new Color(0xffff00ff))) .addSingleParticleGenerator(new SingleParticleGenerator() { @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { particles.color[index].a = 0.0f; } }) .addSingleParticleGenerator(new SetPositionSingleParticleGenerator()) ; emitter.addParticleGenerator(gen); emitter.addParticleUpdater(new ParticleUpdater() { @Override public void reset() { } @Override public void update(TimeStep timeStep, ParticleData particles) { ClientEntity ent = emitter.attachedTo(); if(ent!=null) { Vector2f pos = ent.getCenterPos(); Vector2f vel = ent.getMovementDir(); for(int index = 0; index < particles.numberOfAliveParticles; index++) { float offset = index; Vector2f.Vector2fMS(pos, vel, offset, particles.pos[index]); float percentange = (float)index / particles.numberOfAliveParticles; particles.color[index].a = 0.9512f * (1f - percentange); } } else { for(int index = 0; index < particles.numberOfAliveParticles; index++) { particles.color[index].a = 0f; } } } }); emitter.addParticleUpdater(new KillIfAttachedIsDeadUpdater()); emitter.addParticleRenderer(new RectParticleRenderer(3,3)); return emitter; } public static Emitter newBulletImpactEmitter(Vector2f pos, Vector2f targetVel) { // 5, 5200, 4000, 0, 60); // int maxParticles, int emitterTimeToLive, int particleTimeToLive, int timeToNextSpawn, int maxSpread) { Vector2f vel = targetVel.isZero() ? new Vector2f(-1.0f, -1.0f) : new Vector2f(-targetVel.x*1.0f, -targetVel.y*1.0f); Emitter emitter = new Emitter(pos.createClone(), 200, 30) .setName("BulletImpactEmitter") .setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(0, 30); gen.addSingleParticleGenerator(new SingleParticleGenerator() { @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { particles.speed[index] = 125f; } }) .addSingleParticleGenerator(new SetPositionSingleParticleGenerator()) .addSingleParticleGenerator(new RandomColorSingleParticleGenerator(new Color(0x8B7355ff), new Color(0x8A7355ff))) .addSingleParticleGenerator(new RandomVelocitySingleParticleGenerator(vel, 60)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(200, 250)) ; emitter.addParticleGenerator(gen); emitter.addParticleUpdater(new KillUpdater()); emitter.addParticleUpdater(new RandomMovementParticleUpdater(85)); emitter.addParticleUpdater(new AlphaDecayUpdater(0f, 0.82718f)); emitter.addParticleRenderer(new CircleParticleRenderer()); return emitter; } public static Emitter newTankTrackSplatterEmitter(Vector2f pos, Vector2f targetVel) { // 5, 5200, 4000, 0, 60); // int maxParticles, int emitterTimeToLive, int particleTimeToLive, int timeToNextSpawn, int maxSpread) { Vector2f vel = targetVel.isZero() ? new Vector2f(-1.0f, -1.0f) : new Vector2f(-targetVel.x*1.0f, -targetVel.y*1.0f); Emitter emitter = new Emitter(pos.createClone(), 200, 30) .setName("TankTrackSplatterEmitter") .setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(0, 30); gen.addSingleParticleGenerator(new SingleParticleGenerator() { @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { particles.speed[index] = 125f; } }) .addSingleParticleGenerator(new SetPositionSingleParticleGenerator()) .addSingleParticleGenerator(new RandomColorSingleParticleGenerator(new Color(0x8B7355ff), new Color(0x8A7355ff))) .addSingleParticleGenerator(new RandomVelocitySingleParticleGenerator(vel, 30)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(200, 250)) ; emitter.addParticleGenerator(gen); emitter.addParticleUpdater(new KillUpdater()); emitter.addParticleUpdater(new RandomMovementParticleUpdater(85)); emitter.addParticleUpdater(new AlphaDecayUpdater(0f, 0.72718f)); emitter.addParticleRenderer(new CircleParticleRenderer()); return emitter; } public static Emitter newGlassBreakEmitter(Vector2f pos, Vector2f targetVel) { Vector2f vel = targetVel.createClone(); final int ttl = 15_000; Emitter emitter = new Emitter(pos.createClone(), ttl, 30) .setName("GlassBreakEmitter") .setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(0, 30); gen.addSingleParticleGenerator(new SingleParticleGenerator() { @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { particles.speed[index] = 125f; } }) .addSingleParticleGenerator(new SetPositionSingleParticleGenerator()) .addSingleParticleGenerator(new RandomColorSingleParticleGenerator(new Color(0xf8f8f83f), new Color(0xbde7f43f), new Color(0xf6f6f63f), new Color(0xadd7f43f))) .addSingleParticleGenerator(new RandomVelocitySingleParticleGenerator(vel, 60)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(ttl, ttl)) .addSingleParticleGenerator(new RandomRotationSingleParticleGenerator()) .addSingleParticleGenerator(new RandomScaleSingleParticleGenerator(8f, 15f)) ; emitter.addParticleGenerator(gen); emitter.addParticleUpdater(new KillUpdater()); emitter.addParticleUpdater(new MovementParticleUpdater(0, 12f)); emitter.addParticleUpdater(new AlphaDecayUpdater(3_000, 0f, 0.995718f)); emitter.addParticleRenderer(new TriangleParticleRenderer(4.5f)); return emitter; } public static Emitter newSingleSparksEmitter(final Vector2f pos, Vector2f targetVel) { final Vector2f vel = targetVel.createClone(); final int maxParticles = 60; final Emitter emitter = new Emitter(pos.createClone(), Integer.MAX_VALUE, maxParticles) .setName("SparksEmitter") .setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(5050, 8200, maxParticles); gen.addSingleParticleGenerator(new SingleParticleGenerator() { @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { particles.speed[index] = 285; particles.pos[index].set(emitter.getPos()); } }) .addSingleParticleGenerator(new SetPositionSingleParticleGenerator()) .addSingleParticleGenerator(new RandomColorSingleParticleGenerator(new Color(0xF7DC6Fff), new Color(0xF9E79Fff),new Color(0xF4D03Fff))) .addSingleParticleGenerator(new RandomVelocitySingleParticleGenerator(vel, 60)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(2000, 2050)) ; emitter.addParticleGenerator(gen); emitter.addParticleUpdater(new KillUpdater()); emitter.addParticleUpdater(new RandomMovementParticleUpdater(285, 0.6f, 0f)); emitter.addParticleUpdater(new AlphaDecayUpdater(0f, 0.9822718f)); emitter.addParticleRenderer(new CircleParticleRenderer()); return emitter; } public static Emitter newSparksEmitter(final Vector2f pos, Vector2f targetVel) { final Vector2f vel = targetVel.createClone(); final int maxParticles = 30; final CompositeEmitter emitter = new CompositeEmitter(pos.createClone(), Integer.MAX_VALUE, maxParticles, newSingleSparksEmitter(pos, targetVel)); emitter.setName("SparksEmitter"); emitter.setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(2050, 3200, maxParticles); gen.addSingleParticleGenerator(new SingleParticleGenerator() { @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { particles.speed[index] = 285; particles.pos[index].set(emitter.getPos()); } }) .addSingleParticleGenerator(new SetPositionSingleParticleGenerator()) .addSingleParticleGenerator(new RandomColorSingleParticleGenerator(new Color(0xF7DC6Fff), new Color(0xF9E79Fff),new Color(0xF4D03Fff))) .addSingleParticleGenerator(new RandomVelocitySingleParticleGenerator(vel, 30)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(2000, 2050)) ; emitter.addParticleGenerator(gen); emitter.addParticleUpdater(new KillUpdater()); emitter.addParticleUpdater(new RandomMovementParticleUpdater(285, 0.5f, 0f)); emitter.addParticleUpdater(new AlphaDecayUpdater(0f, 0.9822718f)); emitter.addParticleRenderer(new CircleParticleRenderer()); return emitter; } public static Emitter newWallCrumbleEmitter(Tile tile, Vector2f pos) { final int maxParticles = 44; final int timeToLive = 100_000; Emitter emitter = new Emitter(pos, timeToLive, maxParticles) .setPersistent(true) .setDieInstantly(false); Random rand = emitter.getRandom(); // TODO: fix the flipping business // in tiles, this is driving me nuts! Sprite image = new Sprite(tile.getImage()); image.flip(false, true); TextureRegion[] images = new TextureRegion[44]; int i = 0; for(; i < images.length-15; i++) { int x = rand.nextInt(image.getRegionWidth()); int y = rand.nextInt(image.getRegionHeight()); int width = rand.nextInt(image.getRegionWidth()/2); int height = rand.nextInt(image.getRegionHeight()/2); if(x+width > image.getRegionWidth()) { width = image.getRegionWidth() - x; } if(y+height > image.getRegionHeight()) { height = image.getRegionHeight() - y; } Sprite sprite = new Sprite(image); TextureUtil.setFlips(sprite, tile.isFlippedHorizontal(), tile.isFlippedVertical(), tile.isFlippedDiagnally()); sprite.setRegion(sprite, x, y, width, height); images[i] = sprite; } Sprite sprite = new Sprite(Art.BLACK_IMAGE, 0, 0, 2, 4); for(;i<images.length;i++) { images[i] = sprite; } BatchedParticleGenerator gen = new BatchedParticleGenerator(0, maxParticles) .addSingleParticleGenerator(new RandomPositionInRadiusSingleParticleGenerator(10)) .addSingleParticleGenerator(new RandomRotationSingleParticleGenerator()) //.addSingleParticleGenerator(new RandomScaleSingleParticleGenerator(0.15f, 1.9f)) .addSingleParticleGenerator(new RandomSpeedSingleParticleGenerator(250f, 250f)) .addSingleParticleGenerator(new RandomVelocitySingleParticleGenerator(new Vector2f(1,0), 180)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(timeToLive, timeToLive)) .addSingleParticleGenerator(new RandomSpriteSingleParticleGenerator(images)) ; emitter.addParticleGenerator(gen); //emitter.addParticleUpdater(new KillUpdater()); emitter.addParticleUpdater(new MovementParticleUpdater(0, 40f)); //emitter.addParticleUpdater(new AlphaDecayUpdater(0f, 0.9878f)); emitter.addParticleRenderer(new SpriteParticleRenderer()); return emitter; } public static Emitter newSpawnEmitter(Vector2f pos, int emitterTimeToLive) { int maxParticles = 40; int maxSpread = 45; Emitter emitter = new Emitter(pos.createClone(), emitterTimeToLive, maxParticles) .setName("SpawnEmitter") .setDieInstantly(false); BatchedParticleGenerator gen = new BatchedParticleGenerator(100, 2) .addSingleParticleGenerator(new RandomColorSingleParticleGenerator(new Color(0xffa701ff),new Color(0xeeb803ff),new Color(0xffb805ff))) .addSingleParticleGenerator(new SingleParticleGenerator() { @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { particles.color[index].a = 0.82f; } }) .addSingleParticleGenerator(new RandomPositionInRadiusSingleParticleGenerator(maxSpread)) .addSingleParticleGenerator(new RandomScaleSingleParticleGenerator(0.15f, 0.55f)) .addSingleParticleGenerator(new RandomSpeedSingleParticleGenerator(1, 1)) .addSingleParticleGenerator(new RandomVelocitySingleParticleGenerator(new Vector2f(1,0), 180)) .addSingleParticleGenerator(new RandomTimeToLiveSingleParticleGenerator(1800, 2300)) .addSingleParticleGenerator(new RandomSpriteSingleParticleGenerator(Art.smokeImage)) ; emitter.addParticleGenerator(gen); emitter.addParticleUpdater(new KillUpdater()); emitter.addParticleUpdater(new KillIfAttachedIsDeadUpdater()); emitter.addParticleUpdater(new RandomMovementParticleUpdater(40)); //emitter.addParticleUpdater(new MovementParticleUpdater(0, 40f)); emitter.addParticleUpdater(new AlphaDecayUpdater(0f, 0.96898f)); emitter.addParticleRenderer(new SpriteParticleRenderer()); return emitter; } }
32,429
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
RandomTimeToLiveSingleParticleGenerator.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/RandomTimeToLiveSingleParticleGenerator.java
/* * see license.txt */ package seventh.client.gfx.effects.particle_system; import java.util.Random; import seventh.client.gfx.effects.particle_system.BatchedParticleGenerator.SingleParticleGenerator; import seventh.shared.TimeStep; /** * Randomly assigns a time to live factor to a particle * * @author Tony * */ public class RandomTimeToLiveSingleParticleGenerator implements SingleParticleGenerator { private final long minTimeToLive, maxTimeToLive; public RandomTimeToLiveSingleParticleGenerator(long minTimeToLive, long maxTimeToLive) { this.minTimeToLive = minTimeToLive; this.maxTimeToLive = maxTimeToLive; } /* (non-Javadoc) * @see seventh.client.gfx.particle_system.BatchedParticleGenerator.SingleParticleGenerator#onGenerateParticle(int, seventh.shared.TimeStep, seventh.client.gfx.particle_system.ParticleData) */ @Override public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) { Random rand = particles.emitter.getRandom(); long timeToLive = minTimeToLive + rand.nextInt( (int)maxTimeToLive); particles.timeToLive[index].setEndTime(timeToLive); particles.timeToLive[index].reset(); } }
1,251
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
EmitterPool.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/EmitterPool.java
/* * see license.txt */ package seventh.client.gfx.effects.particle_system; import java.util.LinkedList; import java.util.Queue; import seventh.math.Vector2f; /** * @author Tony * */ public class EmitterPool { public static interface EmitterFactory { public Emitter newEmitter(); } private Queue<Emitter> pool; private EmitterFactory factory; /** * */ public EmitterPool(EmitterFactory factory) { this.factory = factory; this.pool = new LinkedList<>(); } public Emitter allocate(Vector2f pos) { Emitter emitter = this.pool.poll(); if(emitter == null) { emitter = this.factory.newEmitter(); } emitter.reset(); emitter.setPos(pos); return emitter; } public void free(Emitter emitter) { this.pool.add(emitter); } }
912
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
KillUpdater.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/KillUpdater.java
/* * see license.txt */ package seventh.client.gfx.effects.particle_system; import seventh.client.gfx.effects.particle_system.Emitter.ParticleUpdater; import seventh.shared.TimeStep; /** * @author Tony * */ public class KillUpdater implements ParticleUpdater { /** * */ public KillUpdater() { } @Override public void reset() { } /* (non-Javadoc) * @see seventh.client.gfx.particle_system.Emitter.ParticleUpdater#update(seventh.shared.TimeStep, seventh.client.gfx.particle_system.ParticleData) */ @Override public void update(TimeStep timeStep, ParticleData particles) { for(int i = 0; i < particles.numberOfAliveParticles; i++) { particles.timeToLive[i].update(timeStep); if(particles.timeToLive[i].isTime()) { particles.kill(i); } } } }
914
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
CompositeEmitter.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/CompositeEmitter.java
/* * The Seventh * see license.txt */ package seventh.client.gfx.effects.particle_system; import seventh.client.entities.ClientEntity; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.math.Vector2f; import seventh.shared.TimeStep; /** * @author Tony * */ public class CompositeEmitter extends Emitter { private Emitter[] subEmitters; /** * */ public CompositeEmitter(Vector2f pos, int timeToLive, int maxParticles, Emitter ... subEmitters) { super(pos, timeToLive, maxParticles); this.subEmitters = subEmitters; } /** * @return the subEmitters */ public Emitter[] getSubEmitters() { return subEmitters; } @Override public Emitter attachTo(ClientEntity ent) { for(int i = 0; i < this.subEmitters.length; i++) { this.subEmitters[i].attachTo(ent); } super.attachTo(ent); return this; } @Override public Emitter setPersistent(boolean persist) { for(int i = 0; i < this.subEmitters.length; i++) { this.subEmitters[i].setPersistent(persist); } super.setPersistent(persist); return this; } @Override public Emitter setPos(Vector2f pos) { for(int i = 0; i < this.subEmitters.length; i++) { this.subEmitters[i].setPos(pos); } super.setPos(pos); return this; } @Override public CompositeEmitter kill() { for(int i = 0; i < this.subEmitters.length; i++) { this.subEmitters[i].kill(); } super.kill(); return this; } @Override public CompositeEmitter start() { for(int i = 0; i < this.subEmitters.length; i++) { this.subEmitters[i].start(); } super.start(); return this; } @Override public CompositeEmitter stop() { for(int i = 0; i < this.subEmitters.length; i++) { this.subEmitters[i].stop(); } super.stop(); return this; } @Override public CompositeEmitter pause() { for(int i = 0; i < this.subEmitters.length; i++) { this.subEmitters[i].pause(); } super.pause(); return this; } @Override public CompositeEmitter reset() { for(int i = 0; i < this.subEmitters.length; i++) { this.subEmitters[i].reset(); } super.reset(); return this; } @Override public CompositeEmitter resetTimeToLive() { for(int i = 0; i < this.subEmitters.length; i++) { this.subEmitters[i].resetTimeToLive(); } super.resetTimeToLive(); return this; } @Override public void destroy() { for(int i = 0; i < this.subEmitters.length; i++) { this.subEmitters[i].destroy(); } super.destroy(); } @Override public void update(TimeStep timeStep) { for(int i = 0; i < this.subEmitters.length; i++) { this.subEmitters[i].update(timeStep); } super.update(timeStep); } @Override public void render(Canvas canvas, Camera camera, float alpha) { for(int i = 0; i < this.subEmitters.length; i++) { this.subEmitters[i].render(canvas, camera, alpha); } super.render(canvas, camera, alpha); } }
3,524
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
Emitter.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/Emitter.java
/* * The Seventh * see license.txt */ package seventh.client.gfx.effects.particle_system; import java.util.ArrayList; import java.util.List; import java.util.Random; import seventh.client.entities.ClientEntity; import seventh.client.gfx.Camera; import seventh.client.gfx.Canvas; import seventh.client.gfx.effects.Effect; import seventh.math.Rectangle; import seventh.math.Vector2f; import seventh.shared.TimeStep; import seventh.shared.Timer; /** * @author Tony * */ public class Emitter implements Effect { public static interface EmitterLifeCycleListener { public void onKilled(Emitter emitter); } /** * Spawns and setup particles * * @author Tony * */ public static interface ParticleGenerator { /** * Resets the generator */ public void reset(); /** * Spawns the appropriate particles * * @param timeStep * @param particles */ public void update(TimeStep timeStep, ParticleData particles); } /** * Updates the particles * * @author Tony * */ public static interface ParticleUpdater { public void reset(); /** * Updates the particles * * @param timeStep * @param particles */ public void update(TimeStep timeStep, ParticleData particles); } /** * Spawns and setup particles * * @author Tony * */ public static interface ParticleRenderer { /** * Spawns the appropriate particles * * @param timeStep * @param particles */ public void update(TimeStep timeStep, ParticleData particles); public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles); } protected Timer timeToLive; private Vector2f pos; private Random random; private boolean dieInstantly; private boolean kill, isPersistent; protected Rectangle visibileBounds; private ClientEntity attachedTo; private List<ParticleGenerator> generators; private List<ParticleUpdater> updaters; private List<ParticleRenderer> renderers; private ParticleData particles; private String name; private EmitterLifeCycleListener lifeCycleListener; /** * */ public Emitter(Vector2f pos, int timeToLive, int maxParticles) { this.pos = pos; this.generators = new ArrayList<>(); this.updaters = new ArrayList<>(); this.renderers = new ArrayList<>(); this.particles = new ParticleData(maxParticles); this.particles.emitter = this; this.timeToLive = new Timer(false, timeToLive); this.visibileBounds = new Rectangle(250, 250); this.visibileBounds.centerAround(pos); this.dieInstantly = true; this.kill = false; this.isPersistent = false; this.name = ""; // used for debugging purposes } public Emitter setLifeCycleListener(EmitterLifeCycleListener listener) { this.lifeCycleListener = listener; return this; } public Emitter addParticleGenerator(ParticleGenerator generator) { this.generators.add(generator); return this; } public Emitter addParticleUpdater(ParticleUpdater updater) { this.updaters.add(updater); return this; } public Emitter addParticleRenderer(ParticleRenderer renderer) { this.renderers.add(renderer); return this; } /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public Emitter setName(String name) { this.name = name; return this; } /** * If this emitter should stick around even after its timers have expired. this should * be used if the emitter is cached and will want to be reused * * @return the persist */ public boolean isPersistent() { return isPersistent; } /** * @param persist the persist to set */ public Emitter setPersistent(boolean persist) { this.isPersistent = persist; return this; } /** * @param dieInstantly the dieInstantly to set */ public Emitter setDieInstantly(boolean dieInstantly) { this.dieInstantly = dieInstantly; return this; } /** * @return the dieInstantly */ public boolean isDieInstantly() { return dieInstantly; } /** * @param pos the pos to set */ public Emitter setPos(Vector2f pos) { this.pos.set(pos); this.visibileBounds.centerAround(pos); return this; } public Emitter attachTo(ClientEntity ent) { this.attachedTo = ent; this.pos.set(ent.getPos()); return this; } public ClientEntity attachedTo() { return this.attachedTo; } /** * @return the random */ public Random getRandom() { if(random==null) random = new Random(); return random; } /** * @return the pos */ public Vector2f getPos() { return pos; } public Emitter kill() { this.kill = true; if(this.lifeCycleListener!=null) { this.lifeCycleListener.onKilled(this); } return this; } /** * Starts this emitter */ public Emitter start() { this.timeToLive.start(); return this; } public Emitter stop() { this.timeToLive.expire(); return this; } public Emitter pause() { this.timeToLive.pause(); return this; } public Emitter reset() { resetTimeToLive(); this.particles.reset(); this.kill = false; resetUpdaters(); return this; } public Emitter resetUpdaters() { for(int i = 0; i < this.updaters.size(); i++) { this.updaters.get(i).reset(); } return this; } public Emitter resetGenerators() { for(int i = 0; i < this.generators.size(); i++) { this.generators.get(i).reset(); } return this; } public Emitter resetTimeToLive() { this.timeToLive.reset(); resetGenerators(); return this; } public long getTimeToLive() { return this.timeToLive.getEndTime(); } /** * @return true if this is still active */ public boolean isAlive() { if(this.kill) { return false; } boolean expired = this.timeToLive.isTime(); boolean pseudoAlive = /*this.isPaused ||*/ this.isPersistent; if(isDieInstantly()) { return expired || pseudoAlive; } return (!expired || this.particles.numberOfAliveParticles > 0) || pseudoAlive; } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#isDone() */ @Override public boolean isDone() { return !isAlive(); } /* (non-Javadoc) * @see seventh.client.gfx.particle.Effect#destroy() */ @Override public void destroy() { //reset(); kill(); } /* (non-Javadoc) * @see leola.live.gfx.Renderable#update(leola.live.TimeStep) */ @Override public void update(TimeStep timeStep) { if(isAlive() /*&& !this.isPaused*/) { if(this.attachedTo!=null) { this.pos.set(this.attachedTo.getPos()); } this.timeToLive.update(timeStep); if(!this.timeToLive.isTime()) { for(int i = 0; i < this.generators.size(); i++) { this.generators.get(i).update(timeStep, this.particles); } } for(int i = 0; i < this.updaters.size(); i++) { this.updaters.get(i).update(timeStep, this.particles); } for(int i = 0; i < this.renderers.size(); i++) { this.renderers.get(i).update(timeStep, this.particles); } this.visibileBounds.centerAround(pos); } } /* (non-Javadoc) * @see leola.live.gfx.Renderable#render(leola.live.gfx.Canvas, leola.live.gfx.Camera, long) */ @Override public void render(Canvas canvas, Camera camera, float alpha) { if(isAlive() /*&& !this.isPaused*/ && (this.attachedTo!=null || this.visibileBounds.intersects(camera.getWorldViewPort())) ) { for(int i = 0; i < this.renderers.size(); i++) { this.renderers.get(i).render(canvas, camera, alpha, this.particles); } } } }
9,211
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z
BatchedParticleGenerator.java
/FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/BatchedParticleGenerator.java
/* * see license.txt */ package seventh.client.gfx.effects.particle_system; import java.util.ArrayList; import java.util.List; import java.util.Random; import seventh.client.gfx.effects.particle_system.Emitter.ParticleGenerator; import seventh.shared.TimeStep; import seventh.shared.Timer; /** * Spawns a batch of particles * * @author Tony * */ public class BatchedParticleGenerator implements ParticleGenerator { /** * Handles a single generated particle * * @author Tony * */ public static interface SingleParticleGenerator { void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles); } private final Timer spawnTimer; private final int batchSize; private List<SingleParticleGenerator> generators; private final long minSpawnTime, maxSpawnTime; /** * */ public BatchedParticleGenerator(long spawnTime, int batchSize) { this(spawnTime, spawnTime, batchSize); } /** * @param spawnTime * @param batchSize */ public BatchedParticleGenerator(long minSpawnTime, long maxSpawnTime, int batchSize) { this.spawnTimer = new Timer(true, minSpawnTime); this.minSpawnTime = minSpawnTime; this.maxSpawnTime = maxSpawnTime; this.batchSize = batchSize; this.generators = new ArrayList<>(); this.spawnTimer.start(); } public BatchedParticleGenerator addSingleParticleGenerator(SingleParticleGenerator gen) { this.generators.add(gen); return this; } protected void updateSingleParticles(int index, TimeStep timeStep, ParticleData particles) { for(int i = 0; i < this.generators.size();i++) { this.generators.get(i).onGenerateParticle(index, timeStep, particles); } } @Override public void reset() { this.spawnTimer.reset(); this.spawnTimer.start(); } @Override public void update(TimeStep timeStep, ParticleData particles) { this.spawnTimer.update(timeStep); if(this.spawnTimer.isOnFirstTime()) { particles.emitter.resetUpdaters(); Random rand = particles.emitter.getRandom(); if(this.maxSpawnTime > this.minSpawnTime) { long timer = this.minSpawnTime + rand.nextInt((int)(this.maxSpawnTime - this.minSpawnTime)); this.spawnTimer.setEndTime(timer); this.spawnTimer.reset(); particles.reset(); } for(int i = 0; i < this.batchSize; i++) { int index = particles.spawnParticle(); if(index > -1) { updateSingleParticles(index, timeStep, particles); } } } } }
2,946
Java
.java
tonysparks/seventh
49
30
7
2014-05-05T22:57:09Z
2019-11-27T01:44:13Z