![]() |
XNA Smaller Snake
June 30, 2008 on 9:48 pm | In Uncategorized | 1 Comment | Jeremy ReadXNA Version of Snake Source Code Download
A bit bigger than some of the others, but it’s using textures unlike the original smaller snake.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; namespace SnakeXNA { static class Program { static void Main(string[] args) { using (SnakeXNA game = new SnakeXNA()) { game.IsFixedTimeStep = true; game.TargetElapsedTime = new TimeSpan(500000); game.Run(); } } } public class SnakeXNA : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; private static Random myRnd = new Random(); private Point apple = new Point(myRnd.Next(64 - 1) * 10, myRnd.Next(48 - 1) * 10); private Point dir = new Point(0, 10); private LinkedList<Point> snake = new LinkedList<Point>(); //LinkedList doesn't have add... private Texture2D mySquare; //In XNA we need a texture to draw stuff with private Boolean isRunning = true; public SnakeXNA() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { snake.AddFirst(new Point(10, 10)); base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); mySquare = Content.Load<Texture2D>("GameThumbnail"); } protected override void Update(GameTime gameTime) { KeyboardState myState = Keyboard.GetState(); if (myState.IsKeyDown(Keys.Left)) { dir = new Point(-10, 0); } if (myState.IsKeyDown(Keys.Right)) { dir = new Point(10, 0); } if (myState.IsKeyDown(Keys.Up)) { dir = new Point(0, -10); } if (myState.IsKeyDown(Keys.Down)) { dir = new Point(0, 10); } if (isRunning) { snake.AddFirst(new Point(snake.First.Value.X + dir.X, snake.First.Value.Y + dir.Y)); snake.RemoveLast(); } base.Update(gameTime); } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(SpriteBlendMode.AlphaBlend); spriteBatch.Draw(mySquare, new Rectangle(apple.X + 2, apple.Y + 2, 5, 5), Color.Green); //Draw apple. int i = 0; foreach (Point cur in snake) //Draw snake and check self collision { spriteBatch.Draw(mySquare, new Rectangle(cur.X , cur.Y , 10, 10), Color.White); if (i != 0 && snake.First.Value.X == cur.X && snake.First.Value.Y == cur.Y) { isRunning = false ; } i++; } if (snake.First.Value.X == apple.X && snake.First.Value.Y == apple.Y) //Collision apple { apple = new Point((myRnd.Next(64 - 1)) * 10, (myRnd.Next(48 - 1)) * 10); snake.AddLast(snake.Last.Value); } spriteBatch.End(); base.Draw(gameTime); } } } |
![]() |
Smaller snake in C#
June 29, 2008 on 4:55 pm | In Uncategorized | No Comments | Jeremy ReadNow with full initialization. Tomorrow I should have XNA up as well. Then I’ll get to work on a simple tower defense game. Smaller Snake in C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; namespace SnakeCSharp { public partial class SnakeCSharpWindow : Form { private Timer t = new Timer(); private static Random myRnd = new Random(); private Point apple = new Point(myRnd.Next(64-1) * 10, myRnd.Next(48-1) * 10); private Point dir = new Point(0, 10); private LinkedList<Point> snake = new LinkedList<Point>(); //LinkedList doesn't have add... public SnakeCSharpWindow() { this.ClientSize = new System.Drawing.Size(640, 480); this.FormBorderStyle = FormBorderStyle.FixedSingle; this.Name = "SnakeCSharpWindow"; this.Text = "SnakeCSharp"; this.Paint += new PaintEventHandler(SnakeCSharpWindow_Paint); this.KeyDown += new KeyEventHandler(SnakeCSharpWindow_KeyDown); t.Tick += new EventHandler(t_Tick); t.Start(); snake.AddFirst(new Point(10,10)); } void SnakeCSharpWindow_KeyDown(object sender, KeyEventArgs e) //Change direction { if (e.KeyCode == Keys.Left) {dir = new Point (-10,0 );} if (e.KeyCode == Keys.Right) {dir = new Point(10, 0);} if (e.KeyCode == Keys.Up) {dir = new Point(0, -10);} if (e.KeyCode == Keys.Down) {dir = new Point(0, 10);} } void SnakeCSharpWindow_Paint(object sender, PaintEventArgs e) { e.Graphics.FillRectangle(Brushes.Green, apple.X + 2, apple.Y + 2, 5, 5); int i = 0; foreach (Point cur in snake) //Draw snake and check self collision { e.Graphics.FillRectangle(Brushes.Black, cur.X, cur.Y, 10, 10); if (i != 0 && snake.First.Value.X == cur.X && snake.First.Value.Y == cur.Y ) { t.Stop(); } i++; } if (snake.First.Value.X == apple.X && snake.First.Value.Y == apple.Y) //Collision apple { apple = new Point((myRnd.Next(64-1)) * 10, (myRnd.Next(48-1)) * 10); snake.AddLast(snake.Last.Value); } } void t_Tick(object sender, EventArgs e) //Move Snake { snake.AddFirst(new Point(snake.First.Value.X + dir.X, snake.First.Value.Y + dir.Y)); snake.RemoveLast(); this.Refresh(); } } } |
![]() |
Smaller snake
June 22, 2008 on 4:51 pm | In Uncategorized | 2 Comments | Jeremy ReadSince we all love CompSci 101 so much, also as I’m testing out the source code highlighting plugin I present ’smaller snake’. You could write Snake a little smaller by storing head and apple in the same array as each other, or better yet with the snake. But I think this is just about as small as you can make it in java and still be ‘readable’. Apple probably shouldn’t be from fixed values or should be based on the container size, but I’m too lazy to fix it now.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; public class SnakeJPanel extends JPanel implements ActionListener, KeyListener, MouseListener { private javax.swing.Timer t = new javax.swing.Timer(75,this); private LinkedList<Point> snake = new LinkedList(); private Point apple = new Point( (int)(Math.random() * 45) * 10, (int)(Math.random() * 45) * 10); private Point dir = new Point(0,10); public SnakeJPanel() { t.start(); //To make stuff work. addMouseListener(this); addKeyListener(this); snake.add(new Point(10,10)); } public void paintComponent(Graphics g) { super.paintComponent(g); g.fill3DRect(apple.x + 2,apple.y + 2, 5,5,true) ; //Draw apple for(int i = 0; i < snake.size(); i++){ //Draw snake and check self collision g.fill3DRect( snake.get(i).x, snake.get(i).y , 10 , 10, true); if( i != 0 && snake.get(i).x == snake.getFirst().x && snake.get(i).y == snake.getFirst().y){ t.stop(); } //Check collision. } if(snake.getFirst().x == apple.x && snake.getFirst().y == apple.y){ //Collision apple apple = new Point((int)(Math.random() * 45) * 10,(int)(Math.random() * 45) * 10); snake.add(snake.getLast()); } } public void actionPerformed(ActionEvent e){ //Move snake snake.addFirst(new Point(snake.getFirst().x + dir.x, snake.getFirst().y + dir.y)); snake.removeLast(); repaint(); } public void keyPressed(KeyEvent e){ //Change direction if(e.getKeyCode() == KeyEvent.VK_LEFT){dir = new Point(-10,0);} if(e.getKeyCode() == KeyEvent.VK_RIGHT){dir = new Point(10,0);} if(e.getKeyCode() == KeyEvent.VK_UP){dir = new Point(0,-10);} if(e.getKeyCode() == KeyEvent.VK_DOWN){dir = new Point(0,10);} } public void mousePressed(MouseEvent e){ //Java Hack super.requestFocus(); repaint(); } public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} } |
![]() |
Ramble ramble rambo
June 21, 2008 on 6:34 pm | In Uncategorized | No Comments | Jeremy ReadIt’s that time again. There’s not much you can to do avoid it, since I hold the trump card of Admin. Mostly I don’t post as I don’t think anyone really gives a shit anyway. So I just work away in the background fixing what breaks every couple of weeks. But I’m going to take a break from playing Urban Terror (I blame Abhishek for introducing me) and utilizing my subscription to Marvel Digital, both of which I’m quite glad for really as they help break up the monotony of trying to work out what to do next.
Thus I’m going to post a fraction of my thoughts on the past week.
The Tiramisu and Creme Brulee chocolate from cadbury, don’t taste anything like what they’re supposed to. They’re okay though, as long as you forget what they’re meant to be.
Cadbury Old Gold Liquer Flavoured Selection.
Tastes like cooking chocolate. The Irish creme centers are pretty bland
What’s up with “Intensity” though?
Their entire range is rated 3/5 cocoa beans for intensity! Why would you rate your own product like that?
On the chocolate note I went down the local liquor store last night and purchased another two bottles of Creme da Cacao. One bottle of De Kuyper dark and one of Continental white.
De Kuyper is about $25 to the Continental at $20, it’s less syrupy with a more complex taste but unfortunately that complex taste also tastes kind of like dirt. Drinking it straight the De Kuyper is probably better, but if you were mixing it with say milk then I’d save my money and get the Continental if possible.
Though I possibly shouldn’t do that since apparently I live in Manurewa now (who’s border is soon to reach the North Shore if TV3 has it’s way) and drinking alcohol will thus fuel me to commit further murders.
Maybe the only place safe is to go further south. Last Thursday I went out with some friends to the Sahara Tent for dinner in Papakura, (brand loyalty most likely, if you haven’t been it’s worth going at least once [get the Chef's Special, trust me]) and I believe that we all successfully went without being stabbed, shot etc.
Though whether in the greater scheme of things this is important who knows, with the world ending in half a month. Which is fitting in a way since it’s like three days after I’ll get my laptop, on the plus side I won’t have to worry about the interest payments on my credit card.
Which reminds me, how are you meant to buy a house now?
Suppose you had a reasonably well paying job at 80K/year before tax.
Before tax: $80000/year
Tax: $22470/year
After $57530/year
The maximum you ever borrow is such that the interest payments are at most 30% of your after tax income.
$57530* 30% = $17259/year
At the moment variable rate is about 11% per annum.
Loan*11% = 17529
Loan*0.11 = 17529
Loan = 17529/0.11
=$159354.54
= ~$160,000
That’s not much, you’re going to have to save a pretty hefty deposit to afford to live inside Auckland. No wonder so many people are flatting.
Well not that it’ll matter next month anyway
Link of the day: Desktopography.net
![]() |
Voicebot tester
June 11, 2008 on 10:43 pm | In Uncategorized | No Comments | Jeremy ReadAs promised a debug build.
Use at own risk. No documentation, but I suggest looking in config.xml.
![]() |
Bringing star trek a little closer
June 10, 2008 on 3:26 pm | In Wang | No Comments | Jeremy ReadLectures are over for uni at the moment, so it’s that time of year again when I start doing work. Inspired from watching Iron Man the day it came out in NZ I decided to build my own voice powered bot.
I’m too lazy to write my own speech recognition engine, so I started using SAPI 5.3. But I’ve switched over to using the .NET 3.5 Speech library at the moment.
The hard part now is defining the formal grammar, as all it does now is check for “computer email” and opens up webmail for me. But given that dynamic grammars can hook directly into databases the possibilities are incredible.
Unfortunately I need to grab another 900MB SDK to quickly build these up. Otherwise I’d have to work with the w3c spec by hand. So I’ll leave it on hold for a bit until my XPS 1530 arrives (I don’t have 900MB of room left on my hdd…)
Also I need to think about how to map the resulting accept state into the list of actions to perform. Since currently I just know that I have an accept state, and the string, but what I really want to have is the list of states that I had to pass through to get there.
i.e it’s no good knowing that “computer fetch images from my documents”, what I want is something like:
computer -> fetch -> images -> from -> my documents
Not computer -> fetch -> images -> from -> my -> documents
as I’m too lazy to do a double parse.
That way I quickly build up some sort of structure for scripts, so that it can look for “computer fetch $1 from $2″ and just pass along the required variables.
Though since a week is a long time to wait I’ll write a speech to action program for unique speech strings on wednesday.
So to keep Mathew happy, since it can run an arbitary url you can in fact have “computer order ice cream” and it’ll work.
![]() |
I took one for the team
June 6, 2008 on 9:49 pm | In Uncategorized | No Comments | Jeremy ReadGuinness fudge. Do not attempt this.
![]() |
Saturday Photoset
June 2, 2008 on 10:03 pm | In Pictures | 2 Comments | Jeremy ReadTotal chaos as usual.
Food.
Nobody mention Hard Candy ever again.
![]() |
Predictions on Microsoft
May 14, 2008 on 12:14 am | In Uncategorized | 2 Comments | Jeremy ReadSometimes, I hear a piece of information that in a single sentence changes my world view.
The XNA Community Games Platform team has announced the first feature of the coming XNA Game Studio 3.0, the ability to build games for the Zune platform.
It took a while for this to sink and then I realized the enormity of this statement. I’d be willing to bet money that Microsoft is going to enter the handheld gaming platform market and take a massive chunk out of Nintendo’s “gameboy” pie. I really want a Zune now. I care about it, if Microsoft make this I’m thinking it’s going to be as successful as the Xbox360 rather than the GP32.
And to be honest, it’s the most successful out of any of the consoles, they won this time. Sure Nintendo managed to sell marginally more Wiis but you forget Xbox Live. Which has more active subscribers than WoW. Combined with them owning the IP in their chips, thus when Opus and Valhalla come out we’ll see both system stability (no more red rings of death) and higher profit margins. Microsoft is simply raking in the money.
How did this happen though? Well simply put, it’s the best platform to develop for. Microsoft is a platform company, it’s simply a lot easier to hit F5 and it “just work” in Visual Studio than it is anywhere else. And this is where XNA comes in. It’s a development framework that lets us write code and it “just work” by hitting F5 on BOTH the Xbox360 and the windows platforms. Users don’t care about this, developers do. The thing is though, only developers count. I can’t write easily to do what I want on the PS3, if I want to write for the Xbox360 it’s a breeze, so given a choice I’d choose the Xbox.
Now what Microsoft is trying to do is harness these developers so that they WANT to write code for the “Zune” platform. I want to write code for it now, so it passes the litmus test.
All they need to do now is rebrand the platform and they’ve won the handheld war as well. Whoever has more developers wins. So go download XNA
and have fun.
I’m also guessing we’ll see support for Windows Mobile possibly in version 4.
![]() |
Custard and Raisin Fudge
May 10, 2008 on 12:33 pm | In Food | No Comments | Jeremy ReadAdd the following to a microwave safe bowl. I’m doing this in the microwave because there’s no reason to make fudge on the stove top. You don’t want it to burn, which it may do on the stove, and it’s simple enough in the microwave. The entire point is just to get the sugar to recrystallize correctly, the microwave method is significantly more repeatable and will turn out better results.
100g of Butter
1 cup of Sugar
1/4 cup of Golden Syrup
1 can of condensed milk (remove from can…)
1/4 cup of custard powder
Microwave for two minute intervals, stirring on the breaks and checking if it’s reached soft boil stage. This should be roughly at the 10 to 12 minute mark. Once it’s reached soft boil leave it for 2 minutes.
Then add
1tsp of Vanilla Essence
1/3 cup of raisins
And proceed to stir until the mixture stops looking glossy. Pour into a baking paper lined tin of some sort. Lamington tins are slightly too big, you need something slightly smaller.
If you want to make Bailey’s fudge.
Don’t add the custard powder or the golden syrup.
Use half of the amount of condensed milk. (Neenish tarts will use up the leftovers)
Add 1 cup of Bailey’s.
You probably don’t want to add the raisins at the end either, but it’s upto you, I haven’t tried it.
Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds.
Valid XHTML and CSS. ^Top^































































