flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > simple physics game

Author
Thread Post new topic Reply to topic
me239



Joined: 06 Jan 2011
Posts: 200
me239
So I know this isn't assembly (that's why I'm putting it in heap), but I thought I might just share this little physics based game I wrote in qbasic 4.5. Basically the objective of the game is to destroy the 20 meter long enemy tank (big ass tank!) at a certain distance. You are given a choice between a short, medium, and long range shell and you are told their speed and max distance. All that is left for you to do is decide on a launch angle. You only get one shot, so make a wise choice! BTW, there are no graphics, just text.
Code:
RANDOMIZE TIMER
r = INT(RND * 2050) + 1
PRINT "ALERT! Tank spotted"; r; "meters away"
PRINT "You have 3 shell types: "
PRINT "Short range: 50 m/s and 255 meter max"
PRINT "Medium range: 100 m/s 1,020 meter max"
PRINT "Long range: 200 m/s 4,081 meter max"
INPUT "(S)hort range, (M)edium range, or (L)ong range"; c$
IF c$ = "s" OR c$ = "S" THEN v = 50
IF c$ = "m" OR c$ = "M" THEN v = 100
IF c$ = "l" OR c$ = "L" THEN v = 200
INPUT "Launch angle: "; a
a = a / (180 / (22 / 7))
ha = COS(a) * v
va = SIN(a) * v
t = (va / 9.8) * 2
d = ha * t
'd = d + (ha * .494)
IF d > r + 10 THEN GOTO miss
IF d < r - 10 THEN GOTO miss
PRINT "HIT! Enemy tank has been destroyed!"
PRINT "Distance: "; d
PRINT "Time: "; t
END
miss:
PRINT "MISS! The enemy tank has shot AND killed you "
PRINT "Distance: "; d
PRINT "Time: "; t
    


Description:
Filesize: 11.72 KB
Viewed: 6294 Time(s)

tankm.png


Description:
Filesize: 13.47 KB
Viewed: 6294 Time(s)

tankh.png


Post 17 Oct 2011, 05:55
View user's profile Send private message Reply with quote
Akujin



Joined: 11 Oct 2011
Posts: 26
Location: Exile
Akujin
Lets make an asm port...

_________________
CLI
HLT
Post 17 Oct 2011, 09:41
View user's profile Send private message Visit poster's website Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239
Akujin wrote:
Lets make an asm port...
I would, but I don't know how exactly to use floating point in assembly.
Post 17 Oct 2011, 20:45
View user's profile Send private message Reply with quote
Akujin



Joined: 11 Oct 2011
Posts: 26
Location: Exile
Akujin

_________________
CLI
HLT
Post 17 Oct 2011, 20:55
View user's profile Send private message Visit poster's website Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239
Hey! So I made some quick hack job graphics for my QB game. The tank is now a blue box and it graphs the parabolic path of the projectile.
Code:
SCREEN 9
WINDOW (-30, -200)-(2200, 1000)
LINE (0, -200)-(0, 1000)
LINE (-30, 0)-(2200, 0)
RANDOMIZE TIMER
r = INT(RND * 2050) + 1
PSET ((r / 2), 1), 3
DRAW "l5 u5 r15 d5 l15"
PRINT "ALERT! Tank spotted"; r; "meters away"
PRINT "You have 3 shell types: "
PRINT "Short range: 50 m/s and 255 meter max"
PRINT "Medium range: 100 m/s 1,020 meter max"
PRINT "Long range: 200 m/s 4,081 meter max"
INPUT "(S)hort range, (M)edium range, or (L)ong range"; c$
IF c$ = "s" OR c$ = "S" THEN v = 50
IF c$ = "m" OR c$ = "M" THEN v = 100
IF c$ = "l" OR c$ = "L" THEN v = 200
INPUT "Launch angle: "; a
a = a / (180 / (22 / 7))
ha = COS(a) * v
va = SIN(a) * v
FOR x = 0 TO 60 STEP .0002
y = (va - (9.8 * x)) * x
h = (ha * x)
IF y < 0 THEN GOTO done
PSET (h, y), 4
NEXT x
done:
t = (va / 9.8) * 2
d = ha * t
IF d > r + 10 THEN GOTO miss
IF d < r - 10 THEN GOTO miss
PRINT "HIT! Enemy tank has been destroyed!"
PRINT "Distance: "; d
PRINT "Time: "; t
WHILE INKEY$ = ""
WEND
END
miss:
PRINT "MISS! The enemy tank has shot AND killed you "
PRINT "Distance: "; d
PRINT "Time: "; t
WHILE INKEY$ = ""
WEND
    


Description:
Filesize: 11.6 KB
Viewed: 6114 Time(s)

tankm.png


Description:
Filesize: 13.79 KB
Viewed: 6114 Time(s)

tankh.png


Post 22 Oct 2011, 21:32
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239
Yet another update. I've changed the range so it's more realistic (1 - 4 Km), changed the speeds to 100, 150, and 200 m/s, and also two little secret options. "G" automatically finds the fastest route and "GA" finds the longest path.
Code:
SCREEN 9
WINDOW (-30, -200)-(2200, 1000)
LINE (0, -200)-(0, 1000)
LINE (-30, 0)-(2200, 0)
RANDOMIZE TIMER
r = INT((RND + .25) * 3250)
PSET ((r / 2), 1), 3
DRAW "l5 u5 r15 d5 l15"
PRINT "ALERT! Tank spotted"; r; "meters away"
PRINT "You have 3 shell types: "
PRINT "Short range: 100 m/s and 1,020 meter max"
PRINT "Medium range: 150 m/s 2,296 meter max"
PRINT "Long range: 200 m/s 4,081 meter max"
INPUT "(S)hort range, (M)edium range, or (L)ong range"; c$
IF c$ = "s" OR c$ = "S" THEN v = 100
IF c$ = "m" OR c$ = "M" THEN v = 150
IF c$ = "l" OR c$ = "L" THEN v = 200
IF c$ = "g" OR c$ = "G" THEN GOTO calc
IF c$ = "ga" OR c$ = "GA" OR c$ = "Ga" OR c$ = "gA" THEN GOTO calc
INPUT "Launch angle: "; a
a = a / (180 / (22 / 7))
game:
ha = COS(a) * v
va = SIN(a) * v
FOR x = 0 TO 60 STEP .0002
y = (va - (9.8 * x)) * x
h = (ha * x)
IF y < 0 THEN GOTO done
PSET (h, y), 4
NEXT x
done:
t = (va / 9.8) * 2
d = ha * t
'd = d + (ha * .494)
IF d > r + 10 THEN GOTO miss
IF d < r - 10 THEN GOTO miss
PRINT "HIT! Enemy tank has been destroyed!"
PRINT "Distance: "; d
PRINT "Time: "; t
WHILE INKEY$ = ""
WEND
END
miss:
PRINT "MISS! The enemy tank has shot AND killed you "
PRINT "Distance: "; d
PRINT "Time: "; t
WHILE INKEY$ = ""
WEND
END
calc:
IF r <= 1020 THEN v = 100
IF r <= 2296 THEN v = 150
IF r <= 4081 THEN v = 200
a = (r * 9.8)
a = a / v ^ 2
a = ATN(a / SQR(-a * a + 1)) / 2
IF c$ = "ga" OR c$ = "GA" OR c$ = "Ga" OR c$ = "gA" THEN a = 1.5707963267# - a
GOTO game
    
Post 23 Oct 2011, 01:29
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.