extends.bmx 973 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. Rem
  2. Extends is used in a BlitzMax Type declaration to derive the Type from a specified base class.
  3. End Rem
  4. Type TShape
  5. Field xpos,ypos
  6. Method Draw() Abstract
  7. End Type
  8. Type TCircle extends TShape
  9. Field radius
  10. Function Create:TCircle(x,y,r)
  11. local c:TCircle=new TCircle
  12. c.xpos=x;c.ypos=y;c.radius=r
  13. return c
  14. End Function
  15. Method Draw()
  16. DrawOval xpos,ypos,radius,radius
  17. End Method
  18. End Type
  19. Type TRect extends TShape
  20. Field width,height
  21. Function Create:TRect(x,y,w,h)
  22. local r:TRect=new TRect
  23. r.xpos=x;r.ypos=y;r.width=w;r.height=h
  24. return r
  25. End Function
  26. Method Draw()
  27. DrawRect xpos,ypos,width,height
  28. End Method
  29. End Type
  30. local shapelist:TShape[4]
  31. local shape:TShape
  32. shapelist[0]=TCircle.Create(200,50,50)
  33. shapelist[1]=TRect.Create(300,50,40,40)
  34. shapelist[2]=TCircle.Create(400,50,50)
  35. shapelist[3]=TRect.Create(200,180,250,20)
  36. graphics 640,480
  37. while not keyhit(KEY_ESCAPE)
  38. cls
  39. for shape=eachin shapelist
  40. shape.draw
  41. next
  42. flip
  43. wend
  44. end