File: testsuite_sprite_include.kbs

package info (click to toggle)
basic256 2.0.99.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,888 kB
  • sloc: cpp: 17,185; yacc: 4,025; lex: 1,466; java: 1,091; sh: 39; xml: 33; makefile: 20
file content (142 lines) | stat: -rw-r--r-- 3,868 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# testsuite_sprite_include section for BASIC256

# Modification History
# date		programmer	description
# 20140204	j.m.reneau	added crazy if structures when if/then/else
#				moved to a statement and not a stand alone line (1010002)
# 20160510      j.m.reneau      use new form of the clg statetement to clear to a color
# 20160603  j.m.reneau      updated to use more sprite features for better testing
# 20160805	j.m.reneau		changed lists to listsoflists (1.99.99.53)
#								Added additional sprite testing logic
# 20160908	j.m.reneau		changes getslice to return an array - added serialize
# 20161101  j.m.reneau  added [] to all array passing to functions

currentsuite = "sprite"


graphsize 150,150

nsprites = 7

dim spritedx(nsprites)
dim spritedy(nsprites)
dim spritedr(nsprites)
dim spriteds(nsprites)

spritedim nsprites
# make the sprites from polys using the subroutine polysprite
penwidth 3
# two big squares
points =  {0,0,40,0,40,40,0,40}
penwidth 1
color black,red
spritepoly 0, points[]
color black,green
spritepoly 1, points[]
# two small right triangles
points =  {{20,0},{20,10},{15,5}}
color black, blue
spritepoly 2,{{20,0},{20,10},{15,5}}
color orange, grey
spritepoly 3,{5,0,5,10,0,5}
# one medium triangle
points =  {10,0,10,10,0,10}
penwidth 2
color black, cyan
spritepoly 4, {10,0,10,10,0,10}
# load image
spriteload 5, "testsuite_sprite.png"
call n("sprite height",spriteh(5),50)
call n("sprite width",spritew(5),50)

spriteslice 6, 100,100,20,30
call n("sprite height",spriteh(6),30)
call n("sprite width",spritew(6),20)

# draw a black and white pattern on the screen for under the sprites
clg purple
color white
penwidth 3
for t = 0 to graphwidth step 10
	line 0,0,t,graphheight
next t
for t = 0 to graphheight step 10
	line 0,0,graphwidth,t
next t
refresh

# calculate the md5 hash of the screen
originalscreen$ = md5(serialize(getslice(0,0,graphwidth, graphheight)))

for t = 0 to nsprites-1
	spriteshow t
	spritedx[t] = rand*5-1
	spritedy[t] = rand*5-1
	spritedr[t] = rand*pi*.1+-pi*.05
	spriteds[t] = rand *.3 - .15
	spriteplace t, rand*graphwidth, rand*graphheight, 1, spritedr[t]
next t

collissions = 0
# move the sprites
for n = 1 to 500
	for t = 0 to nsprites-1
		x = spritex(t) + spritedx[t]
		if x > graphwidth-10 then x = 10
		if x < 10 then x = graphwidth-10
		y = spritey(t) + spritedy[t]
		if y > graphwidth-10 then y = 10
		if y < 10 then y = graphwidth - 10
		r = spriter(t) + spritedr[t]
		s = sprites(t) + spriteds[t]
		if s > 1.5 then s = .5
		if s < .5 then s = 1.5
		spriteplace t,x,y,s,r
		refresh
	next t
	if spritecollide(0,1) then collissions++
next n

call n("0 and 1 should have collided (collissions>0)",collissions>0,1)

screenwith = md5(serialize(getslice(0,0,graphwidth, graphheight)))
call sne("Screen different with sprites",originalscreen$,screenwith)

for t = 0 to nsprites-1
	spritehide t
next t
refresh
# calculate the md5 hash of the screen
call s("Screen original after sprites",originalscreen$,md5(serialize(getslice(0,0,graphwidth, graphheight))))

spriteshow 2
spriteshow 3
spriteshow 4
refresh
screenwiththree = md5(serialize(getslice(0,0,graphwidth, graphheight)))
call sne("Screen with three is different from original",originalscreen$,screenwiththree)
call sne("Screen with three is different from all sprites",originalscreen$,screenwiththree)

t = 0
for n = 0 to nsprites-1
	if spritev(n) then
		t = t + n
	endif
next n
call n("only three sprites are visible",t,9)

# move them and move them back
for t = 1 to 20
	spritemove 2,1,0
	spritemove 3,0,2
	spritemove 4,3,3
	refresh
next t
call sne("sprites move them", screenwiththree, md5(serialize(getslice(0,0,graphwidth, graphheight))))

for t = 0 to nsprites-1
	spritehide t
next t
refresh
# calculate the md5 hash of the screen
call s("Screen original after sprites",originalscreen$,md5(serialize(getslice(0,0,graphwidth, graphheight))))