Lists and Class instantiation
Monkey Forums/Monkey Programming/Lists and Class instantiation
| ||
Hey guys, Not sure what I'm doing wrong here but, basically, I'm trying to create a list of enemies which are instantiated class instances of my enemy class object. My imported class is as follows: Strict Import mojo.graphics Class Enemy Global enemyList := New List<Enemy> Field x:Float, y:Float, speed:Int, timer:Int, shield:Int, shootRate:Int, aim:Bool, img:Image Method New(x:Float, y:Float, speed:Float, timer:Int, shield:Int, shootRate:Int, aim:Bool, img:Image) Self.x = x Self.y = y Self.speed = speed Self.timer = timer Self.shield = shield Self.shootRate = shootRate Self.aim = aim Self.img = img End Method Update:Void(screenWidth:Float) For Local i := Eachin enemyList If i.x > 0 i.x -= i.speed Else i.x = screenWidth End End error line >> Method Create:Void(level:Int, screenWidth:Float, screenHeight:Float, img:Image) Local tmp:Enemy Select level Case 1 For Local i:Int = 0 To 10 tmp = New Enemy(screenWidth, Rnd(screenHeight), 1000, 300, 15, True, img) enemyList.AddLast tmp Next Case 2 End End Function Draw:Void() For Local i := Eachin enemyList DrawImage(i.img, i.x, i.y) Next End End And in my main source (cut down here for brevity): Class SpaceWhale Extends App Field blob:Image .. Method OnCreate:Int() blob = LoadImage("ship.png") Return(0) End Method OnUpdate:Int() .. If joyButton = BUTTON_A loadEnemies(level) End .. Enemy.Update(SCREEN_WIDTH) .. Return(0) End Method OnRender:Int() .. Enemy.Draw() .. Return(0) End Method loadEnemies:Void(level:Int) Select level Case 1 Enemy.Create(level, SCREEN_WIDTH, SCREEN_HEIGHT, blob) Case 2 ' Nothing yet End End I'm getting a syntax error: Unexpected Token 'method' on this line of the enemy class: Method Create:Void(level:Int, screenWidth:Float, screenHeight:Float, img:Image) Any ideas what I'm doing wrong? All I'm trying to do is to create a new enemy and add it to the enemylist. SCREEN_WIDTH and SCREEN_HEIGHT are global floats. |
| ||
Its missing the "End"(or "Next") for the For loop on the Update Method. |
| ||
Oh jeez thanks mate. I guess this is what happens when you're coding at 2:30am :-) |