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

Username:   Password: 
 RegisterRegister   
 SQUARE CHASE - 2 player game
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
statistic-48260137985




PostPosted: Wed Feb 23, 2005 7:12 pm   Post subject: SQUARE CHASE - 2 player game

well this is a simple game i made a while back, but im still proud of it, the code is simple and sloppy but it works, im going to clean it up a bit then im thinking of putting in a vs cpu version.

code:

%This game made by the Martin Lindsay November 2004.
%Do not illegally alter this game in any way, or i will yell at you angrily.
setscreen ( "graphics:500;500, nobuttonbar" )
var chars : array char of boolean
var x, y, x2, y2, a, b, a2, b2, blue_wins, red_wins : int := 0
var ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8, ch9 : int   
var attacker, word : string
var sidecheckred, timer, sidecheckblue, randomattack : int

%instructions for playing, and enterting of names
var player_red, player_blue : string
put "Enter the name of the red player... " ..
get player_red
put "Red player will use the arrow keys to move."
put "Enter the name of the blue player... " ..
get player_blue
put "Blue player will use w, s, a and d to move."
put "What ever colour is at the top is the attacking colour."
delay (5000)


loop
%makes the attacker random
randomattack:= Rand.Int (1, 2)
%sets all the variables for the beginning of the round
a := 490
b := 0
x := 1
a2 := a + 10
b2 := b + 10
y := 1
x2 := x + 10
y2 := y + 10
timer := 0
put "Get ready..."
delay (3000)
cls
%shows users who the attacker is
if randomattack=1 then
attacker := "red"
drawfillbox (0, 401, 500, 500, red)
elsif randomattack=2 then
attacker := "blue"
drawfillbox (0, 401, 500, 500, blue)
timer:=6001
end if

%main body loop
loop
%erases the boxes
drawfillbox (a, b, a2, b2, white)
drawfillbox (x, y, x2, y2, white)
%loop count increases
timer := timer + 1 
%player controls     
Input.KeyDown (chars)
locate (1, 1)
if chars (KEY_UP_ARROW) then
y := y + 1
end if
if chars (KEY_RIGHT_ARROW) then
x := x + 1   
end if
if chars (KEY_LEFT_ARROW) then
x := x - 1   
end if
if chars (KEY_DOWN_ARROW) then
y := y - 1
end if
if chars ('w') then
b := b + 1
end if
if chars ('s') then
b := b - 1
end if
if chars ('a') then
a := a - 1
end if
if chars ('d') then
a := a + 1
end if
%figures out the rest of the variables for drawing the squares
a2 := a + 10
b2 := b + 10
x2 := x + 10
y2 := y + 10
%keeps the squares in the screen
if x=491 then
x:=x-1
end if
if x=-1 then
x :=x+1
end if
if y=-1 then
y:=y+1
end if
if y=391 then
y:=y - 1
end if
if a=491 then
a:=a - 1
end if
if a=-1 then
a :=a +1
end if
if b=-1 then
b:=b + 1
end if
if b=391 then
b:=b - 1
end if
%calculates the coordinates of the suares again
x2 := x + 10
y2 := y + 10
a2 := a + 10
b2 := b + 10
%draws the squares
drawfillbox (a, b, a2, b2, blue)
drawfillbox (x, y, x2, y2, red)
            delay (2)

            %prepares for overlapping check
ch1 := y + 1
ch2 := y + 2
ch3 := y + 3
ch4 := y + 4
ch5 := y + 5
ch6 := y + 6
ch7 := y + 7
ch8 := y + 8
ch9 := y + 9

%the following area of the code checks if the squares overlap
%now i know i could do this much faster with arrays and for blocks...
%but i originally made this game 3 weeks after i started programming, so ill spruce it up later
if attacker="red" or attacker="blue" then
if x=a then
if y=b then
exit
elsif y=b2 then
exit
elsif y2=b then
exit
elsif y2=b2 then
exit
elsif ch1=b then
exit
elsif ch1=b2 then
exit
elsif ch2=b then
exit
elsif ch2=b2 then
exit
elsif ch3=b then
exit
elsif ch3=b2 then
exit
elsif ch4=b then
exit
elsif ch4=b2 then
exit
elsif ch5=b then
exit
elsif ch5=b2 then
exit
elsif ch6=b then
exit
elsif ch6=b2 then
exit
elsif ch7=b then
exit
elsif ch7=b2 then
exit
elsif ch8=b then
exit
elsif ch8=b2 then
exit
elsif ch9=b then
exit
elsif ch9=b2 then
exit
end if
elsif x=a2 then
if y=b then
exit
elsif y=b2 then
exit
elsif y2=b then
exit
elsif y2=b2 then
exit

