Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Tuesday, August 12, 2014

Learn something about HTML5 via the simplest game

I was thinking, I should learn about HTML5.
I thought, maybe I should look at making a simple game in HTML5 
What's the simplest game? Pong.
So I googled 'pong in html5' and got this:

http://cssdeck.com/labs/ping-pong-game-tutorial-with-html5-canvas-and-sounds

It has a multi-pane window approach and you can see the code results on the right, instantly.

Thursday, December 23, 2010

Pac-Man ghost behavior

This article explaining how pac-man's ghosts work was pretty interesting. Their complex behavior emerges from a few simple rules. I suppose my interest stems from my status as a programmer wannabe more than anything...I'm not super likely to sit down and make a Pac-Man clone, but maybe I'll try to make a working arcade-style game again one of these days.

Thursday, March 18, 2010

A Word macro for wordcount

I'm doing 500-word writing sessions; to do that, I need to know how many words there are in my file when I start, I need a quick way to get the current wordcount, and I need to know what my goal is.

So I came up with this macro. It's for Word 2003. When you run it, it generates a line like this:

Start 11609, current 12167, goal 12109

and the value for the current wordcount is a field code, so you can update it at any time by clicking on it and hitting F9. Yes, this would be unnecessary if I had the latest version of Word, which displays the wordcount in the status bar, but I don't have that. Also, that version of Word hides menu options from you more effectively than any previous version.

I thought the code for generating the field code was pretty arcane, but I got it by recording the action of adding a field code.



Sub WordCount()
'
' WordCount Macro
' This macro puts a line about wordcount into the current document.
' It puts the 'start' wordcount..the count you start with
' then the 'current', which is a NumWords field code that you can update with F9
' then it puts the 'goal, which is start + 500.
Dim Numwords As Integer
Dim Goalwords As Integer

'Ok, now populate Numwords with the value of the wordcount property
Numwords = ActiveDocument.BuiltInDocumentProperties(wdPropertyWords)
Goalwords = Numwords + 500

'The rest of this is just outputting text at the selection point
Selection.TypeText Text:="Start "
Selection.TypeText (Numwords)
Selection.TypeText Text:=", current "

'I generated the line below using a recording.
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"NUMWORDS ", PreserveFormatting:=True
Selection.TypeText Text:=", goal "
Selection.TypeText (Goalwords)
End Sub

Saturday, February 06, 2010

ChoiceScript....language for writing choose-your-own-adventure games

I do think about writing a choose-your-own adventure thing now and then. I'm hampered by the knowledge that most of them are terrible. Sure, you could open an infinity of choices for the player, but in practice, the writer doesn't want to spend infinity writing choices, so the writer collapses many options down so they either result in a quick end to the story (often a death), or joins them.

It would be interesting to try this in an online format, though, since pagecount wouldn't be a limit. I imagine pagecount was a big limit on the old Choose Your Own Adventure books.

Wait, they're not old. They have a website for a company called Choose Your Own Adventure.

HTML, of course, makes a choose-your-own-adventure thing pretty easy to make at home; you could simply have each 'page' be an HTML file, and provide the choices as links.

But you can get more interesting than that. Up to now, when I muse about this possibility, of writing electronic choicebooks, I think of TiddlyWiki as format...because it has a lot of features that would help, like being a single-file format, and a built-in editor.

Then I bumped into ChoiceScript: it's designed for doing these things. It's got a simple wiki-like script. And it looks like it makes HTML aided by JavaScript. I liked the company's page about why they make such multiple-choice text games.

Oh, and this might well be a good way to get a kid into programming, with a nicely concrete application. That might get me to actually try it out.

The makers of this script have a fairly interesting game, Choice of the Dragon. It clearly uses variables to make the game text more tailored than a paper game could.

Thursday, January 15, 2009

Make video game sounds

From a recent post on Metafilter, I found the application sfxr, a little utility that makes video game sounds. It actually has buttons labeled "powerup" and "explosion." When you click one of these, you get a randomly generated sound, but one generated according to parameters that make it fit its label. I don't know how that works, but all the explosions do sound like explosions...explosions from an early arcade game. After you generate a sound, you can tweak a bunch of sliders to change it, or save it to a file. Great tool for adding sounds to homebrewed games. 

sfxr's author, DrPetter, has a number of other interesting programs on his web site, including a multiplayer boat fight game, netboats, that I want to try out. For some of these he includes source code, so it's an interesting site to explore.

The tool is available for Windows/Mac/Linux. All of DrPetter's programs seem to be offered as zip downloads: give 'em a folder to live in and run the .exe and you're done, no install needed. I love that.

Wednesday, February 20, 2008

Trying out the Processing language

I had seen references to the Processing language on a few web pages (like kevan.org), but a couple of key things I read about it recently led to me actually trying it out:
  • I noticed that a variation of it is used as the language for the Arduino boards, which I had become interested in as a useful way to get into PIC-type electronics
  • I learned that it has a feature to export programs as Java applets, complete with wrapper html pages, making it super easy to put a program out for people to consume
  • I learned that it's graphically-oriented, with a ton of features for 2d and 3d graphics. I've been looking for a graphically-oriented, easy, hobbyist-type open source language for several years now, and this one seems to fit the bill.
So I installed it and tried it out yesterday. This evening I was showing it to my 10 year old, and said that I thought it would be easy to make a simple arcade game like Space Invaders using it. And then I coded up a simplified clone, in one evening. :) And here it is.

This ability to easily post a program on a web page is a big deal, because most languages I've tried require a lot more work to do that. I like Perl, but someone would need to install Perl and any modules I used, before they could use a script...or I'd have to compile the script into an executable, at a minimum. Emacs lisp is fun, but you have to install Emacs first before you can do anything with it.

Now my amateur game programming shall be limited only by my time and sticktoitiveness. Maybe I'll finally write the computer version of Dungeon's Revenge I've been dreaming about for years (a takeoff on the Dungeon! boardgame, where you play monsters who come out of a dungeon to attack the city).