Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit: Added console weapon commands, added Machete, Cannon, Melee, Elephantgun #844

Merged
merged 8 commits into from Mar 12, 2012
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file modified res/art/weapons/weapon_list.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion res/constants/constants.txt
@@ -1,4 +1,4 @@
options.locale_af = AFRIKAANS
options.locale_af = AFRIKAANS
options.locale_de = DEUTSCH
options.locale_en = ENGLISH
options.locale_es = ESPAÑOL
Expand Down Expand Up @@ -56,3 +56,17 @@ com.mojang.mojam.entity.weapon.Shotgun.shootDelay=35
com.mojang.mojam.entity.weapon.VenomShooter.bulletDamage=0.5
com.mojang.mojam.entity.weapon.VenomShooter.accuracy=0.15
com.mojang.mojam.entity.weapon.VenomShooter.shootDelay=5

com.mojang.mojam.entity.weapon.Cannon.bulletDamage=30
com.mojang.mojam.entity.weapon.Cannon.accuracy=0.0
com.mojang.mojam.entity.weapon.Cannon.shootDelay=900

com.mojang.mojam.entity.weapon.ElephantGun.bulletDamage=15
com.mojang.mojam.entity.weapon.ElephantGun.accuracy=0.05
com.mojang.mojam.entity.weapon.ElephantGun.shootDelay=120

com.mojang.mojam.entity.weapon.Machete.bulletDamage=2
com.mojang.mojam.entity.weapon.Machete.attackDelay=35

com.mojang.mojam.entity.weapon.Melee.bulletDamage=1.5
com.mojang.mojam.entity.weapon.Melee.attackDelay=30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used. instead I get an error because shootDelay is not defined. Why not leave this shootDelay

177 changes: 175 additions & 2 deletions src/com/mojang/mojam/Console.java
Expand Up @@ -3,7 +3,18 @@
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.Date;

import com.mojang.mojam.entity.Player;
import com.mojang.mojam.entity.weapon.Cannon;
import com.mojang.mojam.entity.weapon.ElephantGun;
import com.mojang.mojam.entity.weapon.Machete;
import com.mojang.mojam.entity.weapon.Melee;
import com.mojang.mojam.entity.weapon.Raygun;
import com.mojang.mojam.entity.weapon.Rifle;
import com.mojang.mojam.entity.weapon.Shotgun;
import com.mojang.mojam.entity.weapon.VenomShooter;
import com.mojang.mojam.gui.TitleMenu;
import com.mojang.mojam.gui.components.Font;
import com.mojang.mojam.screen.Screen;

