Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Laser Wars
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
s_climax




PostPosted: Fri May 07, 2004 6:25 pm   Post subject: Laser Wars

Read next post
Sponsor
Sponsor
Sponsor
sponsor
s_climax




PostPosted: Mon May 17, 2004 9:02 pm   Post subject: (No subject)

Here is the finished version. The only thing it doesn't have is a good interface.

Controls for 1st player are:

up/down/left/right : move
control : shoot

For 2nd player:

w/s/a/d : move
shift : shoot

Tell me what you think.

code:

setscreen ("nooffscreenonly")
var speed, x, y, pastx, pasty, dir, bulletx, bullety, bulletdir, bulletspeed : real
var speed2, x2, y2, pastx2, pasty2, dir2, bulletx2, bullety2, bulletdir2 : real
var chars : array char of boolean
var shoot, shoot2 : int
var gamespeed, score1, score2 : int
var pics1, pics2 : array 0 .. 359 of int
var hit : boolean
hit := false
score1 := 0
score2 := 0
gamespeed := 2
%Pic.ScreenLoad ("man.bmp", 0, 0, picMerge)
drawdot(9,11,10)
drawdot(9,12,10)
drawdot(9,17,10)
drawdot(9,18,10)
drawdot(10,11,10)
drawdot(10,12,10)
drawdot(10,17,10)
drawdot(10,18,10)
drawfillbox(11,11,12,18,10)
drawfillbox(13,11,16,12,20)
drawfillbox(13,17,16,18,20)
drawfillbox(16,13,17,16,20)
drawfillbox(13,13,16,16,110)
drawfillbox(13,10,16,7,40)
drawfillbox(13,18,16,20,40)
drawfillbox(13,21,18,22,68)
drawfillbox(13,5,18,6,68)
drawfillbox(19,5,22,6,7)
drawfillbox(23,7,28,8,7)
pics1 (0) := Pic.New (0, 0, 28, 28)
cls
for angle : 1 .. 359
    drawbox (maxx div 2 - 180, maxy div 2 - 50, maxx div 2 + 180, maxy div 2 + 50, 7)
    drawfillbox (maxx div 2 - 180, maxy div 2 - 50, maxx div 2 - 180 + (angle div 2), maxy div 2 + 50, 7)
    %locate (3, 3)
    %put "Creating picture rotated ", angle, " degrees"
    pics1 (angle) := Pic.Rotate (pics1 (0), angle, 14, 14)
end for
%Pic.ScreenLoad ("man2.bmp", 0, 0, picMerge)
drawdot(9,11,6)
drawdot(9,12,6)
drawdot(9,17,6)
drawdot(9,18,6)
drawdot(10,11,6)
drawdot(10,12,6)
drawdot(10,17,6)
drawdot(10,18,6)
drawfillbox(11,11,12,18,6)
drawfillbox(13,11,16,12,42)
drawfillbox(13,17,16,18,42)
drawfillbox(16,13,17,16,42)
drawfillbox(13,13,16,16,110)
drawfillbox(13,10,16,7,56)
drawfillbox(13,18,16,20,56)
drawfillbox(13,21,18,22,68)
drawfillbox(13,5,18,6,68)
drawfillbox(19,5,22,6,7)
drawfillbox(23,7,28,8,7)
pics2 (0) := Pic.New (0, 0, 28, 28)
cls
for angle : 1 .. 359
    %locate (3, 3)
    drawbox (maxx div 2 - 180, maxy div 2 - 50, maxx div 2 + 180, maxy div 2 + 50, 7)
    drawfillbox (maxx div 2 - 180, maxy div 2 - 50, maxx div 2 + (angle div 2), maxy div 2 + 50, 7)
    %put "Creating picture rotated ", angle, " degrees"
    pics2 (angle) := Pic.Rotate (pics2 (0), angle, 14, 14)
end for
cls
setscreen ("offscreenonly;nocursor")
loop
    put "You are playing a game up to ", (50 * (6 - gamespeed)), " points."
    put "Press any key to continue"
    View.Update
    cls
    exit when hasch
end loop
speed := 1 * gamespeed
bulletspeed := 20 * gamespeed
dir := 180
x := maxx div 2 - 50
y := maxy div 2
shoot := 0
speed2 := 1 * gamespeed
dir2 := 0
x2 := maxx div 2 + 50
y2 := maxy div 2
shoot2 := 0
loop
    shoot := 0
    shoot2 := 0
    loop
        pastx := x
        pasty := y
        pastx2 := x2
        pasty2 := y2
        %1st Player Controls
        Input.KeyDown (chars)
        if chars (KEY_UP_ARROW) then
            x += cosd (dir) * speed
            y += sind (dir) * speed
        end if
        if chars (KEY_DOWN_ARROW) then
            x += cosd (dir) * -speed
            y += sind (dir) * -speed
        end if
        if chars (KEY_LEFT_ARROW) then
            dir += speed
        end if
        if chars (KEY_RIGHT_ARROW) then
            dir -= speed
        end if
        if chars (KEY_CTRL) then
            shoot := 1
        end if
        %2nd Player Controls
        if chars ('w') then
            x2 += cosd (dir2) * speed2
            y2 += sind (dir2) * speed2
        end if
        if chars ('s') then
            x2 += cosd (dir2) * -speed2
            y2 += sind (dir2) * -speed2
        end if
        if chars ('a') then
            dir2 += speed2
        end if
        if chars ('d') then
            dir2 -= speed2
        end if
        if chars (KEY_SHIFT) then
            shoot2 := 1
        end if
        %1st Player Bullet
        if shoot = 1 then
            bulletx += cosd (bulletdir) * bulletspeed
            bullety += sind (bulletdir) * bulletspeed
        else
            bulletx := x + cosd (dir - 40) * 10
            bullety := y + sind (dir - 40) * 10
            bulletdir := dir
        end if
        if bulletx > 0 or bulletx < maxx or bullety > 0 or bullety < maxy then
            shoot := 0
        end if
        %2nd Player Bullet
        if shoot2 = 1 then
            bulletx2 += cosd (bulletdir2) * bulletspeed
            bullety2 += sind (bulletdir2) * bulletspeed
        else
            bulletx2 := x2 + cosd (dir2 - 40) * 10
            bullety2 := y2 + sind (dir2 - 40) * 10
            bulletdir2 := dir2
        end if
        if bulletx2 > 0 or bulletx2 < maxx or bullety2 > 0 or bullety2 < maxy then
            shoot2 := 0
        end if
        if x <= 10 or x >= maxx - 20 or y <= 10 or y >= maxy - 30 then
            x := pastx
            y := pasty
        end if
        if x2 <= 10 or x2 >= maxx - 20 or y <= 10 or y2 >= maxy - 30 then
            x2 := pastx2
            y2 := pasty2
        end if
        if round (sqrt ((x2 - x) ** 2 + (y2 - y) ** 2)) < 35 then
            x := pastx
            y := pasty
            x2 := pastx2
            y2 := pasty2
        end if
        if dir <= 0 then
            dir += 359
        elsif dir >= 359 then
            dir -= 359
        end if
        if dir2 <= 0 then
            dir2 += 359
        elsif dir2 >= 359 then
            dir2 -= 359
        end if
        delay (0)
        cls
        Pic.Draw (pics1 (round (dir)), round (x) - 14, round (y) - 14, picMerge)
        Pic.Draw (pics2 (round (dir2)), round (x2) - 14, round (y2) - 14, picMerge)
        drawdot (round (bulletx), round (bullety), black)
        drawdot (round (bulletx2), round (bullety2), black)
        drawline (round (x + cosd (dir - 40) * 10), round (y + sind (dir - 40) * 10), round (bulletx), round (bullety), brightred)
        drawline (round (x2 + cosd (dir2 - 40) * 10), round (y2 + sind (dir2 - 40) * 10), round (bulletx2), round (bullety2), brightred)
        drawfillbox (0, maxy, maxx, maxy - 30, 7)
        %drawline(0,maxy,
        locatexy (0, maxy)
        put score1
        if score2 < 100 then
            locatexy (maxx - 10, maxy)
        else
            locatexy (maxx - 20, maxy)
        end if
        put score2
        Pic.ScreenLoad ("man.bmp", 30, maxy - 30, picMerge)
        Pic.ScreenLoad ("man2.bmp", maxx - 60, maxy - 30, picMerge)
        View.Update
        if round (sqrt ((bulletx - x2) ** 2 + (bullety - y2) ** 2)) < 20 then
            hit := true
            shoot := 0
            score1 += 1
        end if
        if round (sqrt ((bulletx2 - x) ** 2 + (bullety2 - y) ** 2)) < 20 then
            hit := true
            shoot2 := 0
            score2 += 1
        end if
        exit when score1 > (50 * (6 - gamespeed)) or score2 > (5 * (6 - gamespeed)) or hit = true
    end loop
    exit when score1 > (50 * (6 - gamespeed)) or score2 > (5 * (6 - gamespeed))
end loop
if score1 > score2 then
    locatexy (maxx div 2, maxy div 2)
    put "Player 1 Wins"
else
    locatexy (maxx div 2, maxy div 2)
    put "Player 2 Wins"
end if
guruguru




PostPosted: Mon May 17, 2004 9:22 pm   Post subject: (No subject)

Question Where is it Question Wow... there seem to be more and more files that people say to try that simply are not there... Crying or Very sad
netninja




PostPosted: Tue May 18, 2004 6:49 am   Post subject: (No subject)

Not bad, but its way too hard to hit the enemy, the keyboards too sensitive. And the movements a bit too fast. Also, you should tell us the controls before gameplay so people know what to do, maybe make some obstacles on course. And last, but very important. When you hold the laser and you turn around, it shoots the the same spot as where it originally was, kinda weird. For your next game it would be fun if you made a paintball game, and you could play over internet or lan or w/e.

Nice though, good example of key movement.
Mazer




PostPosted: Tue May 18, 2004 6:49 am   Post subject: (No subject)

Holding down the fire button while aimed directly at someone only gives you one point. If you're going to force the player to fire single shots for points, at least make the fire button shoot a single beam instead of a continuous one so they know that. Er, know what I mean?

Also, if you shoot in one direction and hold down the fire button, if you turn he'll still be shooting in the original direction.

Still, kinda neat.
Paul




PostPosted: Tue May 18, 2004 4:07 pm   Post subject: (No subject)

Hm... whenever I run this, it crashes my turing, maybe because I don't have the picture files?
s_climax




PostPosted: Tue May 18, 2004 4:09 pm   Post subject: (No subject)

The picture files are commented. That should not be why.
Paul




PostPosted: Tue May 18, 2004 4:24 pm   Post subject: (No subject)

Well, I can get to the loading bar, but just when its about to finish, it goes "the environment (not your program) has crashed" etc with a bunch of technical stuff.
Sponsor
Sponsor
Sponsor
sponsor
AsianSensation




PostPosted: Tue May 18, 2004 5:08 pm   Post subject: (No subject)

Omg! Red railguns.....

lol, +5 bits to this neat program.
Viper




PostPosted: Wed Nov 17, 2004 9:16 am   Post subject: little guys

the one guy can runn right oss screen n gets lost and i agree with that othr guy you should make the shooting single not umm.... continuos ray
zomg




PostPosted: Wed Nov 17, 2004 12:06 pm   Post subject: (No subject)

LOL NICE PROGRAM I LOVE THIS THING

Great job(so basic yet so fun)
m&m




PostPosted: Wed Nov 17, 2004 4:09 pm   Post subject: (No subject)

cool game. this is fun thanks nice work
MattyGG




PostPosted: Mon Nov 22, 2004 11:37 am   Post subject: (No subject)

I think its pretty good, and fun...kinda hard to aim the shots right, and i think that you should get more points for a shot if its up to 200...but other than that, i really like it
Viper




PostPosted: Mon Nov 22, 2004 1:03 pm   Post subject: (No subject)

it would be kool if more poeple could play like have it ask how many players n have it go up 2 like 4 people
Carino




PostPosted: Mon Nov 22, 2004 3:53 pm   Post subject: (No subject)

Cool prog, add some obstacles that will stop the lasers/men so it adds a more strategic affect to it, but altogether its good.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 22 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: