Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / a really noob question: adding"badguys" to the tutorial game
- - By stevengrx20 Date 2011-11-23 14:18
hi, i always wanted, as a programmer, to make a game.... and i decided to learn ruby from scratch in a fun way... so i'm into gosu and ruby and it's pretty fun, but i have a question..

i got working the tutorial source code, it works just fine, but now i want to get this thing modified so i can add my own things to see what happens, so i decided to add "badguys"... it should work in the same way as the stars (i just copy the whole thing and added a static parameter to the ZOrder module), but with a different sprite and it should rest score in order to avoid them to get higher scores..

everything seems to work fine until i draw this badguys on the GameWindow's draw method.. i got this error:

GameWindow.rb:108:in draw': Expected argument 3 of type Gosu::ZPos, but got NilClass nil (TypeError)
  in SWIG method 'draw'
  from GameWindow.rb:108:in
draw'
  from GameWindow.rb:161:in block in draw'
  from GameWindow.rb:161:in
each'
  from GameWindow.rb:161:in draw'
  from GameWindow.rb:175:in
<main>'


dont know what i'm doing wrong, it's the same code as the stars.... the source code is attached..

thanks in advance..
Attachment: GameWindow (3k)
Parent - - By Spooner Date 2011-11-23 15:23 Edited 2011-11-23 15:29
The error is in how you set up ZOrder

module ZOrder
  Background, Stars, Player, UI, BadGuys = *0..3
end


Needs to be *0..4 to "fill" all the constants (you might want to use *0..100 just to make sure you never have to remember to increment the number when adding extra constants). *0..4 is equivalent to writing:

module ZOrder
  Background, Stars, Player, UI, BadGuys = 0, 1, 2, 3, 4
end


EDIT: Incidentally, you can use #draw_rot to simplify your drawing of the bad guys:
img.draw_rot(@x, @y, ZOrder::BadGuys, 0, 0.5, 0.5, 1, 1, @color, :add)
Parent - By stevengrx20 Date 2011-11-23 15:42
thanks!! now it's working...
Up Topic Gosu / Gosu Exchange / a really noob question: adding"badguys" to the tutorial game

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill