Need Help With Lagging Program!
Author |
Message |
Randolf Nitler
|
Posted: Mon Jan 14, 2008 8:48 pm Post subject: Need Help With Lagging Program! |
|
|
My program is a huge lag. I'm still working on my tanks or gunbound game, and this is a test to it. I have it incorporated into my original program but he outcome is the same... lag! What can i do to fix this. Please point out the mistakes and ill get right to fixing them. Thanks again
Randolf Nitler
code: |
setscreen ("offscreenonly")
var player1locationX, player1locationY, player2locationX, player2locationY : int
var radius : int
radius := 15
player1locationX := 150
player1locationY := 150
player2locationX := 450
player2locationY := 150
drawfilloval (player1locationX, player1locationY, radius, radius, brightred)
drawfilloval (player1locationX, player1locationY, 3, 3, black)
drawfilloval (player2locationX, player2locationY, radius, radius, brightblue)
drawfilloval (player2locationX, player2locationY, 3, 3, black)
% variables for player 1's and 2's power
var power1, power2 : int
power1 := 0
power2 := 0
% p1angle and p2angle
var p1angle, p2angle : int
p1angle := 0
p2angle := 180
% small oval coordinates
var oval1X, oval1Y, oval2X, oval2Y : int
oval1X := 25 + player1locationX
oval1Y := player1locationY
oval2X := 25 + player2locationX
oval2Y := player2locationY
loop
% movement variables
var chars : array char of boolean
Input.KeyDown (chars)
if chars ('w') then
p1angle := p1angle + 1
delay (25)
end if
Input.KeyDown (chars)
if chars ('s') then
p1angle := p1angle - 1
delay (25)
end if
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
p2angle := p2angle + 1
delay (25)
end if
Input.KeyDown (chars)
if chars (KEY_DOWN_ARROW) then
p2angle := p2angle - 1
delay (25)
end if
% set p1angle parameters
if p1angle > 180 then
p1angle := 180
elsif p1angle < 0 then
p1angle := 0
end if
if p2angle > 180 then
p2angle := 180
elsif p2angle < 0 then
p2angle := 0
end if
% display the p1angle on the screen
locate (1, 10)
put "PLAYER 1's ANGLE:", p1angle, " PLAYER 1's POWER: ", power1
% display the p2angle on the screen
locate (2, 10)
put "PLAYER 2's ANGLE:", p2angle, " PLAYER 2's POWER: ", power2
%Keys for player 1 to change their power
Input.KeyDown (chars)
if chars ('d') then
power1 := power1 + 1
drawfillbox (50, 450, 50 + power1, 470, brightred)
delay (10)
end if
% keys for player 2 to change their power
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then
power2 := power2 + 1
drawfillbox (850, 450, 850 + power2, 470, brightblue)
delay (10)
end if
% for player 1's missile must go up, and then come down at a certain time
% put time in a for loop
for t : 1 .. 100
delay (2)
% name missile variables
var currentXlocation1, currentYlocation1, gravity : real
gravity := -1
currentXlocation1 := player1locationX + (cosd (p1angle) * power1 * t) % calculate the missiles current x position
currentYlocation1 := player1locationY + (sind (p1angle) * power1 * t + 0.5 * gravity * (t) ** 2) % calculate the missiles current y position
% draw player 1's missile missile
Input.KeyDown (chars)
if chars ('q') then
drawfilloval (round (currentXlocation1), round (currentYlocation1), 3, 3, black)
end if
end for
% for player 2's missile must go up, and then come down at a certain time
% put time in a for loop
for t : 1 .. 100
delay (2)
% name missile variables
var currentXlocation2, currentYlocation2, gravity : real
gravity := -1
currentXlocation2 := player2locationX + (cosd (p2angle) * power2 * t) % calculate ht emissiles current x position
currentYlocation2 := player2locationY + (sind (p2angle) * power2 * t + 0.5 * gravity * (t) ** 2) % calculate the missile current y position
% draw player 2's missile missile
Input.KeyDown (chars)
if chars (KEY_ENTER) then
drawfilloval (round (currentXlocation2), round (currentYlocation2), 3, 3, black)
end if
end for
View.Update
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Saad
|
Posted: Mon Jan 14, 2008 8:55 pm Post subject: RE:Need Help With Lagging Program! |
|
|
It's lagging because of the fact that you told the program to delay in the last 2 for loops. And it does delaying a total of 400ms. |
|
|
|
|
|
StealthArcher
|
Posted: Mon Jan 14, 2008 9:00 pm Post subject: Re: Need Help With Lagging Program! |
|
|
If you want this to move as fast as I think you do, you don't need to check Input.Keydown four times. It would make it faster as well.
Try this:
Turing: |
setscreen ("offscreenonly")
var player1locationX, player1locationY, player2locationX, player2locationY : int
var radius : int
radius := 15
player1locationX := 150
player1locationY := 150
player2locationX := 450
player2locationY := 150
drawfilloval (player1locationX, player1locationY, radius, radius, brightred)
drawfilloval (player1locationX, player1locationY, 3, 3, black)
drawfilloval (player2locationX, player2locationY, radius, radius, brightblue)
drawfilloval (player2locationX, player2locationY, 3, 3, black)
% variables for player 1's and 2's power
var power1, power2 : int
power1 := 0
power2 := 0
% p1angle and p2angle
var p1angle, p2angle : int
p1angle := 0
p2angle := 180
% small oval coordinates
var oval1X, oval1Y, oval2X, oval2Y : int
oval1X := 25 + player1locationX
oval1Y := player1locationY
oval2X := 25 + player2locationX
oval2Y := player2locationY
loop
% movement variables
var chars : array char of boolean
Input.KeyDown (chars )
if chars ('w') then
p1angle := p1angle + 1
delay (25)
elsif chars ('s') then
p1angle := p1angle - 1
delay (25)
end if
Input.KeyDown (chars )
if chars (KEY_UP_ARROW) then
p2angle := p2angle + 1
delay (25)
elsif chars (KEY_DOWN_ARROW) then
p2angle := p2angle - 1
delay (25)
end if
% set p1angle parameters
if p1angle > 180 then
p1angle := 180
elsif p1angle < 0 then
p1angle := 0
end if
if p2angle > 180 then
p2angle := 180
elsif p2angle < 0 then
p2angle := 0
end if
% display the p1angle on the screen
locate (1, 10)
put "PLAYER 1's ANGLE:", p1angle, " PLAYER 1's POWER: ", power1
% display the p2angle on the screen
locate (2, 10)
put "PLAYER 2's ANGLE:", p2angle, " PLAYER 2's POWER: ", power2
%Keys for player 1 to change their power
Input.KeyDown (chars )
if chars ('d') then
power1 := power1 + 1
drawfillbox (50, 450, 50 + power1, 470, brightred)
delay (10)
end if
% keys for player 2 to change their power
Input.KeyDown (chars )
if chars (KEY_RIGHT_ARROW) then
power2 := power2 + 1
drawfillbox (850, 450, 850 + power2, 470, brightblue)
delay (10)
end if
% for player 1's missile must go up, and then come down at a certain time
% put time in a for loop
for t : 1 .. 100
% name missile variables
var currentXlocation1, currentYlocation1, gravity : real
gravity := - 1
currentXlocation1 := player1locationX + (cosd (p1angle ) * power1 * t ) % calculate the missiles current x position
currentYlocation1 := player1locationY + (sind (p1angle ) * power1 * t + 0. 5 * gravity * (t ) ** 2) % calculate the missiles current y position
% draw player 1's missile missile
Input.KeyDown (chars )
if chars ('q') then
drawfilloval (round (currentXlocation1 ), round (currentYlocation1 ), 3, 3, black)
end if
end for
% for player 2's missile must go up, and then come down at a certain time
% put time in a for loop
for t : 1 .. 100
% name missile variables
var currentXlocation2, currentYlocation2, gravity : real
gravity := - 1
currentXlocation2 := player2locationX + (cosd (p2angle ) * power2 * t ) % calculate ht emissiles current x position
currentYlocation2 := player2locationY + (sind (p2angle ) * power2 * t + 0. 5 * gravity * (t ) ** 2) % calculate the missile current y position
% draw player 2's missile missile
Input.KeyDown (chars )
if chars (KEY_ENTER ) then
drawfilloval (round (currentXlocation2 ), round (currentYlocation2 ), 3, 3, black)
end if
end for
View.Update
end loop
|
Cases and labels would do, and probably better, but meh.. I'm lazy.
BTW you forgot a key to decrease the player's power levels (OVER 9000!). |
|
|
|
|
|
Randolf Nitler
|
Posted: Mon Jan 14, 2008 9:15 pm Post subject: Re: Need Help With Lagging Program! |
|
|
it's just a bloody test... and i have that so it wont get over 100 in my original program =D |
|
|
|
|
|
|
|