elsif ch1=b then
exit
elsif ch1=b2 then
exit
elsif ch2=b then
exit
elsif ch2=b2 then
exit
elsif ch3=b then
exit
elsif ch3=b2 then
exit
elsif ch4=b then
exit
elsif ch4=b2 then
exit
elsif ch5=b then
exit
elsif ch5=b2 then
exit
elsif ch6=b then
exit
elsif ch6=b2 then
exit
elsif ch7=b then
exit
elsif ch7=b2 then
exit
elsif ch8=b then
exit
elsif ch8=b2 then
exit
elsif ch9=b then
exit
elsif ch9=b2 then
end if
elsif x2=a then
if y=b then
exit
elsif y=b2 then
exit
elsif y2=b then
exit
elsif y2=b2 then
exit
end if
elsif x2=a2 then
if y=b then
exit
elsif y=b2 then
exit
elsif y2=b then
exit
elsif y2=b2 then
exit
end if
end if
end if
%checks for attaqck change
if timer=6000 then
attacker :="blue"
drawfillbox (0, 401, 500, 500, blue)
elsif timer=5000 then
attacker := "none"
drawfillbox (0, 401, 500, 500, white)
locate (3, 10)
put "Attacker is Changing..."
elsif timer=11000 then
attacker:="none"
drawfillbox (0, 401, 500, 500, white)
locate (3, 10)
put "Attacker is Changing..."
elsif timer=12000 then
attacker:="red"
drawfillbox (0, 401, 500, 500, red)
timer := 0
end if           
end loop
%outputs scores.
if attacker="red"
then cls
put player_red ," Wins."
red_wins :=red_wins + 1
elsif attacker="blue" then
cls
put player_blue ," Wins."
blue_wins := blue_wins + 1
end if
put player_red ,"-", red_wins ,"    ", player_blue ,"-", blue_wins
put "Play again? (y)es or (n)o."
loop
Input.KeyDown (chars)
if chars ('y') or chars ('Y') then
word:="y"
exit
elsif chars ('n') or chars ('N') then
word:="n"
exit
end if
end loop
if word="y" then
put "Yes."
else
exit
end if
end loop
cls
put "Thank you for playing."
Sponsor
Sponsor
Sponsor
sponsor
ssr




PostPosted: Wed Feb 23, 2005 7:21 pm   Post subject: (No subject)

I made the same game a while ago, go search for "simple game" and download teh TAG AII file
lol

btw, what u can use is
code:
View.Update 

8) 8)
ssr




PostPosted: Wed Feb 23, 2005 7:23 pm   Post subject: (No subject)

ooo
I just found out
man use whatdotcolor for collusion detection
it will save u at least 40 lines Very Happy
person




PostPosted: Thu Feb 24, 2005 4:56 pm   Post subject: (No subject)

absolutely magnificent
Cervantes




PostPosted: Thu Feb 24, 2005 7:47 pm   Post subject: (No subject)

Seems buggy to me. For one, collisions are off (seemed to take a second or two to register). Second, it takes a while for the attacker to change. Maybe you meant to do that, but it needs some explanation. Also, I don't know if there's more to it, but I can't get the attacker to change very often.
MiX-MaztA-M8riX




PostPosted: Sat Feb 26, 2005 11:08 am   Post subject: (No subject)

Cervantes wrote:
Seems buggy to me. For one, collisions are off (seemed to take a second or two to register). Second, it takes a while for the attacker to change. Maybe you meant to do that, but it needs some explanation. Also, I don't know if there's more to it, but I can't get the attacker to change very often.


I dunno about you, but it works perfectly fine on mine, what kinda comp you using?
Cervantes




PostPosted: Sat Feb 26, 2005 11:38 am   Post subject: (No subject)

p4 1.6ghz.
maybe we just have different ideas of how the game should work? :/
xHoly-Divinity




PostPosted: Sat Feb 26, 2005 1:23 pm   Post subject: (No subject)

I would suggest using a scoring system of say up to 5 or 10 rather than every time you have to restart the game. Put score blue = and score red =. Then first one to lets say 10 would win
Sponsor
Sponsor
Sponsor
sponsor
xHoly-Divinity




PostPosted: Sat Feb 26, 2005 1:25 pm   Post subject: (No subject)

Woops! Sorry I didn't see that you already had it. My mistake. However, maybe you don't always have to go back to the menu screen, just make it restart on its own, and display the score at the very top.
jamonathin




PostPosted: Sun Feb 27, 2005 6:37 pm   Post subject: (No subject)

yeah i definately reccomend using "offscreenonly"/View.Update and whatdotcolor, because it'll make ur game look better, and the "tag" will be more accurate.
flamemaster89




PostPosted: Sun Oct 30, 2005 3:46 pm   Post subject: (No subject)

AWESOME!!!!!!!!

Mod Edit:
Bringing up old topics to say "AWESOME" is a no-no on these boards. Rules. This rule.
goboenomo




PostPosted: Sun Oct 30, 2005 5:23 pm   Post subject: (No subject)

ummm
i think ive seen this before
unless this is the same one

Most likely, since this is an old topic. Also, please shrink your signature. It's nice and all, but really too tall. One of them would do.

Locked.
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 1  [ 12 Posts ]
Jump to:   


Style:  
Search: