Implementing Chess PyGame into Visual Novel...

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
marigoldsofthenight
Regular
Posts: 44
Joined: Sat Aug 14, 2010 5:31 pm
Contact:

Implementing Chess PyGame into Visual Novel...

#1 Post by marigoldsofthenight » Sat Aug 14, 2010 5:37 pm

I've been using RenPy for about a month and a half or so, and I've been trying to learn more about implementing pygame into my novel...and to be honest, I'm totally lost.

I've been wanting to include a simple scene where the player is challenged by a character to a game of chess. The match is played, and there is a scene for if the player wins, loses, or if there is a draw.

Specifically, I've found the following pygame code to use:

http://www.pygame.org/project-ChessBoard-282-.html

I haven't the first clue as to how to use the code in my novel, and even after reading the documentation and using the Renpygame Framework, I'm still completely lost.

Anyone out there willing to help a coding newbie? :P

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Implementing Chess PyGame into Visual Novel...

#2 Post by Showsni » Sat Aug 14, 2010 6:50 pm

Well, I did what I thought should work but I'm getting errors, so presumably I'm doing something wrong. I can get it to do a section of Visual Novel in Ren'Py, then play a game of chess just fine; but if it tries to return to Ren'Py or you close the window I get hit with this traceback:

Code: Select all

I'm sorry, but an exception occured while executing your Ren'Py
script.

AttributeError: 'pygame.Surface' object has no attribute 'surface'

While running game code:
 - script at line 18 of C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\Chess/game/script.rpy
 - python at line 18 of C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\Chess/game/script.rpy.

-- Full Traceback ------------------------------------------------------------

  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\bootstrap.py", line 260, in bootstrap
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\main.py", line 308, in main
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\main.py", line 92, in run
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\execution.py", line 230, in run
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\ast.py", line 558, in execute
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\python.py", line 921, in py_exec_bytecode
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\Chess/game/script.rpy", line 18, in <module>
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\exports.py", line 592, in pause
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\ui.py", line 69, in interact
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\display\core.py", line 1364, in interact
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\display\core.py", line 1663, in interact_core
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\display\core.py", line 992, in show
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\display\render.py", line 739, in draw_screen
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\display\render.py", line 613, in draw
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\display\render.py", line 613, in draw
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\display\render.py", line 613, in draw
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\display\render.py", line 613, in draw
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\display\render.py", line 613, in draw
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\display\render.py", line 613, in draw
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\display\render.py", line 497, in draw
  File "C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\renpy\display\scale.py", line 362, in blit
AttributeError: 'pygame.Surface' object has no attribute 'surface'

While running game code:
 - script at line 18 of C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\Chess/game/script.rpy
 - python at line 18 of C:\Documents and Settings\Owner\My Documents\Flash\renpy-6.9.3\Chess/game/script.rpy.

Ren'Py Version: Ren'Py 6.9.3c
Line 18 is the first line of Ren'Py script after the game has finished running, it doesn't seem to matter what it is, it always gives this traceback. I'm guessing I need to adjust something in the pygame thing but I don't know what; there's nothing I can see that even uses surface as an attribute (unless it's hidden in Ren'Py somewhere).

marigoldsofthenight
Regular
Posts: 44
Joined: Sat Aug 14, 2010 5:31 pm
Contact:

Re: Implementing Chess PyGame into Visual Novel...

#3 Post by marigoldsofthenight » Sat Aug 14, 2010 10:49 pm

Ah...so I'm not the only one with a problem...perhaps it is simply that the pygame is not coded properly for renpy integration? Maybe I can hunt around for another chess simulator that will work.

User avatar
Mihara
Regular
Posts: 113
Joined: Thu Mar 11, 2010 2:52 pm
Location: Moscow, Russia
Contact:

Re: Implementing Chess PyGame into Visual Novel...

#4 Post by Mihara » Sat Aug 14, 2010 11:05 pm

If I were you, I'd try to implement the chessboard purely through RenPy means (they're quite sufficient and it's a considerably easier programming task, especially with screens) and then patch in an XBoard-compatible chess engine (you could include binaries for all supported OSes easily) -- these have the advantage of only communicating in text -- you start a process using simple Python means and get a file-like object you write text to and get responses from. It might turn out much less problematic to do, if only because you would only be doing well-documented things instead of trying to get someone else's code to work in an alien environment.

marigoldsofthenight
Regular
Posts: 44
Joined: Sat Aug 14, 2010 5:31 pm
Contact:

Re: Implementing Chess PyGame into Visual Novel...

#5 Post by marigoldsofthenight » Sun Aug 15, 2010 10:45 pm

*cue whoosh of it all going over my head*

So you would suggest coding the entire system myself? :\

Sounds like too big of a task for me to handle by myself, given the limited experience in coding that I have. I suppose I could just use some 'creative liberties' and do the entire sequence of the chess match through text and pictures.

User avatar
Mihara
Regular
Posts: 113
Joined: Thu Mar 11, 2010 2:52 pm
Location: Moscow, Russia
Contact:

Re: Implementing Chess PyGame into Visual Novel...

#6 Post by Mihara » Mon Aug 16, 2010 12:23 am

Hacking in alien code in this case would be harder, in my opinion, than just implementing a board with moving pieces and talking to a chess engine someone else wrote. You don't have to code chess thinking, you just need to code a board... hey, I did it in Amiga BASIC back in the day, can't be hard. :) It is, however, only my opinion and which is easier depends on what your particular skills are.

Stylistically, trying to add chess as a minigame into a visual novel feels rather silly unless you're making a chess tournament game with the visual novel as a story vehicle, where the best route would be learning how to stitch in a proper chess engine anyway. :) Switching gears from trying to a appreciate a (presumably romantic) story to trying to beat a (probably crude) chess machine is not going to go very well with most readers - or the most chess players, who will hardly find it a satisfying game.
If you decide to go with text and pictures, making a 3-5 decision branching tree that offers the reader to choose sensible (from a chess point of view) courses of action in key positions during the game will go much better. ("She started off with Sicilian Defence, and I decided to...", "and then I saw a magnificent queen sacrifice combination...", etc.) And you can still use pure RenPy to assemble the image of the board from piece sprites on the fly. :)

User avatar
vaanknight
Regular
Posts: 118
Joined: Sun Mar 28, 2010 6:01 pm
Completed: Happy Weird-Day! How a freckled fairy can save your world (Or get more freckles in the process...)"
Projects: Nameless 2D Fighting Game
Contact:

Re: Implementing Chess PyGame into Visual Novel...

#7 Post by vaanknight » Mon Aug 16, 2010 12:15 pm

^ Wow, that's a kickar$e idea... I might as well steal it for some future project >.> <.<
Image

User avatar
Soraminako
Veteran
Posts: 277
Joined: Sun Sep 04, 2011 1:36 am
Projects: A thingie without a title. With messy code.
Contact:

Re: Implementing Chess PyGame into Visual Novel...

#8 Post by Soraminako » Fri Sep 16, 2011 12:41 am

I found this thread as I was looking around to see if it was possible to implement chess into a VN.

From the sound of it all, it seems like it would be an easy thing to do for someone skilled at code, but completely impossible for a noob like me.

So my question is, is there a kind volunteer willing to write the code necessary for me to be able to have the player fight another character (AI controlled) in chess in the game? Something like the character's sprite will be on the screen, off to the side, and we'll see the board in a close up so that the player can move the pieces and yet still see the other character off to the side as if you're playing with them? ( Ideally, in a way that depending whether you win or lose, I can have it go to one label or the other and move on with the game that way. It may sound odd but it's actually relevant for my story. ^^;
And also ideally with the AI character able to say some preset phrases based on whether he gets your pieces or you get his pieces...)

It may sound stupid, but this is relevant for my VN's story... :oops:

If anyone is willing to write the code to make this chess thing possible in my VN, I'll happily draw free sprites for your game if you want. Or cover art or anything like that. (You can see an example of my art in my avatar. I can do cutesy style like this as well as anything else you want. Code is not my thing, commissioned artwork is.)

Anyone willing to help? Either for the free art or just out of the kindness of your heart/mercy towards code noobs like me? :cry:
(I drew my avatar especially to express the scary feeling I get from the code as I type it... XD)

DrathFox
Regular
Posts: 25
Joined: Tue Sep 06, 2011 12:59 am
Projects: DrathFox Project (fighter/adventure)
Location: Utah, US
Contact:

Re: Implementing Chess PyGame into Visual Novel...

#9 Post by DrathFox » Sat Sep 17, 2011 5:11 pm

I myself am all new to scripting languages / python stuffs. I'm experimenting around with renpy and pygame and would like to help but I'll only provide solutions when I actually find out the best way(s) to go about implementing it all together. I'm wondering if it would be best to just import pygame into renpy instead, it would make everything more fluid. Isn't pygame just a bunch of python files with definitions as well as renpy? so technically it's possible to write all the code in either pygame or renpy and you'd get the same results? I'm making my tests using the renpygame-demo to study the integration with it all.

I did some browsing on pygame's site and found this chess game and tested it out briefly, it looks promising.

http://pygame.org/project-Python+Chess-1099-.html

User avatar
Soraminako
Veteran
Posts: 277
Joined: Sun Sep 04, 2011 1:36 am
Projects: A thingie without a title. With messy code.
Contact:

Re: Implementing Chess PyGame into Visual Novel...

#10 Post by Soraminako » Sat Sep 17, 2011 10:04 pm

Yeah, I had seen that page as well. The problem is, I'm a total code noob, so I don't really even understand the difference between Pygame and Python as a whole, or the difference with ren'py itself. I mean, I understand that ren'py was designed specifically to make VNs, but I don't understand in what it's different from the other stuff or what works or doesn't work with one or the other. ^^;

All I know is that based on the previous messages in this thread, what I have in mind is possible to achieve. I just don't know how to do it myself. ^^;

But if you can get it to work, it would be utterly awesome! :D I would be so grateful!! It's really something I want to have in my game, so much.

(And I'll happily draw free art for you if you succeed and if you want me to! :D)
(I drew my avatar especially to express the scary feeling I get from the code as I type it... XD)

User avatar
luminarious
Veteran
Posts: 353
Joined: Thu May 01, 2008 1:12 pm
Projects: Winter, winter
Location: Estonia
Contact:

Re: Implementing Chess PyGame into Visual Novel...

#11 Post by luminarious » Sun Sep 18, 2011 3:19 am

Since most Visual Novel players can't be expected to be very good chess players, you could get away with a rather simplistic chess engine. This 1KB javascript came to mind immediately as something that could be easily converted to Python.

User avatar
Soraminako
Veteran
Posts: 277
Joined: Sun Sep 04, 2011 1:36 am
Projects: A thingie without a title. With messy code.
Contact:

Re: Implementing Chess PyGame into Visual Novel...

#12 Post by Soraminako » Sun Sep 18, 2011 4:03 pm

luminarious wrote:Since most Visual Novel players can't be expected to be very good chess players, you could get away with a rather simplistic chess engine. This 1KB javascript came to mind immediately as something that could be easily converted to Python.
I totally agree that it doesn't have to be very complicated at all. It's for fun rather than for very serious chess. In fact, if the matches can be somewhat fast (even at the cost of the AI losing sometimes/often XD), it would be totally fine. :D

That seems very promising, but I have no idea how it would be possible to convert it. ^^; I'm a total noob at Python.

Would you be able to do the conversion and make it look nice in Ren'py? :D
(I drew my avatar especially to express the scary feeling I get from the code as I type it... XD)

Post Reply

Who is online

Users browsing this forum: No registered users