Expand Down Expand Up @@ -38,6 +49,17 @@ public class Console implements KeyListener {
*/
public static final int yOffset = 5;

public Console()
{
log("------------------------------------------------------------");//Deep magic lining it up
log("|Catacomb Snatch Console v1.1 |");
log("|Type commands with a slash in front, like /this |");
log("|If in doubt, type /help |");
log("------------------------------------------------------------");
log("");
}


/***
* Logs the verbose info into the console
*
Expand Down Expand Up @@ -98,9 +120,9 @@ public void render(Screen s) {
int fontHeight = Font.FONT_WHITE_SMALL.getFontHeight();
int consoleHeight = (MAX_LINES + 1) * fontHeight + yOffset; //+1 for the input line

s.alphaFill(0, 0, s.w, consoleHeight, 0xff000000, 0x50); //50% black I believe. took it from PauseMenu and changed 0x30 to 0x50
s.alphaFill(0, 0, s.w, consoleHeight, 0xff000000, 0x80); //50% black,fixed from 0x50 (31.25%)

Font.FONT_WHITE_SMALL.draw(s, typing + "|", xOffset,(consoleHeight -= fontHeight)); //draws bottom up starting with typing
Font.FONT_WHITE_SMALL.draw(s, typing + (((((int)(System.currentTimeMillis()/500))&1)==1)?"|":""), xOffset,(consoleHeight -= fontHeight)); //draws bottom up starting with typing

for(int i = 0; i < verboseData.size(); i++) {
Font.FONT_WHITE_SMALL.draw(s, verboseData.get(i), xOffset, (consoleHeight -= fontHeight) ); // and then the verbose data in order of newest first
Expand Down Expand Up @@ -289,6 +311,157 @@ public void doCommand(String[] args) {
}
};

public Command load = new Command("load", 1, "Loads a map by name")
{
@Override
public void doCommand(String[] args)
{
log("Loading map " + args[0]);
log("Incomplete");
//TitleMenu.level = new LevelInformation(args[0], "/levels/" + args[0].replace('_', ' ') + ".bmp", true);
//TODO: Needs MUCH work
//MojamComponent.instance.handleAction(TitleMenu.START_GAME_ID);
}
};
public Command lang = new Command("lang", 1, "Sets the language")
{
@Override
public void doCommand(String[] args)
{
if(args[0].equals("help"))
{
log("Enter your two letter language code, e.g. /lang af -> Afrikaans, /lang it -> Italiano");
}
else
{
MojamComponent.instance.setLocale(args[0]);
}
}
};
public Command menu = new Command("menu", 0, "Return to menu")
{
@Override
public void doCommand(String[] args)
{
MojamComponent.instance.handleAction(TitleMenu.RETURN_TO_TITLESCREEN);
}
};

public Command give = new Command("give", 1, "Gives a weapon")
{
@Override
public void doCommand(String[] args)
{
args[0].trim();
Player player = MojamComponent.instance.player;
int i;
if(args[0].toLowerCase().equals("shotgun"))
{
log("Giving player a shotgun");
if(!player.weaponInventory.add(new Shotgun(player))) {
log("You already have this item.");
}
}
else if(args[0].toLowerCase().equals("rifle"))
{
log("Giving player a rifle");
if(!player.weaponInventory.add(new Rifle(player))) {
log("You already have this item.");
}
}
else if(args[0].toLowerCase().equals("venom"))
{
log("Giving player a veonomshooter");
if(!player.weaponInventory.add(new VenomShooter(player))) {
log("You already have this item.");
}
}
else if(args[0].toLowerCase().equals("elephant"))
{
log("Giving player an elephant gun");
if(!player.weaponInventory.add(new ElephantGun(player))) {
log("You already have this item.");
}
}
else if(args[0].toLowerCase().equals("fist"))
{
log("Giving player a lesson in boxing");
if(!player.weaponInventory.add(new Melee(player))) {
log("You already have this item.");
}
}
else if(args[0].toLowerCase().equals("raygun"))
{
log("Giving player a raygun");
if(!player.weaponInventory.add(new Raygun(player))) {
log("You already have this item.");
}
}
else if(args[0].toLowerCase().equals("machete"))
{
log("Giving player a machete");
if(!player.weaponInventory.add(new Machete(player))) {
log("You already have this item.");
}
}
else if(args[0].toLowerCase().equals("cannon"))
{
log("Giving player a cannon!");
if(!player.weaponInventory.add(new Cannon(player))) {
log("You already have this item.");
}
}
else if(args[0].toLowerCase().equals("help"))
{
log("Options:");
log(">rifle (Rifle)");
log(">shotgun (Shotgun)");
log(">venom (VenomShooter)");
log(">elephant (Elephant Gun)");
log(">fist (Melee)");
log(">raygun (Raygun)");
log(">machete (Machete)");
log(">cannon (Cannon)");
log("Or you can use a numerical value to receive money.");
}
try{
player.score+=Integer.parseInt(args[0]);
}catch (NumberFormatException e)
{

}
}
};
Command time = new Command("time", 0, "Show the current time"){
@Override
public void doCommand(String[] s)
{
log(new Date(System.currentTimeMillis()).toString());
}
};
Command cooldown = new Command("cool", 1, "Cools the currently held weapon to a certain value"){
@Override
public void doCommand(String[] s)
{
try {
int i = Integer.parseInt(s[0].trim());
log("Cooling weapon from " + i + " centispecks.");
for(;i>0;i--)
{
MojamComponent.instance.player.weapon.weapontick();
}
} catch (NumberFormatException e)
{
log("Cooling weapon");
int i = 600;
for(;i>0;i--)
{
MojamComponent.instance.player.weapon.weapontick();
}
}
}
};

public abstract static class Command {

public String name;
Expand Down
60 changes: 60 additions & 0 deletions src/com/mojang/mojam/entity/BulletCannonball.java
@@ -0,0 +1,60 @@
package com.mojang.mojam.entity;

import java.util.Set;

import com.mojang.mojam.MojamComponent;
import com.mojang.mojam.entity.animation.LargeBombExplodeAnimation;
import com.mojang.mojam.entity.mob.Mob;
import com.mojang.mojam.screen.Art;
import com.mojang.mojam.screen.Screen;

public class BulletCannonball extends Bullet
{

public BulletCannonball(Mob e, double xa, double ya, float damage)
{
super(e, xa, ya, damage);
}

@Override
public void tick()
{
if (--duration <= -20) {
remove();
return;
}
if(!move(xa,ya))
{
if(move(-xa,ya))xa = -xa;
if(move(xa,-ya))ya = -ya;
}
xa *= 0.95;
ya *= 0.95;
}

@Override
public void remove()
{
level.addEntity(new LargeBombExplodeAnimation(pos.x, pos.y));
MojamComponent.soundPlayer.playSound("/sound/Explosion 2.wav",
(float) pos.x, (float) pos.y);
float BOMB_DISTANCE = 100;
Set<Entity> entities = level.getEntities(pos.x - BOMB_DISTANCE, pos.y
- BOMB_DISTANCE, pos.x + BOMB_DISTANCE, pos.y + BOMB_DISTANCE,
Mob.class);
for (Entity e : entities) {
double distSqr = pos.distSqr(e.pos);
if (distSqr < (BOMB_DISTANCE * BOMB_DISTANCE)) {
((Mob) e).hurt(this, (float) (damage*damage/distSqr));
}
}
super.remove();
}

@Override
public void render(Screen screen)
{
screen.blit(Art.bomb, pos.x-16, pos.y-16);
}

}
32 changes: 32 additions & 0 deletions src/com/mojang/mojam/entity/BulletMelee.java
@@ -0,0 +1,32 @@
package com.mojang.mojam.entity;

import com.mojang.mojam.entity.mob.Mob;
import com.mojang.mojam.screen.Screen;

public class BulletMelee extends Bullet
{

public BulletMelee(Mob e, double xa, double ya, float damage, int range)
{
super(e, xa, ya, damage);
duration = range;
}

@Override
public void tick()
{
if (--duration <= 0) {
remove();
return;
}
super.tick();
}

@Override
public void render(Screen screen)
{
//super.render(screen);
//TODO: Effects
}

}