Showing posts with label tank. Show all posts
Showing posts with label tank. Show all posts

Thursday, 10 March 2011

miTanks, Part 11

FINALLY!!! After 5 days searching the net and testing heaps of different custom views, I've drawn a circle. That's right. 5 days of work and all I've done is draw a circle. This must sound rediculous but this is the biggest break though. Look! Here it is:



It's amazing. Now I simply had to copy over the view handling bits of code to miTanks and BAM!



We get an ugly, badly drawn game of tanks. It's nice. So now I'm working on tweeking the look so that it, well, works. For those of you using the code snippets I'm putting on here, the main bits are:

In the main class:

public class miTanks extends Activity {

private GameView gv;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GameView gv = new GameView(this);
setContentView(gv);
}

In the GameView:

public class GameView extends View{

private final Paint PAINT;
private static final Bitmap[] TANK_IMAGES = new Bitmap[8];
private static final int[] TANK_COLOURS = new int[8];
private final GradientDrawable BACKGROUND_GRADIENT;
private static GameView INSTANCE;

/**
 * Initialises the GameView.
 * @param context
 */
public GameView(Context context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
...
/**
 * Draws the game onto the canvas.
 */
protected void onDraw(Canvas canvas){
drawBackground(canvas);
drawGround(canvas);
drawTanks(canvas);
}

In the main.xml:

<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <com.miTanks.game.GameView
  android:id="@+id/View01"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:maxHeight="40dip" />
 </LinearLayout>

Tuesday, 8 March 2011

miTanks, Part 10

It's not working... I've been trying different ways to get the game to draw to screen though I just don't have it working yet. Fixed a couple minor bugs, as I hadn't moved everything across from the PC version.

When running I follow the debug and step through the program. Turns out the game runs perfectly, that is the game constructs and plays out completely with two random computer players, except it never draws to the screen. Thought the onDraw(Canvas canvas) method would be called automatically every couple of milliseconds. Turns out no. So, I need a way to get the canvas (i.e. the screen) so that I can call the method myself. Working on it...

If anyone knows how android views work, let me know...

As for sounds, I have this site that generates old school game noises. So I'll probably use that for my sounds. Means I don't have to search for people to make decent sounds. Lol. Sorry to those of you that did help with that. There just weren't enough to continue with them.

So the site looks like this:



Here is the link. Will probably be my one stop shop for sounds in the future. Check it out.

My roommate made me a little icon for the game as well. His tanks looks better than the little ones I made in the last post. So may end up replacing them with copies of his. I'll post the icon when I have my computer again.

Cheers,
Milk

Saturday, 5 March 2011

miTanks, Part 9

That's right! miTanks is back. After a very very long break I've got motivated to finish it. Or at least get it on the platform it was originally for. Haven't really had much commitment from Foo, which is both our faults really. I'm not the best teacher and he has little / no coding experience. And lobbing him with graphics was not the best move.

Sorry to everyone that doesn't have an Android, but you can still enjoy my struggle with xml and the Android graphics classes... And the PC version will still have the same look and feel as the Android version, with the obvious touch-screen exception.

Can't remember if I've said already or not but this is a fantastic, simple example of how to make a game on Android. The game is open source so I'm basing the majority of figuring out how to do graphics on this. For those of you know don't know software programming is basically: "Learn the basics; google the rest."


Image courtesy of xkcd.

I think I have a pretty good idea of what I need to do now. The tanks are going to look something like this:
 

And the turrets are just going to be a black smooth edged square, pointing at whatever angle they need to. The ground is either going to be a solid colour or each pixel will be 1 of three colours. This will depend on how much time it takes up to search and utilise a very very large 2D colour array.

I'll be using the sky square (not a box, it's 2D) Foo created earlier, because it is awesome. This will be the background of most of the levels. Might end up overlaying some objects like a building or something.




What else? Damage isn't quite right. The tank only takes damage if the very centre is hit. Not a major flaw but not very ascetically pleasing.

I'll get to work on this all tonight and post something on Monday(?) about what I have done.

Links to the other miTanks posts:
Part 1, The Plan
Part 2, Initial Concept
Part 3, Object Oriented Design + Update
Part 4, Sound Request + Update
Part 5, First Screenshots
Part 6, Ground Types
Part 7, Weapons + Ground Dynamics
Part 8, Initial Release

The last one contains the initial release for PC. Have a look at that if you haven't already. Just renamed all my posts... I had two part 4's AND 2 part 6's. That's just bad...

And as always suggestions are always appreciated.

Cheers,
Milk

Thursday, 17 February 2011

Back With a Plan

I'm back. Fiji was awesome. Got a wee bit burnt... But no visible tan due to the copious amounts of sunblock I was applying. Damn. Also I left the sunblock at home so never found out about taking it through customs. Crystal clear water and fish everywhere. Also a lot of frogs. I found that strange. I don't have the camera with me at the moment so pictures will have to wait. Though they will be on here at some point.

As for tanks: No progress. Aside from the visuals there isn't too much to do (that is fun to code). So I'll have a chat with Foo to see where we are heading with this and will let you know.

In the mean time. I did come home to a large amount of Magic Cards at the door. I'm not expecting to use them all, large is an entire shoe box full which I got for NZD$10.50, so I going to try to make some of my money back by reselling them individually on TradeMe.

I'm not a hardcore fan so I have little to no idea of the worth of the cards, so what I am going to do is write another web crawler, like this one. Woo! Finally back to some coding. This is going to search StarCity for each card and return the value of said card for me, then dump it into a txt file; which I can directly import to a spreadsheet. Should let me know the most valuable to least.

I'm going to be using Python for this. Will post the source later on Ok? Ok.

Wednesday, 12 January 2011

miTanks, Part 8, Initial Release!!!

Added another ground type, gravel. But thats about it.


The ground is randomly up and down, but never so high that you can't climb it. I think it's the most realistic ground I have made. Suprisingly easy as well.

Ok guys. I'm running out of ideas. Foo's to get to work on having the menu up and running. I'll going to get to work on some of the inside bits.

I really want to make a release for you guys. What I'm going to do is find a way to put up a .jar file. Because the program has no real visual output, I'll leave you instructions on how to run it through the command line. This will allow you to see what I see. Playable, but in no way is it finished.

Download Link:
http://rapidshare.com/files/442108182/miTanks.jar

How to use:
Download the jar file and place it somewhere on your computer.
Right-click on the file and click 'Properties'.
Copy the location of the file.

Open the command line. (Windows > Search > "cmd").
Type "cd [location in full]" and press enter.
Type "java -jar miTanks.jar" and press enter.

This will open the game.

Notes:
The ground is gravel and there are 3 players (2 human controlled and a computer controlled). The first player is the blue one, he is human controlled. The second is red, and is also human controlled. The last is still red, but he is a computer player that randomly picks a direction, power and fires.
If I get some comments, I'll upload versions with a certain amount of what players and what ground etc.
The angle works like this: 0 is straight up, -90 is left, 90 is right.
Power goes between 0 and 100.
Your power and angle will be displayed in the command line.
Your life comes up here as well as you get damaged.
And some other crap. Sorry I'm still using these tracers so that's why they are still there.
Once you win you will have to close and open again. Just press up when in the command line then Enter.
Controls:
w = increase power
s = decrease power
a = decrease angle
d = increase angle
z = move left
x = move right
q = previous weapon
e = next weapon
Enter = fire

Please leave a comment! Chances are, there will be some issues with this.

Tuesday, 11 January 2011

miTanks, Part 7

A little more progress and some more screenshots.

Had a game against my brother yesterday. Found a couple bugs, but it was still playable. The first most obvious bug is that bullets would explode halfway through some walls. This was due to the movement calculations. They were somewhat refined though needed to be more so with the bullets jumping instead of moving through every pixel in their path. Took some thinking but I figured out to solve that.

Also I made the first tank blue and all the others red. A quick fix so I could tell which was the first. Also made it playable for two people. Eventually colours will be selected on start up.


The ground now falls nicely into place if a shot blows up the ground beneath it. Only one line added so this may be a temp fix. Seems to be good for the game needs though. I was too slow with taking the screen shots but the ground falls line by line. Looks ok. Will make it even smoother later on.


Found an issue with falling as well. When you fall it moves you according to gravity. Though you can still move back and forth between the fall movements. If I implement an automatic redraw of the canvas, this shouldn't be an issue. Unfortunately that would ruin how I'm doing my other calculations, so that may have to wait. I'm sure there is another way to resolve this.


Added a laser beam. Fires in a straight line destroying all the ground in it's path. Damn I missed him.


You can kinda see the ground adjustment here. Got a screenshot about halfway through it.


I'm having a meeting with Foo about the game tomorrow. Now that I have alot of the game done, he can get started on creating the game view for Android. Hopefully he has a better idea about how to do this then I do.

By the way, all these screens are from the PC version. Don't worry. I will release it for you all.

Cheers,
Milk

Sunday, 9 January 2011

miTanks, Part 6

A little more progress. Moved the ground builder into the Ground enum so that each type of ground has it's own way to build the terrain. Implemented a Sand random ground generator and a Rock random ground generator. Guess which one is which.



You can see the code behind building these is only a few lines each. Writing the rock one took less then 10 mins. The sand one was just over an hour.

The sand one still has some issues. I haven't quite got the constraints for the range, period and shift of the wave. And then applying some additional scaling so that it doesn't fall off the bottom of the game.

Haven't done much else really. Will look at adding a straight shot weapon that moves through the floor. This is probably going to be alot more enjoyable then the game to work. To be honest there isn't that much else to do to get it playable.

There are a couple of steps I have when I create a game:
Working = It does what it should.
Playable = You can see it doing what it should.
Done/Fun = There is enough story/options/levels/bells and wistles that you will enjoy playing it.
Finished = It's actually done.

At the moment miTanks for PC is at a proof of concept stage. Which is some wierd combination of fun and playable, but not quite working. This usaully happens when I get bored of doing behind the scenes code and start making stuff that I can actually see. Like the ground generators.

Please read this:
I've made the sound support on this PC version. Still waiting some sound effects. If you go to Vocaroo and make me a sound, I will put it in my game, and your name in credits.
Just post the Vocaroo link in a reply below.
If you want a weapon just tell me what it should do, how to move and shoot. I'll put that in aswel. Credit will be made to you also.

See example comment below.

Friday, 7 January 2011

miTanks, Part 5

Here's a some pics of what I've got so far for testing.


Support for an arbitrary amount of players. They are actually all human controlled at the moment.



In this one you can see the error with damage. You can see it has broken one line correctly. But hasn't done the others.


 If anyone can help me with code formatting on here let me know. Here's a screen of it. Lol.




ground is a 2d array of size game_width x game_height. All the others should be self explanatory.
When it prints we see:


Destroy: -5, 0
Destroy: -4, 0
Destroy: -3, 0
Destroy: -2, 0
Destroy: -1, 0
Destroy: 0, 0
Destroy: 1, 0
Destroy: 2, 0
Destroy: 3, 0
Destroy: 4, 0
Destroy: 5, 0

So for every x, y = 0. But why! Should be something like. x = -5, y = 0; x = -4, y = 1; ...

[Edit: Found it!!

Not sure why I was scaling y by the bullet location... Removed this.bullet_x and this.bullet_y in the y calculation and it works. Too easy. Doesn't even look that circular... How to fix that?

]

Wednesday, 5 January 2011

miTanks, Part 4

Happy New Year!

Hope everyone's holidays are going well. Nothing too exciting going on in mine. Had a nice few days off work for drinks and general relaxation. Didn't do too much on the tanks game but thought I should update what has been happening. Foo is currently on holidays afk so not much in the lines of GUI completed.

Sorry I don't have many pictures for this project. As the GUI is last on the TODO list, this will come when the app is in the testing phase. I'll get some code up here later on for you all aswell. As this uses Java classes the code is spread across multiple files. I'll upload any interesting code I make though. Have a couple little bits in mind for later on.

Completed:
More of the inner workings are completed for in game.
The game physics work.
(better now)
Simple flat terrain completed.
Support for differing gravity, wind and landscape. (three landscapes have been added, one fully completed)
Support for random terrain generator. (included in landscape)
Support for multiple weapons, including weapon movement and collision calculations.
One weapon implemented. (fully implemented, including circular proximity damage)
Multiple matches in a game. (support for)
Game cycle. (may need to be editted once visuals and sounds are added.)

Still to do:
Getting input. Once input can be received the usage is already implemented.
Tank movement.
Display. Location calculations implemented. Just need to know how to put an image on the screen.
AI calculations, of differing skill levels.
Perfect AI, should be easy to do.
Absolutely useless AI, is even easier.
Realistic AI is somewhat harder. Shouldn't take too long. I'd just fudge some numbers from the perfect AI.
Defensive weaponry support. Shields and such.

NOTE TO FOLLOWERS:
I'm going to need some sound effects for this game. Such as a tank moving sound, bullet fire sound, bullet fall, explosion, and probably some others. If you can link me some sounds you've made I'll give them a listen and add the best ones into the game.

Saturday, 1 January 2011

miTanks, Part 3

As neither me or Foo know how to successfully draw to the screen, we thought we'd make it as easy as we could. Firstly the game will be the size of the screen. This will remove the need for scrolling. The battlefield size will be in relation to some fixed variables, so can be easily changed at will. The game will be completely in landscape view.

Foo agreed to do the visual side of the application. Considering the amount of lower-level coding Foo has actually done, and the combined skills we possess for graphics, this looks like the hardest part. Seemingly working from scratch, the progress on this is slow. So far there is nothing to show.

Done so far:
Did a quick class diagram for the actual game.

























Most of the inner workings are completed for in game.
The game physics work, (untested).
Simple flat terrain completed.
Support for differing gravity, wind and landscape.
Support for random terrain generator.
Support for multiple weapons, including weapon movement and collision calculations.
One weapon implemented.
Multiple matches in a game.

Still to do:
Getting input. Once input can be received the usage is already implemented.
Tank movement.
Display. Location calculations implemented. Just need to know how to put an image on the screen.
The game cycle. This will be very easy. Just need to actually do it.
AI calculations, of differing skill levels.
Perfect AI, should be easy to do.
Absolutely useless AI, is even easier.
Realistic AI is somewhat harder. Shouldn't take too long. I'd just fudge some numbers from the perfect AI.
Defensive weaponry support. Shields and such.

Things YOU think I should add:
Leave a comment. Tell me what you would like to see.

Friday, 31 December 2010

miTanks, Part 2

Something I've missed:
Android apps are written in Java plus some xml for view layouts etc.

I have started drawing up a rough class diagram for the game and started to think about how to implement destructible terrain. As we want a clean fall animation for the ground when a piece is broken below, I am currently thinking about having the entire game screen as a 3d boolean array. Animations with this will be incredably easy. Hopefully this won't be too much to process every turn.

Some minor code has been written to help visualise the working of the tank class. As this is early on in the process it is likely to be rearranged quite regularly, due to the nature of eXtreme Programming.

I will try to have the game run on both the Android and a computer. This will help for initial game development as testing on the Android Virtual Device is time consuming. Also when the game is complete I will release a run-able jar file so everyone on here can play the game.

Most likely won't be doing small releases as we go, due to the size of the app. When it is actually playable it will almost be finished. Just bug fixes, extra weapons and smoothing out code after the app works.

Here are some initial concept shots by Foo.
Initial Concept Screenshot
Second Concept Screenshot


Sky

Tree

Concept Tank 1

Thursday, 30 December 2010

miTanks, Part 1

So now that I have an Android phone my next plan is to create an app. I could port some of my CLI games across very easily, but that's no fun. I'm going to remake Tanks, with the help of a friend, herein refered to as Foo.

Tanks is a simple turn-based game. Each player has a tank. On your turn you select the angle to shoot and the power, and then fire. Some minor physics determine travel of the shot. Then there is collision and damage calculations. Rince and repeat until there is only one tank left standing.


I'll get Foo to post an about Foo thing here aswell. Foo has an LG p500 (Optimus One), that runs Android 2.2. Slightly better specs than the Galaxy 580 for a similar price. Galaxy 580 runs Android 2.1, so will use that as the minimum version.