Computer Science Canada

Guitar Hero

Author:  chrisbrown [ Tue May 22, 2007 6:37 pm ]
Post subject:  Guitar Hero

My work-in-progress: this version has no music, no beginning or ending, nor any order to the frets hit points.

Turing:

%Guitar Hero 0.5
%By Chris Brown
%Based directly on the Guitar Hero games (no sh!t)
%NOT based on Frets on Fire (since I haven't played it yet)
%See scoring below

View.Set ("graphics:max;max;offscreenonly;nocursor")

%Performance/Gameplay
const COMP_SPEED := 6   %Resolution of movement, among else
const DELAY := 20       %Time (in ms) between main program loop cycles
const DIFF := 50        %Difficulty/spacing between consecutive fret hit nodes, low
const HIT_LOC := 40     %Depth, in pixels, of the fixed fret points
const NODES := 20       %Number of fret hit nodes
const SPEED := 5        %Speed, in pixels per cycle, of the fret hit nodes
const maxz := 500       %Depth of Z-axis

%Controls: de-comment your preferred methoed
const STRUM : char := KEY_ENTER
const KEYS : array 1 .. 5 of char := init ('1', '2', '3', '4', '5')
%const KEYS : array 1 .. 5 of char := init ('`', '1', '2', '3', '4')

%Scoring
const HIT := 1000       %Increase for each good fret hit
const ALMOST := 1       %Slight decrease
const MISS := 100       %Complete miss
const OVERSTRUM := 1    %Decrease every time enter is held down

%Display
const LINE_WIDTH := 5   %Spacing between wall lines
const H := 20           %Height of fret hit points
const W := 40           %Width of fret hit points

%Colors
RGB.SetColour (200, .8, .1, .1)
RGB.SetColour (201, .1, .1, .8)
RGB.SetColour (202, .1, .8, .1)
RGB.SetColour (203, .8, .8, .1)
RGB.SetColour (204, 1, .6, .1)
RGB.SetColour (205, .4, .05, .05)
RGB.SetColour (206, .05, .05, .4)
RGB.SetColour (207, .05, .4, .05)
RGB.SetColour (208, .4, .4, .05)
RGB.SetColour (209, .5, .3, .05)
const RED : int := 200
const BLUE : int := 201
const GREEN : int := 202
const YELLOW : int := 203
const ORANGE : int := 204
const DARKRED : int := 205
const DARKBLUE : int := 206
const DARKGREEN : int := 207
const DARKYELLOW : int := 208
const DARKORANGE : int := 209
const C1 : array 1 .. 5 of int := init (GREEN, RED, YELLOW, BLUE, ORANGE)
const C2 : array 1 .. 5 of int := init (DARKGREEN, DARKRED, DARKYELLOW, DARKBLUE, DARKORANGE)

%Misc globals - no need to change
type Point2D :
    record
        x, y : real
    end record

type Point3D :
    record
        x, y, z : real
    end record

type Node :
    record
        p : Point3D
        n : int
        t : int
        hit : boolean
    end record

var keys : array char of boolean
var score : int := 0
var song : string
var mult : int := 1
var node : array 1 .. NODES of Node

process playSong (s : string)
    Music.PlayFile (s)
end playSong

%Convert 3D to 2D from Point3D record
fcn to2DFromPoint (threed : Point3D) : Point2D
    var twod : Point2D
    twod.x := maxx div 2 + (threed.x - maxx div 2) / (1 + (threed.z / 100))
    twod.y := maxy div 2 + (threed.y - maxy div 2) / (1 + (threed.z / 100))
    result twod
end to2DFromPoint

%Convert 3D to 2D from x, y, z coordinates
fcn to2D (x, y, z : real) : Point2D
    var twod : Point2D
    twod.x := maxx div 2 + (x - maxx div 2) / (1 + (z / 100))
    twod.y := maxy div 2 + (y - maxy div 2) / (1 + (z / 100))
    result twod
end to2D

%Draws everything
proc draw (dir : int)
    const f := Font.New ("Arial:20")
    Draw.FillBox (0, 0, maxx, maxy, black)
    %White hit point lines
    Draw.ThickLine (round (to2D (0, 0, HIT_LOC - sqrt (DIFF * 2)).x),
        round (to2D (0, 0, HIT_LOC - sqrt (DIFF * 2)).y),
        round (to2D (maxx, 0, HIT_LOC - sqrt (DIFF * 2)).x),
        round (to2D (maxx, 0, HIT_LOC - sqrt (DIFF * 2)).y), 5, white)
    Draw.ThickLine (round (to2D (0, 0, HIT_LOC + sqrt (DIFF * 2)).x),
        round (to2D (0, 0, HIT_LOC + sqrt (DIFF * 2)).y),
        round (to2D (maxx, 0, HIT_LOC + sqrt (DIFF * 2)).x),
        round (to2D (maxx, 0, HIT_LOC + sqrt (DIFF * 2)).y), 5, white)
    for z : 1 .. maxz by round (SPEED * LINE_WIDTH)
        Draw.Box (round (to2D (0, 0, z - (Time.Elapsed mod (SPEED * LINE_WIDTH - 1)) * dir).x),
            round (to2D (0, 0, z - (Time.Elapsed mod (SPEED * LINE_WIDTH - 1)) * dir).y),
            round (to2D (maxx, maxy, z - (Time.Elapsed mod (SPEED * LINE_WIDTH - 1)) * dir).x),
            round (to2D (maxx, maxy, z - (Time.Elapsed mod (SPEED * LINE_WIDTH - 1)) * dir).y), blue)
    end for
    %bottom lines
    for x : 50 .. maxx - 50 by maxx div 6
        Draw.ThickLine (x, 0, round (to2D (x, 0, maxz).x), round (to2D (x, 0, maxz).y), 3, brightgreen)
    end for
    %Hit points
    for i : 1 .. 5
        %Hit point
        for j : 1 .. 3
            if keys (KEYS (i)) then
                Draw.FillOval (round (to2D ((maxx - (maxx div 5)) div 5 * i, 0, HIT_LOC).x),
                    round (to2D ((maxx - (maxx div 5)) div 5 * i, 0, HIT_LOC).y),
                    W, H, C2 (i))
                Draw.Oval (round (to2D ((maxx - (maxx div 5)) div 5 * i, 0, HIT_LOC).x),
                    round (to2D ((maxx - (maxx div 5)) div 5 * i, 0, HIT_LOC).y + j),
                    W + j, H, C1 (i))
            else
                Draw.Oval (round (to2D ((maxx - (maxx div 5)) div 5 * i, 0, HIT_LOC).x),
                    round (to2D ((maxx - (maxx div 5)) div 5 * i, 0, HIT_LOC).y + j),
                    W + j, H, C1 (i))
            end if
        end for
    end for
    %Nodes
    for i : 1 .. upper (node)
        if node (i).p.z < maxz then
            %White surrounding
            Draw.FillOval (round (to2DFromPoint (node (i).p).x),
                round (to2DFromPoint (node (i).p).y),
                min (W, round (W ** 1.5 / sqrt (node (i).p.z))),
                min (H, round (H ** 1.5 / sqrt (node (i).p.z))), grey)
            %Dark outline
            Draw.FillOval (round (to2DFromPoint (node (i).p).x),
                round (to2DFromPoint (node (i).p).y + 1),
                min (W - 3, round ((W - 3) ** 1.5 / sqrt (node (i).p.z))),
                min (H - 3, round ((H - 3) ** 1.5 / sqrt (node (i).p.z))), C2 (node (i).n))
            %Main body
            Draw.FillOval (round (to2DFromPoint (node (i).p).x),
                round (to2DFromPoint (node (i).p).y + 2),
                min (W - 4, round ((W - 4) ** 1.5 / sqrt (node (i).p.z))),
                min (H - 3, round ((H - 3) ** 1.5 / sqrt (node (i).p.z))), C1 (node (i).n))
            %Top outline
            Draw.FillOval (round (to2DFromPoint (node (i).p).x),
                round (to2DFromPoint (node (i).p).y + 4),
                min (W div 2, round ((W div 2) ** 1.5 / sqrt (node (i).p.z))),
                min (H div 2, round ((H div 2) ** 1.5 / sqrt (node (i).p.z))), C2 (node (i).n))
            %Top body
            Draw.FillOval (round (to2DFromPoint (node (i).p).x),
                round (to2DFromPoint (node (i).p).y + 5),
                min ((W div 2) - 1, round (((W div 2) - 1) ** 1.5 / sqrt (node (i).p.z))),
                min ((H div 2) - 1, round (((H div 2) - 1) ** 1.5 / sqrt (node (i).p.z))), grey)

        end if
    end for
    put "Score: ", score, " Mult: ", mult
end draw

%Initialize array of hit nodes
for i : 1 .. NODES
    node (i).n := Rand.Int (1, 5)
    node (i).p.x := (maxx - (maxx div 5)) div 5 * node (i).n
    node (i).p.y := 0
    node (i).p.z := HIT_LOC + ((DIFF * Rand.Int (0, 3) * i))
end for

%Execution
loop
    cls
    Input.KeyDown (keys)
    for i : 1 .. NODES
        %Move each node
        node (i).p.z -= SPEED
        %Reset appropriate nodes to back of queue in random location
        if node (i).p.z <= SPEED + 1 then
            node (i).p.z += DIFF * NODES
            node (i).n := Rand.Int (1, 5)
            node (i).p.x := (maxx - (maxx div 5)) div 5 * node (i).n
            score -= MISS
        elsif keys (KEYS (node (i).n)) and keys (STRUM) then
            if abs (node (i).p.z - (HIT_LOC)) < sqrt (DIFF * 2) then
                score += HIT
                node (i).p.z += DIFF * NODES
                node (i).n := Rand.Int (1, 5)
                node (i).p.x := (maxx - (maxx div 5)) div 5 * node (i).n
            else
                score -= ALMOST
            end if
        end if
        if keys (STRUM) then
            score -= OVERSTRUM
        end if
    end for
    Time.DelaySinceLast (DELAY)
    draw (1)
    View.Update
end loop


Author:  DIIST [ Tue May 22, 2007 7:44 pm ]
Post subject:  Re: Guitar Hero

Visually appealing, Smile

As for your code, you need to free up your recourses. Do not create fonts within procedural calls unless you plan on freeing them at the end. If their going to be constant leave them as global variables. Other than that good job.

Author:  Geostigma [ Tue May 22, 2007 11:07 pm ]
Post subject:  RE:Guitar Hero

Impressed.

Author:  Saad [ Wed May 23, 2007 6:23 am ]
Post subject:  RE:Guitar Hero

Remove the blue line background, it hurts the eyes somewhat. Other then that looks visually very good. Need to wait for gameplay

Author:  ashiphire [ Wed May 23, 2007 7:11 am ]
Post subject:  RE:Guitar Hero

very interesting

Author:  lilmizeminem [ Wed May 23, 2007 11:03 am ]
Post subject:  RE:Guitar Hero

this is pretty sweet.
mustve taken a while to make lol ?

Author:  Qamar [ Wed May 23, 2007 3:22 pm ]
Post subject:  Re: Guitar Hero

haha this is really cool.

good stuff.

Author:  Tallguy [ Thu May 24, 2007 12:04 pm ]
Post subject:  Re: Guitar Hero

Really cool

Author:  tenniscrazy [ Thu May 24, 2007 4:10 pm ]
Post subject:  RE:Guitar Hero

good game...its kida impossible to acually play tho, and i cant tell if i get a button or not. nice graphics tho

Author:  ZeppelinManiac [ Mon May 28, 2007 8:57 am ]
Post subject:  Re: Guitar Hero

oh man, this is by far the best program on this site, try this, pick up your keyboard like a guitar, and think of it as guitar hero

Author:  lilmizeminem [ Mon May 28, 2007 11:02 am ]
Post subject:  RE:Guitar Hero

haha
yeah thats what everyone should do Razz

Author:  Metal-Head91 [ Thu Jun 07, 2007 11:10 pm ]
Post subject:  Re: Guitar Hero

for some reason its not working for me. it keeps giving me errors. first on the "KEY_ENTER", it says that "KEY_ENTER" was not declared than it said that "Input.KeyDown" was not on the exported list of 'Input'. and i dont know why this is happeneing... Confused Sad

Author:  Carey [ Fri Jun 08, 2007 8:22 am ]
Post subject:  Re: Guitar Hero

You probly have an outdated version of turing

Author:  chrisbrown [ Sat Jun 09, 2007 6:12 pm ]
Post subject:  Re: Guitar Hero

Newer version, still random, but getting closer to something usable. After this post, this project will be on hold while I finish more important things.

Author:  UraniumLobster [ Mon Sep 10, 2007 10:02 am ]
Post subject:  RE:Guitar Hero

Thats pretty cool, all though the scoring is a bit odd... great graphics =)

Author:  Prince Pwn [ Tue Sep 11, 2007 12:47 am ]
Post subject:  RE:Guitar Hero

This is the best Turing program I've ever seen. All you need to do is add some random Music.Sound to the game.

Author:  chrisbrown [ Tue Sep 11, 2007 10:19 am ]
Post subject:  RE:Guitar Hero

Thanks for the feedback. I just started a full rewrite so as soon as I'm finished I'll post the new version. Should be a full-featured game by that point.

Author:  Dannyd534 [ Tue Feb 12, 2008 9:10 am ]
Post subject:  RE:Guitar Hero

man...this game is so much fun

Author:  nastynika [ Wed Feb 13, 2008 9:12 am ]
Post subject:  Re: Guitar Hero

amazing keep up the good work

Author:  Prince Pwn [ Mon Apr 07, 2008 1:04 pm ]
Post subject:  RE:Guitar Hero

Hey dude did you continue working on it? One tip: Make the scoring more visible with Font.Draw and Font.New and intstr.

Author:  repsoccer16 [ Tue Apr 08, 2008 8:08 am ]
Post subject:  RE:Guitar Hero

great game...extremely difficult..try to work it so that you know when you actually hit the notes.

Author:  FC7321 [ Tue May 14, 2013 5:54 pm ]
Post subject:  Re: Guitar Hero

This is some really impressive work. One question though: How did you get each note to come down one after another at different intervals of time?

It would be great if you could help me answer that. Thanks

Author:  Insectoid [ Tue May 14, 2013 5:58 pm ]
Post subject:  RE:Guitar Hero

Nobody's posted here since 2008.
Anyway, you do it the same way you animate anything else. There isn't really a trick to it.

Author:  FC7321 [ Tue May 14, 2013 7:20 pm ]
Post subject:  RE:Guitar Hero

You see, I've been working on something similar for the past week, and I just came across this post today.

The way I programmed mine (the noob way) is completely different from his. I made the notes come down using a loop, but to change WHEN each one comes down, I put a 'delay' before 'end loop'. The problem is that the number of milliseconds following the delay is inconsistent.

Author:  Nathan4102 [ Tue May 14, 2013 7:27 pm ]
Post subject:  RE:Guitar Hero

I don't think you can use a delay for the time inbetween notes, because other notes would be unclickable, and all the animations would stop.

Author:  FC7321 [ Tue May 14, 2013 7:43 pm ]
Post subject:  RE:Guitar Hero

Yeah, because of that, I won't designing the program so that more than 1 note will be played at the same time. Thanks for you help, I'll try to find another way to bypass this problem, if I can.


: